Re: [PATCH v14 08/39] sched/deadline: Keep the deadline of a departed constrained task

From: sashiko-bot

Date: Thu Dec 03 2026 - 10:45:30 EST


Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [High] sched/deadline: switched_from_dl() wipes preserved deadline of
queued task
- [Medium] sched/deadline: non-idempotent dl_release_params() wipes
preserved deadline
- [Medium] sched/deadline: preserved deadline breaks PI boost in
update_dl_entity()
- [Medium] sched/deadline: dl_release_params() retains stale deadline
across reentry
- [Medium] sched/deadline: dl_release_params() leaves future deadline
with zero runtime
- [Medium] sched/deadline: dl_release_params() keeps replenished
next-period deadline
--

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

sched/deadline: Keep the deadline of a departed constrained task

This patch introduces dl_release_params() and calls it from
task_non_contending() and inactive_task_timer() in place of
__dl_clear_params() so that a departed constrained SCHED_DEADLINE task
keeps its deadline after its bandwidth is released.

Link: https://lore.kernel.org/all/axAxdNEE1Q2OuxNQ@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/

> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index c88cac6bc5fe7..422a8120454a3 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c

[ ... ]

> @@ -2341,7 +2342,7 @@ static enum hrtimer_restart inactive_task_timer(struct hrtimer *timer)
> raw_spin_lock(&dl_b->lock);
> __dl_sub(dl_b, p->dl.dl_bw, dl_bw_cpus(task_cpu(p)));
> raw_spin_unlock(&dl_b->lock);
> - __dl_clear_params(dl_se);
> + dl_release_params(dl_se);
>
> goto unlock;
> }

[Severity: Medium]
Can a race between inactive_task_timer() and task_non_contending() call
dl_release_params() twice and wipe the preserved deadline?

CPU0 CPU1
inactive_task_timer()
(waits on task_rq_lock)
switched_to_dl()
cancel_inactive_timer() -> -1
switched_from_dl()
task_non_contending(&p->dl, false)
hrtimer_active() is true
dl_release_params(dl_se)
(zeroes dl_deadline/dl_period,
keeps deadline)
task_rq_unlock()
task_rq_lock()
!dl_task(p) is true
dl_release_params(dl_se) <-- wipes deadline to 0

On the second call, dl_deadline and dl_period are both 0, so
dl_is_implicit(dl_se) evaluates to true and __dl_clear_params() overwrites
the preserved deadline with 0. If the task re-enters SCHED_DEADLINE before
its next period, it bypasses dl_check_constrained_dl() throttling and can
exceed its reserved bandwidth.

Returning early when !dl_se->dl_runtime in dl_release_params() or
inactive_task_timer() would keep parameter release idempotent.

[Severity: Medium]
When a throttled constrained task leaves SCHED_DEADLINE with an overrun,
does inactive_task_timer() preserve the replenished next-period deadline
with zero runtime?

When dl_se->runtime < 0, dl_time_to_zerolag() places the 0-lag time strictly
after dl_next_period(dl_se). At dl_next_period(dl_se), dl_task_timer()
fires first and calls replenish_dl_entity(), advancing dl_se->deadline into
the next period.

When inactive_task_timer() then runs at the 0-lag time, dl_release_params()
clears dl_se->runtime to 0 while keeping that next-period deadline. If the
task re-enters SCHED_DEADLINE during that next period after already waiting
out its previous period and overrun, it has zero runtime and is throttled
for an entire extra period.

[ ... ]

> @@ -3682,7 +3683,8 @@ static void switched_from_dl(struct rq *rq, struct task_struct *p)
> * the "inactive timer" fires, it can continue to consume its current
> * runtime using its current deadline. If it stays outside of
> * SCHED_DEADLINE until the 0-lag time passes, inactive_task_timer()
> - * will reset the task parameters.
> + * will reset the task parameters. A constrained task keeps its
> + * deadline: see dl_release_params().
> */
> if (task_on_rq_queued(p) && p->dl.dl_runtime)
> task_non_contending(&p->dl, false);

[Severity: High]
Does switched_from_dl() immediately wipe the deadline that
dl_release_params() just preserved for a queued constrained task?

When a queued constrained task leaves SCHED_DEADLINE after its 0-lag time
has passed, task_non_contending(&p->dl, false) calls dl_release_params(),
which zeroes p->dl.dl_runtime while keeping p->dl.deadline. The block
right below then sees !p->dl.dl_runtime and clears p->dl.deadline back to 0:

