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=1796309952; b=PxPYhLRTqhcfV4MVk6qMnosgUb6HkNS4rQ3qHWYixQDndwtLHCGD84TCHMy+7N5EI8Rw KdJGB/PI/UWKnTgMlQELi8r/bZ0O4RB68cotkTSwL5AHhAyrDh44Qmi+cafCXe2N0dtKO XTY9lt/QAl310N1/1IwbpYVP1tPsVLLCIJ8tlZRABsKEzKogw6EOpKPL7/i//i9j3mFLD BddEXIdZwyjwuFl7/UwsHBmrBky+BXccYICu1SYV8h/vv6urNTrqEjuDexHlLxc39PheT bfwuSV9C39MLvwquxzJj0JozXsUnBmnn87oZw02IX5nqGMUgb/Rn2H6hd4/V4CbMw5A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796309952; 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=u65wGEkq5173aBCkoBIwIbnE/mdUiY3hd9M8h69N2Jk=; b=mn7GdtkNbzcDNhvI+mGp30iU6dEb9rO0YsUVPb4FwlQjsoJ5YGl0SY+FZYPSJP+lNCk2 W1BPHVbjr06h3KniRwVcsYjpX2Ez0SSktTjCVCoKfZjBYVuXs6ep3hF7wHqJssQs2YLdY SlVmyzB1Rl2XIIRG/2txqDSnnJNa/SYTkWf399MpGt6n79R+YS1DqEUvljGEhrpdKIPpH IS0DSMZU8Hzk1aa3dVscuLfXlEXKpmrHMNKDvzA7Uj+V6jH+PQNsjfUG6J9XPV0R82F3n BCmTmjH2Bsw+p+pB3imZ11u24RmX2FwXMkkl2RsmvEhbk26moY8vAmTUTMVkIl5e0qA== 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=YFZVioyy; 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 9F839606A6B2; Thu, 3 Dec 2026 14:59:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9F839606A6B2 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=YFZVioyy DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=smtpout1; t=1796309945; bh=u65wGEkq5173aBCkoBIwIbnE/mdUiY3hd9M8h69N2Jk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YFZVioyytW6RZ4M/n+edN5Tcsonvh2zvocE/6bc/HyiW7Aztb4/ksFwKVRioAwtFC tko8SpvW7jkbvvV/RCL4SuXZExslGSee7oavzF0UGUdpefU27Oq5uDJC6GIeAW51bA 6SlL8DDYFss5+d72tVJbd0i3iSIR/QsaIKA5XZeQObmwOfnaPt5sUr4PI32NHcG2Nk e23j8RzlEqfdOtzbvqysg3qDmwmdbc/bmECKw6jUhj/Z4Vf0L2gG4xGylp0fsoJSGs tCUFSPXeh/RZhNQXIBVNUlicCC0UmN8KObJtEy811bfQYozyROWN9ZLDUIsu9XbGsZ m0xurPWD9zoPQ== Received: from thinkos.internal.efficios.com (unknown [IPv6:2605:8d80:7180:6739:ac39:5d4:4093:61c6]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4jgHnz3WSrzZBN; Thu, 03 Dec 2026 09:59:03 -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, stable@vger.kernel.org Subject: [PATCH v14 03/39] sched/deadline: Do not truncate a bandwidth to 32 bits in __dl_add/sub() Date: Thu, 3 Dec 2026 09:58:17 -0500 Message-ID: <8a76aff21635e77a6d28ec031d5154edddcf7f38.1796296313.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 __dl_add() and __dl_sub() spread a change of total_bw over the extra_bw of the active CPUs of the root domain. Commit daec57983670 ("sched/deadline: Reclaim bandwidth not used by dl tasks") added this, for the bandwidth of one task. That is at most 1 << 20, the bandwidth of one CPU. But cpuset_can_attach() reserves the sum of the bandwidths of all the deadline tasks it moves, with dl_bw_alloc(). __dl_add() and __dl_sub() cast the bandwidth to s32 before the division. Past S32_MAX, more than 2048 CPUs of deadline bandwidth, the cast flips its sign. The extra_bw of each CPU then moves the wrong way. GRUB lets reclaiming tasks run more than the free bandwidth, or less. This was found by reading. It needs a machine with more than 2048 CPUs, so no case tests it. Fix this by dividing on 64 bits, with div_u64(). The Sashiko AI review of the first series found this. Fixes: daec57983670 ("sched/deadline: Reclaim bandwidth not used by dl tasks") Signed-off-by: Mathieu Desnoyers Reviewed-by: Juri Lelli Cc: stable@vger.kernel.org --- kernel/sched/deadline.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index e137eb7efa1f..a12b26b94642 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -199,7 +199,7 @@ void __dl_sub(struct dl_bw *dl_b, u64 tsk_bw, int cpus) { dl_b->total_bw -= tsk_bw; if (cpus) - __dl_update(dl_b, (s32)tsk_bw / cpus); + __dl_update(dl_b, div_u64(tsk_bw, cpus)); } static inline @@ -207,7 +207,7 @@ void __dl_add(struct dl_bw *dl_b, u64 tsk_bw, int cpus) { dl_b->total_bw += tsk_bw; if (cpus) - __dl_update(dl_b, -((s32)tsk_bw / cpus)); + __dl_update(dl_b, -(s64)div_u64(tsk_bw, cpus)); } static inline bool -- 2.47.3