Re: [PATCH 09/16] sched/deadline: Reset the deadline and the runtime with the parameters

From: sashiko-bot

Date: Wed Nov 18 2026 - 15:38:06 EST


Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] sched/deadline: donor runtime and deadline retained after PI
boost in switched_from_dl()
- [Medium] sched/deadline: uncanceled dl_timer in __dl_clear_params()
unthrottles new period early
--

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

sched/deadline: Reset the deadline and the runtime with the parameters

This commit resets dl_se->deadline and dl_se->runtime in
__dl_clear_params() and in switched_from_dl() when a boosted task with no
parameters of its own leaves SCHED_DEADLINE, so that the next entry into
the class starts a new period.

> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index 71b1c155c2424..d6d2657dcddd6 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c

> + /*
> + * A task with no parameters of its own was boosted into the class.
> + * Its deadline and runtime are the donor's. Reset them, so that its
> + * next entry into the class starts a new period.
> + */
> + if (!p->dl.dl_runtime) {
> + p->dl.deadline = 0;
> + p->dl.runtime = 0;
> + }
> +
> /*
> * In case a task is setscheduled out from SCHED_DEADLINE we need to
> * keep track of that on its cpuset (for correct bandwidth tracking).

[Severity: Medium]
Can a task still retain the donor's runtime and deadline after a PI
deboost if p->dl.dl_runtime is non-zero?

If a non-deadline task is PI-boosted by a SCHED_DEADLINE waiter and
sched_setattr() switches it to SCHED_DEADLINE while still boosted,
__sched_setscheduler() sees prev_class == next_class == &dl_sched_class
and skips switched_from_dl() and switched_to_dl(). __setparam_dl() sets
p->dl.dl_runtime to the task's new reservation without clearing the donor's
p->dl.deadline and p->dl.runtime (and if the task is sleeping, skipping
switched_to_dl() also misses add_rq_bw(), causing a later __sub_rq_bw()
underflow warning). When rt_mutex_setprio() later deboosts the task, it
remains in dl_sched_class with the donor's future deadline, so
enqueue_dl_entity() skips setup_new_dl_entity() and the task runs on the
donor's remaining runtime.

Similarly, if a task that recently left SCHED_DEADLINE is PI-boosted
before its 0-lag inactive_timer expires, switched_to_dl() cancels
inactive_timer while p->dl.dl_runtime is still non-zero, and
replenish_dl_entity() overwrites p->dl.deadline and p->dl.runtime from the
donor. On deboost, !p->dl.dl_runtime is false, so switched_from_dl()
leaves the donor's deadline and runtime in place and passes them to
task_non_contending().

> @@ -3984,7 +3994,8 @@ bool __checkparam_dl(const struct sched_attr *attr)
> }
>
> /*
> - * This function clears the sched_dl_entity static params.
> + * Clear the static parameters of @dl_se. Also reset its deadline and its
> + * runtime, so that its next enqueue starts a new period.
> */
> static void __dl_clear_params(struct sched_dl_entity *dl_se)
> {
> @@ -3995,6 +4006,9 @@ static void __dl_clear_params(struct sched_dl_entity *dl_se)
> dl_se->dl_bw = 0;
> dl_se->dl_density = 0;
>
> + dl_se->deadline = 0;
> + dl_se->runtime = 0;
> +
> dl_se->dl_throttled = 0;
> dl_se->dl_yielded = 0;
> dl_se->dl_non_contending = 0;

[Severity: Medium]
If dl_se->dl_timer was armed before the task left SCHED_DEADLINE, can
leaving it queued in __dl_clear_params() unthrottle the task's new period
early?

If a task throttles (for example via sched_yield() while its 0-lag time is
still before the end of its period) and switches out of SCHED_DEADLINE,
dl_se->dl_timer remains armed for the old period's replenishment time.
When inactive_task_timer() fires at the 0-lag time, __dl_clear_params()
now resets dl_se->deadline, dl_se->runtime, and dl_se->dl_throttled so
that re-entering SCHED_DEADLINE starts a fresh period with a later
deadline, but dl_se->dl_timer is not canceled. If the task re-enters
SCHED_DEADLINE and throttles in its new period before the old timer
expires, start_dl_timer() sees hrtimer_is_queued(&dl_se->dl_timer) and
does not reprogram it:

kernel/sched/deadline.c:start_dl_timer() {
...
if (!hrtimer_is_queued(timer)) {
if (!dl_server(dl_se))
get_task_struct(dl_task_of(dl_se));
hrtimer_start(timer, act, HRTIMER_MODE_ABS_HARD);
}
return 1;
}

When the stale timer fires at the old period boundary, dl_task_timer()
replenishes and unthrottles the task before its new period ends.

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