Re: [PATCH 07/16] sched/deadline: Do not lose a throttled task switched out and back

From: sashiko-bot

Date: Wed Nov 18 2026 - 15:31:51 EST


Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] sched/deadline: stale dl_timer and deadline after
__dl_clear_params() [1]
--

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

sched/deadline: Do not lose a throttled task switched out and back

This commit replenishes a throttled SCHED_DEADLINE task in dl_task_timer()
if the task has switched to another scheduling policy, so that it can be
enqueued if it switches back to SCHED_DEADLINE before its 0-lag time.

> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index b614d5fc1a1ac..e4d7cbf4861de 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -1233,9 +1233,18 @@ static enum hrtimer_restart dl_task_timer(struct hrtimer *timer)
> /*
> * The task might have changed its scheduling policy to something
> * different than SCHED_DEADLINE (through switched_from_dl()).
> + * It keeps its parameters until its 0-lag time. If it comes back
> + * before then, nothing else would lift its throttle. So replenish
> + * it now, as the !queued case below does. Its return enqueues it.
> */
> - if (!dl_task(p))
> + if (!dl_task(p)) {
> + if (dl_se->dl_throttled && !is_dl_boosted(dl_se)) {
> + sched_clock_tick();
> + update_rq_clock(rq);
> + replenish_dl_entity(dl_se);
> + }
> goto unlock;
> + }

[Severity: High]
This problem wasn't introduced by this patch, but in the opposite order
where the 0-lag time elapses before dl_se->dl_timer fires [1], does
__dl_clear_params() leave a stale dl_se->dl_timer armed along with stale
dl_se->deadline and dl_se->runtime values?

When a task calls sched_yield() with remaining runtime (or a
constrained-deadline task overruns slightly), its 0-lag time is earlier
than dl_next_period(dl_se). If the task then switches out of
SCHED_DEADLINE, task_non_contending() or inactive_task_timer() calls
__dl_clear_params(), which clears dl_se->dl_throttled without cancelling
dl_se->dl_timer or resetting dl_se->deadline and dl_se->runtime:

kernel/sched/deadline.c:__dl_clear_params() {
dl_se->dl_runtime = 0;
dl_se->dl_deadline = 0;
dl_se->dl_period = 0;
dl_se->flags = 0;
dl_se->dl_bw = 0;
dl_se->dl_density = 0;

dl_se->dl_throttled = 0;
dl_se->dl_yielded = 0;
...
}

If the task switches back to SCHED_DEADLINE before the old period ends,
enqueue_dl_entity() with ENQUEUE_MOVE sees dl_se->deadline still in the
future and skips setup_new_dl_entity(), running the task with stale
runtime and deadline values. If the task then throttles under its new
reservation while the old dl_se->dl_timer is still queued,
start_dl_timer() sees hrtimer_is_queued(&dl_se->dl_timer) and skips
reprogramming it, delaying replenishment until the old timer expires.

[1] https://sashiko.dev/#/bug/linux-5f16aeeb-544a-4da3-a8a9-3a7be85e8892

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