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

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

 



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@xxxxxx>
---
 .../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 --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;
 }
-- 
2.34.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