[PATCH v11 22/43] rtmutex: Do not stop the chain walk at an owner whose top waiter changed
From: Mathieu Desnoyers
Date: Wed Nov 25 2026 - 20:11:40 EST
rt_mutex_adjust_prio_chain() stops the walk early at an owner in two
cases. Each case misses a change of the owner's priority:
- The owner's 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 requeue 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.
With deadlock detection on, the walk went on, but without requeueing.
It now requeues there too.
- The owner has no pi waiters left. A waiter that left caused this, and
remove_waiter() walks on from the owner itself. But that walk can be
preempted and come late.
The walk then stops at the owner, and the next owner keeps the old
priority or the old donor. With deadline tasks, the old donor can exit.
The refill of the next owner would then read its freed task_struct.
When the waiters are SCHED_FIFO tasks, the first case leaves the next
owner boosted to the old priority until it releases its lock.
Fix this by removing 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. A late walk can still
leave an owner on an exited donor for a while. The next patch keeps the
donor's task_struct alive as long as a boost points at it.
The first case, with deadline tasks. 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. It takes the top of L1' from W:
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
The second case. 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 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