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=PMsBEgJ39O2kMXeldYN1DrFb9G59Tijne7NOrdpHB7QIdRz2lflMCNod/Au7uV6MtEh/ yLUnM5ynZ65KcGZxec7uGO2l7DJJLciCQmcRIBuFEiDmqEpYDEg5IbrvjILgvl1SdTIDy cRhhQhg50o/+2YfIwvcW4Ubh3iEgCh5mxXHyPyWF/HU29VzBqj5BAB1XvDdqJNJ88T4E5 RibxeE/PZDs4V0/Ui+t7U6J8v52Tibb1HAcqV8qPSmU8bsVSI0Px69WtnLRaPSElsgLYm BvmSyzEFq8u7TnhytRnH3LfqSDEfDogpVCSlNCRsfnFjPWHrT5B8ZRAb3JU915VGlow== 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=3mw8gCQLFWm186e3z4L/2vVI0gcYGo3zrQif1APfiLc=; b=XbzpJKNGgltJAzvtZIn3/uN2Enj8I+qB63NPIDcfVTVkjUgjmFfrOh2lVPBCcJhVmwy4 1IdNbXjK/xFoxbNki83mFy4lP11ezOSFYnuHSqtscXtgn3AyYfhTHxX+3211E+A+560y7 qrWGyDslBmPn9oMGcdFJMeG3TlmCZ5VjosFJuPUcCssdv6fGaL2URtheh7JayiEm1gtCG l7RTg7HFD3qSMI5SzrjQWphHGy3pO+dvc1sTwpQtOT8ZWTq7dnfZ16t+dnmqavdMbzw+N nXuLYmUbvErpUFxrPu8kYZhQjro0/hwu1exMKW0bbq7t28jyfa3GilldH4mcJjRXyzA== 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="iTdQS/X5"; 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 1BC8F60A6F7D; Tue, 1 Dec 2026 17:44:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1BC8F60A6F7D 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=iTdQS/X5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=smtpout1; t=1796147079; bh=3mw8gCQLFWm186e3z4L/2vVI0gcYGo3zrQif1APfiLc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iTdQS/X5d1JQoyBM9RE5hVPen3Alp/mOWVrNAsoiv8CPuTbp8x7HgRRx4fvLQhJ/0 oc/09VmfgI33FbKnJSRaMpxw855oL/Vb7G0/NpBs/BBGr1zwHeIK1fRRXd4S/Qkem9 eYGyMlpxIY43RcuilNh53rkNUvJaq3CtPDHPeco2XOGcztqhNdb0ZZFzPI/Er0SeQ3 NTP4kI8eC9i6m7mgfmNjvUULCOKvum1FC6nYnsLfCqkZRffb/fVsA7KhPFakPY/4Pk JrJLH/EG/w1sx5GKlt1x14ijGTD6+fz6/1ux8dkFSwlDsPkSY63SG0sU1BpnNrz6JF GficurGa4MPsQ== Received: from thinkos.internal.efficios.com (mtl.efficios.com [216.120.195.104]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4jf7Yz2lm4zYXD; 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 Subject: [PATCH v13 34/36] sched/deadline: Warn when a runqueue keeps the bandwidth of a task Date: Tue, 1 Dec 2026 12:44:28 -0500 Message-ID: <7903f201509943f992c93dc914a03fdf80bbba9f.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 The this_bw of a runqueue counts the bandwidth of each task whose dl_bw_oncpu is set. add_rq_bw() sets the flag and sub_rq_bw() clears it. Two states would leave a bandwidth in this_bw for ever: - A task which left the deadline class still has its flag set, and moves to another CPU. Only the deadline class takes the bandwidth off the old runqueue: dequeue_task_dl() for a queued task, and migrate_task_rq_dl() for a waking one. So nothing takes it off. - task_non_contending() or inactive_task_timer() releases the bandwidth of a task while its flag is still set. They then call __dl_clear_params(), which clears both the flag and dl_bw. After that, nothing can take the bandwidth off the runqueue. Without a check, a test sees such a leak only later, as a this_bw which does not return to its starting value. It cannot tell which path leaked. Warn about the first state in set_task_cpu(). Warn about the second in task_non_contending() and inactive_task_timer(), before they call __dl_clear_params(). No warning fires in the selftests of this series. A review of the accounting code by an LLM suggested these checks. Signed-off-by: Mathieu Desnoyers --- kernel/sched/core.c | 3 +++ kernel/sched/deadline.c | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 2700c8e98b0e..879ac7d6cdfd 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -3517,6 +3517,9 @@ void set_task_cpu(struct task_struct *p, unsigned int new_cpu) */ WARN_ON_ONCE(!cpu_online(new_cpu)); + /* A task of another class would leave its bandwidth in this_bw. */ + WARN_ON_ONCE(!dl_task(p) && p->dl.dl_bw_oncpu); + /* * Proxy execution can move a blocked task's scheduling context to any * CPU without moving its migration-disabled execution context. The diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index e759e4f27cc7..8892523ada9d 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -904,6 +904,8 @@ static void task_non_contending(struct sched_dl_entity *dl_se, bool dl_task) if (!dl_task || READ_ONCE(p->__state) == TASK_DEAD) { if (dl_task && READ_ONCE(p->__state) == TASK_DEAD) sub_rq_bw(dl_se, &rq->dl); + /* No runqueue may still count dl_bw. */ + WARN_ON_ONCE(dl_se->dl_bw_oncpu); dl_task_release_bw(p); cancel_replenish_timer(dl_se); __dl_clear_params(dl_se); @@ -2848,6 +2850,8 @@ static enum hrtimer_restart inactive_task_timer(struct hrtimer *timer) dl_se->dl_non_contending = 0; } + /* No runqueue may still count dl_bw. */ + WARN_ON_ONCE(dl_se->dl_bw_oncpu); dl_task_release_bw(p); cancel_replenish_timer(dl_se); __dl_clear_params(dl_se); -- 2.47.3