Re: [PATCH v6 10/37] sched/deadline: Reset the donor's runtime at a deboost in the class
From: sashiko-bot
Date: Mon Nov 16 2026 - 14:38:19 EST
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] sched/deadline: implicit declaration of
dl_note_donor_refill()
- [Medium] sched/deadline: rt_mutex_setprio() skips dl_deboost() on
donor change
- [Medium] sched/deadline: donor runtime kept when leaving
dl_sched_class
- [Medium] sched/deadline: missing dl_note_donor_refill() on cleared
donor
- [Low] sched/deadline: __dl_clear_params() fails to clear
dl_donor_refill
--
commit 25ef3546a7248ed2f828d8c39dc34ecf7474dcc4
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 struct sched_dl_entity to track
when a priority-inherited SCHED_DEADLINE task has been replenished from its
donor's reservation, resetting its period on in-class deboost.
> 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]
When a SCHED_DEADLINE task was refilled from an earlier donor and now switches
to a new top waiter pi_task, doesn't the outer dl_entity_preempt(&pi_task->dl,
&p->dl) check compare pi_task against the old donor's postponed deadline
before dl_deboost() can reset p->dl to its own reservation?
If the first donor's refill pushed p->dl.deadline past pi_task->dl.deadline,
rt_mutex_setprio() takes the first branch and skips dl_deboost(). Because
p->dl.dl_deadline is non-zero and p->dl.runtime > 0, replenish_dl_entity()
leaves the first donor's remaining runtime and postponed deadline in place
after the unlock. Calling dl_deboost(&p->dl) unconditionally when
dl_prio(p->normal_prio) before testing dl_entity_preempt(&pi_task->dl, &p->dl)
would reset the period first and then boost from the new waiter if needed.
> } 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]
What happens if a task with its own deadline parameters (p->dl.dl_runtime != 0)
is refilled from a donor and then leaves dl_sched_class at deboost, for
instance after changing its policy via sched_setattr() while boosted (or being
boosted again before its 0-lag timer fires)?
sched_change_begin() runs switched_from_dl() before dl_drop_boost() clears
dl_donor_refill, and switched_from_dl() only resets deadline and runtime when
!p->dl.dl_runtime:
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;
}
}
task_non_contending() then computes zerolag_time from the donor's refilled
deadline and runtime combined with p's own dl_period and dl_runtime. If the
donor's remaining runtime makes zerolag_time negative, task_non_contending()
immediately clears p's parameters even though p already exhausted its own
budget in this period; otherwise p keeps the donor's runtime and deadline
with dl_donor_refill cleared if it returns to SCHED_DEADLINE before the
inactive timer fires.
> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index dd48f74412b87..1f3da0e0a698c 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -93,6 +93,38 @@ static inline bool is_dl_boosted(struct sched_dl_entity *dl_se)
> {
> return pi_of(dl_se) != dl_se;
> }
> +
> +/*
> + * Record that @dl_se had its runtime refilled from the parameters of its
> + * donor, if it is boosted.
> + */
> +static inline void dl_note_donor_refill(struct sched_dl_entity *dl_se)
> +{
> + if (is_dl_boosted(dl_se))
> + dl_se->dl_donor_refill = 1;
> +}
> +
> +/*
> + * End the boost of @dl_se, whose task stays in the class. If the boost
> + * refilled its runtime from the donor's parameters, start a new period
> + * now. The next enqueue is too late for a task blocked on another
> + * rt_mutex: the chain walk copies its deadline into its waiter node
> + * first. Without a refill, the task keeps the runtime and the deadline
> + * of its own reservation.
> + *
> + * The caller holds the rq lock and the pi_lock of the task, and has
> + * updated the rq clock.
> + */
> +void dl_deboost(struct sched_dl_entity *dl_se)
> +{
> + struct rq *rq = rq_of_dl_se(dl_se);
> +
> + if (dl_se->dl_donor_refill) {
> + dl_se->deadline = rq_clock(rq) + dl_se->dl_deadline;
> + dl_se->runtime = dl_se->dl_runtime;
> + }
> + dl_drop_boost(dl_se);
> +}
> #else /* !CONFIG_RT_MUTEXES: */
> static inline struct sched_dl_entity *pi_of(struct sched_dl_entity *dl_se)
> {
[Severity: Medium]
Does this break the build when CONFIG_RT_MUTEXES is disabled?
dl_note_donor_refill() is defined inside #ifdef CONFIG_RT_MUTEXES with no
stub in the #else branch, but replenish_dl_new_period() and
replenish_dl_entity() call it unconditionally.
[ ... ]
> @@ -842,11 +875,15 @@ static void replenish_dl_entity(struct sched_dl_entity *dl_se)
> (dl_se->dl_defer_armed && dl_entity_overflow(dl_se, rq_clock(rq)))) {
> dl_se->deadline = rq_clock(rq) + deadline;
> dl_se->runtime = runtime;
> + dl_note_donor_refill(dl_se);
> }
>
> if (dl_se->dl_yielded && dl_se->runtime > 0)
> dl_se->runtime = 0;
>
> + if (dl_se->runtime <= 0)
> + dl_note_donor_refill(dl_se);
> +
[Severity: Medium]
Should the early return when !runtime earlier in replenish_dl_entity() also
call dl_note_donor_refill(dl_se)?
kernel/sched/deadline.c:replenish_dl_entity() {
if (unlikely(!runtime)) {
WARN_ON_ONCE(!is_dl_boosted(dl_se));
dl_se->dl_yielded = 0;
dl_se->dl_throttled = 0;
return;
}
}
When a donor leaves the class and its parameters are cleared before the lock
owner is deboosted, this path keeps the owner runnable after it exhausted its
runtime, and update_curr_dl_se() continues driving dl_se->runtime negative.
Without dl_donor_refill set, dl_deboost() will not start a new period and the
boosted execution is charged against the owner's own reservation (or leaves
deadline at 0 if the owner entered SCHED_DEADLINE while boosted).
> diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
> index 92134ce326a49..d87296abec4c2 100644
> --- a/kernel/sched/sched.h
> +++ b/kernel/sched/sched.h
> @@ -356,6 +356,16 @@ extern int sched_dl_global_validate(void);
> extern void sched_dl_do_global(void);
> extern int sched_dl_overflow(struct task_struct *p, int policy, const struct sched_attr *attr);
> extern void __setparam_dl(struct task_struct *p, const struct sched_attr *attr);
> +#ifdef CONFIG_RT_MUTEXES
> +extern void dl_deboost(struct sched_dl_entity *dl_se);
> +
> +/* End the boost of @dl_se. The caller holds the rq lock of its task. */
> +static inline void dl_drop_boost(struct sched_dl_entity *dl_se)
> +{
> + dl_se->pi_se = dl_se;
> + dl_se->dl_donor_refill = 0;
> +}
> +#endif
[Severity: Low]
Should __dl_clear_params() also clear dl_donor_refill (or call
dl_drop_boost()) instead of only setting dl_se->pi_se = dl_se?
kernel/sched/deadline.c:__dl_clear_params() {
...
dl_se->dl_defer_running = 0;
dl_se->dl_defer_armed = 0;
#ifdef CONFIG_RT_MUTEXES
dl_se->pi_se = dl_se;
#endif
}
If a task forks while boosted and refilled by a donor, dup_task_struct()
copies dl_donor_refill = 1 into the child and __sched_fork() ->
init_dl_entity() -> __dl_clear_params() leaves it set, which would cause an
unintended period reset if the child later becomes SCHED_DEADLINE and passes
through dl_deboost().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116190549.230119-1-mathieu.desnoyers@xxxxxxxxxxxx?part=10