Re: [PATCH v11 21/43] rtmutex: Continue the chain walk when a waiter's deadline donor changes

From: Mathieu Desnoyers

Date: Fri Nov 27 2026 - 08:49:06 EST


> Can waiter->pi_se get out of sync with the donor that rt_mutex_setprio()
> copies to the lock owner?

Not as drawn. W blocks with task_blocks_on_rt_mutex(), which runs a
chain walk from M before W can time out. That walk sees that the donor
recorded in w_M differs from M's donor. So it goes on, records the new
donor in w_M and gives it to O.

A variant of it is real, though. rt_mutex_setprio(O, M) reads M's
donor without M's pi_lock. If that donor changes before the read, and
changes back after it, both later walks stop requeueing at M. The
window is narrow.

O and M are SCHED_OTHER tasks. H and W are SCHED_DEADLINE tasks, and W
has the earlier deadline. O owns L2. M owns L1 and waits on L2, with
w_M as its waiter. H has just blocked on L1, so M's donor is H, and
CPU0 runs the chain walk of H. A task on CPU2 calls sched_setattr() on
H. "Up to date" means that rt_waiter_up_to_date(w_M, M) is true, so the
walk does not requeue w_M. [7], [11] and [13] are the steps of
rt_mutex_adjust_prio_chain():

CPU0 (walk of H) CPU1 (W) CPU2
[7] w_M->pi_se = &H
unlock M->pi_lock
blocks on L1
M's donor = W
walk: w_M != M's donor,
trylock of L2->wait_lock
fails
[11] rt_mutex_setprio(O, M)
O's donor = W
[13] unlock L2->wait_lock
sched_setattr(H):
earlier deadline
than W
M's donor = H
walk: w_M up to
date, no requeue
walk again: w_M up to
date, no requeue

O then runs on W's parameters, with a later deadline than H's, while H
waits behind it. This is what remains of the bug that this patch fixes.
The patch makes it rarer, and does not add it. It needs two locks, not
three as the v11 changelog says. v12 will state it in the changelog
and in the cover as a known limit. A fix would read the donor under the
pi_lock, and pass a reference along the walk. That is for a follow-up.

Thanks,

Mathieu