Message ID | 20240402105610.1695644-5-dawei.li@shingroup.cn (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | perf: Avoid explicit cpumask var allocation from stack | expand |
Hi Dawei, kernel test robot noticed the following build errors: [auto build test ERROR on soc/for-next] [also build test ERROR on linus/master v6.9-rc2 next-20240402] [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/Dawei-Li/perf-alibaba_uncore_drw-Avoid-explicit-cpumask-var-allocation-from-stack/20240402-192244 base: https://git.kernel.org/pub/scm/linux/kernel/git/soc/soc.git for-next patch link: https://lore.kernel.org/r/20240402105610.1695644-5-dawei.li%40shingroup.cn patch subject: [PATCH 4/9] perf/arm_dsu: Avoid explicit cpumask var allocation from stack config: arm64-defconfig (https://download.01.org/0day-ci/archive/20240403/202404030702.vL5Ep98R-lkp@intel.com/config) compiler: aarch64-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240403/202404030702.vL5Ep98R-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/202404030702.vL5Ep98R-lkp@intel.com/ All errors (new ones prefixed by >>): drivers/perf/arm_dsu_pmu.c: In function 'dsu_pmu_get_online_cpu_any_but': >> drivers/perf/arm_dsu_pmu.c:243:31: error: passing argument 1 of 'cpumask_any_but' from incompatible pointer type [-Werror=incompatible-pointer-types] 243 | ret = cpumask_any_but(&online_supported, cpu); | ^~~~~~~~~~~~~~~~~ | | | struct cpumask (*)[1] In file included from arch/arm64/include/asm/cpufeature.h:26, from arch/arm64/include/asm/ptrace.h:11, from arch/arm64/include/asm/irqflags.h:10, from include/linux/irqflags.h:18, from include/linux/spinlock.h:59, from include/linux/mmzone.h:8, from include/linux/gfp.h:7, from include/linux/slab.h:16, from include/linux/resource_ext.h:11, from include/linux/acpi.h:13, from drivers/perf/arm_dsu_pmu.c:14: include/linux/cpumask.h:379:52: note: expected 'const struct cpumask *' but argument is of type 'struct cpumask (*)[1]' 379 | unsigned int cpumask_any_but(const struct cpumask *mask, unsigned int cpu) | ~~~~~~~~~~~~~~~~~~~~~~^~~~ cc1: some warnings being treated as errors vim +/cpumask_any_but +243 drivers/perf/arm_dsu_pmu.c 232 233 static unsigned int dsu_pmu_get_online_cpu_any_but(struct dsu_pmu *dsu_pmu, int cpu) 234 { 235 cpumask_var_t online_supported; 236 unsigned int ret; 237 238 if (!alloc_cpumask_var(&online_supported, GFP_KERNEL)) 239 return -ENOMEM; 240 241 cpumask_and(online_supported, 242 &dsu_pmu->associated_cpus, cpu_online_mask); > 243 ret = cpumask_any_but(&online_supported, cpu); 244 245 free_cpumask_var(online_supported); 246 247 return ret; 248 } 249
Hi Dawei, kernel test robot noticed the following build errors: [auto build test ERROR on soc/for-next] [also build test ERROR on linus/master v6.9-rc2 next-20240402] [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/Dawei-Li/perf-alibaba_uncore_drw-Avoid-explicit-cpumask-var-allocation-from-stack/20240402-192244 base: https://git.kernel.org/pub/scm/linux/kernel/git/soc/soc.git for-next patch link: https://lore.kernel.org/r/20240402105610.1695644-5-dawei.li%40shingroup.cn patch subject: [PATCH 4/9] perf/arm_dsu: Avoid explicit cpumask var allocation from stack config: arm64-randconfig-001-20240403 (https://download.01.org/0day-ci/archive/20240403/202404030906.L4BhRzHw-lkp@intel.com/config) compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240403/202404030906.L4BhRzHw-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/202404030906.L4BhRzHw-lkp@intel.com/ All errors (new ones prefixed by >>): >> drivers/perf/arm_dsu_pmu.c:243:24: error: incompatible pointer types passing 'cpumask_var_t *' (aka 'struct cpumask **') to parameter of type 'const struct cpumask *'; remove & [-Werror,-Wincompatible-pointer-types] ret = cpumask_any_but(&online_supported, cpu); ^~~~~~~~~~~~~~~~~ include/linux/cpumask.h:379:52: note: passing argument to parameter 'mask' here unsigned int cpumask_any_but(const struct cpumask *mask, unsigned int cpu) ^ 1 error generated. vim +243 drivers/perf/arm_dsu_pmu.c 232 233 static unsigned int dsu_pmu_get_online_cpu_any_but(struct dsu_pmu *dsu_pmu, int cpu) 234 { 235 cpumask_var_t online_supported; 236 unsigned int ret; 237 238 if (!alloc_cpumask_var(&online_supported, GFP_KERNEL)) 239 return -ENOMEM; 240 241 cpumask_and(online_supported, 242 &dsu_pmu->associated_cpus, cpu_online_mask); > 243 ret = cpumask_any_but(&online_supported, cpu); 244 245 free_cpumask_var(online_supported); 246 247 return ret; 248 } 249
diff --git a/drivers/perf/arm_dsu_pmu.c b/drivers/perf/arm_dsu_pmu.c index bae3ca37f846..87efdca05807 100644 --- a/drivers/perf/arm_dsu_pmu.c +++ b/drivers/perf/arm_dsu_pmu.c @@ -230,13 +230,21 @@ static const struct attribute_group *dsu_pmu_attr_groups[] = { NULL, }; -static int dsu_pmu_get_online_cpu_any_but(struct dsu_pmu *dsu_pmu, int cpu) +static unsigned int dsu_pmu_get_online_cpu_any_but(struct dsu_pmu *dsu_pmu, int cpu) { - struct cpumask online_supported; + cpumask_var_t online_supported; + unsigned int ret; - cpumask_and(&online_supported, - &dsu_pmu->associated_cpus, cpu_online_mask); - return cpumask_any_but(&online_supported, cpu); + if (!alloc_cpumask_var(&online_supported, GFP_KERNEL)) + return -ENOMEM; + + cpumask_and(online_supported, + &dsu_pmu->associated_cpus, cpu_online_mask); + ret = cpumask_any_but(&online_supported, cpu); + + free_cpumask_var(online_supported); + + return ret; } static inline bool dsu_pmu_counter_valid(struct dsu_pmu *dsu_pmu, u32 idx)
For CONFIG_CPUMASK_OFFSTACK=y kernel, explicit allocation of cpumask variable on stack is not recommended since it can cause potential stack overflow. Instead, kernel code should always use *cpumask_var API(s) to allocate cpumask var in config- neutral way, leaving allocation strategy to CONFIG_CPUMASK_OFFSTACK. Use *cpumask_var API(s) to address it. Signed-off-by: Dawei Li <dawei.li@shingroup.cn> --- drivers/perf/arm_dsu_pmu.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)