]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.19.29/perf-script-fix-crash-with-printing-mixed-trace-poin.patch
fixes for 4.19
[thirdparty/kernel/stable-queue.git] / releases / 4.19.29 / perf-script-fix-crash-with-printing-mixed-trace-poin.patch
1 From 99e92a69ece6aacaaf6c08be49fabfbfd5810717 Mon Sep 17 00:00:00 2001
2 From: Andi Kleen <ak@linux.intel.com>
3 Date: Thu, 17 Jan 2019 11:48:34 -0800
4 Subject: perf script: Fix crash with printing mixed trace point and other
5 events
6
7 [ Upstream commit 96167167b6e17b25c0e05ecc31119b73baeab094 ]
8
9 'perf script' crashes currently when printing mixed trace points and
10 other events because the trace format does not handle events without
11 trace meta data. Add a simple check to avoid that.
12
13 % cat > test.c
14 main()
15 {
16 printf("Hello world\n");
17 }
18 ^D
19 % gcc -g -o test test.c
20 % sudo perf probe -x test 'test.c:3'
21 % perf record -e '{cpu/cpu-cycles,period=10000/,probe_test:main}:S' ./test
22 % perf script
23 <segfault>
24
25 Committer testing:
26
27 Before:
28
29 # perf probe -x /lib64/libc-2.28.so malloc
30 Added new event:
31 probe_libc:malloc (on malloc in /usr/lib64/libc-2.28.so)
32
33 You can now use it in all perf tools, such as:
34
35 perf record -e probe_libc:malloc -aR sleep 1
36
37 # perf probe -l
38 probe_libc:malloc (on __libc_malloc@malloc/malloc.c in /usr/lib64/libc-2.28.so)
39 # perf record -e '{cpu/cpu-cycles,period=10000/,probe_libc:*}:S' sleep 1
40 [ perf record: Woken up 1 times to write data ]
41 [ perf record: Captured and wrote 0.023 MB perf.data (40 samples) ]
42 # perf script
43 Segmentation fault (core dumped)
44 ^C
45 #
46
47 After:
48
49 # perf script | head -6
50 sleep 2888 94796.944981: 16198 cpu/cpu-cycles,period=10000/: ffffffff925dc04f get_random_u32+0x1f (/lib/modules/5.0.0-rc2+/build/vmlinux)
51 sleep 2888 [-01] 94796.944981: probe_libc:malloc:
52 sleep 2888 94796.944983: 4713 cpu/cpu-cycles,period=10000/: ffffffff922763af change_protection+0xcf (/lib/modules/5.0.0-rc2+/build/vmlinux)
53 sleep 2888 [-01] 94796.944983: probe_libc:malloc:
54 sleep 2888 94796.944986: 9934 cpu/cpu-cycles,period=10000/: ffffffff922777e0 move_page_tables+0x0 (/lib/modules/5.0.0-rc2+/build/vmlinux)
55 sleep 2888 [-01] 94796.944986: probe_libc:malloc:
56 #
57
58 Signed-off-by: Andi Kleen <ak@linux.intel.com>
59 Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
60 Acked-by: Jiri Olsa <jolsa@kernel.org>
61 Link: http://lkml.kernel.org/r/20190117194834.21940-1-andi@firstfloor.org
62 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
63 Signed-off-by: Sasha Levin <sashal@kernel.org>
64 ---
65 tools/perf/builtin-script.c | 2 +-
66 1 file changed, 1 insertion(+), 1 deletion(-)
67
68 diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
69 index 6c1e7ceedcf3..ce2aee11e360 100644
70 --- a/tools/perf/builtin-script.c
71 +++ b/tools/perf/builtin-script.c
72 @@ -1658,7 +1658,7 @@ static void process_event(struct perf_script *script,
73 return;
74 }
75
76 - if (PRINT_FIELD(TRACE)) {
77 + if (PRINT_FIELD(TRACE) && sample->raw_data) {
78 event_format__fprintf(evsel->tp_format, sample->cpu,
79 sample->raw_data, sample->raw_size, fp);
80 }
81 --
82 2.19.1
83