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=1796310009; b=0CKqmKUN9opJDNwuI/bCDP6qqsTjgBj5sfBEZ4pyaGaYeME7najMNvcGeX9I5gNMEDmZ Pg2GGoUcPvo7aZehxaFajIiTz0idZrRSj7yNzdmGtlw6jcMJ1jfVusxoE/MrKZNj6t7GS wRXzX9X950Q3rc5veNy3H6RY36hLpBf/mf0kawyHAAOSSY8U6VmDlK9HXPv5r7+5ncW6k JhnbLC4fdRlknG0vTnNnRYkibWAzkQWdj6OVe+Hosx85BnHSf2Qro6K55qjVZA4mMtOKH snxrGT/aH2raugVFFRDpbuQ7AGpGcEyUbbFnr3PSFdLpGcZyKeRq7HWXjhXh0wh6yGQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796310009; 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=2WJKvJM64zTFrxbNhALsSL+5EsIdljh5SNomEPw2rnE=; b=xLPsRcnGRAju6dId9wCnl8A2C28KTvJEz+MVFm1kKQETtLGzsh7OozkAidB4G6AIl2tM zqIVQTsl7xNCYWQIa9gnlPuR4UZ3eLqUJe37v/EB4Qt5NLJegQagq27yzda4dNyTDzgIk nKUOVFBGvOgwqf7sKkqCM72GS+qQxq744jOjC0lfcn1wQbAsxnLVlnf6vscypWmxRHCs8 p4mx5LNTitHCPc9qectoNGFeG/NGoBn+cGlD98veSNNrvKg4VCB0a2XK6qxLW0amS3/ee CsAGOBEfzxmj9kxXYwLOEleB0YGKi2rzOVnBxOMYUKYmuVTCpkjkBBUS+oKPsfnU2FA== 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=SKJMPUns; 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 15FB0606AC56; Thu, 3 Dec 2026 15:00:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 15FB0606AC56 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=SKJMPUns DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=smtpout1; t=1796310008; bh=2WJKvJM64zTFrxbNhALsSL+5EsIdljh5SNomEPw2rnE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SKJMPUns+nTzqiDkULHvbYBVqhOFgkqzxzx9XE99Xaq95T9dqI2wjMUtjrmYszL9i V13xwi/jR1FTTN36km+ki+3gYYMBVasY3mUkrN5vL8q3kcvBPx/+1dmOA+hrkrBOe8 i6GvVDEQAh3YSjMEoRHOrQqsccZO8tKW87txfpDaaKI08cfz/ijdiRl0Wld70aX9cs SB1wW9PuLU6u9qYwrE7r9/D1dOgNcyFJ6PyJctt8oc3Wy91iu2x2p5zo4Dg8AwexPg 2cJP4C2iKbfRPtK3tv5TPKLwEaU2erLCFLqQMHCyZjzi6RpBXzuRD06wfrWM+yum9h NzUMLYW1qPL1Q== Received: from thinkos.internal.efficios.com (unknown [IPv6:2605:8d80:7180:6739:ac39:5d4:4093:61c6]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4jgHqB4Q8dzZqw; Thu, 03 Dec 2026 10:00:06 -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, anna-maria@linutronix.de, frederic@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 v14 37/39] sched/deadline: Warn when a runqueue keeps the bandwidth of a task Date: Thu, 3 Dec 2026 09:58:51 -0500 Message-ID: <971ed46848b9e82355ccaf53bd20f0736ec885c3.1796296314.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 1eba22b9010b..6243f8df898b 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -870,6 +870,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_release_params(dl_se); @@ -2788,6 +2790,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_release_params(dl_se); -- 2.47.3