Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf: Fix topology_sibling_cpumask check warning on ARM

The below warning is triggered when building with arm
multi_v7_defconfig.

kernel/events/core.c: In function 'perf_event_setup_cpumask':
kernel/events/core.c:14012:13: warning: the comparison will always evaluate as 'true' for the address of 'thread_sibling' will never be NULL [-Waddress]
14012 | if (!topology_sibling_cpumask(cpu)) {

The perf_event_init_cpu() may be invoked at the early boot stage, while
the topology_*_cpumask hasn't been initialized yet. The check is to
specially handle the case, and initialize the perf_online_<domain>_masks
on the boot CPU.

X86 uses a per-cpu cpumask pointer, which could be NULL at the early
boot stage. However, ARM uses a global variable, which never be NULL.

Use perf_online_mask as an indicator instead. Only initialize the
perf_online_<domain>_masks when perf_online_mask is empty.

Fix a typo as well.

Fixes: 4ba4f1afb6a9 ("perf: Generic hotplug support for a PMU with a scope")
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Closes: https://lore.kernel.org/lkml/20240911153854.240bbc1f@canb.auug.org.au/
Reported-by: Steven Price <steven.price@arm.com>
Closes: https://lore.kernel.org/lkml/1835eb6d-3e05-47f3-9eae-507ce165c3bf@arm.com/
Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
Tested-by: Steven Price <steven.price@arm.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Kan Liang and committed by
Linus Torvalds
673a5009 88264981

+5 -5
+5 -5
kernel/events/core.c
··· 14002 14002 struct cpumask *pmu_cpumask; 14003 14003 unsigned int scope; 14004 14004 14005 - cpumask_set_cpu(cpu, perf_online_mask); 14006 - 14007 14005 /* 14008 14006 * Early boot stage, the cpumask hasn't been set yet. 14009 14007 * The perf_online_<domain>_masks includes the first CPU of each domain. 14010 - * Always uncondifionally set the boot CPU for the perf_online_<domain>_masks. 14008 + * Always unconditionally set the boot CPU for the perf_online_<domain>_masks. 14011 14009 */ 14012 - if (!topology_sibling_cpumask(cpu)) { 14010 + if (cpumask_empty(perf_online_mask)) { 14013 14011 for (scope = PERF_PMU_SCOPE_NONE + 1; scope < PERF_PMU_MAX_SCOPE; scope++) { 14014 14012 pmu_cpumask = perf_scope_cpumask(scope); 14015 14013 if (WARN_ON_ONCE(!pmu_cpumask)) 14016 14014 continue; 14017 14015 cpumask_set_cpu(cpu, pmu_cpumask); 14018 14016 } 14019 - return; 14017 + goto end; 14020 14018 } 14021 14019 14022 14020 for (scope = PERF_PMU_SCOPE_NONE + 1; scope < PERF_PMU_MAX_SCOPE; scope++) { ··· 14029 14031 cpumask_any_and(pmu_cpumask, cpumask) >= nr_cpu_ids) 14030 14032 cpumask_set_cpu(cpu, pmu_cpumask); 14031 14033 } 14034 + end: 14035 + cpumask_set_cpu(cpu, perf_online_mask); 14032 14036 } 14033 14037 14034 14038 int perf_event_init_cpu(unsigned int cpu)