diff mbox series

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

Message ID 20220714191455.2101834-10-roberto.sassu@huawei.com (mailing list archive)
State RFC
Delegated to: BPF
Headers show
Series bpf: Add bpf_verify_pkcs7_signature() kfunc | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-VM_Test-3 fail Logs for Kernel LATEST on z15 with gcc
bpf/vmtest-bpf-next-VM_Test-1 success Logs for Kernel LATEST on ubuntu-latest with gcc
bpf/vmtest-bpf-next-PR fail PR summary
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Kernel LATEST on ubuntu-latest with llvm-15
netdev/tree_selection success Guessed tree name to be net-next, async
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit fail Errors and warnings before: 29 this patch: 31
netdev/cc_maintainers warning 13 maintainers not CCed: haoluo@google.com delyank@fb.com netdev@vger.kernel.org edumazet@google.com memxor@gmail.com pabeni@redhat.com linux-kselftest@vger.kernel.org kuba@kernel.org davem@davemloft.net mykolal@fb.com jolsa@kernel.org sdf@google.com shuah@kernel.org
netdev/build_clang success Errors and warnings before: 6 this patch: 6
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn fail Errors and warnings before: 29 this patch: 31
netdev/checkpatch warning WARNING: externs should be avoided in .c files
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Roberto Sassu July 14, 2022, 7:14 p.m. UTC
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(+)
diff mbox series

Patch

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;