[PATCH v10 22/40] rtmutex: Do not stop the chain walk at an owner whose top waiter changed

From: Mathieu Desnoyers

Date: Fri Nov 20 2026 - 15:46:25 EST


rt_mutex_adjust_prio_chain() stops the walk 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
runs out of runtime
refill reads O->dl.pi_se:
W's freed task_struct

If W and Z are SCHED_FIFO tasks instead, O stays boosted to W's old
priority until it unlocks L2.

A second check next to it stops the walk at an owner that has no pi
waiters left. A waiter that leaves can cause this. remove_waiter() then
walks on from the owner, but that walk can be preempted and come late.

O, M and X are SCHED_OTHER tasks. W is a SCHED_DEADLINE task. Another
task, S, changes the policy of W:

O M S W X

locks L2 locks L1
blocks on L2
blocks on L1
M, O get W's parameters
blocks on L1
sched_setscheduler(W)
walk at L1: W behind X,
M deboosted
times out on L1
not top waiter: no walk
times out on L1
M: no pi waiters
walk from M:
preempted
walk at M:
no pi waiters, stops
exits
runs out of runtime
refill reads O->dl.pi_se:
W's freed task_struct

The next patch keeps the donor's task_struct alive as long as a boost
points at it.

Remove both checks. The next check 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 the first case.
pi_chain_top_moves_rt fails without this patch and passes with it.
pi_chain_top_moves also needs the previous patch. No case tests the
second one: it needs a walk preempted at the right step.

The Sashiko AI review of this series found both cases.

Fixes: 23f78d4a03c5 ("[PATCH] pi-futex: rt mutex core")
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
---
kernel/locking/rtmutex.c | 27 +++++++--------------------
1 file changed, 7 insertions(+), 20 deletions(-)

diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c
index c78dfe9c93fc..b09816977d4e 100644
--- a/kernel/locking/rtmutex.c
+++ b/kernel/locking/rtmutex.c
@@ -818,27 +818,14 @@ static int __sched rt_mutex_adjust_prio_chain(struct task_struct *task,
detect_deadlock = false;

/*
- * Drop out, when the task has no waiters. Note,
- * top_waiter can be NULL, when we are in the deboosting
- * mode!
+ * Do not stop at a task that has no pi waiters, or whose top pi
+ * waiter is not top_waiter. The previous step can have made a
+ * waiter on another lock the top pi waiter of the task. A waiter
+ * can also have left meanwhile, and its own walk can be late. 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 the waiter priority is the same as the task priority
* then there is no further priority adjustment necessary. The
--
2.47.3