From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from stravinsky.debian.org (stravinsky.debian.org [82.195.75.108]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A53F03DA7F1 for ; Mon, 13 Apr 2026 14:28:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=82.195.75.108 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776090484; cv=none; b=VAQy5kM80l4AtoRk2/usDx8UZQoHlBhT6/cg6BqM4thx60MnyX4lSNp913IErZPBUkHh5SrGuvkOGLvO6sfvHLaW15Ei0/I13Q/h6OuFoEbiQcRxrN936phgyhczXMIToCGtZlvAp8QQFuJ5Gkp0LdPieO1PzeVYYMuyI8Y0jSA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776090484; c=relaxed/simple; bh=2ItvhG++0OVXZNC6O3ZggCgFEo/0+nAJx58UK/51X34=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=Ccan/q4KKGGkA4FaMpWH3QYqGUb6gjoGEpcQb4GKpVUxCqo3N7GFglsvNLFRO82k7uAyPxFjlcZs9gUtgwFAP5uawp7Gw4Xb9QBvAVZS5nC1H+0xgtBZv66PklqiWTlCmHQ/rHLM0E8KATvHA7AbPyrq0VXGArSa0VZqCxZwWlY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=none smtp.mailfrom=debian.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b=BwpXdQmn; arc=none smtp.client-ip=82.195.75.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=debian.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b="BwpXdQmn" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org; s=smtpauto.stravinsky; h=X-Debian-User:Cc:To:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From: Reply-To:Content-ID:Content-Description:In-Reply-To:References; bh=SIYAY7F6Frv9bxwGjTRHIN0h2/+R4sqrjRTV7cETpJg=; b=BwpXdQmngfo9N09VWNhC4m7MId DbPtfrjPa+Z5VlvM5JVDzwptLDS0RVRn5Q1VEcBKJPshKXjNfQGlGorR+7uF/PbSiSCqDw9cW5YS9 olRCmbRuu/6EpXc299sHvi4bMR8ArSpLwTxesGXgVHZuircqMMZJreri4Y1irO6dedOSam+cfhVkg LRFeUzgL0D4wa/ZDYUo6RgLsqTBks2atwve9sbB9z9eDT/q6zGuab3p4e1AKv584fzug7Cl02qfN4 ti6gVO8eTJRf85ftTyRAjJmu2otF8SbzIxAUB+NICUFj/Q11LpJXUg+QME6Aro/lcyR/s+GUll9Xw p7LzhFhQ==; Received: from authenticated user by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1wCIGb-00CMKD-0m; Mon, 13 Apr 2026 14:27:58 +0000 From: Breno Leitao Date: Mon, 13 Apr 2026 07:26:47 -0700 Subject: [PATCH v2] workqueue: validate cpumask_first() result in llc_populate_cpu_shard_id() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260413-workqueue_fix_nios-v2-1-2cf6a61b6bb3@debian.org> X-B4-Tracking: v=1; b=H4sIACb93GkC/32NQQqDMBAAvxL2bEqSakRP/UcRSXTVbSGxiVqL+ Peivfc4MMxsEDEQRijZBgEXiuQdlEwlDJrBuB45tVAyUEJpkUrB3z48XzPOWHe01o585KhzfS1 EahALSBiMATtaz+i9+nGc7QOb6SgdxkBx8uFzXhd5eH8Hi+SSG2ut0lmeWWlvLVoy7uJDD9W+7 18RfxnGxwAAAA== X-Change-ID: 20260410-workqueue_fix_nios-e6763904aee9 To: Tejun Heo , Lai Jiangshan Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, kernel test robot , Breno Leitao X-Mailer: b4 0.16-dev-453a6 X-Developer-Signature: v=1; a=openpgp-sha256; l=2976; i=leitao@debian.org; h=from:subject:message-id; bh=2ItvhG++0OVXZNC6O3ZggCgFEo/0+nAJx58UK/51X34=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBp3P1pQTjeurPPreHdCto3Lncossuqgif3z7aup WgFtZqPc1WJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCadz9aQAKCRA1o5Of/Hh3 bYqHD/4yUAElKXnxfkGeyzJv/OVQguyLh5yDN5JZfTjjngrdwgnMhmSrJbN9J3boQCnueafjTIN vPnKvJnFdT9U9B+q3sCKNKGPTJ6gUS/CiHPEQXlnXrP5SrSvJ5CfxtTeJHja/CsuxfSZpkcRcoE QTE7YSUuWKBzUOCrwb4u6BkSrkgYG5cfOKn+kXVGHKgGsSMAKG4SpofPcCpr6Fw6jyirWRsPzUD 6TvaJQw3gimzcFoa4HV7FjVGcb7AG2z7A2aByv1z1W0jms3FNFI40zAQ9RtD6Dflc3f3+LxEhh9 RiH2F7vtMecBdRimpmwxmtg3Jlpc8kY1zgaPbdR7NiDZpfCEuhFJw9dbYGRrrhcQoul+iyznatk huedRHoUoZdyBQpaAuS87P6n/Fh1lM6KXhygCumGSamnwQIff2oxBVpwf+lydHjbsA0MUeZhylz oIQ8jmAq6kRjzAKIN6Y0PfNgXBerC4GR409qCTffdiTgvvhTpj3b/ffsqOLRqhO9CR22ec0eqXQ jopR6jXo/kOWnV7+99rwC3xJX7jNrf2oaQ7GdXZNOOj/b0z7QhURdqWfBqSa9jH4qWYmLCBZhbi +zxrV1m/dWXAhyRylxtp4Xq0ktjHuaoHOb3ExGMqaqIfOqPrFaLRtoUQnzhWlzaCeypDGfbBH+b +OyoxAglhAqdmnA== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao On uniprocessor (UP) configs such as nios2, NR_CPUS is 1, so cpu_shard_id[] is a single-element array (int[1]). In llc_populate_cpu_shard_id(), cpumask_first(sibling_cpus) returns an unsigned int that the compiler cannot prove is always 0, triggering a -Warray-bounds warning when the result is used to index cpu_shard_id[]: kernel/workqueue.c:8321:55: warning: array subscript 1 is above array bounds of 'int[1]' [-Warray-bounds] 8321 | cpu_shard_id[c] = cpu_shard_id[cpumask_first(sibling_cpus)]; | ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This is a false positive: sibling_cpus can never be empty here because 'c' itself is always set in it, so cpumask_first() will always return a valid CPU. However, the compiler cannot prove this statically, and the warning only manifests on UP configs where the array size is 1. Add a bounds check with WARN_ON_ONCE to silence the warning, and store the result in a local variable to make the code clearer and avoid calling cpumask_first() twice. Fixes: 5920d046f7ae3 ("workqueue: add WQ_AFFN_CACHE_SHARD affinity scope") Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202604022343.GQtkF2vO-lkp@intel.com/ Signed-off-by: Breno Leitao --- Changes in v2: - Better describe the fix and that it only happens on UP configurations (tejun) - Declare leader as unsigned. - Link to v1: https://patch.msgid.link/20260410-workqueue_fix_nios-v1-1-abbb26575b1b@debian.org --- kernel/workqueue.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 083d8fe301f46..5f747f241a5f1 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -8298,6 +8298,7 @@ static void __init llc_populate_cpu_shard_id(const struct cpumask *pod_cpus, const struct cpumask *sibling_cpus; /* Count the number of cores in the current shard_id */ int cores_in_shard = 0; + unsigned int leader; /* This is a cursor for the shards. Go from zero to nr_shards - 1*/ int shard_id = 0; int c; @@ -8318,7 +8319,17 @@ static void __init llc_populate_cpu_shard_id(const struct cpumask *pod_cpus, * The siblings' shard MUST be the same as the leader. * never split threads in the same core. */ - cpu_shard_id[c] = cpu_shard_id[cpumask_first(sibling_cpus)]; + leader = cpumask_first(sibling_cpus); + + /* + * This check silences a Warray-bounds warning on UP + * configs where NR_CPUS=1 makes cpu_shard_id[] + * a single-element array, and the compiler can't + * prove the index is always 0. + */ + if (WARN_ON_ONCE(leader >= nr_cpu_ids)) + continue; + cpu_shard_id[c] = cpu_shard_id[leader]; } } --- base-commit: 3fa7d958829eb9bc3b469ed07f11de3d2804ef71 change-id: 20260410-workqueue_fix_nios-e6763904aee9 Best regards, -- Breno Leitao