bpf: A verifier that joins states
Subsystems (8)
[email protected]
AI reviewRe: [PATCH bpf-next v4 46/46] selftests/bpf: Test progs without bpf_for(), zero, can_loop and such
In reply to Alexei StarovoitovTL;DR: - Test issue: plain_c arena tests are not serial, so parallel runs on KASAN VMs may bring back OOM kills - plain_c wakeup_source test may fail instead of skip where the kfuncs are missing…
Quoted 1 line
selftests/bpf: Test progs without
bpf_for(), zero,can_loopand such
TL;DR:
- Test issue: plain_c arena tests are not serial, so parallel runs on KASAN VMs may bring back OOM kills
- plain_c wakeup_source test may fail instead of skip where the kfuncs are missing (e.g. s390)
Quoted 5 lines
tools/testing/selftests/bpf/prog_tests/plain_c.c new file +0
-0
[ ... ]
Quoted 1 line
+#define RUN(name)
RUN_TESTS(plain_c_##name)
[ ... ]
tools/testing/selftests/bpf/prog_tests/plain_c.c line 123
Quoted 12 lines
tools/testing/selftests/bpf/prog_tests/plain_c.c new file +12
-0+void test_plain_c_arena_htab (void ) {RUN (arena_htab); } +void test_plain_c_arena_htab_asm (void ) {RUN (arena_htab_asm); } + +void test_plain_c_arena_list (void ) +{ +RUN (arena_list); +if (test__start_subtest ("run" )) +arena_list_add_del (); +} + +void test_plain_c_arena_race (void ) {RUN (arena_race); } +void test_plain_c_arena_strsearch (void ) {RUN (arena_strsearch); }
Should these arena tests be serial_test_plain_c_arena_htab(), serial_test_plain_c_arena_htab_asm(), serial_test_plain_c_arena_list() and serial_test_plain_c_arena_strsearch(), to match the tests they mirror?
As written they are test_*(), so test_progs runs them in the parallel phase. The same applies to test_plain_c_verifier_arena_large() below.
plain_c_arena_htab, plain_c_arena_htab_asm (it includes plain_c_arena_htab.c), plain_c_arena_list, plain_c_arena_strsearch and plain_c_verifier_arena_large all declare a BPF_MAP_TYPE_ARENA map. Each RUN() subtest opens and loads the object again, so each creates a new arena, and the "run" subtest of test_plain_c_arena_list() creates one more.
Every arena reserves a 4GB kernel VM area:
arena_map_alloc() kernel/bpf/arena.c:
kern_vm = get_vm_area(KERN_VM_SZ, VM_SPARSE | VM_USERMAP);and alloc_vmap_area() populates the KASAN shadow for the whole area right away:
mm/vmalloc.c:
ret = kasan_populate_vmalloc(addr, size, gfp_mask);On a generic KASAN build that is about 512MB of shadow per live arena.
Commit a14f9ba080c1 ("selftests/bpf: Run arena tests serially") renamed arena_list, arena_htab, arena_strsearch and the other arena_* tests to serial_test_*() for this reason. Its message says:
When several arena tests run in parallel their shadow adds up, exhausts the memory of a small CI VM and trips the OOM killer during map creation.
It left verifier_arena* parallel only because those share RUN() suites, which does not apply here, since each plain_c test is its own top-level function.
The parallel dispatcher in test_progs.c skips only tests that have run_serial_test:
if (!test->should_run || test->run_serial_test)
continue;So with test_progs -j on a KASAN VM, several workers can be inside plain_c_arena_* subtests at once, on top of the parallel verifier_arena* tests. Can this bring back the OOM kills that a14f9ba080c1 fixed?
[ ... ]
Quoted 1 line
+void
test_plain_c_test_wakeup_source(void){RUN(test_wakeup_source); }
[ ... ]
Quoted 1 line
+void
test_plain_c_verifier_arena_large(void){RUN(verifier_arena_large); }
[ ... ]
Quoted 5 lines
tools/testing/selftests/bpf/progs/plain_c_test_wakeup_source.c new file +0
-0
[ ... ]
tools/testing/selftests/bpf/progs/plain_c_test_wakeup_source.c line 27
Quoted 8 lines
tools/testing/selftests/bpf/progs/plain_c_test_wakeup_source.c new file +8
-0+struct bpf_ws_lock ; +struct bpf_ws_lock *bpf_wakeup_sources_read_lock (void ) __ksym; +void bpf_wakeup_sources_read_unlock(struct bpf_ws_lock *lock) __ksym; +void *bpf_wakeup_sources_get_head (void ) __ksym; + +SEC("syscall") +__success __retval(0) +int iterate_wakeupsources(void *ctx)
A subsystem pattern flags this as potentially concerning: a selftest that fails, rather than skips, when a feature or config option is missing.
bpf_wakeup_sources_read_lock(), bpf_wakeup_sources_read_unlock() and bpf_wakeup_sources_get_head() live in drivers/base/power/wakeup.c, which is built only with CONFIG_PM_SLEEP:
obj-$(CONFIG_PM_SLEEP) += main.o wakeup.o wakeup_stats.o
PM_SLEEP needs SUSPEND || HIBERNATE_CALLBACKS, and s390 has neither ARCH_SUSPEND_POSSIBLE nor ARCH_HIBERNATION_POSSIBLE. The kfunc externs are not __weak, so on such kernels libbpf fails the object load with "extern (func ksym) '...': not found in kernel or module BTFs".
The driver is just:
void test_plain_c_test_wakeup_source(void) { RUN(test_wakeup_source); }so run_subtest() in test_loader.c takes the
!ASSERT_OK(err, "unexpected_load_failure") path for this __success prog, and test_progs exits with EXIT_FAILURE.
The original driver, test_wakeup_source() in prog_tests/wakeup_source.c, handles this case:
id = btf__find_by_name_kind(btf, "bpf_wakeup_sources_get_head", BTF_KIND_FUNC);
...
if (id < 0) {
printf("%s:SKIP:bpf_wakeup_sources_get_head kfunc not found in BTF\n", __func__);
test__skip();
return;
}DENYLIST.s390x has no plain_c_test_wakeup_source entry either.
This is test-only code, and the prog itself matches the original. Could the plain C driver keep the same BTF probe and test__skip(), or could the test be denylisted where the kfuncs cannot exist?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/42335829855
[email protected]
AI reviewRe: [PATCH bpf-next v4 46/46] selftests/bpf: Test progs without bpf_for(), zero, can_loop and such
In reply to Alexei StarovoitovThank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] selftests/bpf: missing BTF kfunc skip check in test_plain_c_test_wakeup_source() - [Low]…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] selftests/bpf: missing BTF kfunc skip check in test_plain_c_test_wakeup_source()
- [Low] selftests/bpf: missing __skip_without_arena in plain_c arena_htab and arena_list
--
commit 803ffb91b4f8392f64289683ec7ad50605335c6c
Author: Alexei Starovoitov <[email protected]>
selftests/bpf: Test progs without bpf_for(), zero, can_loop and such
This commit adds plain-C versions of existing BPF selftest programs without verifier-oriented loop macros and workarounds, along with test runners in prog_tests/plain_c.c.
Quoted 6 lines
tools/testing/selftests/bpf/prog_tests/plain_c.c new file +0
-0@@ -0,0 +1,160 @@
[ ... ]
Quoted 17 lines
tools/testing/selftests/bpf/prog_tests/plain_c.c new file +17
-0+/* prog_tests/arena_list.c: add 1000 elems, delete them, compare the sums */ +static void arena_list_add_del (void ) +{ +LIBBPF_OPTS (bpf_test_run_opts, opts); +struct plain_c_arena_list *skel; +int cnt =1000 , sum = cnt * (cnt -1 ) /2 ; + + skel =plain_c_arena_list__open_and_load (); +if (!ASSERT_OK_PTR (skel,"open_and_load" )) +return ; + skel->bss->cnt = cnt; +ASSERT_OK (bpf_prog_test_run_opts (bpf_program__fd (skel->progs.arena_list_add), &opts), +"add" ); +if (skel->bss->skip) { +test__skip (); + goto out; + }
[ ... ]
Quoted 9 lines
tools/testing/selftests/bpf/prog_tests/plain_c.c new file +9
-0+void test_plain_c_arena_htab (void ) {RUN (arena_htab); } +void test_plain_c_arena_htab_asm (void ) {RUN (arena_htab_asm); } + +void test_plain_c_arena_list (void ) +{ +RUN (arena_list); +if (test__start_subtest ("run" )) +arena_list_add_del (); +}
[ ... ]
Quoted 1 line
+void
test_plain_c_test_wakeup_source(void){RUN(test_wakeup_source); }
[Severity: Medium]
Does test_plain_c_test_wakeup_source() fail when CONFIG_PM_SLEEP is not enabled in the kernel (for example on s390x, where ARCH_SUSPEND_POSSIBLE and ARCH_HIBERNATION_POSSIBLE are not supported)?
plain_c_test_wakeup_source.c declares bpf_wakeup_sources_read_lock(), bpf_wakeup_sources_read_unlock(), and bpf_wakeup_sources_get_head() as strong __ksym externs. Unlike test_wakeup_source() in prog_tests/wakeup_source.c, which checks vmlinux BTF for bpf_wakeup_sources_get_head and calls test__skip() when absent, test_plain_c_test_wakeup_source() unconditionally invokes RUN(test_wakeup_source), causing bpf_object__load() to fail with unresolved kfunc externs.
Quoted 6 lines
tools/testing/selftests/bpf/progs/plain_c_arena_htab.c new file +0
-0@@ -0,0 +1,222 @@
[ ... ]
Quoted 8 lines
tools/testing/selftests/bpf/progs/plain_c_arena_htab.c new file +8
-0+SEC("syscall") +__success __retval(0) +#if !defined(__clang__) && defined(BPF_ARENA_FORCE_ASM ) +__skip("GCC calls htab_init(): a global function gets an arena pointer as a scalar") +#endif +int arena_htab_llvm (void *ctx) +{ +#if defined(__BPF_FEATURE_ADDR_SPACE_CAST) || defined(BPF_ARENA_FORCE_ASM )
[ ... ]
tools/testing/selftests/bpf/progs/plain_c_arena_htab.c line 220
Quoted 5 lines
tools/testing/selftests/bpf/progs/plain_c_arena_htab.c new file +5
-0+#else + skip = true; +#endif +return 0 ; +}
[Severity: Low]
Should arena_htab_llvm() (when BPF_ARENA_FORCE_ASM is not defined) and arena_list_add() / arena_list_del() in plain_c_arena_list.c be annotated with __skip_without_arena, similar to plain_c_arena_strsearch.c and plain_c_verifier_arena_large.c?
Without __BPF_FEATURE_ADDR_SPACE_CAST (such as in test_progs-bpf_gcc or test_progs-no_alu32), these programs compile to skip = true; return 0;, and RUN(arena_htab) and RUN(arena_list) load the no-op stubs via test_loader without checking skel->bss->skip, reporting OK instead of SKIP. Also, arena_list_add_del() in prog_tests/plain_c.c calls test__skip() without printing a reason message.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=46
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 5 lines · On Sat, 7 Nov 2026 03:37:08 +0000 you wrote:
From: Alexei Starovoitov <[email protected]>
The verifier follows each path of a prog, and each branch can double the number of paths. The work grows with the paths, not with the prog:
insns processed today this series
Quoted 7 lines
rust-bpf scx_beerland/beerland_init_task 1000001 * 16430 rust-bpf scx_qmap/qmap_init_cids 131088 * 196 scx scx_eevdf/eevdf_dispatch 350041 15322 Cilium bpf_host/cil_to_netdev, Oct 2026 64658 7538* "BPF program is too large", "The sequence of 8193 jumps is too complex"
[...]
Here is the summary with links:
- [bpf-next,v4,01/46] bpf: Add may_goto to the loops that the verifier marks
https://git.kernel.org/bpf/bpf-next/c/8ed7285ee075 - [bpf-next,v4,02/46] bpf: Limit depth and time of recursive subprogs at run time https://git.kernel.org/bpf/bpf-next/c/7b7dc9c6e8e9 - [bpf-next,v4,03/46] bpf: Add union and widening of the range of a register https://git.kernel.org/bpf/bpf-next/c/ff3712ef1106 - [bpf-next,v4,04/46] bpf: Add join of registers and stack slots https://git.kernel.org/bpf/bpf-next/c/47388a4c175e - [bpf-next,v4,05/46] bpf: Add join of verifier states https://git.kernel.org/bpf/bpf-next/c/ff30ca620432 - [bpf-next,v4,06/46] bpf: Tell which arguments of a call a join must leave alone https://git.kernel.org/bpf/bpf-next/c/af6bda3802af - [bpf-next,v4,07/46] bpf: Add the data structures of the main pass over the control flow graph https://git.kernel.org/bpf/bpf-next/c/0c30e60b214c - [bpf-next,v4,08/46] bpf: Order the insns, find what stops a loop and where may_goto can go https://git.kernel.org/bpf/bpf-next/c/9075b1169d6b - [bpf-next,v4,09/46] bpf: Find the registers that hold a number or a pointer to arena https://git.kernel.org/bpf/bpf-next/c/0c5ce2587057 - [bpf-next,v4,10/46] bpf: Find the registers and stack slots that later checks depend on https://git.kernel.org/bpf/bpf-next/c/a8bfc00bacb4 - [bpf-next,v4,11/46] bpf: Add the sets of states at an insn and the entries of functions https://git.kernel.org/bpf/bpf-next/c/8468842a8950 - [bpf-next,v4,12/46] bpf: Compare states of different iterations of a loop https://git.kernel.org/bpf/bpf-next/c/6a3204708703 - [bpf-next,v4,13/46] bpf: Decide which states are not joined https://git.kernel.org/bpf/bpf-next/c/773b03804ab1 - [bpf-next,v4,14/46] bpf: Merge the state that arrives into the set at an insn https://git.kernel.org/bpf/bpf-next/c/9b56d2e47f3a - [bpf-next,v4,15/46] bpf: Move states along edges, into loops and subprogs and out of them https://git.kernel.org/bpf/bpf-next/c/19d27a501a52 - [bpf-next,v4,16/46] bpf: Make the state after a call from the caller's state and an exit state https://git.kernel.org/bpf/bpf-next/c/8875170bb1d2 - [bpf-next,v4,17/46] bpf: Enter and leave loops in the main pass, build flow.c https://git.kernel.org/bpf/bpf-next/c/a784eb58f12b - [bpf-next,v4,18/46] bpf: Tell the passes over the graph where an added may_goto goes https://git.kernel.org/bpf/bpf-next/c/51bfd6314dcc - [bpf-next,v4,19/46] bpf: Verify programs as a fixpoint over the control flow graph https://git.kernel.org/bpf/bpf-next/c/5395aa9bbeb5 - [bpf-next,v4,20/46] bpf: Keep the count of a loop when a register has no closed form https://git.kernel.org/bpf/bpf-next/c/9b202a8c7722 - [bpf-next,v4,21/46] bpf: Verify static subprogs on their own https://git.kernel.org/bpf/bpf-next/c/8fd58560b71e - [bpf-next,v4,22/46] bpf: Allow recursive subprogs https://git.kernel.org/bpf/bpf-next/c/eaea73907052 - [bpf-next,v4,23/46] bpf: Remove is_state_visited(), bpf_compute_scc() and iter.depth https://git.kernel.org/bpf/bpf-next/c/6771f70a4733 - [bpf-next,v4,24/46] bpf: Remove precision tracking https://git.kernel.org/bpf/bpf-next/c/9f644d937dcf - [bpf-next,v4,25/46] bpf: Remove prune points, levels of state comparison and pop_stack() https://git.kernel.org/bpf/bpf-next/c/8ecf70baad8b - [bpf-next,v4,26/46] bpf: Update comments about paths, pruning and explored states https://git.kernel.org/bpf/bpf-next/c/b7bf79dd6f1e - [bpf-next,v4,27/46] bpf: Track a pointer to one of a set of functions https://git.kernel.org/bpf/bpf-next/c/edcafaec6256 - [bpf-next,v4,28/46] bpf: callx reads what the subprogs whose address is taken read https://git.kernel.org/bpf/bpf-next/c/6d4131627eae - [bpf-next,v4,29/46] bpf: Keep the first iteration of a counted loop apart https://git.kernel.org/bpf/bpf-next/c/df9b13a441c9 - [bpf-next,v4,30/46] bpf: What a call returns in each iteration is like what the loop loads https://git.kernel.org/bpf/bpf-next/c/89557ca1fc86 - [bpf-next,v4,31/46] bpf: Find where the jumps of a loop stop a number https://git.kernel.org/bpf/bpf-next/c/e2b83f4db687 - [bpf-next,v4,32/46] bpf: A loop is one iteration shorter behind the jump that counts it https://git.kernel.org/bpf/bpf-next/c/a00c8eafb381 - [bpf-next,v4,33/46] bpf: Give the places of a back edge to the jumps that count https://git.kernel.org/bpf/bpf-next/c/95ff2abedf64 - [bpf-next,v4,34/46] bpf: Count a loop whose exit tests a copy of the counter https://git.kernel.org/bpf/bpf-next/c/ab5fa7281144 - [bpf-next,v4,35/46] bpf: Allow tail calls and LD_ABS in subprogs that return void https://git.kernel.org/bpf/bpf-next/c/1dcc217fefba - [bpf-next,v4,36/46] bpf: A part of a pointer that is spilled is a number https://git.kernel.org/bpf/bpf-next/c/50ea1f0797de - [bpf-next,v4,37/46] bpf: 32-bit add to a pointer and pointer op pointer make a number https://git.kernel.org/bpf/bpf-next/c/4a3a9c2d6896 - [bpf-next,v4,38/46] selftests/bpf: Adjust tests to log lines that are gone https://git.kernel.org/bpf/bpf-next/c/7e363442447f - [bpf-next,v4,39/46] selftests/bpf: Adjust tests to new verdicts, messages and order https://git.kernel.org/bpf/bpf-next/c/dd43eeaf99eb - [bpf-next,v4,40/46] selftests/bpf: Test states that are not joined https://git.kernel.org/bpf/bpf-next/c/8292b648ae99 - [bpf-next,v4,41/46] selftests/bpf: Test static subprogs that are verified on their own https://git.kernel.org/bpf/bpf-next/c/489b946f5f6a - [bpf-next,v4,42/46] selftests/bpf: Test loops that are counted, walked or widened https://git.kernel.org/bpf/bpf-next/c/d0a8c63bfc66 - [bpf-next,v4,43/46] selftests/bpf: Test progs that run out of budget https://git.kernel.org/bpf/bpf-next/c/bab5cb94006e - [bpf-next,v4,44/46] selftests/bpf: Test callx of one of a set of functions https://git.kernel.org/bpf/bpf-next/c/d14f973f1559 - [bpf-next,v4,45/46] selftests/bpf: Test pointers that become numbers and subprogs that return void https://git.kernel.org/bpf/bpf-next/c/d13baed274e6 - [bpf-next,v4,46/46] selftests/bpf: Test progs without bpf_for(), zero, can_loop and such https://git.kernel.org/bpf/bpf-next/c/b5ae07f77d27
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html