]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
selftests/bpf: Fix a user_ringbuf failure with arm64 64KB page size
authorYonghong Song <yonghong.song@linux.dev>
Sat, 7 Jun 2025 01:36:26 +0000 (18:36 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Sat, 7 Jun 2025 02:21:43 +0000 (19:21 -0700)
The ringbuf max_entries must be PAGE_ALIGNED. See kernel function
ringbuf_map_alloc(). So for arm64 64KB page size, adjust max_entries
properly.

Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/r/20250607013626.1553001-1-yonghong.song@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/prog_tests/user_ringbuf.c

index d424e7ecbd12d0ef9dc186538eb60bfd2cbbced7..9fd3ae987321021b3ac7a111224e29554ee7cada 100644 (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;