diff options
author | Martin KaFai Lau <kafai@fb.com> | 2021-03-24 18:52:52 -0700 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2021-03-26 20:41:52 -0700 |
commit | 7bd1590d4eba1583f6ee85e8cfe556505f761e19 (patch) | |
tree | 81b9cba9579d98af8e9bc27622a8e16e0905848f /tools/testing/selftests/bpf/progs/kfunc_call_test_subprog.c | |
parent | 78e60bbbe8e8f614b6a453d8a780d9e6f77749a8 (diff) | |
download | linux-7bd1590d4eba1583f6ee85e8cfe556505f761e19.tar.bz2 |
bpf: selftests: Add kfunc_call test
This patch adds a few kernel function bpf_kfunc_call_test*() for the
selftest's test_run purpose. They will be allowed for tc_cls prog.
The selftest calling the kernel function bpf_kfunc_call_test*()
is also added in this patch.
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20210325015252.1551395-1-kafai@fb.com
Diffstat (limited to 'tools/testing/selftests/bpf/progs/kfunc_call_test_subprog.c')
-rw-r--r-- | tools/testing/selftests/bpf/progs/kfunc_call_test_subprog.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/kfunc_call_test_subprog.c b/tools/testing/selftests/bpf/progs/kfunc_call_test_subprog.c new file mode 100644 index 000000000000..b2dcb7d9cb03 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/kfunc_call_test_subprog.c @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2021 Facebook */ +#include <linux/bpf.h> +#include <bpf/bpf_helpers.h> +#include "bpf_tcp_helpers.h" + +extern const int bpf_prog_active __ksym; +extern __u64 bpf_kfunc_call_test1(struct sock *sk, __u32 a, __u64 b, + __u32 c, __u64 d) __ksym; +extern struct sock *bpf_kfunc_call_test3(struct sock *sk) __ksym; +int active_res = -1; +int sk_state = -1; + +int __noinline f1(struct __sk_buff *skb) +{ + struct bpf_sock *sk = skb->sk; + int *active; + + if (!sk) + return -1; + + sk = bpf_sk_fullsock(sk); + if (!sk) + return -1; + + active = (int *)bpf_per_cpu_ptr(&bpf_prog_active, + bpf_get_smp_processor_id()); + if (active) + active_res = *active; + + sk_state = bpf_kfunc_call_test3((struct sock *)sk)->__sk_common.skc_state; + + return (__u32)bpf_kfunc_call_test1((struct sock *)sk, 1, 2, 3, 4); +} + +SEC("classifier") +int kfunc_call_test1(struct __sk_buff *skb) +{ + return f1(skb); +} + +char _license[] SEC("license") = "GPL"; |