perf: fix segfault in `lock contention -b`
PATCH v2 1/1 perf: fix segfault in `lock contention -b`
From: "Tycho Andersen (AMD)" <[email protected]>
When run on a kernel without BTF info, perf crashes:
libbpf: kernel BTF is missing at '/sys/kernel/btf/vmlinux', was CONFIG_DEBUG_INFO_BTF enabled?
libbpf: failed to find valid kernel BTF
Program received signal SIGSEGV, Segmentation fault.
0x00005555556915b7 in btf.type_cnt ()
(gdb) bt
#0 0x00005555556915b7 in btf.type_cnt ()
#1 0x0000555555691fbc in btf_find_by_name_kind ()
#2 0x00005555556920d0 in btf.find_by_name_kind ()
#3 0x00005555558a1b7c in init_numa_data (con=0x7fffffffd0a0) at util/bpf_lock_contention.c:125
#4 0x00005555558a264b in lock_contention_prepare (con=0x7fffffffd0a0) at util/bpf_lock_contention.c:313
#5 0x0000555555620702 in __cmd_contention (argc=0, argv=0x7fffffffea10) at builtin-lock.c:2084
#6 0x0000555555622c8d in cmd_lock (argc=0, argv=0x7fffffffea10) at builtin-lock.c:2755
#7 0x0000555555651451 in run_builtin (p=0x555556104f00 <commands+576>, argc=3, argv=0x7fffffffea10)
at perf.c:349
#8 0x00005555556516ed in handle_internal_command (argc=3, argv=0x7fffffffea10) at perf.c:401
#9 0x000055555565184e in run_argv (argcp=0x7fffffffe7fc, argv=0x7fffffffe7f0) at perf.c:445
#10 0x0000555555651b9f in main (argc=3, argv=0x7fffffffea10) at perf.c:553Check if btf loading failed, and don't do anything with it in init_numa_data(). This leads to the following error message, instead of just a crash:
libbpf: kernel BTF is missing at '/sys/kernel/btf/vmlinux', was CONFIG_DEBUG_INFO_BTF enabled?
libbpf: failed to find valid kernel BTF
libbpf: kernel BTF is missing at '/sys/kernel/btf/vmlinux', was CONFIG_DEBUG_INFO_BTF enabled?
libbpf: failed to find valid kernel BTF
libbpf: Error loading vmlinux BTF: -ESRCH
libbpf: failed to load BPF skeleton 'lock_contention_bpf': -ESRCH
Failed to load lock-contention BPF skeleton
lock contention BPF setup failed
--- tools/perf/util/bpf_lock_contention.c | 3 +++ 1 file changed, 3 insertions(+)
tools/perf/util/bpf_lock_contention.c +3 -0
@@ -117,6 +117,9 @@ static void init_numa_data(struct lock_contention *con)long last =-1 ;int ret; +if (!con->btf) +return ; +/* * 'struct zone' is embedded in 'struct pglist_data' as an array. * As we may not have full information of the struct zone in the
base-commit: 18f7fcd5e69a04df57b563360b88be72471d6b62
Signature · 1 line
2.52.0
Hello,
Quoted 36 lines · Tycho Andersen
From: "Tycho Andersen (AMD)" <[email protected]>
When run on a kernel without BTF info, perf crashes:
libbpf: kernel BTF is missing at '/sys/kernel/btf/vmlinux', was CONFIG_DEBUG_INFO_BTF enabled? libbpf: failed to find valid kernel BTF Program received signal SIGSEGV, Segmentation fault. 0x00005555556915b7 in btf.type_cnt () (gdb) bt #0 0x00005555556915b7 in btf.type_cnt () #1 0x0000555555691fbc in btf_find_by_name_kind () #2 0x00005555556920d0 in btf.find_by_name_kind () #3 0x00005555558a1b7c in init_numa_data (con=0x7fffffffd0a0) at util/bpf_lock_contention.c:125 #4 0x00005555558a264b in lock_contention_prepare (con=0x7fffffffd0a0) at util/bpf_lock_contention.c:313 #5 0x0000555555620702 in __cmd_contention (argc=0, argv=0x7fffffffea10) at builtin-lock.c:2084 #6 0x0000555555622c8d in cmd_lock (argc=0, argv=0x7fffffffea10) at builtin-lock.c:2755 #7 0x0000555555651451 in run_builtin (p=0x555556104f00 <commands+576>, argc=3, argv=0x7fffffffea10) at perf.c:349 #8 0x00005555556516ed in handle_internal_command (argc=3, argv=0x7fffffffea10) at perf.c:401 #9 0x000055555565184e in run_argv (argcp=0x7fffffffe7fc, argv=0x7fffffffe7f0) at perf.c:445 #10 0x0000555555651b9f in main (argc=3, argv=0x7fffffffea10) at perf.c:553Check if btf loading failed, and don't do anything with it in
init_numa_data(). This leads to the following error message, instead of just a crash:libbpf: kernel BTF is missing at '
/sys/kernel/btf/vmlinux', wasCONFIG_DEBUG_INFO_BTFenabled?
libbpf: failed to find valid kernel BTF
libbpf: kernel BTF is missing at '/sys/kernel/btf/vmlinux', wasCONFIG_DEBUG_INFO_BTFenabled?
libbpf: failed to find valid kernel BTF
libbpf: Error loading vmlinux BTF:-ESRCH
libbpf: failed to load BPF skeleton 'lock_contention_bpf':-ESRCH
Failed to load lock-contention BPF skeleton
lock contention BPF setup failed
Quoted 3 lines
Signed-off-by Tycho Andersen (AMD) <[email protected]>CC Ravi Bangoria <[email protected]>CC K Prateek Nayak <[email protected]>
Thanks,
Namhyung
Quoted 23 lines
--- tools/perf/util/bpf_lock_contention.c | 3 +++ 1 file changed, 3 insertions(+)tools/perf/util/bpf_lock_contention.c +3
-0@@ -117,6 +117,9 @@ static void init_numa_data(struct lock_contention *con)long last =-1 ;int ret; +if (!con->btf) +return ; +/* * 'struct zone' is embedded in 'struct pglist_data' as an array. * As we may not have full information of the struct zone in the base-commit:
18f7fcd5e69a04df57b563360b88be72471d6b62Signature · 1 line
2.52.0
Quoted 13 lines · Namhyung Kim
Quoted 11 lines · Tycho Andersen
Check if btf loading failed, and don't do anything with it in
init_numa_data(). This leads to the following error message, instead of
just a crash:
libbpf: kernel BTF is missing at '/sys/kernel/btf/vmlinux', wasCONFIG_DEBUG_INFO_BTFenabled?
libbpf: failed to find valid kernel BTF
libbpf: kernel BTF is missing at '/sys/kernel/btf/vmlinux', wasCONFIG_DEBUG_INFO_BTFenabled?
libbpf: failed to find valid kernel BTF
libbpf: Error loading vmlinux BTF:-ESRCH
libbpf: failed to load BPF skeleton 'lock_contention_bpf':-ESRCH
Failed to load lock-contention BPF skeleton
lock contention BPF setup failed
Quoted 3 lines
Quoted 1 line
Signed-off-by Tycho Andersen (AMD) <[email protected]>Acked-by Namhyung Kim <[email protected]>
Thanks, applied to perf-tools-next,
- Arnaldo