[PATCH v2 4/4] test-ww_mutex: Retry lock acquisition after timeout if deadlocked
From: Håkon Bugge
Date: Mon Jul 13 2026 - 12:38:42 EST
stress_inorder_work() terminates when its timeout expires. If the
final lock acquisition attempt returns -EDEADLK at that point, the
test may report a false failure.
With a high number of threads and few locks, there is a very high
probability that a thread will be subject to lock contention. That
implies, when the loop times out, we will most probably have been
exposed to a -EDEADLK return.
Therefore, we retry a finite number of times after timeout before
reporting failure.
We retry up to 10,000 loops after timeout. This value was determined
empirically: 10 and 100 retries were insufficient on the test systems,
while 10,000 provided stable results and avoided false negatives.
Without this commit, we may see in the log:
Beginning ww (wound) mutex selftests
stress (stress_inorder_work) failed with -35
Fixes: cfa92b6d5207 ("locking/ww_mutex/test: Make sure we bail out instead of livelock")
Signed-off-by: Håkon Bugge <haakon.bugge@xxxxxxxxxx>
---
v1 -> v2:
* Reworded commit message
---
kernel/locking/test-ww_mutex.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kernel/locking/test-ww_mutex.c b/kernel/locking/test-ww_mutex.c
index 190b8ac5c5520..e97f7d94ca5ef 100644
--- a/kernel/locking/test-ww_mutex.c
+++ b/kernel/locking/test-ww_mutex.c
@@ -457,6 +457,7 @@ static void stress_inorder_work(struct work_struct *work)
struct ww_acquire_ctx ctx;
int *order;
int err;
+ int attempts_after_tmout = 10000;
stress->result = -ENOMEM;
@@ -489,7 +490,7 @@ static void stress_inorder_work(struct work_struct *work)
ww_mutex_unlock(&locks[order[n]]);
if (err == -EDEADLK) {
- if (!time_after(jiffies, stress->timeout)) {
+ if ((!time_after(jiffies, stress->timeout)) || attempts_after_tmout--) {
ww_mutex_lock_slow(&locks[order[contended]], &ctx);
goto retry;
}
--
2.43.5