@@ -551,6 +551,11 @@ struct sock * noinline bpf_kfunc_call_test3(struct sock *sk)
return sk;
}
+struct sock *noinline bpf_kfunc_call_test4(struct sock *sk__maybe_null)
+{
+ return sk__maybe_null;
+}
+
struct prog_test_member1 {
int a;
};
@@ -683,6 +688,10 @@ noinline void bpf_kfunc_call_test_mem_len_pass1(void *mem, int mem__sz)
{
}
+noinline void bpf_kfunc_call_test_mem_len_pass2(u64 *mem__maybe_null)
+{
+}
+
noinline void bpf_kfunc_call_test_mem_len_fail1(void *mem, int len)
{
}
@@ -699,6 +708,7 @@ BTF_SET_START(test_sk_check_kfunc_ids)
BTF_ID(func, bpf_kfunc_call_test1)
BTF_ID(func, bpf_kfunc_call_test2)
BTF_ID(func, bpf_kfunc_call_test3)
+BTF_ID(func, bpf_kfunc_call_test4)
BTF_ID(func, bpf_kfunc_call_test_acquire)
BTF_ID(func, bpf_kfunc_call_memb_acquire)
BTF_ID(func, bpf_kfunc_call_test_release)
@@ -712,6 +722,7 @@ BTF_ID(func, bpf_kfunc_call_test_fail1)
BTF_ID(func, bpf_kfunc_call_test_fail2)
BTF_ID(func, bpf_kfunc_call_test_fail3)
BTF_ID(func, bpf_kfunc_call_test_mem_len_pass1)
+BTF_ID(func, bpf_kfunc_call_test_mem_len_pass2)
BTF_ID(func, bpf_kfunc_call_test_mem_len_fail1)
BTF_ID(func, bpf_kfunc_call_test_mem_len_fail2)
BTF_SET_END(test_sk_check_kfunc_ids)
@@ -30,6 +30,10 @@ static void test_main(void)
ASSERT_OK(err, "bpf_prog_test_run(test2)");
ASSERT_EQ(topts.retval, 3, "test2-retval");
+ prog_fd = skel->progs.kfunc_call_test4.prog_fd;
+ err = bpf_prog_test_run_opts(prog_fd, &topts);
+ ASSERT_OK(err, "bpf_prog_test_run(test4)");
+
prog_fd = skel->progs.kfunc_call_test_ref_btf_id.prog_fd;
err = bpf_prog_test_run_opts(prog_fd, &topts);
ASSERT_OK(err, "bpf_prog_test_run(test_ref_btf_id)");
@@ -6,6 +6,7 @@
extern int bpf_kfunc_call_test2(struct sock *sk, __u32 a, __u32 b) __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_test4(struct sock *sk__maybe_null) __ksym;
extern struct prog_test_ref_kfunc *bpf_kfunc_call_test_acquire(unsigned long *sp) __ksym;
extern void bpf_kfunc_call_test_release(struct prog_test_ref_kfunc *p) __ksym;
@@ -13,8 +14,23 @@ extern void bpf_kfunc_call_test_pass_ctx(struct __sk_buff *skb) __ksym;
extern void bpf_kfunc_call_test_pass1(struct prog_test_pass1 *p) __ksym;
extern void bpf_kfunc_call_test_pass2(struct prog_test_pass2 *p) __ksym;
extern void bpf_kfunc_call_test_mem_len_pass1(void *mem, int len) __ksym;
+extern void bpf_kfunc_call_test_mem_len_pass2(u64 *mem__maybe_null) __ksym;
extern void bpf_kfunc_call_test_mem_len_fail2(__u64 *mem, int len) __ksym;
+SEC("tc")
+int kfunc_call_test4(struct __sk_buff *skb)
+{
+ struct bpf_sock *sk = skb->sk;
+
+ if (!sk)
+ return -1;
+
+ sk = bpf_sk_fullsock(sk);
+
+ bpf_kfunc_call_test4((struct sock *)sk);
+ return 0;
+}
+
SEC("tc")
int kfunc_call_test2(struct __sk_buff *skb)
{
@@ -87,6 +103,7 @@ int kfunc_call_test_pass(struct __sk_buff *skb)
bpf_kfunc_call_test_mem_len_pass1(&c, sizeof(c));
bpf_kfunc_call_test_mem_len_pass1(&d, sizeof(d));
bpf_kfunc_call_test_mem_len_pass1(&e, sizeof(e));
+ bpf_kfunc_call_test_mem_len_pass2(NULL);
bpf_kfunc_call_test_mem_len_fail2(&b, -1);
return 0;
Extend the test in kfunc_call_test.c to call the newly defined functions bpf_kfunc_call_test4() and bpf_kfunc_call_test_mem_len_pass2(), which have a parameter with the __maybe_null suffix. Ensure that the eBPF program is executed successfully. Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> --- net/bpf/test_run.c | 11 +++++++++++ .../selftests/bpf/prog_tests/kfunc_call.c | 4 ++++ .../selftests/bpf/progs/kfunc_call_test.c | 17 +++++++++++++++++ 3 files changed, 32 insertions(+)