From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 70F513A5E7E for ; Fri, 10 Apr 2026 09:00:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775811631; cv=none; b=aTUtCg93AHo7agUNG+Asqw61+o7w3kewq1+ELLJx4TbqktQPEFCRSoxjCbyLu2N1wULl2JGhK0lWEbxgEAUKRDhijSKyK7nPkvyFkGzNsyAN5UHM9WYO5H5xburCYaKStTry5nvGdUQYuYB4OTloUEC8QYxPi7MkwzyooQcJlUU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775811631; c=relaxed/simple; bh=UipPz6Khw/TaIfq2WRrm2K/M1Zs6QglQGKd5QYP7LIQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Wv7ZdqKfRw+0YmPrLVngDxDf2LVBc6GE2wZyRDfvgwgzFqzY+IYAqGwKPUk65Thq5T86TBJcpksXtwsKTSK607NBnzsOo0sK60m07vB5S20UOttcxj58b7Fo/WNinZCZkHkxgNG77/ThfTr5HuRbMLzo5bZavm1/LYbKC0VJprE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Xdi5e1Bz; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Xdi5e1Bz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E2C20C19421; Fri, 10 Apr 2026 09:00:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775811631; bh=UipPz6Khw/TaIfq2WRrm2K/M1Zs6QglQGKd5QYP7LIQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Xdi5e1Bz0f44apJSa2nz5zCgxStgCMsBmCihd92OfNqofdyVxoJfABkEPAmQI1Bhf 5ZYng2ZzCIxjqG1lPW2aLXTBijLjQcSm5GMNWQ9rTeFo4DILdl9T2ulYcZkoY7Iz2T PTihvRHXvMIiLL3kxZPWbqj13wQhppv+fVdUDL6wGoMtyIclFVSFd6Lbxk2A2ITGc7 LJA05xnphaRRAlDUdW43ZhlbXa5oRY2pKnFnLAmIhCBVl0ZgSy2vFVXvXR0boEIrVX XMU85NIg3d5SuwReLVhAtZD3yIGtmPCUNYhBbBBdeFiylOHThHRBJtdvdp8g5EumSu 4C+xwupKDlvkA== Date: Thu, 9 Apr 2026 23:00:30 -1000 From: Tejun Heo To: Breno Leitao Cc: Lai Jiangshan , linux-kernel@vger.kernel.org, kernel-team@meta.com, kernel test robot Subject: Re: [PATCH] workqueue: validate cpumask_first() result in llc_populate_cpu_shard_id() Message-ID: References: <20260410-workqueue_fix_nios-v1-1-abbb26575b1b@debian.org> 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=us-ascii Content-Disposition: inline In-Reply-To: <20260410-workqueue_fix_nios-v1-1-abbb26575b1b@debian.org> Hello, On Fri, Apr 10, 2026 at 01:49:50AM -0700, Breno Leitao wrote: > In llc_populate_cpu_shard_id(), cpumask_first(sibling_cpus) is used to > find the leader CPU, and the result is then used to index into > cpu_shard_id[]. Add a bounds check with WARN_ON_ONCE to guard against > unexpected values before using it as an array index. > > Store the result in a local variable to make the code clearer, as also > to avoid calling cpumask_first() twice. > > Fixes: 5920d046f7ae3 ("workqueue: add WQ_AFFN_CACHE_SHARD affinity scope") ... > @@ -8318,7 +8319,11 @@ 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); > + > + if (WARN_ON_ONCE(leader >= nr_cpu_ids)) > + continue; > + cpu_shard_id[c] = cpu_shard_id[leader]; sibling_cpus can't be empty, right? This is mostly to shut up the reported compiler warning? If so, can you please note that in a ocmment and the description? Thanks. -- tejun