Re: [PATCH v11 30/43] sched/deadline: Start a period for a task that enters the class blocked

From: sashiko-bot

Date: Wed Nov 25 2026 - 20:53:45 EST


Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] sched/deadline: missing zero-deadline check in
switched_to_dl()
- [Medium] sched/deadline: dl_boost_blocked() skips tasks with non-zero
dl_deadline
- [Medium] sched/deadline: switched_to_dl() skips donor period when
throttled task is boosted
--

commit e2fecf170ee9d540debd8f3437e1896d21f58e13
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 for a task blocked on an rt_mutex
when it enters SCHED_DEADLINE via switched_to_dl() or receives a new
priority-inheritance donor via dl_boost_blocked(), so that the rt_mutex
chain walk sorts its waiter with a current deadline rather than 0.

> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index 5ec1c5eaf7647..4d46d1c9c6981 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
[ ... ]
> @@ -1301,6 +1312,30 @@ static inline void replenish_dl_new_period(struct sched_dl_entity *dl_se,
> trace_sched_dl_replenish_tp(dl_se, cpu_of(rq), dl_get_type(dl_se, rq));
> }
>
> +#ifdef CONFIG_RT_MUTEXES
> +/*
> + * Start a period from the new donor of @p, if @p has no reservation of its
> + * own and waits on an rt_mutex. The enqueue does this for a queued task, in
> + * replenish_dl_entity(). A blocked task is not enqueued, but the chain walk
> + * copies its deadline into its waiter.
> + *
> + * Call it only when the donor changes. A new period changes the deadline,
> + * so the chain walk finds the waiter out of date and goes on. In a ww_mutex
> + * cycle, a new period at each step would never let the walk stop.
> + *
> + * The caller holds the rq lock and the pi_lock of @p, and has updated the
> + * rq clock.
> + */
> +void dl_boost_blocked(struct task_struct *p)
> +{
> + struct sched_dl_entity *dl_se = &p->dl;
> +
> + if (!dl_se->dl_deadline && !dl_se->dl_throttled &&
> + dl_task_pi_blocked(p))
> + replenish_dl_new_period(dl_se, task_rq(p));
> +}
> +#endif

[Severity: Medium]
Can dl_boost_blocked() leave an expired p->dl.deadline in place when a
blocked task still has a non-zero dl_se->dl_deadline?

When a SCHED_DEADLINE task leaves the class before its 0-lag time,
switched_from_dl() leaves dl_se->dl_deadline and dl_se->deadline non-zero
until inactive_timer fires. If that task holds an rt_mutex, blocks on a
second rt_mutex, and gets boosted back into dl_sched_class before
dl_se->deadline passes, switched_to_dl() cancels inactive_timer (so
__dl_clear_params() never clears dl_se->dl_deadline) and does not start a
new period. If a second deadline donor with an earlier deadline boosts
the task after dl_se->deadline has passed, dl_boost_blocked() returns
early because dl_se->dl_deadline is non-zero, and the chain walk requeues
the waiter with the expired dl_se->deadline ahead of waiters with current
deadlines.

> @@ -4866,6 +4901,26 @@ 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);
>
> + /*
> + * The chain walk sorts the waiter of a task by its deadline,
> + * before the wakeup sets the task up. A task new to the class
> + * has a deadline of 0, which goes before every real one. So
> + * start a new period now for a task that waits on an
> + * rt_mutex, as setup_new_dl_entity() does at an enqueue.
> + *
> + * A task that comes back to the class before its 0-lag time
> + * keeps its deadline. For a constrained task, that deadline
> + * can have passed before its next period. As
> + * dl_check_constrained_dl() does, leave such a task alone
> + * unless it is boosted. Its wakeup throttles it until its
> + * next period.
> + */
> + if (dl_task_pi_blocked(p) && !p->dl.dl_throttled &&
> + dl_time_before(p->dl.deadline, rq_clock(rq)) &&
> + (is_dl_boosted(&p->dl) ||
> + !dl_time_before(rq_clock(rq), dl_next_period(&p->dl))))
> + replenish_dl_new_period(&p->dl, rq);
> +
> return;
> }

[Severity: Medium]
Does switched_to_dl() skip replenish_dl_new_period() when a task with
p->dl.deadline == 0 enters SCHED_DEADLINE with a constrained reservation
while blocked on an rt_mutex?

__setparam_dl() writes p->dl.dl_deadline and p->dl.dl_period before
switched_to_dl() runs. When p->dl.deadline is 0, dl_next_period(&p->dl)
evaluates to dl_period - dl_deadline. If rq_clock(rq) < dl_period -
dl_deadline, dl_time_before(rq_clock(rq), dl_next_period(&p->dl)) is
true, so switched_to_dl() treats the never-initialized deadline as being
in a constrained gap and leaves p->dl.deadline at 0 for the rt_mutex
chain walk.

In addition, if a blocked task returning to SCHED_DEADLINE before its
0-lag time changes its dl_deadline or dl_period via sched_setattr(),
dl_next_period(&p->dl) mixes the old p->dl.deadline with the newly
overwritten p->dl.dl_deadline and p->dl.dl_period. Even after the later
commit "sched/deadline: Keep the debt of a task across a change of
parameters" replaces the dl_next_period() check with
dl_in_constrained_gap(), dl_in_constrained_gap() still returns true when
deadline == 0 and period_start == 0 while now < dl_period unless
!p->dl.deadline is checked first.

[Severity: Medium]
Does the !p->dl.dl_throttled check in switched_to_dl() also prevent a
throttled departed task from receiving a donor period when it is boosted
back into SCHED_DEADLINE?

If a constrained SCHED_DEADLINE task exhausts its runtime
(p->dl.dl_throttled = 1), switches to SCHED_OTHER before its next period,
and blocks on an rt_mutex while holding another rt_mutex, a PI boost back
into dl_sched_class after p->dl.deadline has passed sees
p->dl.dl_throttled == 1 in switched_to_dl() and skips
replenish_dl_new_period(). The chain walk then queues the waiter with
the expired p->dl.deadline instead of the donor's deadline, and on unlock
enqueue_task_dl() clears dl_throttled because is_dl_boosted(&p->dl) is
true, letting the task run immediately ahead of earlier-deadline waiters.

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