kernel/sched/deadline.c:switched_from_dl() {
...
if (task_on_rq_queued(p) && p->dl.dl_runtime)
task_non_contending(&p->dl, false);
...
if (!p->dl.dl_runtime) {
p->dl.deadline = 0;
p->dl.runtime = 0;
}
}

Without its deadline, re-entering SCHED_DEADLINE before the next period
immediately starts a new period with full runtime, allowing the task to
exceed its reserved bandwidth. Moving the !p->dl.dl_runtime reset for
PI-boosted tasks above task_non_contending() would avoid wiping it.

[ ... ]

> @@ -4155,6 +4157,29 @@ static void __dl_clear_params(struct sched_dl_entity *dl_se)
> dl_se->dl_bw_oncpu = 0;
> }
>
> +/*
> + * Clear the parameters of a task which left the class, once its
> + * bandwidth is released. A task with a constrained deadline keeps its
> + * deadline. Leaving the class and coming back before its next period
> + * then gives it no new runtime. Back in the class, it waits for that
> + * period, as a task asleep in the class does:
> + * - between its deadline and its next period, dl_check_constrained_dl()
> + * throttles it;
> + * - before its deadline, it has no runtime left.
> + *
> + * An implicit deadline task keeps nothing. In the class too, a wakeup
> + * after its 0-lag time starts a new period.
> + */
> +static void dl_release_params(struct sched_dl_entity *dl_se)
> +{
> + u64 deadline = dl_se->deadline;
> + bool constrained = !dl_is_implicit(dl_se);
> +
> + __dl_clear_params(dl_se);
> + if (constrained)
> + dl_se->deadline = deadline;
> +}

[Severity: Medium]
Can keeping a future dl_se->deadline with runtime == 0 break priority
inheritance when the departed task is later boosted while asleep?

For a constrained task whose 0-lag time precedes its absolute deadline,
dl_release_params() leaves a non-DL task with dl_runtime == 0, runtime == 0,
and a future dl_se->deadline. If a short-deadline waiter boosts the task
while it is asleep, rt_mutex_setprio() sets pi_se and ENQUEUE_REPLENISH,
but sched_change_end() skips the enqueue because the task is not queued.

When the task wakes up before its preserved deadline, update_dl_entity()
sees dl_time_before(dl_se->deadline, rq_clock(rq)) is false and
dl_entity_overflow() is false (because runtime == 0 makes left == 0). It
skips replenish_dl_new_period() and enqueues the boosted task onto dl_rq
with its stale future deadline and zero runtime instead of the donor's
earlier deadline, causing priority inversion and deadline misses for the
donor.

[Severity: Medium]
Does retaining dl_se->deadline indefinitely without clearing it on re-entry
corrupt period calculations when the task returns with a longer dl_period?

Nothing clears the preserved deadline after the old period expires, and
__setparam_dl() installs new dl_deadline and dl_period values without
resetting it. If a task that ran a short constrained period (such as 10ms)
re-enters seconds later with a longer dl_period (such as 4000ms),
dl_next_period() combines the stale deadline with the new dl_period and
produces a timestamp still in the future.

On wakeup, dl_check_constrained_dl() then spuriously throttles the task for
up to the new dl_period even though its old period ended seconds earlier.
If the task instead re-enters asleep and switches back to SCHED_OTHER
without running, dl_time_to_zerolag() sees the future dl_next_period(),
arms inactive_timer, and pins the newly admitted bandwidth in total_bw.

[Severity: Medium]
When a departed constrained task re-enters SCHED_DEADLINE before its
preserved future deadline, does runtime == 0 let it run unbudgeted and
trigger spurious overruns?

If the task's 0-lag time passed before dl_se->deadline (for example, 10ms
runtime, 50ms deadline, 100ms period after running 1ms gives a 0-lag time
of 10ms), dl_release_params() leaves a future deadline with runtime == 0
and dl_throttled == 0. Re-entering SCHED_DEADLINE before that deadline
skips both dl_check_constrained_dl() and update_dl_entity(), so
enqueue_dl_entity() queues the task unthrottled with zero runtime.

When scheduled, the task executes unbudgeted until the next tick or hrtick,
accumulates negative runtime debt in update_curr_dl_se(), and spuriously
sets dl_overrun (delivering SIGXCPU under SCHED_FLAG_DL_OVERRUN). Even
with the zero-runtime throttling added later in commit "sched/deadline:
Keep the debt of a task across a change of parameters", re-entering with a
shorter period where dl_next_period(dl_se) <= rq_clock < dl_se->deadline
still clears dl_throttled without replenishing when start_dl_timer()
returns 0 and enqueues the task with zero runtime.

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