Re: kernel/sched/isolation.c:143 housekeeping_setup() warn: always true condition '(first_cpu >= 0) => (0-u32max >= 0)'
From: Oleg Nesterov
Date: Wed May 22 2024 - 09:15:31 EST
On 05/02, Oleg Nesterov wrote:
>
> I am on PTO till May 9 without my working laptop, can't even read the source code.
> I'll return to this when I'm back. CONFIG_SMP=n I guess.
Sorry for late reply.
So smatch dislikes the
first_cpu >= setup_max_cpus
check because setup_max_cpus is 0 without CONFIG_SMP.
I don't think it makes sense to try to avoid this warning, isolation.c should
not be compiled without CONFIG_SMP=y, but we have
config CPU_ISOLATION
bool "CPU isolation"
depends on SMP || COMPILE_TEST
and this randconfig selects COMPILE_TEST.
Oleg.
> On 04/30, kernel test robot wrote:
> > tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
> > head: 98369dccd2f8e16bf4c6621053af7aa4821dcf8e
> > commit: 257bf89d84121280904800acd25cc2c444c717ae sched/isolation: Fix boot crash when maxcpus < first housekeeping CPU
> > date: 2 days ago
> > config: xtensa-randconfig-r081-20240429 (https://download.01.org/0day-ci/archive/20240430/202404300915.WNvfwBz3-lkp@xxxxxxxxx/config)
> > compiler: xtensa-linux-gcc (GCC) 13.2.0
> >
> > If you fix the issue in a separate patch/commit (i.e. not just a new version of
> > the same patch/commit), kindly add following tags
> > | Reported-by: kernel test robot <lkp@xxxxxxxxx>
> > | Closes: https://lore.kernel.org/oe-kbuild-all/202404300915.WNvfwBz3-lkp@xxxxxxxxx/
> >
> > New smatch warnings:
> > kernel/sched/isolation.c:143 housekeeping_setup() warn: always true condition '(first_cpu >= 0) => (0-u32max >= 0)'
> >
> > Old smatch warnings:
> > arch/xtensa/include/asm/thread_info.h:97 current_thread_info() warn: inconsistent indenting
> >
> > vim +143 kernel/sched/isolation.c
> >
> > 117
> > 118 static int __init housekeeping_setup(char *str, unsigned long flags)
> > 119 {
> > 120 cpumask_var_t non_housekeeping_mask, housekeeping_staging;
> > 121 unsigned int first_cpu;
> > 122 int err = 0;
> > 123
> > 124 if ((flags & HK_FLAG_TICK) && !(housekeeping.flags & HK_FLAG_TICK)) {
> > 125 if (!IS_ENABLED(CONFIG_NO_HZ_FULL)) {
> > 126 pr_warn("Housekeeping: nohz unsupported."
> > 127 " Build with CONFIG_NO_HZ_FULL\n");
> > 128 return 0;
> > 129 }
> > 130 }
> > 131
> > 132 alloc_bootmem_cpumask_var(&non_housekeeping_mask);
> > 133 if (cpulist_parse(str, non_housekeeping_mask) < 0) {
> > 134 pr_warn("Housekeeping: nohz_full= or isolcpus= incorrect CPU range\n");
> > 135 goto free_non_housekeeping_mask;
> > 136 }
> > 137
> > 138 alloc_bootmem_cpumask_var(&housekeeping_staging);
> > 139 cpumask_andnot(housekeeping_staging,
> > 140 cpu_possible_mask, non_housekeeping_mask);
> > 141
> > 142 first_cpu = cpumask_first_and(cpu_present_mask, housekeeping_staging);
> > > 143 if (first_cpu >= nr_cpu_ids || first_cpu >= setup_max_cpus) {
> > 144 __cpumask_set_cpu(smp_processor_id(), housekeeping_staging);
> > 145 __cpumask_clear_cpu(smp_processor_id(), non_housekeeping_mask);
> > 146 if (!housekeeping.flags) {
> > 147 pr_warn("Housekeeping: must include one present CPU, "
> > 148 "using boot CPU:%d\n", smp_processor_id());
> > 149 }
> > 150 }
> > 151
> > 152 if (cpumask_empty(non_housekeeping_mask))
> > 153 goto free_housekeeping_staging;
> > 154
> > 155 if (!housekeeping.flags) {
> > 156 /* First setup call ("nohz_full=" or "isolcpus=") */
> > 157 enum hk_type type;
> > 158
> > 159 for_each_set_bit(type, &flags, HK_TYPE_MAX)
> > 160 housekeeping_setup_type(type, housekeeping_staging);
> > 161 } else {
> > 162 /* Second setup call ("nohz_full=" after "isolcpus=" or the reverse) */
> > 163 enum hk_type type;
> > 164 unsigned long iter_flags = flags & housekeeping.flags;
> > 165
> > 166 for_each_set_bit(type, &iter_flags, HK_TYPE_MAX) {
> > 167 if (!cpumask_equal(housekeeping_staging,
> > 168 housekeeping.cpumasks[type])) {
> > 169 pr_warn("Housekeeping: nohz_full= must match isolcpus=\n");
> > 170 goto free_housekeeping_staging;
> > 171 }
> > 172 }
> > 173
> > 174 iter_flags = flags & ~housekeeping.flags;
> > 175
> > 176 for_each_set_bit(type, &iter_flags, HK_TYPE_MAX)
> > 177 housekeeping_setup_type(type, housekeeping_staging);
> > 178 }
> > 179
> > 180 if ((flags & HK_FLAG_TICK) && !(housekeeping.flags & HK_FLAG_TICK))
> > 181 tick_nohz_full_setup(non_housekeeping_mask);
> > 182
> > 183 housekeeping.flags |= flags;
> > 184 err = 1;
> > 185
> > 186 free_housekeeping_staging:
> > 187 free_bootmem_cpumask_var(housekeeping_staging);
> > 188 free_non_housekeeping_mask:
> > 189 free_bootmem_cpumask_var(non_housekeeping_mask);
> > 190
> > 191 return err;
> > 192 }
> > 193
> >
> > --
> > 0-DAY CI Kernel Test Service
> > https://github.com/intel/lkp-tests/wiki
> >
>