Re: [PATCH v7 09/40] rtmutex: Continue the chain walk when a waiter's deadline donor changes

From: sashiko-bot

Date: Tue Nov 17 2026 - 09:50:51 EST


Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] rtmutex: premature chain walk stop in
rt_mutex_adjust_prio_chain()
--

commit 9c99e3811a419d96fcdd59dd7a4617c1edc67678
Author: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>

rtmutex: Continue the chain walk when a waiter's deadline donor changes

This commit records the task's deadline donor in struct rt_mutex_waiter
and checks it in rt_waiter_up_to_date() so that priority inheritance chain
walks continue when a blocked task's deadline donor changes without
changing its sort keys.

> diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c
> index 5a9534c715b84..c78dfe9c93fc5 100644
> --- a/kernel/locking/rtmutex.c
> +++ b/kernel/locking/rtmutex.c

[ ... ]

> @@ -824,12 +841,13 @@ static int __sched rt_mutex_adjust_prio_chain(struct task_struct *task,
>
> /*
> * If the waiter priority is the same as the task priority
> - * then there is no further priority adjustment necessary. If
> + * then there is no further priority adjustment necessary. The
> + * task must also pass on the same deadline donor. If
> * deadlock detection is off, we stop the chain walk. If its
> * enabled we continue, but stop the requeueing in the chain
> * walk.
> */
> - if (rt_waiter_node_equal(&waiter->tree, task_to_waiter_node(task))) {
> + if (rt_waiter_up_to_date(waiter, task)) {
> if (!detect_deadlock)
> goto out_unlock_pi;
> else

[Severity: High]
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?

Consider the commit message setup where O (SCHED_OTHER) holds L2, M
(SCHED_OTHER) holds L1 and L1' and blocks on L2, W (SCHED_DEADLINE,
earlier deadline) blocks on L1', and Z (SCHED_DEADLINE, later deadline)
blocks on L1, so both M and O have dl.pi_se = &W->dl. If W switches to
SCHED_OTHER via sched_setscheduler() -> rt_mutex_adjust_pi(W), the first
iteration of rt_mutex_adjust_prio_chain() demotes W's waiter on L1' in
M->pi_waiters, making Z's waiter on L1 the new task_top_pi_waiter(M) and
updating M->dl.pi_se = &Z->dl, while step [12] records L1's top waiter:

kernel/locking/rtmutex.c:rt_mutex_adjust_prio_chain() {
...
if (top_waiter) {
if (!task_has_pi_waiters(task))
goto out_unlock_pi;
if (top_waiter != task_top_pi_waiter(task)) {
if (!detect_deadlock)
goto out_unlock_pi;
...
top_waiter = rt_mutex_top_waiter(lock);
}

On the next iteration at M, top_waiter is still W's waiter on L1' while
task_top_pi_waiter(M) is Z's waiter on L1, so the walk exits at
goto out_unlock_pi before reaching rt_waiter_up_to_date(waiter, task).
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).

--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1794922146.git.mathieu.desnoyers@xxxxxxxxxxxx?part=9