Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: Add fexit-to-skb test for global funcs

Add simple fexit prog type to skb prog type test when subprogram is a global
function.

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Song Liu <songliubraving@fb.com>
Link: https://lore.kernel.org/bpf/20200110064124.1760511-4-ast@kernel.org

authored by

Alexei Starovoitov and committed by
Daniel Borkmann
7608e4db 51c39bb1

+44
+1
tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c
··· 98 98 "fexit/test_pkt_access", 99 99 "fexit/test_pkt_access_subprog1", 100 100 "fexit/test_pkt_access_subprog2", 101 + "fexit/test_pkt_access_subprog3", 101 102 }; 102 103 test_fexit_bpf2bpf_common("./fexit_bpf2bpf.o", 103 104 "./test_pkt_access.o",
+15
tools/testing/selftests/bpf/progs/fexit_bpf2bpf.c
··· 79 79 test_result_subprog2 = 1; 80 80 return 0; 81 81 } 82 + 83 + __u64 test_result_subprog3 = 0; 84 + BPF_TRACE_3("fexit/test_pkt_access_subprog3", test_subprog3, 85 + int, val, struct sk_buff *, skb, int, ret) 86 + { 87 + int len; 88 + 89 + __builtin_preserve_access_index(({ 90 + len = skb->len; 91 + })); 92 + if (len != 74 || ret != 74 * val || val != 3) 93 + return 0; 94 + test_result_subprog3 = 1; 95 + return 0; 96 + } 82 97 char _license[] SEC("license") = "GPL";
+28
tools/testing/selftests/bpf/progs/test_pkt_access.c
··· 47 47 return skb->len * val; 48 48 } 49 49 50 + #define MAX_STACK (512 - 2 * 32) 51 + 52 + __attribute__ ((noinline)) 53 + int get_skb_len(struct __sk_buff *skb) 54 + { 55 + volatile char buf[MAX_STACK] = {}; 56 + 57 + return skb->len; 58 + } 59 + 60 + int get_skb_ifindex(int, struct __sk_buff *skb, int); 61 + 62 + __attribute__ ((noinline)) 63 + int test_pkt_access_subprog3(int val, struct __sk_buff *skb) 64 + { 65 + return get_skb_len(skb) * get_skb_ifindex(val, skb, 1); 66 + } 67 + 68 + __attribute__ ((noinline)) 69 + int get_skb_ifindex(int val, struct __sk_buff *skb, int var) 70 + { 71 + volatile char buf[MAX_STACK] = {}; 72 + 73 + return skb->ifindex * val * var; 74 + } 75 + 50 76 SEC("classifier/test_pkt_access") 51 77 int test_pkt_access(struct __sk_buff *skb) 52 78 { ··· 107 81 if (test_pkt_access_subprog1(skb) != skb->len * 2) 108 82 return TC_ACT_SHOT; 109 83 if (test_pkt_access_subprog2(2, skb) != skb->len * 2) 84 + return TC_ACT_SHOT; 85 + if (test_pkt_access_subprog3(3, skb) != skb->len * 3 * skb->ifindex) 110 86 return TC_ACT_SHOT; 111 87 if (tcp) { 112 88 if (((void *)(tcp) + 20) > data_end || proto != 6)