[PATCH v4 11/17] sched/deadline: Release the bandwidth of a task that leaves the class asleep

From: Mathieu Desnoyers

Date: Thu Nov 19 2026 - 11:23:06 EST


A task that leaves SCHED_DEADLINE while it is not queued can keep its
bandwidth in total_bw until the next rebuild of the root domains.
Repeated, this fills total_bw up to the admission limit. Then
sched_setattr(SCHED_DEADLINE) and CPU offlining fail with EBUSY.

A task that leaves the class keeps its bandwidth until its 0-lag time.
Releasing it earlier would allow temporary overloads. For a queued task,
switched_from_dl() calls task_non_contending(). It releases the
bandwidth if the 0-lag time is past. Otherwise it arms the inactive
timer, which releases it then. For a task that is not queued,
switched_from_dl() relies on the timer armed when the task blocked.

But the timer is not always pending when the task leaves the class:
- The task blocked after its 0-lag time. The timer was not armed.
- The timer fired while the task was still in the class. It only
removed running_bw.
- The task was woken up on another CPU and is not enqueued there yet.
The wakeup cancelled the timer.
- The task came back to the class asleep. switched_to_dl() cancelled
the timer.

Then nothing releases total_bw.

Fix this in switched_from_dl(). For a task that is not queued and has
no timer pending, call task_non_contending(), as for a queued task. It
arms the timer if the 0-lag time is ahead. Otherwise it releases the
bandwidth now and clears the parameters, as inactive_task_timer() does.

Clearing the parameters keeps later paths from releasing the bandwidth
again:
- A timer handler that already started finds a dl_bw of 0.
- The deboost of a later priority inheritance boost finds no
parameters.

An owner that the task boosts as a waiter can find the parameters
cleared too. "sched/deadline: Do not replenish a boost from cleared
parameters" handles this, so a backport needs it first. Without it, the
owner's CPU can lock up as soon as the waiter leaves the class.

Before this patch, a task that left the class asleep kept its
parameters. That hid a bug of the rtmutex chain walk. The walk can stop
before the end of a chain. An owner then keeps as its donor a deadline
waiter that left the class. With this patch, the parameters of that
donor are cleared. Until the owner unlocks, each refill gives it no
runtime and a deadline of about now. This is the bail-out of
"sched/deadline: Do not replenish a boost from cleared parameters".
Other deadline tasks keep their bandwidth, but run late. Real-time and
fair tasks on that CPU could starve. The pi_chain_top_moves case of a
later series has the steps. With this patch, the case fails in every
run. It passes on v7.4-rc2. Two rtmutex fixes of that series make it
pass with this patch.

Juri Lelli's first fix, since dropped from tip, released the bandwidth
here without clearing dl_bw. The bandwidth of a boosted task was then
released twice.

Juri Lelli suggested the call to task_non_contending() in review.

The Sashiko AI review of this series found the two cases with the 0-lag
time ahead. deadline_switch_test, added later in this series, tests
the release in asleep_round_trip.

Fixes: 209a0cbda7a0 ("sched/deadline: Improve the tracking of active utilization")
Reported-by: Tejun Heo <tj@xxxxxxxxxx>
Closes: https://lore.kernel.org/all/2b5fb3f22bca6aa383be8f4781923392@xxxxxxxxxx/
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
Reviewed-by: Juri Lelli <juri.lelli@xxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
Link: https://lore.kernel.org/all/20261103-b4-sched-dl-bw-fixes-v1-2-dd761fe005b4@xxxxxxxxxx/
---
kernel/sched/deadline.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index 5e4aff28e9bc..bdeb2ecc9255 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -3620,6 +3620,14 @@ static void switched_from_dl(struct rq *rq, struct task_struct *p)
if (p->dl.dl_non_contending)
sub_running_bw(&p->dl, &rq->dl);
sub_rq_bw(&p->dl, &rq->dl);
+ /*
+ * Without an armed timer, nothing releases total_bw. Do as for
+ * a queued task: arm the timer if the 0-lag time is ahead, or
+ * release the bandwidth and clear the parameters now. Call
+ * task_non_contending() after sub_rq_bw(), which needs dl_bw.
+ */
+ if (!p->dl.dl_non_contending)
+ task_non_contending(&p->dl, false);
}

/*
--
2.47.3