Re: [PATCH v6 08/37] sched/deadline: Do not replenish a boost from cleared parameters

From: sashiko-bot

Date: Mon Nov 16 2026 - 14:42:19 EST


Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] sched/deadline: torn donor parameter reads in
replenish_dl_entity()
- [Medium] sched/deadline: unreset negative runtime in
replenish_dl_entity()
- [Medium] sched/deadline: zero deadline in replenish_dl_entity() on
initial boost
--

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

sched/deadline: Do not replenish a boost from cleared parameters

This commit avoids an infinite loop in replenish_dl_entity() when a
boosted entity's donor has left SCHED_DEADLINE and had its parameters
cleared before the priority inheritance chain walk deboosts the owner.

Link: https://lore.kernel.org/all/avL8oOtjKqVNR7-l@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/

> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index e4d7cbf4861de..c4ea510599415 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -807,8 +807,26 @@ static void replenish_dl_entity(struct sched_dl_entity *dl_se)
> {
> struct dl_rq *dl_rq = dl_rq_of_se(dl_se);
> struct rq *rq = rq_of_dl_rq(dl_rq);
> + struct sched_dl_entity *pi_se = pi_of(dl_se);
> + u64 runtime = READ_ONCE(pi_se->dl_runtime);
> + u64 deadline = READ_ONCE(pi_se->dl_deadline);
> + u64 period = READ_ONCE(pi_se->dl_period);

[Severity: Medium]
Can replenish_dl_entity() observe a non-zero runtime alongside a zeroed
deadline or period when racing with __dl_clear_params()?

__dl_clear_params() zeroes dl_runtime, dl_deadline and dl_period in that
same order under the donor's rq lock without ordering barriers:

CPU0 (boosted owner) CPU1 (donor)
replenish_dl_entity()
runtime = READ_ONCE(pi_se->dl_runtime)
inactive_task_timer()
__dl_clear_params()
dl_se->dl_runtime = 0
dl_se->dl_deadline = 0
dl_se->dl_period = 0
deadline = READ_ONCE(pi_se->dl_deadline) <-- reads 0
period = READ_ONCE(pi_se->dl_period) <-- reads 0

Because only !runtime is checked below, replenish_dl_entity() proceeds
with runtime > 0 and deadline == 0 or period == 0. A boosted non-deadline
task gets dl_se->deadline set to rq_clock(rq) + 0, while a boosted
SCHED_DEADLINE task has runtime added in the while (dl_se->runtime <= 0)
loop without advancing dl_se->deadline. If dl_se->deadline is then in the
past, the lag check emits a false "sched: DL replenish lagged too much"
warning and calls replenish_dl_new_period(), which re-reads
pi_of(dl_se)->dl_deadline and pi_of(dl_se)->dl_runtime directly and sets
dl_se->runtime to 0.

> - WARN_ON_ONCE(pi_of(dl_se)->dl_runtime <= 0);
> + /*
> + * A boosted entity runs on the parameters of its donor, the top
> + * waiter of an rt_mutex. The donor can leave the class and have them
> + * cleared before the chain walk deboosts this entity. They are
> + * cleared under the donor's rq lock, which can be another one. So
> + * read each of them once. Refilling from a runtime of 0 would loop
> + * forever. Leave the entity runnable instead: the walk deboosts it,
> + * or its task releases the lock.
> + */
> + if (unlikely(!runtime)) {
> + WARN_ON_ONCE(!is_dl_boosted(dl_se));
> + dl_se->dl_yielded = 0;
> + dl_se->dl_throttled = 0;
> + return;
> + }

[Severity: Medium]
Does returning here without resetting dl_se->runtime leave the entity with
an accumulating negative runtime?

When a boosted task exhausts its runtime after the donor's parameters are
cleared, dl_se->runtime remains <= 0 across this early return. Every
subsequent tick in update_curr_dl_se() subtracts delta_exec from
dl_se->runtime, sees dl_runtime_exceeded(dl_se), sets dl_se->dl_overrun
(sending repeated SIGXCPU signals if SCHED_FLAG_DL_OVERRUN is enabled),
and re-enters enqueue_task_dl() -> replenish_dl_entity().

With the follow-up commit "sched/deadline: Reset the donor's runtime at a
deboost in the class", this return also happens before
dl_note_donor_refill(dl_se). If a SCHED_DEADLINE owner had not been
refilled from the donor before the donor's parameters were cleared,
dl_donor_refill stays 0 and dl_deboost() does not reset dl_se->runtime;
when dl_se->deadline is still in the future at deboost, the negative
runtime is charged against the owner's own periods on its next replenish,
or pushes zerolag_time past dl_se->deadline in task_non_contending() if
the owner blocks first.

[Severity: Medium]
Can this early return also leave dl_se->deadline at 0 when a runnable
non-deadline task is first boosted into SCHED_DEADLINE?

When rt_mutex_setprio() boosts a runnable non-deadline task whose
dl_se->deadline is 0, it sets ENQUEUE_REPLENISH and calls
enqueue_task_dl() -> enqueue_dl_entity() -> replenish_dl_entity(). If the
donor's parameters were already cleared (for example after
normalize_rt_tasks(), or before a multi-hop PI chain walk finishes
deboosting an intermediate lock owner), replenish_dl_entity() returns here
before the dl_se->dl_deadline == 0 branch initializes dl_se->deadline.

__enqueue_dl_entity() then calls inc_dl_deadline() with deadline == 0:

kernel/sched/deadline.c:inc_dl_deadline() {
if (dl_rq->earliest_dl.curr == 0 ||
dl_time_before(deadline, dl_rq->earliest_dl.curr)) {
if (dl_rq->earliest_dl.curr == 0)
cpupri_set(&rq->rd->cpupri, rq->cpu, CPUPRI_HIGHER);
dl_rq->earliest_dl.curr = deadline;
cpudl_set(&rq->rd->cpudl, rq->cpu, deadline);
}
}

Because dl_rq->earliest_dl.curr == 0 is the sentinel for an empty dl_rq,
enqueuing a subsequent deadline task with a later deadline overwrites
dl_rq->earliest_dl.curr and cpudl, hiding earlier deadlines on this rq
from cross-CPU deadline balancing.

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