Re: [PATCH v7 09/40] rtmutex: Continue the chain walk when a waiter's deadline donor changes
From: Mathieu Desnoyers
Date: Wed Nov 18 2026 - 08:35:34 EST
> Can rt_mutex_adjust_prio_chain() still stop one lock too early at the
> preceding top_waiter != task_top_pi_waiter(task) check when a task
> holds two locks and its top PI waiter switches from one lock to the
> other?
Yes, thanks. I checked it by reading. The walk stops at M, at the
top-waiter test, and never reaches the donor test of this patch. So O
keeps W as its donor.
The test dates from the first rtmutex code, commit 23f78d4a03c5. With RT
priorities only, it stops the walk the same way. O then stays boosted to
W's old priority until it unlocks L2.
> O->dl.pi_se remains &W->dl, and once W unblocks and exits, O's next
> replenish_dl_entity() reads W's freed task_struct (use-after-free).
Not in this exact sequence. W is the top waiter of L1', so its timeout
walks from M. The donor test of this patch sends that walk on to O.
A third waiter on L1' gives the use after free. X is a SCHED_FIFO task.
After W's policy change, X's waiter on L1' sorts before W's. O, M, W and
Z are as in your setup:
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 then reads W's freed task_struct. Before W exits, O
keeps the boost of a task that has left SCHED_DEADLINE.
The next version adds a patch after this one, "rtmutex: Continue the
walk when the owner's top waiter changes lock". It removes the
top_waiter != task_top_pi_waiter() test. The next test, the one this
patch extends, already stops the walk for a waiter that is up to date.
An out of date waiter is now requeued, and the walk goes on. Its
changelog has the diagram above.
Two new test cases cover it, without the exit. In
pi_chain_top_moves_rt, W and Z have RT priorities. On v7, O kept W's
priority in each of 14 runs. With the next version, O follows Z in each
of 14 runs. In pi_chain_top_moves, they are deadline tasks. A deadline
task that shares O's CPU lost one of its periods on v7, in each of 8
runs. It did not with the next version, in 8 runs.
Two more points, both found by reading.
With the test gone, more walks go on. Patch 33 started a new period for
a blocked task at each boost, even with the same donor. Its waiter was
then out of date again after each step. In a ww_mutex cycle, the walk
could run until max_lock_depth. In the next version, patch 33 starts a
new period only when the donor changes.
A narrower window remains. The old donor can leave as a waiter that is
not the top one while a walk is in flight. It starts no walk. The owners
further down keep it until the walk in flight reaches them. The donor
pointer holds no reference on the donor, so no change to this test can
close it. The cover letter widens its known limit to this case.
Thanks,
Mathieu
--
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com