Re: [PATCH v12 32/43] sched/deadline: Start a period for a task requeued onto an rt_mutex

From: sashiko-bot

Date: Fri Nov 27 2026 - 12:21:22 EST


Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] rtmutex: race before try_to_take_rt_mutex() in
__rt_mutex_start_proxy_lock()
--

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

sched/deadline: Start a period for a task requeued onto an rt_mutex

This commit adds dl_proxy_block() and invokes it in
__rt_mutex_start_proxy_lock() and task_blocks_on_rt_mutex() so that a
sleeping SCHED_DEADLINE task requeued onto an rt_mutex receives an
up-to-date deadline before trylock evaluation and waiter queueing.

> diff --git a/kernel/locking/rtmutex_api.c b/kernel/locking/rtmutex_api.c
> index 6bdbd36bac949..f1246efc62d3a 100644
> --- a/kernel/locking/rtmutex_api.c
> +++ b/kernel/locking/rtmutex_api.c
> @@ -342,6 +342,18 @@ int __sched __rt_mutex_start_proxy_lock(struct rt_mutex_base *lock,
>
> lockdep_assert_held(&lock->wait_lock);
>
> + /*
> + * A requeued @task sleeps, so its deadline can be stale. The trylock
> + * below and the waiter node both read it: update it first.
> + * futex_lock_pi() passes current, which is running. Its deadline is
> + * up to date.
> + */
> + if (task != current) {
> + raw_spin_lock(&task->pi_lock);
> + dl_proxy_block(task);
> + raw_spin_unlock(&task->pi_lock);
> + }
> +
> if (try_to_take_rt_mutex(lock, task, NULL))
> return 1;

[Severity: Medium]
Can a sleeping task switched to SCHED_DEADLINE after raw_spin_unlock(&task->pi_lock)
still reach try_to_take_rt_mutex() with task->dl.deadline == 0?

The same window noted for task_blocks_on_rt_mutex() exists before
try_to_take_rt_mutex(). Because task is not queued on a runqueue and
task->pi_blocked_on is still NULL, a concurrent sched_setattr() leaves
task->dl.deadline at 0 in switched_to_dl():

CPU0 CPU1
__rt_mutex_start_proxy_lock()
raw_spin_lock(&task->pi_lock)
dl_proxy_block(task)
raw_spin_unlock(&task->pi_lock)
sched_setattr()
raw_spin_lock(&task->pi_lock)
...
switched_to_dl()
/* !dl_task_pi_blocked(task):
* leaves deadline == 0 */
raw_spin_unlock(&task->pi_lock)
try_to_take_rt_mutex(lock, task, NULL)
rt_mutex_steal(task_to_waiter(task),
rt_mutex_top_waiter(lock))
/* reads deadline == 0 */ <-- steals lock ahead of top_waiter

When the rt_mutex is in the unlocked-with-waiters transition state,
try_to_take_rt_mutex() calls rt_mutex_steal() without holding
task->pi_lock, allowing task to steal the lock ahead of a deadline
top_waiter with an earlier real deadline.

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