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

From: Juri Lelli

Date: Wed Nov 18 2026 - 08:15:42 EST


Hello,

On 17/11/26 09:10, Mathieu Desnoyers wrote:
> When a SCHED_DEADLINE waiter boosts the owner of an rt_mutex, the owner
> runs on the waiter's parameters, through dl.pi_se. Commit 2d3d891d3344
> ("sched/deadline: Add SCHED_DEADLINE inheritance logic") calls this a
> temporary solution. The owner is never throttled. When its runtime runs
> out, replenish_dl_entity() refills it at once from the waiter's
> dl_runtime.
>
> The waiter can leave SCHED_DEADLINE before the chain walk deboosts the
> owner. Its parameters can be cleared in between, at its 0-lag time.
> replenish_dl_entity() then loops forever on a dl_runtime of 0. It
> holds the rq lock with interrupts off, so the owner's CPU locks up.
>
> O is a SCHED_OTHER task that holds the rt_mutex L. W is a SCHED_DEADLINE
> task. T is any other task:
>
> CPU 0 (O) CPU 1 (W) CPU 2 (T)
>
> locks L
> blocks on L
> rt_mutex_setprio(O, W)
> O->dl.pi_se = &W->dl
> sleeps
> task_non_contending()
> arms W's inactive timer
> sched_setscheduler(W)
> W leaves SCHED_DEADLINE
> task_rq_unlock(W)
> <W's inactive timer>
> inactive_task_timer()
> __dl_clear_params()
> W->dl.dl_runtime = 0
> <tick>
> update_curr_dl_se()
> enqueue_task_dl()
> replenish_dl_entity()
> runtime += W->dl.dl_runtime
> loops forever
> rt_mutex_adjust_pi(W)
> rt_mutex_setprio(O, W)
> spins on O's rq lock
>
> Fix this by reading the inherited runtime, deadline and period once, and
> by not refilling from cleared ones. They are cleared under the waiter's
> rq lock, not the owner's. So test all three. The owner stays runnable.
> It gets no runtime. A negative runtime is reset to 0: the owner's own
> reservation does not pay for the boost. An owner with no parameters of
> its own gets a deadline of now. A deadline of 0 would mark its dl_rq as
> empty. The wakeup of a boosted task already gives that deadline when its
> donor is cleared. The owner runs until the chain walk deboosts it, or
> until it releases the lock. That also covers sysrq-n:
> normalize_rt_tasks() changes the waiter without a chain walk. The
> warning stays for an entity that is not boosted.

The above paragraph is a bit hard to decipher. :)

Maybe something like the below?

---
Fix this by not refilling from cleared parameters. The donor's
parameters are cleared under the donor's rq lock, not the owner's, so
replenish_dl_entity() can see them change under it. Read dl_runtime,
dl_deadline and dl_period once, and bail out if any of them is 0.

On bailing out, the owner gets no new runtime, but stays runnable and
unthrottled. It runs until the chain walk deboosts it, or until it
releases the lock. Keeping it runnable also covers sysrq-n:
normalize_rt_tasks() changes the waiter without a chain walk, so a
throttled owner might never get to release the lock.

The bandwidth the owner consumed while boosted belongs to the donor, so
a negative runtime is reset to 0 rather than charged to the owner's own
reservation. An owner with no parameters of its own gets a deadline of
now. Its deadline must not stay 0: the dl_rq uses an earliest deadline
of 0 to mean that no deadline entity is queued (see inc_dl_deadline()).

Until the deboost (which should happen "soon enough"), such an owner
sorts first on its CPU's dl_rq and runs ahead of the other deadline
tasks there.

The warning is kept for an entity that is not boosted.
---

> The reset bounds the overrun. But a runtime of 0 still counts as
> exceeded. So until the deboost, update_curr_dl_se() still requeues the
> owner at each update. An owner with SCHED_FLAG_DL_OVERRUN still gets
> SIGXCPU.
>
> With a 300ms debug delay before rt_mutex_adjust_pi(), v7.4-rc2 locks
> up in 8-CPU VMs. A kernel with this patch does not.
>
> The Sashiko AI review of the third posting found the lockup. Juri Lelli
> suggested this fix in place of a larger one.

Also for other changelogs, I am not sure this kind of info adds much, as
I fear it will be hard to track down in history anyway.

> Fixes: a5e7be3b28a2 ("sched/deadline: Clear dl_entity params when setscheduling to different class")
> Suggested-by: Juri Lelli <juri.lelli@xxxxxxxxxx>
> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
> Cc: stable@xxxxxxxxxxxxxxx
> Link: https://lore.kernel.org/all/avL8oOtjKqVNR7-l@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/
> ---

For the implementation,

Reviewed-by: Juri Lelli <juri.lelli@xxxxxxxxxx>

Thanks,
Juri