* Re: [PATCH] perf tools: Fix crash on buildid-list with namespace
2017-10-17 13:29 ` [PATCH] perf tools: Fix crash on buildid-list with namespace Namhyung Kim
@ 2017-10-17 14:05 ` Arnaldo Carvalho de Melo
2017-10-18 0:07 ` Namhyung Kim
2017-10-20 7:20 ` [tip:perf/urgent] perf buildid-list: Fix crash when processing PERF_RECORD_NAMESPACE tip-bot for Namhyung Kim
1 sibling, 1 reply; 4+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-10-17 14:05 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ingo Molnar, Peter Zijlstra, Jiri Olsa, LKML, kernel-team,
Thomas-Mich Richter, linux-perf-use.,
Hendrik Brueckner, Hari Bathini
Em Tue, Oct 17, 2017 at 10:29:00PM +0900, Namhyung Kim escreveu:
> Thomas reported that perf buildid-list gets a segfault due to NULL
> pointer when he ran it on a data with namespace events. It was because
> the buildid_id__mark_dso_hit_ops lacks the namespace event handler and
> perf_too__fill_default() didn't set it.
In these cases, next time I suggest you add a Fixes: tag, so that the
stable@kernel.org guys can automatically figure out which kernels need
this fix, in this case:
Fixes: f3b3614a284d ("perf tools: Add PERF_RECORD_NAMESPACES to include namespaces related info")
The script I have for this even adds this CC line:
Cc: Hari Bathini <hbathini@linux.vnet.ibm.com>
I'm adding it,
Thanks!
- Arnaldo
> Program received signal SIGSEGV, Segmentation fault.
> 0x0000000000000000 in ?? ()
> Missing separate debuginfos, use: dnf debuginfo-install audit-libs-2.7.7-1.fc25.s390x bzip2-libs-1.0.6-21.fc25.s390x elfutils-libelf-0.169-1.fc25.s390x
> +elfutils-libs-0.169-1.fc25.s390x libcap-ng-0.7.8-1.fc25.s390x numactl-libs-2.0.11-2.ibm.fc25.s390x openssl-libs-1.1.0e-1.1.ibm.fc25.s390x perl-libs-5.24.1-386.fc25.s390x
> +python-libs-2.7.13-2.fc25.s390x slang-2.3.0-7.fc25.s390x xz-libs-5.2.3-2.fc25.s390x zlib-1.2.8-10.fc25.s390x
> (gdb) where
> #0 0x0000000000000000 in ?? ()
> #1 0x00000000010fad6a in machines__deliver_event (machines=<optimized out>, machines@entry=0x2c6fd18,
> evlist=<optimized out>, event=event@entry=0x3fffdf00470, sample=0x3ffffffe880, sample@entry=0x3ffffffe888,
> tool=tool@entry=0x1312968 <build_id.mark_dso_hit_ops>, file_offset=1136) at util/session.c:1287
> #2 0x00000000010fbf4e in perf_session__deliver_event (file_offset=1136, tool=0x1312968 <build_id.mark_dso_hit_ops>,
> sample=0x3ffffffe888, event=0x3fffdf00470, session=0x2c6fc30) at util/session.c:1340
> #3 perf_session__process_event (session=0x2c6fc30, session@entry=0x0, event=event@entry=0x3fffdf00470,
> file_offset=file_offset@entry=1136) at util/session.c:1522
> #4 0x00000000010fddde in __perf_session__process_events (file_size=11880, data_size=<optimized out>,
> data_offset=<optimized out>, session=0x0) at util/session.c:1899
> #5 perf_session__process_events (session=0x0, session@entry=0x2c6fc30) at util/session.c:1953
> #6 0x000000000103b2ac in perf_session__list_build_ids (with_hits=<optimized out>, force=<optimized out>)
> at builtin-buildid-list.c:83
> #7 cmd_buildid_list (argc=<optimized out>, argv=<optimized out>) at builtin-buildid-list.c:115
> #8 0x00000000010a026c in run_builtin (p=0x1311f78 <commands+24>, argc=argc@entry=2, argv=argv@entry=0x3fffffff3c0)
> at perf.c:296
> #9 0x000000000102bc00 in handle_internal_command (argv=<optimized out>, argc=2) at perf.c:348
> #10 run_argv (argcp=<synthetic pointer>, argv=<synthetic pointer>) at perf.c:392
> #11 main (argc=<optimized out>, argv=0x3fffffff3c0) at perf.c:536
> (gdb)
>
> Fix it by adding a stub event handler for namespace event.
>
> Reported-and-Tested-by: Thomas-Mich Richter <tmricht@linux.vnet.ibm.com>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
> tools/perf/util/session.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
> index a7ebd9fe8e40..76ab0709a20c 100644
> --- a/tools/perf/util/session.c
> +++ b/tools/perf/util/session.c
> @@ -374,6 +374,8 @@ void perf_tool__fill_defaults(struct perf_tool *tool)
> tool->mmap2 = process_event_stub;
> if (tool->comm == NULL)
> tool->comm = process_event_stub;
> + if (tool->namespaces == NULL)
> + tool->namespaces = process_event_stub;
> if (tool->fork == NULL)
> tool->fork = process_event_stub;
> if (tool->exit == NULL)
> --
> 2.14.2
^ permalink raw reply [flat|nested] 4+ messages in thread* [tip:perf/urgent] perf buildid-list: Fix crash when processing PERF_RECORD_NAMESPACE
2017-10-17 13:29 ` [PATCH] perf tools: Fix crash on buildid-list with namespace Namhyung Kim
2017-10-17 14:05 ` Arnaldo Carvalho de Melo
@ 2017-10-20 7:20 ` tip-bot for Namhyung Kim
1 sibling, 0 replies; 4+ messages in thread
From: tip-bot for Namhyung Kim @ 2017-10-20 7:20 UTC (permalink / raw)
To: linux-tip-commits
Cc: namhyung, tmricht, hbathini, peterz, acme, brueckner,
linux-kernel, tglx, jolsa, mingo, hpa
Commit-ID: 7f0cd23615040b9e53bb4980c986b721cba08bbc
Gitweb: https://git.kernel.org/tip/7f0cd23615040b9e53bb4980c986b721cba08bbc
Author: Namhyung Kim <namhyung@kernel.org>
AuthorDate: Tue, 17 Oct 2017 22:29:00 +0900
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 17 Oct 2017 11:09:19 -0300
perf buildid-list: Fix crash when processing PERF_RECORD_NAMESPACE
Thomas reported that 'perf buildid-list' gets a SEGFAULT due to NULL
pointer deref when he ran it on a data with namespace events. It was
because the buildid_id__mark_dso_hit_ops lacks the namespace event
handler and perf_too__fill_default() didn't set it.
Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
Missing separate debuginfos, use: dnf debuginfo-install audit-libs-2.7.7-1.fc25.s390x bzip2-libs-1.0.6-21.fc25.s390x elfutils-libelf-0.169-1.fc25.s390x
+elfutils-libs-0.169-1.fc25.s390x libcap-ng-0.7.8-1.fc25.s390x numactl-libs-2.0.11-2.ibm.fc25.s390x openssl-libs-1.1.0e-1.1.ibm.fc25.s390x perl-libs-5.24.1-386.fc25.s390x
+python-libs-2.7.13-2.fc25.s390x slang-2.3.0-7.fc25.s390x xz-libs-5.2.3-2.fc25.s390x zlib-1.2.8-10.fc25.s390x
(gdb) where
#0 0x0000000000000000 in ?? ()
#1 0x00000000010fad6a in machines__deliver_event (machines=<optimized out>, machines@entry=0x2c6fd18,
evlist=<optimized out>, event=event@entry=0x3fffdf00470, sample=0x3ffffffe880, sample@entry=0x3ffffffe888,
tool=tool@entry=0x1312968 <build_id.mark_dso_hit_ops>, file_offset=1136) at util/session.c:1287
#2 0x00000000010fbf4e in perf_session__deliver_event (file_offset=1136, tool=0x1312968 <build_id.mark_dso_hit_ops>,
sample=0x3ffffffe888, event=0x3fffdf00470, session=0x2c6fc30) at util/session.c:1340
#3 perf_session__process_event (session=0x2c6fc30, session@entry=0x0, event=event@entry=0x3fffdf00470,
file_offset=file_offset@entry=1136) at util/session.c:1522
#4 0x00000000010fddde in __perf_session__process_events (file_size=11880, data_size=<optimized out>,
data_offset=<optimized out>, session=0x0) at util/session.c:1899
#5 perf_session__process_events (session=0x0, session@entry=0x2c6fc30) at util/session.c:1953
#6 0x000000000103b2ac in perf_session__list_build_ids (with_hits=<optimized out>, force=<optimized out>)
at builtin-buildid-list.c:83
#7 cmd_buildid_list (argc=<optimized out>, argv=<optimized out>) at builtin-buildid-list.c:115
#8 0x00000000010a026c in run_builtin (p=0x1311f78 <commands+24>, argc=argc@entry=2, argv=argv@entry=0x3fffffff3c0)
at perf.c:296
#9 0x000000000102bc00 in handle_internal_command (argv=<optimized out>, argc=2) at perf.c:348
#10 run_argv (argcp=<synthetic pointer>, argv=<synthetic pointer>) at perf.c:392
#11 main (argc=<optimized out>, argv=0x3fffffff3c0) at perf.c:536
(gdb)
Fix it by adding a stub event handler for namespace event.
Committer testing:
Further clarifying, plain using 'perf buildid-list' will not end up in a
SEGFAULT when processing a perf.data file with namespace info:
# perf record -a --namespaces sleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 2.024 MB perf.data (1058 samples) ]
# perf buildid-list | wc -l
38
# perf buildid-list | head -5
e2a171c7b905826fc8494f0711ba76ab6abbd604 /lib/modules/4.14.0-rc3+/build/vmlinux
874840a02d8f8a31cedd605d0b8653145472ced3 /lib/modules/4.14.0-rc3+/kernel/arch/x86/kvm/kvm-intel.ko
ea7223776730cd8a22f320040aae4d54312984bc /lib/modules/4.14.0-rc3+/kernel/drivers/gpu/drm/i915/i915.ko
5961535e6732a8edb7f22b3f148bb2fa2e0be4b9 /lib/modules/4.14.0-rc3+/kernel/drivers/gpu/drm/drm.ko
f045f54aa78cf1931cc893f78b6cbc52c72a8cb1 /usr/lib64/libc-2.25.so
#
It is only when one asks for checking what of those entries actually had
samples, i.e. when we use either -H or --with-hits, that we will process
all the PERF_RECORD_ events, and since tools/perf/builtin-buildid-list.c
neither explicitely set a perf_tool.namespaces() callback nor the
default stub was set that we end up, when processing a
PERF_RECORD_NAMESPACE record, causing a SEGFAULT:
# perf buildid-list -H
Segmentation fault (core dumped)
^C
#
Reported-and-Tested-by: Thomas-Mich Richter <tmricht@linux.vnet.ibm.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Hari Bathini <hbathini@linux.vnet.ibm.com>
Cc: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas-Mich Richter <tmricht@linux.vnet.ibm.com>
Fixes: f3b3614a284d ("perf tools: Add PERF_RECORD_NAMESPACES to include namespaces related info")
Link: http://lkml.kernel.org/r/20171017132900.11043-1-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/session.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index a7ebd9f..76ab070 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -374,6 +374,8 @@ void perf_tool__fill_defaults(struct perf_tool *tool)
tool->mmap2 = process_event_stub;
if (tool->comm == NULL)
tool->comm = process_event_stub;
+ if (tool->namespaces == NULL)
+ tool->namespaces = process_event_stub;
if (tool->fork == NULL)
tool->fork = process_event_stub;
if (tool->exit == NULL)
^ permalink raw reply [flat|nested] 4+ messages in thread