Merge branch 'selftests-bpf-fix-a-few-test-failures-with-arm64-64kb-page'

Yonghong Song says:

====================
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/20250606213048.340421-1-yonghong.song@linux.dev/
    - 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/20250606174139.3036576-1-yonghong.song@linux.dev/
    - Fix veristat failure with bpf object file test_ringbuf_write.bpf.o.
  v1 -> v2:
    - v1: https://lore.kernel.org/bpf/20250606032309.444401-1-yonghong.song@linux.dev/
    - Fix a problem with selftest release build, basically from
      BUILD_BUG_ON to ASSERT_LT.
====================

Link: https://patch.msgid.link/20250607013605.1550284-1-yonghong.song@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
Alexei Starovoitov 2025-06-06 19:21:43 -07:00
commit d365993c2d
5 changed files with 24 additions and 14 deletions

View File

@ -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);

View File

@ -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();

View File

@ -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;

View File

@ -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);

View File

@ -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);