[PATCH v9 21/33] rtmutex: Continue the walk when the owner's top waiter changes lock
From: Mathieu Desnoyers
Date: Fri Nov 20 2026 - 09:01:08 EST
The chain walk stops at an owner whose top pi waiter is not the top
waiter of the lock just walked. That lock then does not set the
owner's priority, so there is nothing to pass on.
But the step before can change the owner's top pi waiter. It
requeues a waiter whose priority dropped. The top pi waiter of the
owner can then be a waiter on another lock. The owner's priority, or
its deadline donor, changed. The walk still stops at it, and the next
owner keeps the old ones.
O and M are SCHED_OTHER tasks. W and Z are SCHED_DEADLINE tasks. W
has the earlier deadline. X is a SCHED_FIFO task:
O M W Z X
locks L2 locks L1 and L1'
blocks on L1'
M->dl.pi_se = &W->dl
blocks on L2
O->dl.pi_se = &W->dl
blocks on L1
sched_setscheduler(SCHED_OTHER)
rt_mutex_adjust_pi(W)
M->dl.pi_se = &Z->dl
walk at M: L1' is not M's top
stops
blocks on L1'
walk stops at M
times out on L1'
not the top waiter: no walk
exits
O's next refill reads W's freed task_struct. With RT priorities
only, O stays boosted to W's old priority until it unlocks L2.
Remove this test. The next test already stops the walk when the
owner's waiter is up to date. An out of date waiter is now requeued,
and the walk goes on to the next owner.
The cases pi_chain_top_moves and pi_chain_top_moves_rt, added to
deadline_bw_test later in this series, test this. pi_chain_top_moves_rt
fails without this patch and passes with it. pi_chain_top_moves also
needs the previous patch.
The Sashiko AI review of this series found this.
Fixes: 23f78d4a03c5 ("[PATCH] pi-futex: rt mutex core")
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
---
kernel/locking/rtmutex.c | 24 ++++++++----------------
1 file changed, 8 insertions(+), 16 deletions(-)
diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c
index c78dfe9c93fc..c06261259a56 100644
--- a/kernel/locking/rtmutex.c
+++ b/kernel/locking/rtmutex.c
@@ -821,23 +821,15 @@ static int __sched rt_mutex_adjust_prio_chain(struct task_struct *task,
* Drop out, when the task has no waiters. Note,
* top_waiter can be NULL, when we are in the deboosting
* mode!
+ *
+ * Do not compare top_waiter with the top pi waiter of the
+ * task here. The previous step can have made a waiter on
+ * another lock the top pi waiter of the task. The priority of
+ * the task changed then, and the next owner must follow. The
+ * test below tells whether there is something to pass on.
*/
- if (top_waiter) {
- if (!task_has_pi_waiters(task))
- goto out_unlock_pi;
- /*
- * If deadlock detection is off, we stop here if we
- * are not the top pi waiter of the task. If deadlock
- * detection is enabled we continue, but stop the
- * requeueing in the chain walk.
- */
- if (top_waiter != task_top_pi_waiter(task)) {
- if (!detect_deadlock)
- goto out_unlock_pi;
- else
- requeue = false;
- }
- }
+ if (top_waiter && !task_has_pi_waiters(task))
+ goto out_unlock_pi;
/*
* If the waiter priority is the same as the task priority
--
2.47.3