Re: [PATCH v7 11/40] sched/deadline: Reset the donor's runtime at a deboost in the class

From: sashiko-bot

Date: Tue Nov 17 2026 - 09:55:30 EST


Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] sched/deadline: rt_mutex_setprio() skips dl_deboost() on
donor change
- [Medium] sched/deadline: donor runtime kept when leaving
dl_sched_class
- [Low] sched/deadline: missing dl_note_donor_refill() on cleared donor
in replenish_dl_entity()
--

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

sched/deadline: Reset the donor's runtime at a deboost in the class

This commit adds a dl_donor_refill flag to record when a boosted task has its
runtime replenished from a donor's reservation, and starts a new period from
the task's own parameters when the boost ends in the deadline class.

[ ... ]

> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 5ed660f099a55..a22df8b43a1a7 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -7834,16 +7834,26 @@ void rt_mutex_setprio(struct task_struct *p, struct task_struct *pi_task)
> p->dl.pi_se = pi_task->dl.pi_se;
> scope->flags |= ENQUEUE_REPLENISH;
> } else {
> - p->dl.pi_se = &p->dl;
> + dl_deboost(&p->dl);
> + /*
> + * dl_deboost() can start a new period. Its
> + * deadline can then be after the top waiter's.
> + * Boost the task again then.
> + */
> + if (pi_task && dl_prio(pi_task->prio) &&
> + dl_entity_preempt(&pi_task->dl, &p->dl)) {
> + p->dl.pi_se = pi_task->dl.pi_se;
> + scope->flags |= ENQUEUE_REPLENISH;
> + }
> }

[Severity: Medium]
Can a SCHED_DEADLINE task skip dl_deboost(&p->dl) here when switching from
one deadline donor to another?

In rt_mutex_setprio(), the outer if statement tests
dl_entity_preempt(&pi_task->dl, &p->dl) before calling dl_deboost(&p->dl).
When p was refilled from a previous donor W1, p->dl.deadline holds W1's
postponed deadline rather than p's own reservation deadline. If p unlocks
W1's lock while another deadline waiter W2 is queued on a lock held by p, and
W2->dl.deadline is earlier than W1's postponed deadline, the outer check
takes the first branch and skips dl_deboost(&p->dl).

Because p->dl.dl_deadline is non-zero and p->dl.runtime is still positive
from W1's refill, ENQUEUE_REPLENISH in replenish_dl_entity() does not reset
p->dl.runtime or p->dl.deadline either. p then keeps W1's leftover runtime
and postponed deadline, even if p's own new-period deadline would have been
earlier than W2->dl.deadline.

Calling dl_deboost(&p->dl) unconditionally when dl_prio(p->normal_prio)
before testing whether pi_task preempts &p->dl would compare pi_task against
p's own reservation.

> } else if (rt_prio(prio)) {
> if (dl_prio(oldprio))
> - p->dl.pi_se = &p->dl;
> + dl_drop_boost(&p->dl);
> if (oldprio < prio)
> scope->flags |= ENQUEUE_HEAD;
> } else {
> if (dl_prio(oldprio))
> - p->dl.pi_se = &p->dl;
> + dl_drop_boost(&p->dl);
> if (rt_prio(oldprio))
> p->rt.timeout = 0;
> }

[Severity: Medium]
Does a task that still has SCHED_DEADLINE parameters (p->dl.dl_runtime != 0)
keep the donor's refilled runtime and deadline when leaving the deadline
class at deboost?

A task can have p->dl.dl_runtime != 0 and p->dl.dl_donor_refill == 1 while
leaving dl_sched_class (for example, if it changed its policy away from
SCHED_DEADLINE while boosted and then unlocks, or if it left SCHED_DEADLINE
before its 0-lag time and was boosted and refilled before inactive_timer
fired). When it leaves dl_sched_class, sched_change_begin() runs
switched_from_dl() before dl_drop_boost(&p->dl) clears dl_donor_refill:

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;
}
}

Because p->dl.dl_runtime is non-zero, switched_from_dl() passes the donor's
refilled runtime and deadline to task_non_contending(), which mixes them with
p's own dl_period and dl_runtime to compute zerolag_time. If the donor's
remaining runtime makes zerolag_time negative, task_non_contending() clears
p's parameters immediately and lets p re-enter SCHED_DEADLINE with a fresh
budget in the same period; otherwise, p retains the donor's runtime and
deadline if it returns to SCHED_DEADLINE before inactive_timer fires.

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

[ ... ]

> @@ -832,6 +869,7 @@ static void replenish_dl_entity(struct sched_dl_entity *dl_se)
> if (!dl_se->dl_deadline) {
> dl_se->deadline = rq_clock(rq);
> dl_se->runtime = 0;
> + dl_note_donor_refill(dl_se);
> }
> if (dl_se->runtime < 0 || dl_se->dl_yielded)
> dl_se->runtime = 0;

[Severity: Low]
In this cleared-donor fallback (!runtime || !deadline || !period), should
dl_note_donor_refill(dl_se) also be called when dl_se->dl_deadline is
non-zero?

If a boosted SCHED_DEADLINE task hits this path when its runtime is exhausted
or after sched_yield(), replenish_dl_entity() zeroes dl_se->runtime and
clears dl_se->dl_throttled without setting dl_donor_refill. A subsequent
dl_deboost() then leaves the task in the class with runtime == 0,
dl_throttled == 0, and its old deadline.

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