From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=158.69.130.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796147085; b=Hmt6I756WCAV15FEglQnY6L3+fAxlu3Yzf9xFPk/37slNb+FQrNTvqvfPDH3B34gfiJt O1FPTzKEMz2SSicb9z4WxMPw9obknsWHJNVIMos3quXaT/Qkx3e5jRiskvd2fwoAdSXZg Za2UB50KOOpzTDNDEVEudkqhHosgctM24asBW9YQQt5ONK9Be1Hv4sFIVv10NUaEXR5sp tb7cRh4Gpnnj/j39fq59MwVBbOUghxr9EH1NX9dedHHUmTPfuPxoqzoz5VUO8OtG8zwXS 77gUmZ4RTh6lh1cMfEQTSccRXx9nhgxK/U7pji2vJeLrxOgaC890xxnlVYZyc3FPEWA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796147085; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=hoGe5pXYgrlIiNPT5A/dehgs88Hibd214jmK7RPNdj8=; b=jGsKu+2Czx2zjzrziR/juBo5X/ep7zX6KsD/1yi3rOju5JjQTasg4XKG4uQhDQUrN9NZ 9dvX9xIxRVrOcbvRTmziA8ATWoSxtw3/LUMZi3Ef201AAN7etxrPW5ehCEBbGzA74XJYB +TewVUZezK6BVVVsDmihLaoQysF4eMqEyRO82F/lQLS/uh/psuQLTFVEd80LPRuwakddW rg+VsZn7OgUmgwpuwY4SgjFUK4cKCCINGY4UEuvFqEYulnct6NDASNxX5X0+IWAf3EaRP m+WINL1/yv4yHAVjwpGiCaBtMzA+HEChkO8EZJtgpGMaZamj8e3sbXSPE6oIjTFf3NQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=efficios.com; spf=pass smtp.mailfrom=efficios.com; dkim=pass header.d=efficios.com header.i=@efficios.com header.a=rsa-sha256 header.s=smtpout1 header.b=wFTkABYB; arc=none smtp.remote-ip=158.69.130.18 Received: from smtpout.efficios.com (smtpout.efficios.com [158.69.130.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF56260A260D; Tue, 1 Dec 2026 17:44:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BF56260A260D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=efficios.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.a=rsa-sha256 header.s=smtpout1 header.b=wFTkABYB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=smtpout1; t=1796147079; bh=hoGe5pXYgrlIiNPT5A/dehgs88Hibd214jmK7RPNdj8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wFTkABYBu17v43sf705qWiBPJG+Cz7MFRanVcveWL9+4XugSVTFgVkVdz98m4YtC+ 40qyqF8o3vXqNqIsZ66I+2h71wyXvc9AYScwQ5CB2O39VT4BAX+lRmgcrQgLoDs0Ao m9Gxor+VmJZRGdfqqS4BF86+I/+B6hZF2DEagMWV8OaIoOX7g/OzT6SfJLKQR7Azxs 9yXCOvzoTmWY5FD8zy6PuEQwtIKchdGBT+f5kmxrcR5Ibd6P6RnvFBlOm9U9MY0Okf YzUFKxigbYnHBgeAxCY4Tx821B0r12ND5fm2SmX6OPxMboayYKmAUcaWgRrH51AT1a RcsHzSAy0Ak1Q== Received: from thinkos.internal.efficios.com (mtl.efficios.com [216.120.195.104]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4jf7Yz1YBMzYwF; Tue, 01 Dec 2026 12:44:39 -0500 (EST) From: Mathieu Desnoyers To: juri.lelli@redhat.com, peterz@infradead.org, mingo@redhat.com, vincent.guittot@linaro.org Cc: Mathieu Desnoyers , 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 Message-ID: <3edb25262589e32cd881312999f521f9bab9d910.1796146461.git.mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: References: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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 #include #include +#include #include #include #include @@ -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