All of lore.kernel.org
 help / color / mirror / Atom feed
From: kernel test robot <lkp@intel.com>
To: Jan Kara <jack@suse.cz>, Yury Norov <yury.norov@gmail.com>
Cc: oe-kbuild-all@lists.linux.dev,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr>,
	Matthew Wilcox <willy@infradead.org>,
	linux-fsdevel@vger.kernel.org, Jan Kara <jack@suse.cz>
Subject: Re: [PATCH 1/2] lib/find: Make functions safe on changing bitmaps
Date: Thu, 19 Oct 2023 00:23:06 +0800	[thread overview]
Message-ID: <202310190005.NqJcRXtK-lkp@intel.com> (raw)
In-Reply-To: <20231011150252.32737-1-jack@suse.cz>

Hi Jan,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.6-rc6 next-20231018]
[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/Jan-Kara/lib-find-Make-functions-safe-on-changing-bitmaps/20231011-230553
base:   linus/master
patch link:    https://lore.kernel.org/r/20231011150252.32737-1-jack%40suse.cz
patch subject: [PATCH 1/2] lib/find: Make functions safe on changing bitmaps
config: i386-randconfig-002-20231018 (https://download.01.org/0day-ci/archive/20231019/202310190005.NqJcRXtK-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231019/202310190005.NqJcRXtK-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202310190005.NqJcRXtK-lkp@intel.com/

All warnings (new ones prefixed by >>):

   mm/percpu.c: In function 'pcpu_build_alloc_info':
>> mm/percpu.c:2885:26: warning: array subscript 32 is above array bounds of 'int[32]' [-Warray-bounds]
    2885 |                 group_map[cpu] = group;
         |                 ~~~~~~~~~^~~~~
   mm/percpu.c:2842:20: note: while referencing 'group_map'
    2842 |         static int group_map[NR_CPUS] __initdata;
         |                    ^~~~~~~~~


vim +2885 mm/percpu.c

3c9a024fde58b0 Tejun Heo              2010-09-09  2813  
3c9a024fde58b0 Tejun Heo              2010-09-09  2814  /* pcpu_build_alloc_info() is used by both embed and page first chunk */
3c9a024fde58b0 Tejun Heo              2010-09-09  2815  #if defined(BUILD_EMBED_FIRST_CHUNK) || defined(BUILD_PAGE_FIRST_CHUNK)
3c9a024fde58b0 Tejun Heo              2010-09-09  2816  /**
3c9a024fde58b0 Tejun Heo              2010-09-09  2817   * pcpu_build_alloc_info - build alloc_info considering distances between CPUs
3c9a024fde58b0 Tejun Heo              2010-09-09  2818   * @reserved_size: the size of reserved percpu area in bytes
3c9a024fde58b0 Tejun Heo              2010-09-09  2819   * @dyn_size: minimum free size for dynamic allocation in bytes
3c9a024fde58b0 Tejun Heo              2010-09-09  2820   * @atom_size: allocation atom size
3c9a024fde58b0 Tejun Heo              2010-09-09  2821   * @cpu_distance_fn: callback to determine distance between cpus, optional
3c9a024fde58b0 Tejun Heo              2010-09-09  2822   *
3c9a024fde58b0 Tejun Heo              2010-09-09  2823   * This function determines grouping of units, their mappings to cpus
3c9a024fde58b0 Tejun Heo              2010-09-09  2824   * and other parameters considering needed percpu size, allocation
3c9a024fde58b0 Tejun Heo              2010-09-09  2825   * atom size and distances between CPUs.
3c9a024fde58b0 Tejun Heo              2010-09-09  2826   *
bffc4375897ea0 Yannick Guerrini       2015-03-06  2827   * Groups are always multiples of atom size and CPUs which are of
3c9a024fde58b0 Tejun Heo              2010-09-09  2828   * LOCAL_DISTANCE both ways are grouped together and share space for
3c9a024fde58b0 Tejun Heo              2010-09-09  2829   * units in the same group.  The returned configuration is guaranteed
3c9a024fde58b0 Tejun Heo              2010-09-09  2830   * to have CPUs on different nodes on different groups and >=75% usage
3c9a024fde58b0 Tejun Heo              2010-09-09  2831   * of allocated virtual address space.
3c9a024fde58b0 Tejun Heo              2010-09-09  2832   *
3c9a024fde58b0 Tejun Heo              2010-09-09  2833   * RETURNS:
3c9a024fde58b0 Tejun Heo              2010-09-09  2834   * On success, pointer to the new allocation_info is returned.  On
3c9a024fde58b0 Tejun Heo              2010-09-09  2835   * failure, ERR_PTR value is returned.
3c9a024fde58b0 Tejun Heo              2010-09-09  2836   */
258e0815e2b170 Dennis Zhou            2021-02-14  2837  static struct pcpu_alloc_info * __init __flatten pcpu_build_alloc_info(
3c9a024fde58b0 Tejun Heo              2010-09-09  2838  				size_t reserved_size, size_t dyn_size,
3c9a024fde58b0 Tejun Heo              2010-09-09  2839  				size_t atom_size,
3c9a024fde58b0 Tejun Heo              2010-09-09  2840  				pcpu_fc_cpu_distance_fn_t cpu_distance_fn)
3c9a024fde58b0 Tejun Heo              2010-09-09  2841  {
3c9a024fde58b0 Tejun Heo              2010-09-09  2842  	static int group_map[NR_CPUS] __initdata;
3c9a024fde58b0 Tejun Heo              2010-09-09  2843  	static int group_cnt[NR_CPUS] __initdata;
d7d29ac76f7efb Wonhyuk Yang           2020-10-30  2844  	static struct cpumask mask __initdata;
3c9a024fde58b0 Tejun Heo              2010-09-09  2845  	const size_t static_size = __per_cpu_end - __per_cpu_start;
3c9a024fde58b0 Tejun Heo              2010-09-09  2846  	int nr_groups = 1, nr_units = 0;
3c9a024fde58b0 Tejun Heo              2010-09-09  2847  	size_t size_sum, min_unit_size, alloc_size;
3f649ab728cda8 Kees Cook              2020-06-03  2848  	int upa, max_upa, best_upa;	/* units_per_alloc */
3c9a024fde58b0 Tejun Heo              2010-09-09  2849  	int last_allocs, group, unit;
3c9a024fde58b0 Tejun Heo              2010-09-09  2850  	unsigned int cpu, tcpu;
3c9a024fde58b0 Tejun Heo              2010-09-09  2851  	struct pcpu_alloc_info *ai;
3c9a024fde58b0 Tejun Heo              2010-09-09  2852  	unsigned int *cpu_map;
3c9a024fde58b0 Tejun Heo              2010-09-09  2853  
3c9a024fde58b0 Tejun Heo              2010-09-09  2854  	/* this function may be called multiple times */
3c9a024fde58b0 Tejun Heo              2010-09-09  2855  	memset(group_map, 0, sizeof(group_map));
3c9a024fde58b0 Tejun Heo              2010-09-09  2856  	memset(group_cnt, 0, sizeof(group_cnt));
d7d29ac76f7efb Wonhyuk Yang           2020-10-30  2857  	cpumask_clear(&mask);
3c9a024fde58b0 Tejun Heo              2010-09-09  2858  
3c9a024fde58b0 Tejun Heo              2010-09-09  2859  	/* calculate size_sum and ensure dyn_size is enough for early alloc */
3c9a024fde58b0 Tejun Heo              2010-09-09  2860  	size_sum = PFN_ALIGN(static_size + reserved_size +
3c9a024fde58b0 Tejun Heo              2010-09-09  2861  			    max_t(size_t, dyn_size, PERCPU_DYNAMIC_EARLY_SIZE));
3c9a024fde58b0 Tejun Heo              2010-09-09  2862  	dyn_size = size_sum - static_size - reserved_size;
3c9a024fde58b0 Tejun Heo              2010-09-09  2863  
3c9a024fde58b0 Tejun Heo              2010-09-09  2864  	/*
3c9a024fde58b0 Tejun Heo              2010-09-09  2865  	 * Determine min_unit_size, alloc_size and max_upa such that
3c9a024fde58b0 Tejun Heo              2010-09-09  2866  	 * alloc_size is multiple of atom_size and is the smallest
25985edcedea63 Lucas De Marchi        2011-03-30  2867  	 * which can accommodate 4k aligned segments which are equal to
3c9a024fde58b0 Tejun Heo              2010-09-09  2868  	 * or larger than min_unit_size.
3c9a024fde58b0 Tejun Heo              2010-09-09  2869  	 */
3c9a024fde58b0 Tejun Heo              2010-09-09  2870  	min_unit_size = max_t(size_t, size_sum, PCPU_MIN_UNIT_SIZE);
3c9a024fde58b0 Tejun Heo              2010-09-09  2871  
9c01516278ef87 Dennis Zhou (Facebook  2017-07-15  2872) 	/* determine the maximum # of units that can fit in an allocation */
3c9a024fde58b0 Tejun Heo              2010-09-09  2873  	alloc_size = roundup(min_unit_size, atom_size);
3c9a024fde58b0 Tejun Heo              2010-09-09  2874  	upa = alloc_size / min_unit_size;
f09f1243ca2d5d Alexander Kuleshov     2015-11-05  2875  	while (alloc_size % upa || (offset_in_page(alloc_size / upa)))
3c9a024fde58b0 Tejun Heo              2010-09-09  2876  		upa--;
3c9a024fde58b0 Tejun Heo              2010-09-09  2877  	max_upa = upa;
3c9a024fde58b0 Tejun Heo              2010-09-09  2878  
d7d29ac76f7efb Wonhyuk Yang           2020-10-30  2879  	cpumask_copy(&mask, cpu_possible_mask);
d7d29ac76f7efb Wonhyuk Yang           2020-10-30  2880  
3c9a024fde58b0 Tejun Heo              2010-09-09  2881  	/* group cpus according to their proximity */
d7d29ac76f7efb Wonhyuk Yang           2020-10-30  2882  	for (group = 0; !cpumask_empty(&mask); group++) {
d7d29ac76f7efb Wonhyuk Yang           2020-10-30  2883  		/* pop the group's first cpu */
d7d29ac76f7efb Wonhyuk Yang           2020-10-30  2884  		cpu = cpumask_first(&mask);
3c9a024fde58b0 Tejun Heo              2010-09-09 @2885  		group_map[cpu] = group;
3c9a024fde58b0 Tejun Heo              2010-09-09  2886  		group_cnt[group]++;
d7d29ac76f7efb Wonhyuk Yang           2020-10-30  2887  		cpumask_clear_cpu(cpu, &mask);
d7d29ac76f7efb Wonhyuk Yang           2020-10-30  2888  
d7d29ac76f7efb Wonhyuk Yang           2020-10-30  2889  		for_each_cpu(tcpu, &mask) {
d7d29ac76f7efb Wonhyuk Yang           2020-10-30  2890  			if (!cpu_distance_fn ||
d7d29ac76f7efb Wonhyuk Yang           2020-10-30  2891  			    (cpu_distance_fn(cpu, tcpu) == LOCAL_DISTANCE &&
d7d29ac76f7efb Wonhyuk Yang           2020-10-30  2892  			     cpu_distance_fn(tcpu, cpu) == LOCAL_DISTANCE)) {
d7d29ac76f7efb Wonhyuk Yang           2020-10-30  2893  				group_map[tcpu] = group;
d7d29ac76f7efb Wonhyuk Yang           2020-10-30  2894  				group_cnt[group]++;
d7d29ac76f7efb Wonhyuk Yang           2020-10-30  2895  				cpumask_clear_cpu(tcpu, &mask);
d7d29ac76f7efb Wonhyuk Yang           2020-10-30  2896  			}
d7d29ac76f7efb Wonhyuk Yang           2020-10-30  2897  		}
3c9a024fde58b0 Tejun Heo              2010-09-09  2898  	}
d7d29ac76f7efb Wonhyuk Yang           2020-10-30  2899  	nr_groups = group;
3c9a024fde58b0 Tejun Heo              2010-09-09  2900  
3c9a024fde58b0 Tejun Heo              2010-09-09  2901  	/*
9c01516278ef87 Dennis Zhou (Facebook  2017-07-15  2902) 	 * Wasted space is caused by a ratio imbalance of upa to group_cnt.
9c01516278ef87 Dennis Zhou (Facebook  2017-07-15  2903) 	 * Expand the unit_size until we use >= 75% of the units allocated.
9c01516278ef87 Dennis Zhou (Facebook  2017-07-15  2904) 	 * Related to atom_size, which could be much larger than the unit_size.
3c9a024fde58b0 Tejun Heo              2010-09-09  2905  	 */
3c9a024fde58b0 Tejun Heo              2010-09-09  2906  	last_allocs = INT_MAX;
4829c791b22f98 Dennis Zhou            2021-06-14  2907  	best_upa = 0;
3c9a024fde58b0 Tejun Heo              2010-09-09  2908  	for (upa = max_upa; upa; upa--) {
3c9a024fde58b0 Tejun Heo              2010-09-09  2909  		int allocs = 0, wasted = 0;
3c9a024fde58b0 Tejun Heo              2010-09-09  2910  
f09f1243ca2d5d Alexander Kuleshov     2015-11-05  2911  		if (alloc_size % upa || (offset_in_page(alloc_size / upa)))
3c9a024fde58b0 Tejun Heo              2010-09-09  2912  			continue;
3c9a024fde58b0 Tejun Heo              2010-09-09  2913  
3c9a024fde58b0 Tejun Heo              2010-09-09  2914  		for (group = 0; group < nr_groups; group++) {
3c9a024fde58b0 Tejun Heo              2010-09-09  2915  			int this_allocs = DIV_ROUND_UP(group_cnt[group], upa);
3c9a024fde58b0 Tejun Heo              2010-09-09  2916  			allocs += this_allocs;
3c9a024fde58b0 Tejun Heo              2010-09-09  2917  			wasted += this_allocs * upa - group_cnt[group];
3c9a024fde58b0 Tejun Heo              2010-09-09  2918  		}
3c9a024fde58b0 Tejun Heo              2010-09-09  2919  
3c9a024fde58b0 Tejun Heo              2010-09-09  2920  		/*
3c9a024fde58b0 Tejun Heo              2010-09-09  2921  		 * Don't accept if wastage is over 1/3.  The
3c9a024fde58b0 Tejun Heo              2010-09-09  2922  		 * greater-than comparison ensures upa==1 always
3c9a024fde58b0 Tejun Heo              2010-09-09  2923  		 * passes the following check.
3c9a024fde58b0 Tejun Heo              2010-09-09  2924  		 */
3c9a024fde58b0 Tejun Heo              2010-09-09  2925  		if (wasted > num_possible_cpus() / 3)
3c9a024fde58b0 Tejun Heo              2010-09-09  2926  			continue;
3c9a024fde58b0 Tejun Heo              2010-09-09  2927  
3c9a024fde58b0 Tejun Heo              2010-09-09  2928  		/* and then don't consume more memory */
3c9a024fde58b0 Tejun Heo              2010-09-09  2929  		if (allocs > last_allocs)
3c9a024fde58b0 Tejun Heo              2010-09-09  2930  			break;
3c9a024fde58b0 Tejun Heo              2010-09-09  2931  		last_allocs = allocs;
3c9a024fde58b0 Tejun Heo              2010-09-09  2932  		best_upa = upa;
3c9a024fde58b0 Tejun Heo              2010-09-09  2933  	}
4829c791b22f98 Dennis Zhou            2021-06-14  2934  	BUG_ON(!best_upa);
3c9a024fde58b0 Tejun Heo              2010-09-09  2935  	upa = best_upa;
3c9a024fde58b0 Tejun Heo              2010-09-09  2936  
3c9a024fde58b0 Tejun Heo              2010-09-09  2937  	/* allocate and fill alloc_info */
3c9a024fde58b0 Tejun Heo              2010-09-09  2938  	for (group = 0; group < nr_groups; group++)
3c9a024fde58b0 Tejun Heo              2010-09-09  2939  		nr_units += roundup(group_cnt[group], upa);
3c9a024fde58b0 Tejun Heo              2010-09-09  2940  
3c9a024fde58b0 Tejun Heo              2010-09-09  2941  	ai = pcpu_alloc_alloc_info(nr_groups, nr_units);
3c9a024fde58b0 Tejun Heo              2010-09-09  2942  	if (!ai)
3c9a024fde58b0 Tejun Heo              2010-09-09  2943  		return ERR_PTR(-ENOMEM);
3c9a024fde58b0 Tejun Heo              2010-09-09  2944  	cpu_map = ai->groups[0].cpu_map;
3c9a024fde58b0 Tejun Heo              2010-09-09  2945  
3c9a024fde58b0 Tejun Heo              2010-09-09  2946  	for (group = 0; group < nr_groups; group++) {
3c9a024fde58b0 Tejun Heo              2010-09-09  2947  		ai->groups[group].cpu_map = cpu_map;
3c9a024fde58b0 Tejun Heo              2010-09-09  2948  		cpu_map += roundup(group_cnt[group], upa);
3c9a024fde58b0 Tejun Heo              2010-09-09  2949  	}
3c9a024fde58b0 Tejun Heo              2010-09-09  2950  
3c9a024fde58b0 Tejun Heo              2010-09-09  2951  	ai->static_size = static_size;
3c9a024fde58b0 Tejun Heo              2010-09-09  2952  	ai->reserved_size = reserved_size;
3c9a024fde58b0 Tejun Heo              2010-09-09  2953  	ai->dyn_size = dyn_size;
3c9a024fde58b0 Tejun Heo              2010-09-09  2954  	ai->unit_size = alloc_size / upa;
3c9a024fde58b0 Tejun Heo              2010-09-09  2955  	ai->atom_size = atom_size;
3c9a024fde58b0 Tejun Heo              2010-09-09  2956  	ai->alloc_size = alloc_size;
3c9a024fde58b0 Tejun Heo              2010-09-09  2957  
2de7852fe9096e Peng Fan               2019-02-20  2958  	for (group = 0, unit = 0; group < nr_groups; group++) {
3c9a024fde58b0 Tejun Heo              2010-09-09  2959  		struct pcpu_group_info *gi = &ai->groups[group];
3c9a024fde58b0 Tejun Heo              2010-09-09  2960  
3c9a024fde58b0 Tejun Heo              2010-09-09  2961  		/*
3c9a024fde58b0 Tejun Heo              2010-09-09  2962  		 * Initialize base_offset as if all groups are located
3c9a024fde58b0 Tejun Heo              2010-09-09  2963  		 * back-to-back.  The caller should update this to
3c9a024fde58b0 Tejun Heo              2010-09-09  2964  		 * reflect actual allocation.
3c9a024fde58b0 Tejun Heo              2010-09-09  2965  		 */
3c9a024fde58b0 Tejun Heo              2010-09-09  2966  		gi->base_offset = unit * ai->unit_size;
3c9a024fde58b0 Tejun Heo              2010-09-09  2967  
3c9a024fde58b0 Tejun Heo              2010-09-09  2968  		for_each_possible_cpu(cpu)
3c9a024fde58b0 Tejun Heo              2010-09-09  2969  			if (group_map[cpu] == group)
3c9a024fde58b0 Tejun Heo              2010-09-09  2970  				gi->cpu_map[gi->nr_units++] = cpu;
3c9a024fde58b0 Tejun Heo              2010-09-09  2971  		gi->nr_units = roundup(gi->nr_units, upa);
3c9a024fde58b0 Tejun Heo              2010-09-09  2972  		unit += gi->nr_units;
3c9a024fde58b0 Tejun Heo              2010-09-09  2973  	}
3c9a024fde58b0 Tejun Heo              2010-09-09  2974  	BUG_ON(unit != nr_units);
3c9a024fde58b0 Tejun Heo              2010-09-09  2975  
3c9a024fde58b0 Tejun Heo              2010-09-09  2976  	return ai;
3c9a024fde58b0 Tejun Heo              2010-09-09  2977  }
23f917169ef157 Kefeng Wang            2022-01-19  2978  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

  parent reply	other threads:[~2023-10-18 16:24 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-11 15:02 [PATCH 0/2] lib/find: Fix KCSAN warnings in find_*_bit() functions Jan Kara
2023-10-11 15:02 ` [PATCH 1/2] lib/find: Make functions safe on changing bitmaps Jan Kara
2023-10-11 18:26   ` Yury Norov
2023-10-11 18:49     ` Matthew Wilcox
2023-10-11 19:25       ` Mirsad Todorovac
2023-10-12 12:21     ` Jan Kara
2023-10-14  0:15       ` Yury Norov
2023-10-14  2:21         ` Mirsad Goran Todorovac
2023-10-14  2:53           ` Yury Norov
2023-10-14 10:04             ` Mirsad Todorovac
2023-10-16  9:22         ` Jan Kara
2023-10-11 20:40   ` Mirsad Todorovac
2023-10-18 16:23   ` kernel test robot [this message]
2023-10-25  7:18   ` kernel test robot
2023-10-25  8:18     ` Rasmus Villemoes
2023-10-27  3:51       ` Yury Norov
2023-10-27  9:55         ` Jan Kara
2023-10-27 15:51         ` Mirsad Todorovac
2023-10-11 15:02 ` [PATCH 2/2] xarray: Fix race in xas_find_chunk() Jan Kara
2023-10-11 15:38   ` Matthew Wilcox
2023-10-11 20:40   ` Mirsad Todorovac

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202310190005.NqJcRXtK-lkp@intel.com \
    --to=lkp@intel.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=mirsad.todorovac@alu.unizg.hr \
    --cc=oe-kbuild-all@lists.linux.dev \
    --cc=willy@infradead.org \
    --cc=yury.norov@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.