selftests/bpf: Add stress test for rqspinlock in NMI
authorKumar Kartikeya Dwivedi <memxor@gmail.com>
Sat, 27 Sep 2025 20:53:04 +0000 (20:53 +0000)
committerAlexei Starovoitov <ast@kernel.org>
Sun, 28 Sep 2025 10:18:40 +0000 (03:18 -0700)
commit15cf39221e89ad413c3cc2cb8f15a2487db2ba2f
treede1676e77cdc675f17058a367f6c2112436d9b72
parent0e8e60e86cf3292e747a0fa7cc13127f290323ad
selftests/bpf: Add stress test for rqspinlock in NMI

Introduce a kernel module that will exercise lock acquisition in the NMI
path, and bias toward creating contention such that NMI waiters end up
being non-head waiters. Prior to the rqspinlock fix made in the commit
0d80e7f951be ("rqspinlock: Choose trylock fallback for NMI waiters"), it
was possible for the queueing path of non-head waiters to get stuck in
NMI, which this stress test reproduces fairly easily with just 3 CPUs.

Both AA and ABBA flavors are supported, and it will serve as a test case
for future fixes that address this corner case. More information about
the problem in question is available in the commit cited above. When the
fix is reverted, this stress test will lock up the system.

To enable this test automatically through the test_progs infrastructure,
add a load_module_params API to exercise both AA and ABBA cases when
running the test.

Note that the test runs for at most 5 seconds, and becomes a noop after
that, in order to allow the system to make forward progress. In
addition, CPU 0 is always kept untouched by the created threads and
NMIs. The test will automatically scale to the number of available
online CPUs.

Note that at least 3 CPUs are necessary to run this test, hence skip the
selftest in case the environment has less than 3 CPUs available.

Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20250927205304.199760-1-memxor@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/Makefile
tools/testing/selftests/bpf/prog_tests/res_spin_lock.c
tools/testing/selftests/bpf/test_kmods/Makefile
tools/testing/selftests/bpf/test_kmods/bpf_test_rqspinlock.c [new file with mode: 0644]
tools/testing/selftests/bpf/testing_helpers.c
tools/testing/selftests/bpf/testing_helpers.h