Skip to contentSkip to conversation

selftests/bpf: Fix a few test failures with arm64 64KB page

PATCH Applied Yonghong Song 2 participants 6 messages Jun 7, 2025

Subsystems (4)
lore
Share & tools
lore

Yonghong Song

author reviewer
#0 lore raw

v4 cover selftests/bpf: Fix a few test failures with arm64 64KB page

My local arm64 host has 64KB page size and the VM to run test_progs also has 64KB page size. There are a few self tests assuming 4KB page and failed in my environment.

Patch 1 reduced long assert logs so if the test fails, developers can check logs easily. Patches 2-4 fixed three selftest failures.

Changelogs:
v3 -> v4:
- v3: https://lore.kernel.org/bpf/[email protected]/
- In v3, I tried to use __kconfig with CONFIG_ARM64_64K_PAGES to decide to have 4K or 64K aligned. But CI seems unhappy about this. Most likely the reason is due to lskel. So in v4, simply adjust/increase numbers to 64K aligned for test_ringbuf_write test.
v2 -> v3:
- v2: https://lore.kernel.org/bpf/[email protected]/
- Fix veristat failure with bpf object file test_ringbuf_write.bpf.o.
v1 -> v2:
- v1: https://lore.kernel.org/bpf/[email protected]/
- Fix a problem with selftest release build, basically from BUILD_BUG_ON to ASSERT_LT.

Yonghong Song (4):
selftests/bpf: Reduce test_xdp_adjust_frags_tail_grow logs selftests/bpf: Fix bpf_mod_race test failure with arm64 64KB page size selftests/bpf: Fix ringbuf/ringbuf_write test failure with arm64 64KB
page size
selftests/bpf: Fix a user_ringbuf failure with arm64 64KB page size

 .../selftests/bpf/prog_tests/bpf_mod_race.c    |  2 +-
 .../testing/selftests/bpf/prog_tests/ringbuf.c |  4 ++--
 .../selftests/bpf/prog_tests/user_ringbuf.c    | 10 +++++++---
 .../selftests/bpf/prog_tests/xdp_adjust_tail.c | 18 ++++++++++++------
 .../selftests/bpf/progs/test_ringbuf_write.c   |  4 ++--
 5 files changed, 24 insertions(+), 14 deletions(-)
Signature · 1 line
2.47.1
author reviewer
#1 lore raw

PATCH v4 1/4 selftests/bpf: Reduce test_xdp_adjust_frags_tail_grow logs

For selftest xdp_adjust_tail/xdp_adjust_frags_tail_grow, if tested failure, I see a long list of log output like

...
test_xdp_adjust_frags_tail_grow:PASS:9Kb+10b-untouched 0 nsec test_xdp_adjust_frags_tail_grow:PASS:9Kb+10b-untouched 0 nsec test_xdp_adjust_frags_tail_grow:PASS:9Kb+10b-untouched 0 nsec test_xdp_adjust_frags_tail_grow:PASS:9Kb+10b-untouched 0 nsec
...

There are total 7374 lines of the above which is too much. Let us only issue such logs when it is an assert failure.

---
 .../selftests/bpf/prog_tests/xdp_adjust_tail.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c +12 -6
index b2b2d85dbb1b..e361129402a1 100644
@@ -246,14 +246,20 @@ static void test_xdp_adjust_frags_tail_grow(void)
 	ASSERT_EQ(topts.retval, XDP_TX, "9Kb+10b retval");
 	ASSERT_EQ(topts.data_size_out, exp_size, "9Kb+10b size");
 
-	for (i = 0; i < 9000; i++)
-		ASSERT_EQ(buf[i], 1, "9Kb+10b-old");
+	for (i = 0; i < 9000; i++) {
+		if (buf[i] != 1)
+			ASSERT_EQ(buf[i], 1, "9Kb+10b-old");
+	}
 
-	for (i = 9000; i < 9010; i++)
-		ASSERT_EQ(buf[i], 0, "9Kb+10b-new");
+	for (i = 9000; i < 9010; i++) {
+		if (buf[i] != 0)
+			ASSERT_EQ(buf[i], 0, "9Kb+10b-new");
+	}
 
-	for (i = 9010; i < 16384; i++)
-		ASSERT_EQ(buf[i], 1, "9Kb+10b-untouched");
+	for (i = 9010; i < 16384; i++) {
+		if (buf[i] != 1)
+			ASSERT_EQ(buf[i], 1, "9Kb+10b-untouched");
+	}
 
 	/* Test a too large grow */
 	memset(buf, 1, 16384);
Signature · 1 line
2.47.1
author reviewer
#2 lore raw

PATCH v4 2/4 selftests/bpf: Fix bpf_mod_race test failure with arm64 64KB page size

In reply to Yonghong Song

Currently, uffd_register.range.len is set to 4096 for command 'ioctl(uffd, UFFDIO_REGISTER, &uffd_register)'. For arm64 64KB page size, the len must be 64KB size aligned as page size alignment is required. See fs/userfaultfd.c:validate_unaligned_range().

---
 tools/testing/selftests/bpf/prog_tests/bpf_mod_race.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/bpf_mod_race.c +1 -1
index fe2c502e5089..ecc3d47919ad 100644
@@ -78,7 +78,7 @@ static int test_setup_uffd(void *fault_addr)
 	}
 
 	uffd_register.range.start = (unsigned long)fault_addr;
