| From 138151c5d0c378aa43b7d5f15741e3cb8ed89332 Mon Sep 17 00:00:00 2001 |
| From: Sasha Levin <sashal@kernel.org> |
| Date: Fri, 6 Jun 2025 18:36:26 -0700 |
| Subject: selftests/bpf: Fix a user_ringbuf failure with arm64 64KB page size |
| |
| From: Yonghong Song <yonghong.song@linux.dev> |
| |
| [ Upstream commit bbc7bd658ddc662083639b9e9a280b90225ecd9a ] |
| |
| 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> |
| Signed-off-by: Sasha Levin <sashal@kernel.org> |
| --- |
| tools/testing/selftests/bpf/prog_tests/user_ringbuf.c | 10 +++++++--- |
| 1 file changed, 7 insertions(+), 3 deletions(-) |
| |
| diff --git a/tools/testing/selftests/bpf/prog_tests/user_ringbuf.c b/tools/testing/selftests/bpf/prog_tests/user_ringbuf.c |
| index ca81d660eb96..5e88d37973c5 100644 |
| --- a/tools/testing/selftests/bpf/prog_tests/user_ringbuf.c |
| +++ b/tools/testing/selftests/bpf/prog_tests/user_ringbuf.c |
| @@ -23,8 +23,7 @@ |
| static size_t log_buf_sz = 1 << 20; /* 1 MB */ |
| static char obj_log_buf[1048576]; |
| 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) |
| { |
| @@ -426,7 +425,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; |
| @@ -739,6 +740,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; |
| -- |
| 2.39.5 |
| |