From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796047950; b=L/rBMzqwwBYbamXxQEkJN/T8EMYvNC1mxDGGdXWZsLoDD25Z57wdlk1FB+haHJHP0hGn SzmGraXXMc1gXW2kn98tm9UoBKghcC1HOop+s7hefcYeOTH/IG5FgStDMgn9dZ+zc7BLO WQQwR0AM2R8K3opgkzCXflmp63dOJd8akZFa0/GVrqLm/28THgzIOdbNFWdwo+gFcjuQm dySSy7roAnUJ312bOTnzHh5MNEdeMssMk3TU7umssrswqYSohFXx7k4F1OdxtwrplVnpz Csyv6m6LBmTFna7FzAP7845e2JjmwGQwUHHp9R7+pqlq7JTjqbJ0xjyfkDeHAuwRsUw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796047950; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References:X-Mailer: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=A8kaaLF3LbRoc4EYNSmMHmu1512JRet03500xbuEAl4=; b=BmgVQrxojXb5YCNe8UwozJLASjtgpGrMp9yRnj4ouh9EmHBC7W85MEO0eB/MQ2agm66j +1cPDZxvcDjoLdmXI/6YBqE34/ezeo0Onph2E9ezsTF3sT1dChoxKT8GMXb2LgZIC12+W mfnOa3fn1FNTwHnQoMv0Se7mZpzEUY0j/u62zCwaqDMgnpx8BdE0g5JgJ5hqj1ujNrtkS hBIoqKkC4/PZm3OhDdZqUr/Ey0Tl4AmS4IXQkkSisnkZ1EAmppQzfi+qd/mOTYdtE74hi sfzYwK06JxA3t05FrghxrYQV2tyzfVWhVCKkk5MxMS0jphvvj0hOHfQeeUhmvhXFgLA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ree2+JV7; arc=none smtp.remote-ip=209.85.221.42 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B920606A32F for ; Mon, 30 Nov 2026 14:12:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5B920606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=ree2+JV7 Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-492690dd5daso8191249f8f.1 for ; Mon, 30 Nov 2026 06:12:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796047948; x=1796652748; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=A8kaaLF3LbRoc4EYNSmMHmu1512JRet03500xbuEAl4=; b=ree2+JV7B9dL0hA0/YjwsMQkJjXTTIbwRfD65rEkLDZjqgr6fUv02BVmc3zWsrNlt+ iTzz5AbhRSJVC73+Ix4fIwB7iaNT2baJNMlE+d/XlmoA8288kt7PSAeKEzFnUvYSIirv 5psP6mCQxaepHkH/9K0jpsqx0S9hKwKnEBEUbhQZHu55damfXV64YrvxwfzVHSW5Lqve abD2PZ67meqYOWUAp0d8FZwwHY3j6SoDbECcZgR2dCaSlOaFI9+OiH80ARjyCu/FEXm6 tyT6GkYLgKffJa6inRfc7NZYAyvz0G63lgi7cUpBQyPtvlZqgejXJXVTNZnQ0sWaVfrO NruA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796047948; x=1796652748; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=A8kaaLF3LbRoc4EYNSmMHmu1512JRet03500xbuEAl4=; b=K+4aWWVf1qH1sR06xvKWyqyjFVNHziOECr57cseveKG5M5/HT0wmQjN/eyfXwtgt1y 1wRkwBds7cjISWkO2O1A4K8Z/SSZ6ug3cal6DtFA/HctXCb0PdOCO7Oht0SEvHWUQZQo wc/9I8HbSint+HIBB6SHVNWZfLYdPIk4xB9mJV272mOG66xPRO1z+FyxWLm46iDP79lk QvWHG2sLpu4at9o9lDLCOX4+pLXQzPxE45m3W5shJGiwSjUZQGcICQNVlstglfGbpk70 qh6+Jy2mPl0cAt5PsqGbARm1aIZggGqCEZBxzs2I6GpCkIL5qMhp5rc6GBL2yukVC/zS P/mg== X-Forwarded-Encrypted: i=1; AL+hErHwu6B4HYRk9k2CXuYyYsAe/6HN6tQnPIbyr8VnFdD5tO58vudR0VVB1lB+tCXkjR550tJUn/bBISeL/6zid5I=@vger.kernel.org X-Gm-Message-State: APuU4Z/x8uAXqHGLp++gL93g/NZgH7Qk+WFJEftNU8mVgDdEFYqJO4Jl fzzXqZeVqvBaHiKFnofADCe2kud1K79MGllG++8NZ5fq7DthMBp/Kii0 X-Gm-Gg: AZFdTZfUoL315CiGzdBEFTMb5PWgwoSzeBDqeKpJ2DAtMdPaQZeejtsvaBMUU7YW1o2 aLRdUc5WRnL1u6wzpnHMFPeGwrYhQbcqzuhe4xqedhnd5bvEIif8cvd4MM0wmW2cVq35KiuX+L+ pOxh/KkPh19kW1QxVwSmHTcBYZIm2PV5UW6DEFwoJp6Ij7xeIe1bdtsGQIHml1FFDdZw5ZP9wTL SERbAeEM3TFhATFVHDEooQ+7sWSFgZ9P7u+BBvodXgvO8MoMwdi26cKJygPo1jdNkwkyIywjt8/ +aIKlvvSlCHgC8iSRXkbQpI9+yR+0w7MGALNrKUrcdMpBnNE1nBTqaJY/okGJgWrxFMwAVha3CT nv822CO/szxYPKxWnXVQDcAtNb/usDJDQPUvSL8O3Qdza76JpbVJ7smlErSKDrCnr3tPUKYsIrs TlIv80Yx+yHWznu5vVyBg+bd+Cptje4bOmpjf3sxixMtGbzCZyDVpNcl+yx1Fz7h58KWfr1oF+P BIwJJWxb2T3ejyDtkkrWbCByOV0/rMD4MHvYLQV7admf+S5IYc5HTvsJ4QMo6Q9iQ7yhRXTHdy2 aleEDg1OvNqNlHy//QcKHElttnSAPrqmqzhSeksAIlfkocp1CXITxe1s3ULD1amSCg== X-Received: by 2002:a05:600c:34c9:b0:4a3:5d64:df91 with SMTP id 5b1f17b1804b1-4bb88810d28mr743644175e9.18.1796047947488; Mon, 30 Nov 2026 06:12:27 -0800 (PST) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbb39dd4e7sm259499355e9.0.2026.11.30.06.12.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 06:12:27 -0800 (PST) Date: Mon, 30 Nov 2026 14:12:25 +0000 From: David Laight To: Mathieu Desnoyers Cc: juri.lelli@redhat.com, peterz@infradead.org, mingo@redhat.com, vincent.guittot@linaro.org, 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, stable@vger.kernel.org Subject: Re: [PATCH v12 20/43] sched/deadline: Do not truncate a bandwidth to 32 bits in __dl_add/sub() Message-ID: <20261130141225.1e78e5f2@pumpkin> In-Reply-To: <3300daac81b2483e451bca006dfaa2da5b21fced.1795771148.git.mathieu.desnoyers@efficios.com> References: <3300daac81b2483e451bca006dfaa2da5b21fced.1795771148.git.mathieu.desnoyers@efficios.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 27 Nov 2026 09:35:47 -0500 Mathieu Desnoyers wrote: > __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 > 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 3f02d150e15d..7a6057326611 100644 > --- a/kernel/sched/deadline.c > +++ b/kernel/sched/deadline.c > @@ -205,7 +205,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)); It looks like the casts were added to avoid an expensive 64bit divide. So I'm not at all sure it is sensible to remove them. Changing to (u32) is enough to stop the sign being flipped and requires 4096 CPU before there is any overflow. The code seems to have loops across all the cpu - so I'm not sure how well it actually scales for large systems. I'm also not sure of the locking for the 'rq->dl_extra_bw += bw' in __dl_update(). If this code runs every time a deadline process suspends it could get very expensive even without the divide. David > } > > static inline > @@ -213,7 +213,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