-	uffd_register.range.len = 4096;
+	uffd_register.range.len = getpagesize();
 	uffd_register.mode = UFFDIO_REGISTER_MODE_MISSING;
 	if (ioctl(uffd, UFFDIO_REGISTER, &uffd_register)) {
 		close(uffd);
Signature · 1 line
2.47.1
author reviewer
#3 lore raw

PATCH v4 3/4 selftests/bpf: Fix ringbuf/ringbuf_write test failure with arm64 64KB page size

In reply to Yonghong Song

The ringbuf max_entries must be PAGE_ALIGNED. See kernel function ringbuf_map_alloc(). So for arm64 64KB page size, adjust max_entries and other related metrics properly.

---
 tools/testing/selftests/bpf/prog_tests/ringbuf.c       | 4 ++--
 tools/testing/selftests/bpf/progs/test_ringbuf_write.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
tools/testing/selftests/bpf/prog_tests/ringbuf.c +2 -2
index da430df45aa4..d1e4cb28a72c 100644
@@ -97,7 +97,7 @@ static void ringbuf_write_subtest(void)
 	if (!ASSERT_OK_PTR(skel, "skel_open"))
 		return;
 
-	skel->maps.ringbuf.max_entries = 0x4000;
+	skel->maps.ringbuf.max_entries = 0x40000;
 
 	err = test_ringbuf_write_lskel__load(skel);
 	if (!ASSERT_OK(err, "skel_load"))
@@ -108,7 +108,7 @@ static void ringbuf_write_subtest(void)
 	mmap_ptr = mmap(NULL, page_size, PROT_READ | PROT_WRITE, MAP_SHARED, rb_fd, 0);
 	if (!ASSERT_OK_PTR(mmap_ptr, "rw_cons_pos"))
 		goto cleanup;
-	*mmap_ptr = 0x3000;
+	*mmap_ptr = 0x30000;
 	ASSERT_OK(munmap(mmap_ptr, page_size), "unmap_rw");
 
 	skel->bss->pid = getpid();
tools/testing/selftests/bpf/progs/test_ringbuf_write.c +2 -2
index 350513c0e4c9..f063a0013f85 100644
@@ -26,11 +26,11 @@ int test_ringbuf_write(void *ctx)
 	if (cur_pid != pid)
 		return 0;
 
-	sample1 = bpf_ringbuf_reserve(&ringbuf, 0x3000, 0);
+	sample1 = bpf_ringbuf_reserve(&ringbuf, 0x30000, 0);
 	if (!sample1)
 		return 0;
 	/* first one can pass */
-	sample2 = bpf_ringbuf_reserve(&ringbuf, 0x3000, 0);
+	sample2 = bpf_ringbuf_reserve(&ringbuf, 0x30000, 0);
 	if (!sample2) {
 		bpf_ringbuf_discard(sample1, 0);
 		__sync_fetch_and_add(&discarded, 1);
Signature · 1 line
2.47.1
author reviewer
#4 lore raw

PATCH v4 4/4 selftests/bpf: Fix a user_ringbuf failure with arm64 64KB page size

In reply to Yonghong Song

The ringbuf max_entries must be PAGE_ALIGNED. See kernel function ringbuf_map_alloc(). So for arm64 64KB page size, adjust max_entries properly.

---
 tools/testing/selftests/bpf/prog_tests/user_ringbuf.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
tools/testing/selftests/bpf/prog_tests/user_ringbuf.c +7 -3
index d424e7ecbd12..9fd3ae987321 100644
@@ -21,8 +21,7 @@
 #include "../progs/test_user_ringbuf.h"
 
 static const long c_sample_size = sizeof(struct sample) + BPF_RINGBUF_HDR_SZ;
-static const long c_ringbuf_size = 1 << 12; /* 1 small page */
-static const long c_max_entries = c_ringbuf_size / c_sample_size;
+static long c_ringbuf_size, c_max_entries;
 
 static void drain_current_samples(void)
 {
@@ -424,7 +423,9 @@ static void test_user_ringbuf_loop(void)
 	uint32_t remaining_samples = total_samples;
 	int err;
 
-	BUILD_BUG_ON(total_samples <= c_max_entries);
+	if (!ASSERT_LT(c_max_entries, total_samples, "compare_c_max_entries"))
+		return;
+
 	err = load_skel_create_user_ringbuf(&skel, &ringbuf);
 	if (err)
 		return;
@@ -686,6 +687,9 @@ void test_user_ringbuf(void)
 {
 	int i;
 
+	c_ringbuf_size = getpagesize(); /* 1 page */
+	c_max_entries = c_ringbuf_size / c_sample_size;
+
 	for (i = 0; i < ARRAY_SIZE(success_tests); i++) {
 		if (!test__start_subtest(success_tests[i].test_name))
 			continue;
Signature · 1 line
2.47.1
#5 lore raw
In reply to Yonghong Song
This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Hello:

This series was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Quoted 8 lines · On Fri, 6 Jun 2025 18:36:05 -0700 you wrote:

My local arm64 host has 64KB page size and the VM to run test_progs also has 64KB page size. There are a few self tests assuming 4KB page and failed in my environment.

Patch 1 reduced long assert logs so if the test fails, developers can check logs easily. Patches 2-4 fixed three selftest failures.

[...]

Here is the summary with links:
- [bpf-next,v4,1/4] selftests/bpf: Reduce test_xdp_adjust_frags_tail_grow logs

    https://git.kernel.org/bpf/bpf-next/c/ae8824037a0a
  - [bpf-next,v4,2/4] selftests/bpf: Fix bpf_mod_race test failure with arm64 64KB page size
    https://git.kernel.org/bpf/bpf-next/c/377d3715900c
  - [bpf-next,v4,3/4] selftests/bpf: Fix ringbuf/ringbuf_write test failure with arm64 64KB page size
    https://git.kernel.org/bpf/bpf-next/c/8c8c5e3c854a
  - [bpf-next,v4,4/4] selftests/bpf: Fix a user_ringbuf failure with arm64 64KB page size
    https://git.kernel.org/bpf/bpf-next/c/bbc7bd658ddc

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html