Re: [PATCH v7 33/40] sched/deadline: Start a period for a task that enters the class blocked

From: sashiko-bot

Date: Tue Nov 17 2026 - 10:46:32 EST


Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] sched/deadline: unstarted period when sleeping task has
!dl_task_pi_blocked()
- [Medium] sched/deadline: sched_setattr() on PI-boosted blocked task
skips period update
--

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

sched/deadline: Start a period for a task that enters the class blocked

This commit starts a deadline period in switched_to_dl() and
dl_boost_blocked() when a task blocked on an rt_mutex enters the deadline
class or receives a new donor so its waiter does not sort with a deadline
of 0.

> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index 0b30059483136..90b17969554bf 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -125,6 +125,12 @@ void dl_deboost(struct sched_dl_entity *dl_se)
> }
> dl_drop_boost(dl_se);
> }
> +
> +/* Return true if @p waits on an rt_mutex. The caller holds its pi_lock. */
> +static inline bool dl_task_pi_blocked(struct task_struct *p)
> +{
> + return p->pi_blocked_on;
> +}

[Severity: Medium]
Can gating replenish_dl_new_period() on dl_task_pi_blocked(p) still leave
p->dl.deadline at 0 when a sleeping task participates in rt_mutex priority
inheritance before waking up?

A non-deadline task sleeping in futex_wait_requeue_pi() on uaddr1 has
!task_on_rq_queued(p) and p->pi_blocked_on == NULL. If it enters
dl_sched_class while sleeping on uaddr1 (via sched_setattr() or a PI boost
on another rt_mutex it owns), dl_task_pi_blocked(p) is false, so both
switched_to_dl() and dl_boost_blocked() leave p->dl.deadline at 0. A
subsequent FUTEX_CMP_REQUEUE_PI then calls rt_mutex_start_proxy_lock() ->
task_blocks_on_rt_mutex() without waking p, queueing its waiter on uaddr2
with a deadline of 0 ahead of all real deadline waiters.

Similarly, if a task holding an rt_mutex sleeps in a non-rt_mutex syscall
(p->pi_blocked_on == NULL) and sched_setattr() makes it SCHED_DEADLINE,
p->dl.deadline remains 0 while dl_prio(p->normal_prio) becomes true. If an
earlier-deadline waiter then blocks on that rt_mutex before p wakes up,
rt_mutex_setprio() evaluates dl_entity_preempt(&pi_task->dl, &p->dl)
against deadline 0, which returns false and fails to boost p.

[ ... ]

> @@ -4483,6 +4514,17 @@ static void switched_to_dl(struct rq *rq, struct task_struct *p)
> if (!task_on_rq_queued(p)) {
> add_rq_bw(&p->dl, &rq->dl);
>
> + /*
> + * A task that waits on an rt_mutex cannot wait for its wakeup.
> + * The chain walk sorts its waiter by its deadline first. A task
> + * new to the class has a deadline of 0, which goes before every
> + * real one. Start a new period now, as setup_new_dl_entity()
> + * does at an enqueue.
> + */
> + if (dl_task_pi_blocked(p) && !p->dl.dl_throttled &&
> + dl_time_before(p->dl.deadline, rq_clock(rq)))
> + replenish_dl_new_period(&p->dl, rq);
> +
> return;
> }

[Severity: Medium]
What happens when sched_setattr() changes the policy of a task blocked on
an rt_mutex that is already in dl_sched_class due to a PI boost?

Because prev_class and next_class are both &dl_sched_class,
__sched_setscheduler() does not set DEQUEUE_CLASS, so switched_to_dl() does
not run:

kernel/sched/syscalls.c:__setscheduler_dl_pi() {
if (dl_prio(newprio) && !dl_policy(policy)) {
struct task_struct *pi_task = rt_mutex_get_top_task(p);

if (pi_task) {
p->dl.pi_se = pi_task->dl.pi_se;
scope->flags |= ENQUEUE_REPLENISH;
}
}
...
}

When sched_setattr() gives such a blocked task its own SCHED_DEADLINE
reservation with an earlier deadline than its donor's,
__setscheduler_dl_pi() does nothing because dl_policy(policy) is true, and
prio_changed_dl() returns early because !task_on_rq_queued(p). Neither
p->dl.deadline nor p->dl.pi_se is updated, so rt_mutex_adjust_pi() sees
rt_waiter_up_to_date(waiter, p) and stops without re-sorting p's waiter or
propagating the earlier deadline down the lock chain.

Conversely, when a blocked task leaves SCHED_DEADLINE (!dl_policy(policy))
while remaining boosted in dl_sched_class (dl_prio(newprio)), setting
ENQUEUE_REPLENISH in __setscheduler_dl_pi() has no effect while
!scope->queued because dl_boost_blocked() is not called.

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