Skip to content

Commit e9708ad

Browse files
etsalKernel Patches Daemon
authored andcommitted
selftests/bpf: explicitly account for globals in verifier_arena_large
The big_alloc1 test in verifier_arena_large assumes that the arena base and the first page allocated by bpf_arena_alloc_pages are identical. This is not the case, because the first page in the arena is populated by global arena data. The test still passes because the code makes the tacit assumption that the first page is on offset PAGE_SIZE instead of 0. Make this distinction explicit in the code, and adjust the page offsets requested during the test to count from the beginning of the arena instead of using the address of the first allocated page. Signed-off-by: Emil Tsalapatis <[email protected]> Reviewed-by: Eduard Zingerman <[email protected]>
1 parent b57110f commit e9708ad

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

tools/testing/selftests/bpf/progs/verifier_arena_large.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,25 @@ int big_alloc1(void *ctx)
2323
{
2424
#if defined(__BPF_FEATURE_ADDR_SPACE_CAST)
2525
volatile char __arena *page1, *page2, *no_page, *page3;
26-
void __arena *base;
26+
u64 base;
2727

28-
page1 = base = bpf_arena_alloc_pages(&arena, NULL, 1, NUMA_NO_NODE, 0);
28+
base = (u64)arena_base(&arena);
29+
30+
page1 = bpf_arena_alloc_pages(&arena, NULL, 1, NUMA_NO_NODE, 0);
2931
if (!page1)
3032
return 1;
33+
34+
/* Account for global arena data. */
35+
if ((u64)page1 != base + PAGE_SIZE)
36+
return 15;
37+
3138
*page1 = 1;
32-
page2 = bpf_arena_alloc_pages(&arena, base + ARENA_SIZE - PAGE_SIZE * 2,
39+
page2 = bpf_arena_alloc_pages(&arena, (void __arena *)(ARENA_SIZE - PAGE_SIZE),
3340
1, NUMA_NO_NODE, 0);
3441
if (!page2)
3542
return 2;
3643
*page2 = 2;
37-
no_page = bpf_arena_alloc_pages(&arena, base + ARENA_SIZE - PAGE_SIZE,
44+
no_page = bpf_arena_alloc_pages(&arena, (void __arena *)ARENA_SIZE,
3845
1, NUMA_NO_NODE, 0);
3946
if (no_page)
4047
return 3;

0 commit comments

Comments
 (0)