Commit 7608e4db authored by Alexei Starovoitov's avatar Alexei Starovoitov Committed by Daniel Borkmann

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: default avatarAlexei Starovoitov <ast@kernel.org>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarSong Liu <songliubraving@fb.com>
Link: https://lore.kernel.org/bpf/20200110064124.1760511-4-ast@kernel.org
parent 51c39bb1
...@@ -98,6 +98,7 @@ static void test_target_yes_callees(void) ...@@ -98,6 +98,7 @@ static void test_target_yes_callees(void)
"fexit/test_pkt_access", "fexit/test_pkt_access",
"fexit/test_pkt_access_subprog1", "fexit/test_pkt_access_subprog1",
"fexit/test_pkt_access_subprog2", "fexit/test_pkt_access_subprog2",
"fexit/test_pkt_access_subprog3",
}; };
test_fexit_bpf2bpf_common("./fexit_bpf2bpf.o", test_fexit_bpf2bpf_common("./fexit_bpf2bpf.o",
"./test_pkt_access.o", "./test_pkt_access.o",
......
...@@ -79,4 +79,19 @@ int test_subprog2(struct args_subprog2 *ctx) ...@@ -79,4 +79,19 @@ int test_subprog2(struct args_subprog2 *ctx)
test_result_subprog2 = 1; test_result_subprog2 = 1;
return 0; return 0;
} }
__u64 test_result_subprog3 = 0;
BPF_TRACE_3("fexit/test_pkt_access_subprog3", test_subprog3,
int, val, struct sk_buff *, skb, int, ret)
{
int len;
__builtin_preserve_access_index(({
len = skb->len;
}));
if (len != 74 || ret != 74 * val || val != 3)
return 0;
test_result_subprog3 = 1;
return 0;
}
char _license[] SEC("license") = "GPL"; char _license[] SEC("license") = "GPL";
...@@ -47,6 +47,32 @@ int test_pkt_access_subprog2(int val, volatile struct __sk_buff *skb) ...@@ -47,6 +47,32 @@ int test_pkt_access_subprog2(int val, volatile struct __sk_buff *skb)
return skb->len * val; return skb->len * val;
} }
#define MAX_STACK (512 - 2 * 32)
__attribute__ ((noinline))
int get_skb_len(struct __sk_buff *skb)
{
volatile char buf[MAX_STACK] = {};
return skb->len;
}
int get_skb_ifindex(int, struct __sk_buff *skb, int);
__attribute__ ((noinline))
int test_pkt_access_subprog3(int val, struct __sk_buff *skb)
{
return get_skb_len(skb) * get_skb_ifindex(val, skb, 1);
}
__attribute__ ((noinline))
int get_skb_ifindex(int val, struct __sk_buff *skb, int var)
{
volatile char buf[MAX_STACK] = {};
return skb->ifindex * val * var;
}
SEC("classifier/test_pkt_access") SEC("classifier/test_pkt_access")
int test_pkt_access(struct __sk_buff *skb) int test_pkt_access(struct __sk_buff *skb)
{ {
...@@ -82,6 +108,8 @@ int test_pkt_access(struct __sk_buff *skb) ...@@ -82,6 +108,8 @@ int test_pkt_access(struct __sk_buff *skb)
return TC_ACT_SHOT; return TC_ACT_SHOT;
if (test_pkt_access_subprog2(2, skb) != skb->len * 2) if (test_pkt_access_subprog2(2, skb) != skb->len * 2)
return TC_ACT_SHOT; return TC_ACT_SHOT;
if (test_pkt_access_subprog3(3, skb) != skb->len * 3 * skb->ifindex)
return TC_ACT_SHOT;
if (tcp) { if (tcp) {
if (((void *)(tcp) + 20) > data_end || proto != 6) if (((void *)(tcp) + 20) > data_end || proto != 6)
return TC_ACT_SHOT; return TC_ACT_SHOT;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment