linux-stable/tools/perf/arch
Athira Rajeev 341e0e9f59 perf callchain powerpc: Fix addr location init during arch_skip_callchain_idx function
'perf record;  with callchain recording fails as below
in powerpc:

    ./perf record -a -gR sleep 10
    ./perf report
    perf: Segmentation fault

gdb trace points to thread__find_map

    0  0x00000000101df314 in atomic_cmpxchg (newval=1818846826, oldval=1818846827, v=0x1001a8f3) at /home/athira/linux/tools/include/asm-generic/atomic-gcc.h:70
    1  refcount_sub_and_test (i=1, r=0x1001a8f3) at /home/athira/linux/tools/include/linux/refcount.h:135
    2  refcount_dec_and_test (r=0x1001a8f3) at /home/athira/linux/tools/include/linux/refcount.h:148
    3  map__put (map=0x1001a8b3) at util/map.c:311
    4  0x000000001016842c in __map__zput (map=0x7fffffffa368) at util/map.h:190
    5  thread__find_map (thread=0x105b92f0, cpumode=<optimized out>, addr=13835058055283572736, al=al@entry=0x7fffffffa358) at util/event.c:582
    6  0x000000001016882c in thread__find_symbol (thread=<optimized out>, cpumode=<optimized out>, addr=<optimized out>, al=0x7fffffffa358) at util/event.c:656
    7  0x00000000102e12b4 in arch_skip_callchain_idx (thread=<optimized out>, chain=<optimized out>) at arch/powerpc/util/skip-callchain-idx.c:255
    8  0x00000000101d3bf4 in thread__resolve_callchain_sample (thread=0x105b92f0, cursor=0x1053d160, evsel=<optimized out>, sample=0x7fffffffa908, parent=0x7fffffffa778, root_al=0x7fffffffa710,
        max_stack=<optimized out>) at util/machine.c:2940
    9  0x00000000101cd210 in sample__resolve_callchain (sample=<optimized out>, cursor=<optimized out>, parent=<optimized out>, evsel=<optimized out>, al=<optimized out>, max_stack=<optimized out>)
        at util/callchain.c:1112
    10 0x000000001022a9d8 in hist_entry_iter__add (iter=0x7fffffffa750, al=0x7fffffffa710, max_stack_depth=<optimized out>, arg=0x7fffffffbbd0) at util/hist.c:1232
    11 0x0000000010056d98 in process_sample_event (tool=0x7fffffffbbd0, event=0x7ffff6223c38, sample=0x7fffffffa908, evsel=<optimized out>, machine=0x10524ef8) at builtin-report.c:332

Here arch_skip_callchain_idx calls thread__find_symbol and which
invokes thread__find_map with uninitialised "addr_location".
Snippet:

thread__find_symbol(thread, PERF_RECORD_MISC_USER, ip, &al);

Recent change with commit 0dd5041c9a ("perf addr_location: Add
init/exit/copy functions") , introduced "maps__zput" in the function
thread__find_map. This could result in segfault while accessing
uninitialised map from "struct addr_location". Fix this by adding
addr_location__init and addr_location__exit in arch_skip_callchain_idx.

Fixes: 0dd5041c9a ("perf addr_location: Add init/exit/copy functions")
Reported-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Disha Goel <disgoel@linux.vnet.ibm.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linuxppc-dev@lists.ozlabs.org
Link: https://lore.kernel.org/r/20230724165815.17810-1-atrajeev@linux.vnet.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-07-24 17:46:11 -03:00
..
alpha
arc/annotate perf annotate: Introduce basic support for ARC 2018-12-17 14:59:42 -03:00
arm perf thread: Add accessor functions for thread 2023-06-12 15:57:53 -03:00
arm64 perf pmu arm64: Fix reading the PMU cpu slots in sysfs 2023-07-24 13:40:52 -03:00
csky perf arch: Support register names from all archs 2021-12-16 12:18:12 -03:00
loongarch perf annotate: Fix instruction association and parsing for LoongArch 2023-06-20 21:55:06 -07:00
mips tools headers UAPI: Sync files changed by new cachestat syscall with the kernel sources 2023-07-11 11:41:15 -03:00
parisc
powerpc perf callchain powerpc: Fix addr location init during arch_skip_callchain_idx function 2023-07-24 17:46:11 -03:00
riscv perf tools riscv: Fix build error on riscv due to missing header for 'struct perf_sample' 2023-01-02 11:47:22 -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 cachestat syscall with the kernel sources 2023-07-11 11:41:15 -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 cachestat syscall with the kernel sources 2023-07-11 11:41:15 -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