[PATCH v14 06/39] sched/deadline: Admit a returning task without the bandwidth it holds

From: Mathieu Desnoyers

Date: Thu Dec 03 2026 - 09:59:35 EST


A task that leaves SCHED_DEADLINE keeps its bandwidth in total_bw until
its 0-lag time. If it comes back before then, sched_dl_overflow()
removes that old bandwidth and adds the new one. But its admission
check passes 0 as the old bandwidth:

if (dl_policy(policy) && !task_has_dl_policy(p) &&
!__dl_overflow(dl_b, cap, 0, new_bw)) {

So the new bandwidth must fit on top of the old one. The check for a
task that stays in the class does leave the old bandwidth out. When the
root domain has no room for both, sched_setattr() returns EBUSY to a
task that leaves and comes back with the same parameters.

Fix this by passing the old bandwidth to __dl_overflow() when the
inactive timer is active. This is the same condition as the one for
removing it.

The params_return_full case, which "selftests/sched: Test parameter
changes in deadline_bw_test" adds later in this series, tests this.

Fixes: 387e31300b57 ("sched/deadline: Fix the update of the total -deadline utilization")
Reported-by: Juri Lelli <juri.lelli@xxxxxxxxxx>
Closes: https://lore.kernel.org/all/axAxdNEE1Q2OuxNQ@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
---
kernel/sched/deadline.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index 0afcb7b53bc4..26b02ae8683a 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -3959,6 +3959,7 @@ int sched_dl_overflow(struct task_struct *p, int policy,
u64 period = attr->sched_period ?: attr->sched_deadline;
u64 runtime = attr->sched_runtime;
u64 new_bw = dl_policy(policy) ? to_ratio(period, runtime) : 0;
+ u64 old_bw;
int cpus, err = -1, cpu = task_cpu(p);
struct dl_bw *dl_b = dl_bw_of(cpu);
unsigned long cap;
@@ -3979,10 +3980,18 @@ int sched_dl_overflow(struct task_struct *p, int policy,
cpus = dl_bw_cpus(cpu);
cap = dl_bw_capacity(cpu);

+ /*
+ * A task that comes back before its 0-lag time still holds the
+ * bandwidth it left with. The new bandwidth replaces it, so leave
+ * the old one out of the check, as for a task that stays in the
+ * class.
+ */
+ old_bw = hrtimer_active(&p->dl.inactive_timer) ? p->dl.dl_bw : 0;
+
if (dl_policy(policy) && !task_has_dl_policy(p) &&
- !__dl_overflow(dl_b, cap, 0, new_bw)) {
- if (hrtimer_active(&p->dl.inactive_timer))
- __dl_sub(dl_b, p->dl.dl_bw, cpus);
+ !__dl_overflow(dl_b, cap, old_bw, new_bw)) {
+ if (old_bw)
+ __dl_sub(dl_b, old_bw, cpus);
__dl_add(dl_b, new_bw, cpus);
err = 0;
} else if (dl_policy(policy) && task_has_dl_policy(p) &&
--
2.47.3