diff mbox series

[v1,bpf-next,2/2] selftests/bpf: Add test exercising bpf_find_vma's BPF_F_VMA_NEXT flag

Message ID 20230801145414.418145-2-davemarchevsky@fb.com (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series [v1,bpf-next,1/2,RFC] bpf: Introduce BPF_F_VMA_NEXT flag for bpf_find_vma helper | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR fail PR summary
bpf/vmtest-bpf-next-VM_Test-8 success Logs for veristat
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-2 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-4 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-5 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-6 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-3 success Logs for build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-12 pending Logs for test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-16 pending Logs for test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-25 success Logs for test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-26 pending Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-28 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-29 success Logs for veristat
bpf/vmtest-bpf-next-VM_Test-7 success Logs for test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-10 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-11 success Logs for test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-13 success Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-14 success Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-15 success Logs for test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-17 success Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-18 success Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-19 success Logs for test_progs_no_alu32_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-20 success Logs for test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-21 success Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-22 success Logs for test_progs_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-23 success Logs for test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-24 success Logs for test_progs_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-27 success Logs for test_verifier on x86_64 with gcc
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for bpf-next, async
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 9 this patch: 9
netdev/cc_maintainers warning 11 maintainers not CCed: kpsingh@kernel.org martin.lau@linux.dev john.fastabend@gmail.com sdf@google.com song@kernel.org shuah@kernel.org yonghong.song@linux.dev mykolal@fb.com linux-kselftest@vger.kernel.org jolsa@kernel.org haoluo@google.com
netdev/build_clang success Errors and warnings before: 9 this patch: 9
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 9 this patch: 9
netdev/checkpatch warning WARNING: line length of 81 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Dave Marchevsky Aug. 1, 2023, 2:54 p.m. UTC
Nothing is mapped to the zero page, so current find_vma tests use addr 0
to test "failure to find vma containing addr". With the BPF_F_VMA_NEXT
flag, a bpf_find_vma call on an addr 0 will return some vma, so only
small adjustments to existing tests are necessary to validate.

Signed-off-by: Dave Marchevsky <davemarchevsky@fb.com>
---
 .../testing/selftests/bpf/prog_tests/find_vma.c | 17 +++++++++++++----
 tools/testing/selftests/bpf/progs/find_vma.c    |  5 +++--
 2 files changed, 16 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/prog_tests/find_vma.c b/tools/testing/selftests/bpf/prog_tests/find_vma.c
index 5165b38f0e59..dccf1ccd7468 100644
--- a/tools/testing/selftests/bpf/prog_tests/find_vma.c
+++ b/tools/testing/selftests/bpf/prog_tests/find_vma.c
@@ -19,6 +19,7 @@  static void test_and_reset_skel(struct find_vma *skel, int expected_find_zero_re
 	skel->bss->found_vm_exec = 0;
 	skel->data->find_addr_ret = -1;
 	skel->data->find_zero_ret = -1;
+	skel->bss->find_zero_flags = 0;
 	skel->bss->d_iname[0] = 0;
 }
 
@@ -77,16 +78,23 @@  static void test_find_vma_pe(struct find_vma *skel)
 	close(pfd);
 }
 
-static void test_find_vma_kprobe(struct find_vma *skel)
+static void test_find_vma_kprobe(struct find_vma *skel, bool vma_next)
 {
-	int err;
+	int err, expected_find_zero_ret;
 
 	err = find_vma__attach(skel);
 	if (!ASSERT_OK(err, "get_branch_snapshot__attach"))
 		return;
 
+	if (vma_next) {
+		skel->bss->find_zero_flags = BPF_F_VMA_NEXT;
+		expected_find_zero_ret = 0;
+	} else {
+		expected_find_zero_ret = -ENOENT; /* no vma contains ptr 0 */
+	}
+
 	getpgid(skel->bss->target_pid);
-	test_and_reset_skel(skel, -ENOENT /* could not find vma for ptr 0 */, true);
+	test_and_reset_skel(skel, expected_find_zero_ret, true);
 }
 
 static void test_illegal_write_vma(void)
@@ -119,7 +127,8 @@  void serial_test_find_vma(void)
 	skel->bss->addr = (__u64)(uintptr_t)test_find_vma_pe;
 
 	test_find_vma_pe(skel);
-	test_find_vma_kprobe(skel);
+	test_find_vma_kprobe(skel, false);
+	test_find_vma_kprobe(skel, true);
 
 	find_vma__destroy(skel);
 	test_illegal_write_vma();
diff --git a/tools/testing/selftests/bpf/progs/find_vma.c b/tools/testing/selftests/bpf/progs/find_vma.c
index 38034fb82530..73ade81722fa 100644
--- a/tools/testing/selftests/bpf/progs/find_vma.c
+++ b/tools/testing/selftests/bpf/progs/find_vma.c
@@ -17,6 +17,7 @@  pid_t target_pid = 0;
 char d_iname[DNAME_INLINE_LEN] = {0};
 __u32 found_vm_exec = 0;
 __u64 addr = 0;
+__u64 find_zero_flags = 0;
 int find_zero_ret = -1;
 int find_addr_ret = -1;
 
@@ -46,7 +47,7 @@  int handle_getpid(void)
 	find_addr_ret = bpf_find_vma(task, addr, check_vma, &data, 0);
 
 	/* this should return -ENOENT */
-	find_zero_ret = bpf_find_vma(task, 0, check_vma, &data, 0);
+	find_zero_ret = bpf_find_vma(task, 0, check_vma, &data, find_zero_flags);
 	return 0;
 }
 
@@ -64,6 +65,6 @@  int handle_pe(void)
 	/* In NMI, this should return -EBUSY, as the previous call is using
 	 * the irq_work.
 	 */
-	find_zero_ret = bpf_find_vma(task, 0, check_vma, &data, 0);
+	find_zero_ret = bpf_find_vma(task, 0, check_vma, &data, find_zero_flags);
 	return 0;
 }