Re: [PATCH v2 10/16] sched/deadline: Release the bandwidth of a task that leaves the class asleep

From: sashiko-bot

Date: Wed Nov 18 2026 - 16:52:06 EST


Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] sched/deadline: stale params and s64 overflow in
task_non_contending()
--

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

sched/deadline: Release the bandwidth of a task that leaves the class asleep

This commit calls task_non_contending() in switched_from_dl() when an
unqueued task leaves SCHED_DEADLINE without an armed inactive timer, so
that its total_bw contribution is released immediately or at the 0-lag
time.

Link: https://lore.kernel.org/all/20261103-b4-sched-dl-bw-fixes-v1-2-dd761fe005b4@xxxxxxxxxx/

> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index d6d2657dcddd6..f0e03f97fd82f 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -3595,6 +3595,14 @@ static void switched_from_dl(struct rq *rq, struct task_struct *p)
> if (p->dl.dl_non_contending)
> sub_running_bw(&p->dl, &rq->dl);
> sub_rq_bw(&p->dl, &rq->dl);
> + /*
> + * Without an armed timer, nothing releases total_bw. Do as for
> + * a queued task: arm the timer if the 0-lag time is ahead, or
> + * release the bandwidth and clear the parameters now. Call
> + * task_non_contending() after sub_rq_bw(), which needs dl_bw.
> + */
> + if (!p->dl.dl_non_contending)
> + task_non_contending(&p->dl, false);

[Severity: Medium]
Can task_non_contending() compute a bogus zerolag_time here when a
sleeping task had its deadline parameters updated before leaving the
class?

When a sleeping task re-enters SCHED_DEADLINE before its 0-lag time (or
updates its SCHED_DEADLINE parameters in place while asleep),
switched_to_dl() or dl_rq_change_utilization() cancels inactive_timer and
__setparam_dl() overwrites dl_runtime, dl_deadline and dl_period while
leaving the dynamic runtime and deadline from the previous reservation to
be updated at the next wakeup. If the task then leaves SCHED_DEADLINE
while still asleep, task_non_contending() mixes the old runtime and
deadline with the new dl_period and dl_runtime:

kernel/sched/deadline.c:task_non_contending() {
...
zerolag_time = dl_se->deadline -
div64_long((dl_se->runtime * dl_se->dl_period),
dl_se->dl_runtime);
...
}

If the task had negative runtime under the old reservation and was given
a smaller dl_runtime / dl_period ratio, (-runtime * dl_period) /
dl_runtime is scaled up by the new ratio and can arm inactive_timer days
in the future, pinning total_bw and the task_struct reference; if runtime
was positive and dl_runtime was lowered below runtime, zerolag_time
becomes negative before the true 0-lag time and releases total_bw early.

Also, in the same calculation, dl_se->runtime * dl_se->dl_period is
evaluated in unscaled 64-bit arithmetic (unlike dl_entity_overflow(),
which shifts by DL_SCALE), so valid parameters within the default
sysctl_sched_dl_period_max (~4.19s, e.g. dl_period = 4s and remaining
runtime = 2.4s) overflow S64_MAX and wrap the dividend negative, pushing
zerolag_time past the deadline.

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