[RFC][PATCH v8 09/12] selftests/bpf: Test kfuncs with __maybe_null suffix

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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(+)

diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c
index 2ca96acbc50a..22b4efe72ce9 100644
--- a/net/bpf/test_run.c
+++ b/net/bpf/test_run.c
@@ -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)
diff --git a/tools/testing/selftests/bpf/prog_tests/kfunc_call.c b/tools/testing/selftests/bpf/prog_tests/kfunc_call.c
index c00eb974eb85..4b90abb950b5 100644
--- a/tools/testing/selftests/bpf/prog_tests/kfunc_call.c
+++ b/tools/testing/selftests/bpf/prog_tests/kfunc_call.c
@@ -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)");
diff --git a/tools/testing/selftests/bpf/progs/kfunc_call_test.c b/tools/testing/selftests/bpf/progs/kfunc_call_test.c
index 5aecbb9fdc68..258fa89f23b2 100644
--- a/tools/testing/selftests/bpf/progs/kfunc_call_test.c
+++ b/tools/testing/selftests/bpf/progs/kfunc_call_test.c
@@ -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;
-- 
2.25.1




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux