Re: [PATCH 4/4] lib/cpumask: add FORCE_NR_CPUS config option
From: Yury Norov
Date: Fri Sep 02 2022 - 13:33:51 EST
On Tue, Aug 30, 2022 at 02:05:09PM -0700, Yury Norov wrote:
> + Vivek Goyal <vgoyal@xxxxxxxxxx>
> + Yinghai Lu <yinghai@xxxxxxxxxx>
> + H. Peter Anvin <hpa@xxxxxxxxxxxxxxx>
>
> On Wed, Aug 31, 2022 at 02:33:41AM +0800, kernel test robot wrote:
> > Hi Yury,
> >
> > I love your patch! Perhaps something to improve:
> >
> > [auto build test WARNING on tip/x86/core]
> > [also build test WARNING on linus/master v6.0-rc3 next-20220830]
> > [If your patch is applied to the wrong git tree, kindly drop us a note.
> > And when submitting patch, we suggest to use '--base' as documented in
> > https://git-scm.com/docs/git-format-patch#_base_tree_information]
> >
> > url: https://github.com/intel-lab-lkp/linux/commits/Yury-Norov/cpumask-cleanup-nr_cpu_ids-vs-nr_cpumask_bits-mess/20220830-010755
> > base: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git bc12b70f7d216b36bd87701349374a13e486f8eb
> > config: x86_64-randconfig-m001 (https://download.01.org/0day-ci/archive/20220831/202208310215.C2IzssKr-lkp@xxxxxxxxx/config)
> > compiler: gcc-11 (Debian 11.3.0-5) 11.3.0
> >
> > If you fix the issue, kindly add following tag where applicable
> > Reported-by: kernel test robot <lkp@xxxxxxxxx>
> >
> > smatch warnings:
> > arch/x86/kernel/apic/apic.c:2437 generic_processor_info() warn: always true condition '(num_processors >= (1) - 1) => (0-u32max >= 0)'
>
> This is the code that woke up the smatch:
> /*
> * If boot cpu has not been detected yet, then only allow upto
> * nr_cpu_ids - 1 processors and keep one slot free for boot cpu
> */
> if (!boot_cpu_detected && num_processors >= nr_cpu_ids - 1 &&
> apicid != boot_cpu_physical_apicid) {
> int thiscpu = max + disabled_cpus - 1;
>
> pr_warn("APIC: NR_CPUS/possible_cpus limit of %i almost"
> " reached. Keeping one slot for boot cpu."
> " Processor %d/0x%x ignored.\n", max, thiscpu, apicid);
>
> disabled_cpus++;
> return -ENODEV;
> }
>
> It has been added in a patch 14cb6dcf0a023f597 ("x86, boot: Wait for
> boot cpu to show up if nr_cpus limit is about to hit")
>
> My patch adds an option FORCE_NR_CPUS that makes nr_cpu_ids a compile-time
> defined.
>
> Hence, the num_processors >= nr_cpus - 1,
> may become: num_processors >= 0, if NR_CPUS == 1.
>
> So the plain straightforward fix would be:
>
> if (!boot_cpu_detected &&
> #if (NR_CPUS > 1)
> num_processors >= nr_cpu_ids - 1 &&
> #endif
> apicid != boot_cpu_physical_apicid) { ... }
>
> However, I have a feeling that all the logic above is not needed at
> all on UP machines. If that's true, the '#if NR_CPUS > 1' should
> protect the whole condition, or even bigger piece of the
> generic_processor_info().
As Dave Hansen said:
I think it's a reasonable warning, but it's also not something we need
to hack around. We can surely only land in here with
boot_cpu_detected==true if NR_CPUS==1, so the rest of the expression is
moot.
I don't think it's worth adding the #ifdef.
So, leaving things as they are.
If no other comments, moving the series into bitmap-for-next.
Thanks,
Yury