From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.54 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796047949; b=pT25t/ruOBdnI24BMU6AnZqTYrzecl3YPBJaYo+xqnswMJhj9h1mvQ829iAUgXqks27h LFnw1369F9EXwzSAOnKSJx399J2L916R5m5jbV3dN9vXXwtupvnTDVl9uhv2DmVVGq/h3 s3Lba3NH7dXiCAGrsZEcpVQMV9OI+jPKws1mXIgk7w03BZvZGiVVQ3grQagDU1fdlhAVs zIysZM2PwSJQjQ7x7SdHiI7IKc6SO1J2OMM4A46CMPg9QWMBICdIlvSDhU9CNd80MS1wa XGW9wRhc3G7OiswllTcQY+BET7dtIV2CWyfiUQcFy2vl1Upyj8j5y6FTw58Hqr/eFeA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796047949; 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=s0U7qNEXXYAXzNoNgmvcKnpVupfoFLUz9RDClCQMFptYTaNvAMkiSXhMcI7VRxUHeDY3 xjQHrKnk4z6GgUQTMOvVZbQVHhbHarRAJN/c7SOD39ERqtriPej9s/dRKcGlos2Qq3LkO axEx6tWm82Kdy+YXBWMVwADjxs6CMENtv9sz1JhtNHryPguzAWM7sUxOAii/14oHrmHrZ LlPf0VoK6wFi7CxLtm7dV2TbJlKShrwWhSdLUld8bRCGAe8B6qtbLZhskij+k8auX0wix D6ur/zlB4J4VxUrGo14oTSOHNTaXcQ6LSBAN+HpExG49jqphaX2LQtlZExs+C4aqFEg== 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=wFIHc4+T; arc=none smtp.remote-ip=209.85.221.54 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (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 52289606A32C for ; Mon, 30 Nov 2026 14:12:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 52289606A32C 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=wFIHc4+T Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-48dee593f18so10076855f8f.3 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=lists.linux.dev; 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=wFIHc4+TjByK7TPpQwlbFlbpXpXrC1S8TRK0Y6Pz/eADY/D5MNkRee+WlCClJ++i3a ZRw60ZBAOIIn3kr1QHi9zQLeuAa7tb0i7LojEvlh1FPuhnpd6uofQ/VqlyQokqxhxwbK ya1UHk/58j43BeyfaiIpYGUUFf7B0dnDl0pa44VEJ+VyzVL6CjE+Ud4/OYT69MOe98j0 chMGf/4SoESr71DyYx9TPKw7zvVDwZ0bRSUBDbT3sXlkDVTsqEYi+Grq47B94VVgLfGE cuvzDBAocLgoGYKq+Wv7h7SfCYUYUw99Mr2j3WDbzbtN4+rNsa0LzhtOig716S3gC/7i rnrg== 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=mB+2JwjCwM+w+UXtdLPrQniG2iimJaMgBFB7WmOvVVRTSxAzWdlx7h8XjMFGTGSUfh 40P7nMt+L5JeHBXLfPmTywQx5HAO2iEpNpovF28jJlM42mAlkIyuyATHOZdGJ8nywB0I B32wZUehNlbxmQfHKUdi4HiJ9f8bygq5i3bfGnZGrdN5NJhCciaqBzcuBHJ8mw6He5fM DTCyMKKsuAWla+XakM5M0neiXW2ja+88m8qwfg8gPQIN4exWrmez2oxpX9kFQV5ums1y 2O6/WVhU6pJfIiKUhhNHoHdIJCXpfQUxHrtU87IXnT6VL1+9itgR2OBJQTzA1LL0Gb+4 B3XQ== X-Forwarded-Encrypted: i=1; AL+hErEZbLNaX6JZmWHLxLSTOFX9w6vIVL2yyuK+EYMIpDJfiHq63FZduNpJEPb3ZKJ3+d7nQtt7EBAxrOTfrMt1wQ==@lists.linux.dev X-Gm-Message-State: APuU4Z9qBs4NBNi4Sjj/KYmCoFZk/s2P9UdvLQkWN30GtGiej55wfZZz qzsMcrK/2BSHYKNRrSCcvMbunmfjenORFcBb86rw2Wpz7qnJP5XFlp3x X-Gm-Gg: AZFdTZdJPTWM5nB0X7GY876y7QkFmUrClCBQBMh5ZPHvh0r4eh9xId1pY46bEXpcSkD M0fd6/nAZcwkfupz7Ep+6L8aEpbZht8uUL05h1JrUEsZMGrzNtVRXh3BSzPSu1hzlUEeyhEs2A+ smWiM0hTh38Ke9/Ez4TBpcQCCL/rXkTRopsu4c9yBCGnKGz1iOayk3rGKicg5owYtvHGZ/jO4rY 0abusmXp5vv+oZ2g4eLTUnEq3NDn65TWgYCfTs6OptTWhgtyqAixUC792o4SYKt1qtnHKHV0Z3g duzUW7CLDLhO7mma2l/iPrE2lKDYWWJJJMErOYJgWSUXaoU7e5s/bIjrrwsitY01XCWKVYlM2Zj SqufC2D6/IG9hYlWqZ6y/hCRwFfaIQy/rKwXtKVTnuxhIhclZWfV1iaMzzG/mq8JrdyxH7DqVuG RdG0OKE1tIljCubs372Grm1Pc12q/A/gb0fi1MD8qwnsszsPeNjtUtRfZaK/ykSZ+j65oVzRMRT tVyPkidqNJxWyoel5qI7I2S2Zq1+02OLnFVyWN+RtVk922PGMN25aHHPHsZWm6Qc3Ggu2D6qIKH lz8ALNnqMvgpsy+M7g+97sP0h/pbJJjj5Z0052A8QJh/HL+lHx6IyDzesR1fw53Qgw== 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-rt-devel@lists.linux.dev 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