linux-stable/tools/perf/arch
James Clark f989dc0090 perf pmu: Move pmu__find_core_pmu() to pmus.c
[ Upstream commit 3d0f5f456a ]

pmu__find_core_pmu() more logically belongs in pmus.c because it
iterates over all PMUs, so move it to pmus.c

At the same time rename it to perf_pmus__find_core_pmu() to match the
naming convention in this file.

list_prepare_entry() can't be used in perf_pmus__scan_core() anymore now
that it's called from the same compilation unit. This is with -O2
(specifically -O1 -ftree-vrp -finline-functions
-finline-small-functions) which allow the bounds of the array
access to be determined at compile time. list_prepare_entry() subtracts
the offset of the 'list' member in struct perf_pmu from &core_pmus,
which isn't a struct perf_pmu. The compiler sees that pmu results in
&core_pmus - 8 and refuses to compile. At runtime this works because
list_for_each_entry_continue() always adds the offset back again before
dereferencing ->next, but it's technically undefined behavior. With
-fsanitize=undefined an additional warning is generated.

Using list_first_entry_or_null() to get the first entry here avoids
doing &core_pmus - 8 but has the same result and fixes both the compile
warning and the undefined behavior warning. There are other uses of
list_prepare_entry() in pmus.c, but the compiler doesn't seem to be
able to see that they can also be called with &core_pmus, so I won't
change any at this time.

Signed-off-by: James Clark <james.clark@arm.com>
Reviewed-by: Ian Rogers <irogers@google.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Eduard Zingerman <eddyz87@gmail.com>
Cc: Will Deacon <will@kernel.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
Cc: Haixin Yu <yuhaixin.yhx@linux.alibaba.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: linux-arm-kernel@lists.infradead.org
Link: https://lore.kernel.org/r/20230913153355.138331-2-james.clark@arm.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Stable-dep-of: d9c5f5f94c ("perf pmu: Count sys and cpuid JSON events separately")
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-06-12 11:12:31 +02:00
..
alpha
arc/annotate
arm perf pmu: Avoid passing format list to perf_pmu__format_bits() 2023-08-23 14:27:34 -03:00
arm64 perf pmu: Move pmu__find_core_pmu() to pmus.c 2024-06-12 11:12:31 +02:00
csky perf parse-regs: Move out arch specific header from util/perf_regs.h 2023-08-16 08:52:45 -03:00
loongarch perf parse-regs: Move out arch specific header from util/perf_regs.h 2023-08-16 08:52:45 -03:00
mips tools headers UAPI: Sync files changed by new fchmodat2 and map_shadow_stack syscalls with the kernel sources 2023-09-13 08:24:51 -03:00
parisc
powerpc tools headers UAPI: Sync files changed by new fchmodat2 and map_shadow_stack syscalls with the kernel sources 2023-09-13 08:24:51 -03:00
riscv perf parse-regs: Move out arch specific header from util/perf_regs.h 2023-08-16 08:52:45 -03:00
riscv64/annotate perf annotate: Add riscv64 support 2021-09-27 09:33:44 -03:00
s390 tools headers UAPI: Sync files changed by new fchmodat2 and map_shadow_stack syscalls with the kernel sources 2023-09-13 08:24:51 -03:00
sh treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
sparc treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
x86 tools headers UAPI: Sync files changed by new fchmodat2 and map_shadow_stack syscalls with the kernel sources 2023-09-13 08:24:51 -03:00
xtensa treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
Build perf tools: Rename build libperf to perf 2019-02-14 15:18:08 -03:00
common.c perf tools riscv: Add support for riscv lookup_binutils_path 2023-05-12 15:21:48 -03:00
common.h perf annotate: Own objdump_path and disassembler_style strings 2023-04-04 09:39:56 -03:00