Re: [PATCH v6 31/37] sched/deadline: Start a period for a task that enters the class blocked

From: sashiko-bot

Date: Mon Nov 16 2026 - 15:12:42 EST


Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] sched/deadline: unstarted period in switched_to_dl() when
!pi_blocked_on
- [Medium] sched/deadline: switched_to_dl() skips period reset on
boosted pre-0-lag task
- [Medium] sched/deadline: stale deadline on rt_mutex waiter when donor
or policy changes
--

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

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

This commit starts a new period in switched_to_dl() when a task blocked on
an rt_mutex enters dl_sched_class with an expired deadline so that the
rt_mutex waiter tree does not sort it with a deadline of 0.

> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index 69a338c1526d0..ffa8b946e8047 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c

[ ... ]

> @@ -4352,6 +4363,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);

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

While a task sleeps in futex_wait_requeue_pi() on a non-PI futex,
p->pi_blocked_on is NULL. If sched_setattr() or a PI boost moves p into
dl_sched_class there, switched_to_dl() leaves p->dl.deadline at 0, and a
later FUTEX_CMP_REQUEUE_PI calls rt_mutex_start_proxy_lock() ->
task_blocks_on_rt_mutex() without waking p, queuing its waiter ahead of all
deadline waiters with deadline 0. Likewise, if a task holding an rt_mutex
is switched to SCHED_DEADLINE while sleeping on a non-rt_mutex wait,
p->dl.deadline stays 0 and rt_mutex_setprio() fails to boost p when a
deadline waiter with an earlier deadline blocks on that rt_mutex
(dl_entity_preempt(&pi_task->dl, &p->dl) is false against 0).

[Severity: Medium]
What happens when a task that left SCHED_DEADLINE before its 0-lag time is
PI-boosted back into dl_sched_class while blocked on an rt_mutex?

switched_from_dl() preserves p->dl.deadline and p->dl.dl_throttled until
inactive_timer fires. If p then blocks on an rt_mutex while holding
another and is boosted back into dl_sched_class, enqueue_task_dl() is not
called because p is not queued, and switched_to_dl() checks
!p->dl.dl_throttled && dl_time_before(p->dl.deadline, rq_clock(rq)) without
checking is_dl_boosted(&p->dl).

If p->dl.dl_throttled is still set, switched_to_dl() skips
replenish_dl_new_period() and leaves p throttled with its expired deadline;
if p->dl.dl_timer then fires while p is boosted, dl_task_timer() bails out
on is_dl_boosted(dl_se) without clearing dl_throttled, which prevents
enqueue_dl_entity() from queuing p after deboost. Even when p is not
throttled, if its old pre-0-lag p->dl.deadline is still in the future,
switched_to_dl() skips replenish_dl_new_period() and the chain walk sorts p
using its abandoned reservation's deadline instead of the donor's.

[Severity: Medium]
Does starting a period in switched_to_dl() leave p->dl.deadline stale if the
top PI donor on a blocked task changes while it remains in dl_sched_class?

If a non-deadline task p owns rt_mutex M1 and blocks on rt_mutex M2, an
initial deadline waiter W1 on M1 moves p into dl_sched_class and
switched_to_dl() sets p->dl.deadline from W1. If a second deadline waiter
W2 with a much earlier deadline then blocks on M1, rt_mutex_setprio(p, W2)
keeps prev_class == next_class == &dl_sched_class and sets p->dl.pi_se =
W2->dl.pi_se with ENQUEUE_REPLENISH. Because p is not queued,
sched_change_end() calls prio_changed_dl() instead of enqueue_task_dl() or
switched_to_dl(), leaving p->dl.deadline at W1's later deadline.
rt_mutex_adjust_prio_chain() then sees an unchanged waiter deadline and
stops the chain walk on M2, and when p later wakes up, update_dl_entity()
keeps W1's future deadline if dl_entity_overflow() is not triggered.

--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116190549.230119-1-mathieu.desnoyers@xxxxxxxxxxxx?part=31