| 68f4e480 | 09-Jun-2026 |
Emil Tsalapatis <emil@etsalapatis.com> |
selftests/bpf: Avoid spurious spmc parallel selftest errors in libarena
The libarena parallel spmc selftest is nondeterministic by design. As a result it depends up to a point on the relative timing
selftests/bpf: Avoid spurious spmc parallel selftest errors in libarena
The libarena parallel spmc selftest is nondeterministic by design. As a result it depends up to a point on the relative timing between the producer and consumer threads. This introduces the possibility for two kinds of spurious failures that this patch addresses.
1) Spurious timeouts. The test proceeds in phases, and threads use a common counter as a barrier to avoid proceeding to the next phase until all threads are ready to do so. If a thread takes too long to reach the barrier, the already waiting threads may time out.
Increase the current timeout. The timeout's value is a balance between the maximum amount of time spent on the test and the possibility of spurious failures. Right now the timeout is too short. Err on the side of caution and significantly increase it to avoid spurious failures.
2) Spurious resize failures. Some selftests require the spmc queue to resize itself. This in turn requires for the producer side to be materially faster than the consumer side so that the queue gets full enough for a resize. However, in the benchmark the spmc queue's producer is outnumbered 3:1. To offset it we add busy waits for consume queues. However, we still see occasional failures due to the queue never resizing.
Minimize the possibility for this in two ways: First, remove one of the consumers. The 2 consumers still exercise the "race between consumers" scenario. Second, increase the busy wait duration to decrease the rate by which the consumers act on the queue.
While at it, also replace a stray invalid error value "153" with EINVAL.
Fixes: 42998f819256 ("selftests/bpf: libarena: parallel test harness and spmc parallel selftest") Reported-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Emil Tsalapatis <emil@etsalapatis.com> Link: https://lore.kernel.org/r/20260609063630.10245-1-emil@etsalapatis.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
show more ...
|
| 42998f81 | 06-Jun-2026 |
Emil Tsalapatis <emil@etsalapatis.com> |
selftests/bpf: libarena: parallel test harness and spmc parallel selftest
Add a parallel test for the SPMC Lev-Chase workstealing queue. The queue is built to be wait-free even when there are multip
selftests/bpf: libarena: parallel test harness and spmc parallel selftest
Add a parallel test for the SPMC Lev-Chase workstealing queue. The queue is built to be wait-free even when there are multiple consumers, and the parallel selftest provides a signal on whether the queue behaves correctly when stress tested.
To support the test, this patch includes a test harness for parallel selftests. The spmc selftest acts as an example of the naming and other conventions expected by the harness.
Signed-off-by: Emil Tsalapatis <emil@etsalapatis.com> Link: https://lore.kernel.org/r/20260605222020.5231-4-emil@etsalapatis.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
show more ...
|
| 57c6ace8 | 06-Jun-2026 |
Emil Tsalapatis <emil@etsalapatis.com> |
selftests/bpf: libarena: Add spmc queue data structure
Expand libarena with a single producer multiple consumer deque data structure. This is a single producer, multiple consumer lockless structure
selftests/bpf: libarena: Add spmc queue data structure
Expand libarena with a single producer multiple consumer deque data structure. This is a single producer, multiple consumer lockless structure that permits efficient work stealing. The structure is a Lev-Chase queue, so it is lock-free and wait-free.
The data structure exposes three main calls. two of them are available to the thread owning the queue and one available to all threads in the program:
spmc_owner_push(): Push an item to the top of the queue. spmc_owner_pop(): Pop an item from the top of the queue. spmc_steal(): Steal a thread from the bottom of the queue from any thread.
Note that the queue is not really FIFO for all consumers, since non-owners of the queue can only work steal from the bottom.
Signed-off-by: Emil Tsalapatis <emil@etsalapatis.com> Link: https://lore.kernel.org/r/20260605222020.5231-3-emil@etsalapatis.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
show more ...
|
| 367e6e4a | 02-Jun-2026 |
Emil Tsalapatis <emil@etsalapatis.com> |
selftests/bpf: libarena: Directly return arena pointers from functions
Now that the __arena annotation includes a BTF type tag, and the verifier can identify arena pointers at BTF loading time, retu
selftests/bpf: libarena: Directly return arena pointers from functions
Now that the __arena annotation includes a BTF type tag, and the verifier can identify arena pointers at BTF loading time, return arena pointers as their true type instead of casting to u64. Remove the preprocessor typecast wrappers used to hide this from the caller.
Acked-by: Eduard Zingerman <eddyz87@gmail.com> Signed-off-by: Emil Tsalapatis <emil@etsalapatis.com> Link: https://lore.kernel.org/r/20260602004120.17087-6-emil@etsalapatis.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
show more ...
|
| b9b23fe1 | 02-Jun-2026 |
Emil Tsalapatis <emil@etsalapatis.com> |
selftests/bpf: Remove __arg_arena from the codebase
Now that BPF __arg_arena has been subsumed by __arena, remove __arg_arena from the codebase. This way the user has one fewer annotation to worry a
selftests/bpf: Remove __arg_arena from the codebase
Now that BPF __arg_arena has been subsumed by __arena, remove __arg_arena from the codebase. This way the user has one fewer annotation to worry about.
To remove __arg_arena we remove the typedefs we were previously using to minimize __arena annotations. This is because __arena now also includes a BTF type tag, which is ignored for non-pointer types. As a result, we cannot capture the whole __arena annotation inside a typedef and need to directly annotate the pointer type when declaring the variable.
The extra verbosity is worth it because the use of the __arena tag is intuitive to the programmer and removes the __arg_arena tag that has been a consistent source of confusion for users. The typedefs can be reintroduced later (without __arg_arena) once compilers start supporting BTF type tags for non-pointer types.
Acked-by: Eduard Zingerman <eddyz87@gmail.com> Signed-off-by: Emil Tsalapatis <emil@etsalapatis.com> Link: https://lore.kernel.org/r/20260602004120.17087-5-emil@etsalapatis.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
show more ...
|
| 9f5b3ffc | 28-Apr-2026 |
Emil Tsalapatis <emil@etsalapatis.com> |
selftests/bpf: Rename libarena malloc/free methods
The s390 architecture uses the token "free" for an enum, conflicting with the malloc/free definitions. Rename the calls to arena_malloc and arena_f
selftests/bpf: Rename libarena malloc/free methods
The s390 architecture uses the token "free" for an enum, conflicting with the malloc/free definitions. Rename the calls to arena_malloc and arena_free instead to prevent collisions.
Reported-by: Ihor Solodrai <ihor.solodrai@linux.dev> Signed-off-by: Emil Tsalapatis <etsal@meta.com> Fixes: 86426a28c52d ("selftests/bpf: Add buddy allocator for libarena") Acked-by: Ihor Solodrai <ihor.solodrai@linux.dev> Link: https://lore.kernel.org/r/20260428134252.2783519-1-etsal@meta.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
show more ...
|
| 554e4eb9 | 26-Apr-2026 |
Emil Tsalapatis <emil@etsalapatis.com> |
selftests/bpf: Reuse stderr parsing for libarena ASAN tests
Add code to directly test the output of libarena ASAN tests. The code reuses testing infrastructure originally for BPF streams to verify t
selftests/bpf: Reuse stderr parsing for libarena ASAN tests
Add code to directly test the output of libarena ASAN tests. The code reuses testing infrastructure originally for BPF streams to verify that ASAN emits call stacks when the selftests trigger a memory error.
Since stderr() testing uses logic from test_progs, it is only available on the test_progs-based selftest runner. The standalone runner still uses internal ASAN state to verify access errors are triaged as expected.
Signed-off-by: Emil Tsalapatis <emil@etsalapatis.com> Link: https://lore.kernel.org/r/20260426190338.4615-9-emil@etsalapatis.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
show more ...
|
| b1487dc1 | 26-Apr-2026 |
Emil Tsalapatis <emil@etsalapatis.com> |
selftests/bpf: Add selftests for libarena buddy allocator
Introduce selftests for the buddy allocator with and without ASAN. Add the libarena selftests both to the libarena test runner and to test_p
selftests/bpf: Add selftests for libarena buddy allocator
Introduce selftests for the buddy allocator with and without ASAN. Add the libarena selftests both to the libarena test runner and to test_progs, so that they are a) available when libarena is pulled as a standalone library, and b) exercised along with all other test programs in this directory.
ASAN for libarena requires LLVM 22. Add logic in the top-level selftests Makefile to only compile the ASAN variant if the compiler supports it, otherwise skip the test.
Signed-off-by: Emil Tsalapatis <emil@etsalapatis.com> Link: https://lore.kernel.org/r/20260426190338.4615-8-emil@etsalapatis.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
show more ...
|
| 86426a28 | 26-Apr-2026 |
Emil Tsalapatis <emil@etsalapatis.com> |
selftests/bpf: Add buddy allocator for libarena
Add a byte-oriented buddy allocator for libarena. The buddy allocator provides an alloc/free interface for small arena allocations ranging from 16 byt
selftests/bpf: Add buddy allocator for libarena
Add a byte-oriented buddy allocator for libarena. The buddy allocator provides an alloc/free interface for small arena allocations ranging from 16 bytes to 512 KiB. Lower allocations values are rounded up to 16 bytes. The buddy allocator does not handle larger allocations that can instead use the existing bpf_arena_{alloc, free}_pages() kfunc.
Signed-off-by: Emil Tsalapatis <emil@etsalapatis.com> Link: https://lore.kernel.org/r/20260426190338.4615-7-emil@etsalapatis.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
show more ...
|
| 9ab78691 | 26-Apr-2026 |
Emil Tsalapatis <emil@etsalapatis.com> |
selftests/bpf: Add arena ASAN runtime to libarena
Add an address sanitizer (ASAN) runtime to the arena library. The ASAN runtime implements the functions injected into BPF binaries by LLVM sanitizat
selftests/bpf: Add arena ASAN runtime to libarena
Add an address sanitizer (ASAN) runtime to the arena library. The ASAN runtime implements the functions injected into BPF binaries by LLVM sanitization when ASAN is enabled during compilation.
The runtime also includes functions called explicitly by memory allocation code to mark memory as poisoned/unpoisoned to ASAN. This code is a no-op when sanitization is turned off.
Signed-off-by: Emil Tsalapatis <emil@etsalapatis.com> Link: https://lore.kernel.org/r/20260426190338.4615-5-emil@etsalapatis.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
show more ...
|