Skip to contentSkip to conversation

kernel/workqueue.c:8289:34: warning: array subscript 1 is above array bounds of 'int[1]'

PATCH kernel test robot 2 participants 2 messages Apr 3 – Apr 9

lore
Share & tools
lore

kernel test robot

author build bot
#0 lore raw
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/tj/wq.git for-7.1
head:   41e3ccca00b374b7f39cf68e818b59a921cd7069
commit: 5920d046f7ae3bf9cf51b9d915c1fff13d299d84 [14/18] workqueue: add WQ_AFFN_CACHE_SHARD affinity scope
config: nios2-randconfig-001-20260402 (https://download.01.org/0day-ci/archive/20260402/[email protected]/config)
compiler: nios2-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260402/[email protected]/reproduce)

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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

kernel/workqueue.c: In function 'workqueue_init_topology':

>> kernel/workqueue.c:8289:34: warning: array subscript 1 is above array bounds of 'int[1]' [-Warray-bounds]
       cpu_shard_id[c] = cpu_shard_id[cpumask_first(sibling_cpus)];
                         ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

vim +8289 kernel/workqueue.c

8251
8252 /**
8253 * llc_populate_cpu_shard_id - populate cpu_shard_id[] for each CPU in an LLC pod

  8254	 * @pod_cpus:  the cpumask of CPUs in the LLC pod
  8255	 * @smt_pods:  the SMT pod type, used to identify sibling groups
  8256	 * @nr_cores:  number of distinct cores in @pod_cpus (from llc_count_cores())
  8257	 *
  8258	 * Walks @pod_cpus in order. At each SMT group leader, advances to the next
  8259	 * shard once the current shard is full. Results are written to cpu_shard_id[].
  8260	 */
  8261	static void __init llc_populate_cpu_shard_id(const struct cpumask *pod_cpus,
  8262						     struct wq_pod_type *smt_pods,
  8263						     int nr_cores)
  8264	{
  8265		struct llc_shard_layout layout = llc_calc_shard_layout(nr_cores);
  8266		const struct cpumask *sibling_cpus;
  8267		/* Count the number of cores in the current shard_id */
  8268		int cores_in_shard = 0;
  8269		/* This is a cursor for the shards. Go from zero to nr_shards - 1*/
  8270		int shard_id = 0;
  8271		int c;
  8272	
  8273		/* Iterate at every CPU for a given LLC pod, and assign it a shard */
  8274		for_each_cpu(c, pod_cpus) {
  8275			sibling_cpus = smt_pods->pod_cpus[smt_pods->cpu_pod[c]];
  8276			if (cpumask_first(sibling_cpus) == c) {
  8277				/* This is the CPU leader for the siblings */
  8278				if (llc_shard_is_full(cores_in_shard, shard_id, &layout)) {
  8279					shard_id++;
  8280					cores_in_shard = 0;
  8281				}
  8282				cores_in_shard++;
  8283				cpu_shard_id[c] = shard_id;
  8284			} else {
  8285				/*
  8286				 * The siblings' shard MUST be the same as the leader.
  8287				 * never split threads in the same core.
  8288				 */
> 8289				cpu_shard_id[c] = cpu_shard_id[cpumask_first(sibling_cpus)];

8290 }
8291 }
8292
8293 WARN_ON_ONCE(shard_id != (layout.nr_shards - 1));
8294 }
8295

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#1 lore raw
Quoted 12 lines · kernel test robot
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/tj/wq.git for-7.1
head:   41e3ccca00b374b7f39cf68e818b59a921cd7069
commit: 5920d046f7ae3bf9cf51b9d915c1fff13d299d84 [14/18] workqueue: add WQ_AFFN_CACHE_SHARD affinity scope
config: nios2-randconfig-001-20260402 (https://download.01.org/0day-ci/archive/20260402/[email protected]/config)
compiler: nios2-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260402/[email protected]/reproduce)

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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

Quoted 6 lines

All warnings (new ones prefixed by >>):

kernel/workqueue.c: In function 'workqueue_init_topology':

Quoted 1 line
Quoted 1 line

kernel/workqueue.c:8289:34: warning: array subscript 1 is above array bounds of 'int[1]' [-Warray-bounds]

       cpu_shard_id[c] = cpu_shard_id[cpumask_first(sibling_cpus)];
                         ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I can finally reproduce it. This is related to nios2 having NR_CPU=1.

In function ‘llc_populate_cpu_shard_id’,
inlined from ‘precompute_cache_shard_ids’ at /home/leit/Devel/linux-next/kernel/workqueue.c:8321:3,
inlined from ‘workqueue_init_topology’ at /home/leit/Devel/linux-next/kernel/workqueue.c:8354:2:
/home/leit/Devel/linux-next/kernel/workqueue.c:8289:55: warning: array subscript 1 is above array bounds of ‘int[1]’ [-Warray-bounds]
8289 | cpu_shard_id[c] = cpu_shard_id[cpumask_first(sibling_cpus)];
| ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/leit/Devel/linux-next/kernel/workqueue.c: In function ‘workqueue_init_topology’:
/home/leit/Devel/linux-next/kernel/workqueue.c:8171:12: note: while referencing ‘cpu_shard_id’
8171 | static int cpu_shard_id[NR_CPUS] __initdata;
| ^~~~~~~~~~~~
make[1]: Leaving directory '/tmp/wq-nios2'

Working on a fix,

Thanks for the report, dear robot :-)
--breno