Misc rqspinlock updates
Subsystems (3)
Kumar Kartikeya Dwivedi
maintainercover Misc rqspinlock updates
A couple of changes for rqspinlock, the first disables propagation of AA and ABBA deadlocks to waiters succeeding the deadlocking waiter. A more verbose rationale is available in the commit log. The second commit expands the stress test to introduce a ABBCCA mode that will reliably exercise the timeout fallback.
Kumar Kartikeya Dwivedi (2):
rqspinlock: Disable queue destruction for deadlocks selftests/bpf: Add ABBCCA case for rqspinlock stress test
kernel/bpf/rqspinlock.c | 8 ++ .../selftests/bpf/prog_tests/res_spin_lock.c | 8 +- .../bpf/test_kmods/bpf_test_rqspinlock.c | 85 ++++++++++++++----- 3 files changed, 74 insertions(+), 27 deletions(-)
base-commit: 54c134f379ee2816f60130d44e0e386c261dff45
Signature · 1 line
2.51.0
Kumar Kartikeya Dwivedi
maintainerPATCH 1/2 rqspinlock: Disable queue destruction for deadlocks
Disable propagation and unwinding of the waiter queue in case the head waiter detects a deadlock condition, but keep it enabled in case of the timeout fallback.
Currently, when the head waiter experiences an AA deadlock, it will signal all its successors in the queue to exit with an error. This is not ideal for cases where the same lock is held in contexts which can cause errors in an unrestricted fashion (e.g., BPF programs, or kernel paths invoked through BPF programs), and core kernel logic which is written in a correct fashion and does not expect deadlocks.
The same reasoning can be extended to ABBA situations. Depending on the actual runtime schedule, one or both of the head waiters involved in an ABBA situation can detect and exit directly without terminating their waiter queue. If the ABBA situation manifests again, the waiters will keep exiting until progress can be made, or a timeout is triggered in case of more complicated locking dependencies.
We still preserve the queue destruction in case of timeouts, as either the locking dependencies are too complex to be captured by AA and ABBA heuristics, or the owner is perpetually stuck. As such, it would be unwise to continue to apply the timeout for each new head waiter without terminating the queue, since we may end up waiting for more than 250 ms in aggregate with all participants in the locking transaction.
The patch itself is fairly simple; we can simply signal our successor to become the next head waiter, and leave the queue without attempting to acquire the lock.
With this change, the behavior for waiters in case of deadlocks experienced by a predecessor changes. It is guaranteed that call sites will no longer receive errors if the predecessors encounter deadlocks and the successors do not participate in one. This should lower the failure rate for waiters that are not doing improper locking opreations, just because they were unlucky to queue behind a misbehaving waiter. However, timeouts are still a possibility, hence they must be accounted for, so users cannot rely upon errors not occuring at all.
--- kernel/bpf/rqspinlock.c | 8 ++++++++ 1 file changed, 8 insertions(+)
kernel/bpf/rqspinlock.c +8 -0
@@ -572,6 +572,14 @@ int __lockfunc resilient_queued_spin_lock_slowpath(rqspinlock_t *lock, u32 val) val =res_atomic_cond_read_acquire (&lock->val, !(VAL & _Q_LOCKED_PENDING_MASK) ||RES_CHECK_TIMEOUT (ts, ret, _Q_LOCKED_PENDING_MASK)); +/* Disable queue destruction when we detect deadlocks. */ +if (ret == -EDEADLK ) { +if (!next) + next =smp_cond_load_relaxed (&node->next, (VAL )); +arch_mcs_spin_unlock_contended (&next->locked); + goto err_release_node; + } + waitq_timeout:if (ret) {/*
Signature · 1 line
2.51.0
Kumar Kartikeya Dwivedi
maintainerPATCH 2/2 selftests/bpf: Add ABBCCA case for rqspinlock stress test
In reply to Kumar Kartikeya DwivediIntroduce a new mode for the rqspinlock stress test that exercises a deadlock that won't be detected by the AA and ABBA checks, such that we always reliably trigger the timeout fallback. We need 4 CPUs for this particular case, as CPU 0 is untouched, and three participant CPUs for triggering the ABBCCA case.
Refactor the lock acquisition paths in the module to better reflect the three modes and choose the right lock depending on the context.
Also drop ABBA case from running by default as part of test progs, since the stress test can consume a significant amount of time.
--- .../selftests/bpf/prog_tests/res_spin_lock.c | 8 +- .../bpf/test_kmods/bpf_test_rqspinlock.c | 85 ++++++++++++++----- 2 files changed, 66 insertions(+), 27 deletions(-)
tools/testing/selftests/bpf/prog_tests/res_spin_lock.c +4 -4
@@ -110,8 +110,8 @@ void serial_test_res_spin_lock_stress(void)ASSERT_OK (load_module ("bpf_test_rqspinlock.ko" , false),"load module AA" );sleep (5 );unload_module ("bpf_test_rqspinlock" , false); - -ASSERT_OK (load_module_params ("bpf_test_rqspinlock.ko" ,"test_ab=1" , false),"load module ABBA" ); -sleep (5 ); -unload_module ("bpf_test_rqspinlock" , false); +/* +* Insert bpf_test_rqspinlock.ko manually with test_mode=[1|2] to test +* other cases (ABBA, ABBCCA). +*/ }
tools/testing/selftests/bpf/test_kmods/bpf_test_rqspinlock.c +62 -23
140 lines not on this page · raw message
Signature · 1 line
2.51.0
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 11 lines · On Wed, 29 Oct 2025 18:18:26 +0000 you wrote:
A couple of changes for rqspinlock, the first disables propagation of AA and ABBA deadlocks to waiters succeeding the deadlocking waiter. A more verbose rationale is available in the commit log. The second commit expands the stress test to introduce a ABBCCA mode that will reliably exercise the timeout fallback.
Kumar Kartikeya Dwivedi (2):
rqspinlock: Disable queue destruction for deadlocks selftests/bpf: Add ABBCCA case for rqspinlock stress test[...]
Here is the summary with links:
- [bpf-next,v1,1/2] rqspinlock: Disable queue destruction for deadlocks
https://git.kernel.org/bpf/bpf-next/c/7bd6e5ce5be6 - [bpf-next,v1,2/2] selftests/bpf: Add ABBCCA case for rqspinlock stress test https://git.kernel.org/bpf/bpf-next/c/a8a0abf09754
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html