[PATCH 1/2] Revert "powerpc/xive: Fix the size of the cpumask used in xive_find_target_in_mask()"
Mukesh Kumar Chaurasiya
mkchauras at gmail.com
Fri Mar 20 16:57:26 AEDT 2026
On Wed, Mar 18, 2026 at 11:36:45PM -0400, Yury Norov wrote:
> This reverts commit a9dadc1c512807f955f0799e85830b420da47932.
>
> The commit message states:
>
> When called from xive_irq_startup(), the size of the cpumask can be
> larger than nr_cpu_ids. This can result in a WARN_ON.
> [...]
> This happens because we're being called with our affinity mask set to
> irq_default_affinity. That in turn was populated using
> cpumask_setall(), which sets NR_CPUs worth of bits, not nr_cpu_ids
> worth. Finally cpumask_weight() will return > nr_cpu_ids when passed a
> mask which has > nr_cpu_ids bits set.
>
> In modern kernel, cpumask_weight() can't return > nr_cpu_ids.
>
> In inline case, cpumask_setall() explicitly clears all bits above
> nr_cpu_ids, see commit 63355b9884b3 ("cpumask: be more careful with
> 'cpumask_setall()'"). So, despite that cpumask_weight() is passed
> with small_cpumask_bits, which is NR_CPUS in this case, it can't
> count over the nr_cpu_ids.
>
> In outline case, cpumask_setall() may set bits beyond the limit up to
> the next byte alignment, but in this case small_cpumask_bits is wired
> to nr_cpu_ids, thus making overcounting impossible.
>
> Signed-off-by: Yury Norov <ynorov at nvidia.com>
> ---
>
> I've added some explicit tests for cpumask_weight() to make sure:
> https://lore.kernel.org/all/20260319004349.849281-1-ynorov@nvidia.com/
>
> arch/powerpc/sysdev/xive/common.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/powerpc/sysdev/xive/common.c b/arch/powerpc/sysdev/xive/common.c
> index e1a4f8a97393..e91ec9036ad8 100644
> --- a/arch/powerpc/sysdev/xive/common.c
> +++ b/arch/powerpc/sysdev/xive/common.c
> @@ -551,7 +551,7 @@ static int xive_find_target_in_mask(const struct cpumask *mask,
> int cpu, first, num, i;
>
> /* Pick up a starting point CPU in the mask based on fuzz */
> - num = min_t(int, cpumask_weight(mask), nr_cpu_ids);
> + num = cpumask_weight(mask);
> first = fuzz % num;
>
> /* Locate it */
> --
> 2.43.0
>
LGTM
Reviewed-by: Mukesh Kumar Chaurasiya (IBM) <mkchauras at gmail.com>
More information about the Linuxppc-dev
mailing list