From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: juri.lelli@redhat.com, peterz@infradead.org, mingo@redhat.com,
vincent.guittot@linaro.org
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
tglx@kernel.org, will@kernel.org, boqun@kernel.org,
dietmar.eggemann@arm.com, rostedt@goodmis.org,
bsegall@google.com, mgorman@suse.de, vschneid@redhat.com,
kprateek.nayak@amd.com, luca.abeni@santannapisa.it,
tommaso.cucinotta@gmail.com, mathieu.poirier@linaro.org,
longman@redhat.com, ridong.chen@linux.dev, tj@kernel.org,
hannes@cmpxchg.org, mkoutny@suse.com, shuah@kernel.org,
bigeasy@linutronix.de, clrkwllms@kernel.org,
parri.andrea@gmail.com, m.szyprowski@samsung.com,
kayracizmeci@gmail.com, weihengqiuu@gmail.com,
linux-kernel@vger.kernel.org, cgroups@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-rt-devel@lists.linux.dev,
oleg@redhat.com, brauner@kernel.org, stable@vger.kernel.org
Subject: [PATCH v13 33/36] sched/deadline: Keep a reaped deadline task in a rebuild
Date: Tue, 1 Dec 2026 12:44:27 -0500 [thread overview]
Message-ID: <3edb25262589e32cd881312999f521f9bab9d910.1796146461.git.mathieu.desnoyers@efficios.com> (raw)
In-Reply-To: <cover.1796146461.git.mathieu.desnoyers@efficios.com>
A rebuild of the root domains' accounting counts tasks from two places:
dl_departed_list, and the task list. The walk of the task list counts a
dying deadline task until its last schedule. That schedule releases the
bandwidth, or puts the task on dl_departed_list until its 0-lag time.
But release_task() can take a task off the task list before its last
schedule. A thread other than the group leader reaps itself in
exit_notify(). A parent can reap a zombie child while the child still
runs. A rebuild in that window finds the task in neither place, and
drops its bandwidth. total_bw then misses it until the last schedule,
or until the 0-lag time if that is later. Meanwhile, sched_setattr()
would admit tasks beyond the capacity of the root domain.
Fix this by putting such a task on dl_departed_list from release_task(),
in the new dl_task_unhash(). It runs under tasklist_lock, before the
task leaves the task list, so no walk runs in between. A rebuild then
counts the task with the departed tasks. Its last schedule releases the
bandwidth and takes it off the list, or leaves both to the inactive
timer.
A reap after dl_clear_root_domains() and before the walk is covered by
"sched/deadline: Count a task that departs while a rebuild walks the
tasks". dl_task_depart() counts the task then, as the walk would have.
A boost back into the class takes a task off the list, in
dl_task_undepart(). Keep a task that has exited on it: it may be off the
task list already.
A Spin model of the accounting found this case. It was not reproduced:
the window from release_task() to the last schedule is short. With this
fix and the one named above, the model finds no error for two tasks and
one root domain.
Fixes: f9a25f776d78 ("cpusets: Rebuild root domain deadline accounting information")
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: stable@vger.kernel.org
---
include/linux/sched/deadline.h | 1 +
kernel/exit.c | 2 ++
kernel/sched/deadline.c | 37 +++++++++++++++++++++++++++++-----
3 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/include/linux/sched/deadline.h b/include/linux/sched/deadline.h
index bb8c9c1cae5b..1b245fbb31a8 100644
--- a/include/linux/sched/deadline.h
+++ b/include/linux/sched/deadline.h
@@ -36,6 +36,7 @@ extern void dl_clear_root_domains(void);
extern void dl_bw_rebuild_begin(void);
extern void dl_rebuild_rd_accounting(void);
extern bool dl_task_holds_bw(struct task_struct *p);
+extern void dl_task_unhash(struct task_struct *p);
/*
* Keep a rebuild of the root domains' accounting and an admission of
* bandwidth from running at the same time. With cpusets, cpuset_mutex
diff --git a/kernel/exit.c b/kernel/exit.c
index d5e7bc2af804..1656b4d1b661 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -13,6 +13,7 @@
#include <linux/sched/task.h>
#include <linux/sched/task_stack.h>
#include <linux/sched/cputime.h>
+#include <linux/sched/deadline.h>
#include <linux/interrupt.h>
#include <linux/module.h>
#include <linux/capability.h>
@@ -264,6 +265,7 @@ void release_task(struct task_struct *p)
write_lock_irq(&tasklist_lock);
ptrace_release_task(p);
+ dl_task_unhash(p);
__exit_signal(&post, p);
/*
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index d84a459e7a64..e759e4f27cc7 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -253,10 +253,11 @@ __dl_overflow(struct dl_bw *dl_b, unsigned long cap, u64 old_bw, u64 new_bw)
* harmless.
*
* A rebuild drops the bandwidth when the CPU recorded is no longer
- * active. It also drops the bandwidth of a task that release_task()
- * took off the task list, if its last schedule comes after the walk.
- * The walk does not find that task, and it was not on the departed
- * list when the list was put back.
+ * active.
+ *
+ * release_task() can take a task off the task list before its last
+ * schedule. The walk would then miss it. So dl_task_unhash() puts a
+ * reaped deadline task on the list, while it is still in the class.
*
* A task can also depart after the list was put back, and before the
* walk reaches it. Priority inheritance can deboost it, or it can die.
@@ -442,6 +443,27 @@ static void dl_task_depart(struct task_struct *p)
list_add(&dl_se->dl_departed_node, &dl_departed_list);
}
+/*
+ * Put @p on dl_departed_list if it is a deadline task with a bandwidth.
+ * release_task() calls this before it takes @p off the task list, so
+ * that a rebuild still counts @p until its last schedule. That schedule,
+ * or the inactive timer after it, takes @p off the list. The caller holds
+ * tasklist_lock for writing: no walk of the task list runs meanwhile.
+ */
+void dl_task_unhash(struct task_struct *p)
+{
+ struct rq_flags rf;
+ struct rq *rq;
+
+ lockdep_assert_held_write(&tasklist_lock);
+ if (!READ_ONCE(p->dl.dl_bw))
+ return;
+ rq = task_rq_lock(p, &rf);
+ if (dl_task(p) && dl_task_holds_bw(p))
+ dl_task_depart(p);
+ task_rq_unlock(rq, p, &rf);
+}
+
/*
* Take @p off dl_departed_list. @p comes back to the deadline class, and
* its bandwidth is that of a deadline task again. @cpu is the CPU of @p.
@@ -462,7 +484,12 @@ static void dl_task_undepart(struct task_struct *p, int cpu)
if (list_empty(&dl_se->dl_departed_node))
return;
guard(raw_spinlock)(&dl_departed_lock);
- list_del_init(&dl_se->dl_departed_node);
+ /*
+ * Keep a task that has exited on the list. It may be off the task list
+ * already (dl_task_unhash()), and a rebuild must still count it.
+ */
+ if (!p->exit_state)
+ list_del_init(&dl_se->dl_departed_node);
if (dl_se->dl_bw_gen != dl_bw_gen && !dl_bw_move_blocked(p) &&
cpu_active(cpu))
dl_task_count_bw(p, cpu);
--
2.47.3
next prev parent reply other threads:[~2026-12-01 17:44 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 17:43 [PATCH v13 00/36] sched/deadline: bandwidth accounting fixes and selftests Mathieu Desnoyers
2026-12-01 17:43 ` [PATCH v13 01/36] sched/deadline: Hold a reference on the deadline donor of a boosted task Mathieu Desnoyers
2026-12-01 17:43 ` [PATCH v13 02/36] sched/deadline: Replenish a throttled task boosted while asleep Mathieu Desnoyers
2026-12-01 17:43 ` [PATCH v13 03/36] sched/deadline: Do not truncate a bandwidth to 32 bits in __dl_add/sub() Mathieu Desnoyers
2026-12-01 17:43 ` [PATCH v13 04/36] sched/deadline: Count the 0-lag time from the next period Mathieu Desnoyers
2026-12-01 17:43 ` [PATCH v13 05/36] sched/deadline: Keep a departing constrained task until its " Mathieu Desnoyers
2026-12-01 18:17 ` sashiko-bot
2026-12-01 17:44 ` [PATCH v13 06/36] sched/deadline: Keep departing bandwidth across a root domain rebuild Mathieu Desnoyers
2026-12-01 18:20 ` sashiko-bot
2026-12-01 17:44 ` [PATCH v13 07/36] sched/deadline: Rebuild the root domains' accounting from the task list Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 08/36] sched/deadline: Record the root domain holding a task's bandwidth Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 09/36] sched/deadline: Leave a dying task out of a rebuild of the accounting Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 10/36] selftests/sched: Test SCHED_DEADLINE bandwidth across a root domain rebuild Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 11/36] selftests/sched: Test the root domain rebuild in deadline_bw_test Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 12/36] sched/deadline: Move a task's bandwidth only where room was made Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 13/36] cgroup/cpuset: Wait for an attach before rebuilding the sched domains Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 14/36] sched: Make deadline policy and affinity changes wait for a cpuset attach Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 15/36] cgroup/cpuset: Give back the bandwidth an attach did not move Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 16/36] cgroup/cpuset: Reserve the bandwidth in the root domain a task moves to Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 17/36] selftests/sched: Test cpuset moves in deadline_bw_test Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 18/36] sched/deadline: Make a rebuild count a task in the root domain it runs in Mathieu Desnoyers
2026-12-01 19:11 ` sashiko-bot
2026-12-01 17:44 ` [PATCH v13 19/36] sched/deadline: Move a task's bandwidth to " Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 20/36] sched/deadline: Keep a task in the root domain that counts its bandwidth Mathieu Desnoyers
2026-12-01 19:02 ` sashiko-bot
2026-12-01 17:44 ` [PATCH v13 21/36] sched/deadline: Keep the last CPU a task has in its root domain Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 22/36] cgroup/cpuset: Refuse to take a deadline task out of " Mathieu Desnoyers
2026-12-01 19:29 ` sashiko-bot
2026-12-01 17:44 ` [PATCH v13 23/36] selftests/sched: Test the root domain of a task in deadline_bw_test Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 24/36] sched/deadline: Count only active CPUs when spreading extra_bw Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 25/36] sched/deadline: Cancel the replenishment timer with the parameters Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 26/36] sched/deadline: Cap the runtime left of a constrained task at dl_runtime Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 27/36] sched/deadline: Check the runtime of a task that comes back runnable Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 28/36] sched/deadline: Record the start of the period Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 29/36] sched/deadline: Keep the debt of a task across a change of parameters Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 30/36] selftests/sched: Test parameter changes in deadline_bw_test Mathieu Desnoyers
2026-12-01 19:34 ` sashiko-bot
2026-12-01 17:44 ` [PATCH v13 31/36] sched/deadline: Count a task that departs while a rebuild walks the tasks Mathieu Desnoyers
2026-12-01 19:41 ` sashiko-bot
2026-12-01 17:44 ` [PATCH v13 32/36] sched/deadline: Count again a departed task that a boost brings back Mathieu Desnoyers
2026-12-01 19:47 ` sashiko-bot
2026-12-01 17:44 ` Mathieu Desnoyers [this message]
2026-12-01 19:57 ` [PATCH v13 33/36] sched/deadline: Keep a reaped deadline task in a rebuild sashiko-bot
2026-12-01 17:44 ` [PATCH v13 34/36] sched/deadline: Warn when a runqueue keeps the bandwidth of a task Mathieu Desnoyers
2026-12-01 17:44 ` [PATCH v13 35/36] selftests/sched: Test PI against hotplug and rebuilds in deadline_bw_test Mathieu Desnoyers
2026-12-01 19:51 ` sashiko-bot
2026-12-01 17:44 ` [PATCH v13 36/36] selftests/sched: Share the helpers of the deadline tests Mathieu Desnoyers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3edb25262589e32cd881312999f521f9bab9d910.1796146461.git.mathieu.desnoyers@efficios.com \
--to=mathieu.desnoyers@efficios.com \
--cc=bigeasy@linutronix.de \
--cc=boqun@kernel.org \
--cc=brauner@kernel.org \
--cc=bsegall@google.com \
--cc=cgroups@vger.kernel.org \
--cc=clrkwllms@kernel.org \
--cc=dietmar.eggemann@arm.com \
--cc=hannes@cmpxchg.org \
--cc=juri.lelli@redhat.com \
--cc=kayracizmeci@gmail.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=longman@redhat.com \
--cc=luca.abeni@santannapisa.it \
--cc=m.szyprowski@samsung.com \
--cc=mathieu.poirier@linaro.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=mkoutny@suse.com \
--cc=oleg@redhat.com \
--cc=parri.andrea@gmail.com \
--cc=peterz@infradead.org \
--cc=ridong.chen@linux.dev \
--cc=rostedt@goodmis.org \
--cc=shuah@kernel.org \
--cc=stable@vger.kernel.org \
--cc=tglx@kernel.org \
--cc=tj@kernel.org \
--cc=tommaso.cucinotta@gmail.com \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=weihengqiuu@gmail.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®