[PATCH v8 04/33] sched/deadline: Leave a dying task out of a rebuild of the accounting

From: Mathieu Desnoyers

Date: Thu Nov 19 2026 - 15:17:13 EST


A rebuild of the root domains' accounting takes the pi_lock of each
deadline task, not its rq lock. A dying task past its 0-lag time
releases its bandwidth at its last schedule. It holds its rq lock there,
not its pi_lock. Then it clears dl_bw. The rebuild can find the task
between the two steps.

In this diagram, T is a deadline task that exits on CPU 0 past its 0-lag
time. bw is its dl_bw. CPU 1 rebuilds the accounting:

CPU 0 (T) CPU 1 (rebuild)

do_task_dead(): TASK_DEAD, under pi_lock
__schedule(): T's rq lock taken
task_non_contending(T)
dl_task_release_bw(T)
total_bw -= bw
dl_bw_gen recorded
record cleared
dl_rebuild_rd_accounting()
dl_clear_root_domains()
dl_bw_gen++
total_bw reset
dl_add_task_root_domain(T)
T's pi_lock taken
dl_bw != 0, dl_bw_gen old
total_bw += bw
__dl_clear_params(T): dl_bw = 0

dl_bw_gen does not help, since the release came before the rebuild. The
rebuild would count a bandwidth that nothing releases again. The root
domain would then refuse deadline tasks it has room for, until the next
rebuild.

Fix this with the record of the bandwidth, dl_bw_cpu. The release
clears it under dl_departed_lock, which the walk holds. So leave out a
dead task with no record. A dead task with a record has not reached its
last schedule. The walk counts it as a live task. That schedule then
releases the bandwidth, or puts the task on the departed list. A dead
task on the departed list keeps its bandwidth until its timer, and the
rebuild counts it as before.

This patch completes "sched/deadline: Rebuild the root domains'
accounting from the task list". The walk of that patch finds exiting
tasks, which the cpuset iterator skipped. The fix needs the record
that "sched/deadline: Record the root domain holding a task's
bandwidth" adds. The three go to stable together.

The Sashiko AI review of this series found this window. It also found a
gap in the first version of this fix. That version also left out a task
between TASK_DEAD and its last schedule, with its 0-lag time ahead.

Fixes: f9a25f776d78 ("cpusets: Rebuild root domain deadline accounting information")
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>
Reviewed-by: Juri Lelli <juri.lelli@xxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
---
kernel/sched/deadline.c | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index 5a8f38632e54..40d87cd31d33 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -3777,6 +3777,17 @@ void dl_add_task_root_domain(struct task_struct *p)
if (recorded < 0 || !cpu_active(recorded))
goto unlock;
cpu = recorded;
+ } else if (READ_ONCE(p->__state) == TASK_DEAD && p->dl.dl_bw_cpu < 0) {
+ /*
+ * Count nothing for a dead task with no record. Its last
+ * schedule released the bandwidth under its rq lock, and has
+ * not cleared dl_bw yet. The release clears the record under
+ * dl_departed_lock, which this walk holds. A dead task with a
+ * record has not reached its last schedule. Count it as a
+ * live task. That schedule then releases what the walk
+ * counted, or puts the task on the departed list.
+ */
+ goto unlock;
}
rq = cpu_rq(cpu);
dl_b = &rq->rd->dl_bw;
--
2.47.3