]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.20.16/perf-script-fix-crash-when-processing-recorded-stat-.patch
Linux 4.20.16
[thirdparty/kernel/stable-queue.git] / releases / 4.20.16 / perf-script-fix-crash-when-processing-recorded-stat-.patch
1 From da0e5b7cee1cf8a699a9a6cf863ee97ab65f1fd4 Mon Sep 17 00:00:00 2001
2 From: Tony Jones <tonyj@suse.de>
3 Date: Sun, 20 Jan 2019 11:14:14 -0800
4 Subject: perf script: Fix crash when processing recorded stat data
5
6 [ Upstream commit 8bf8c6da53c2265aea365a1de6038f118f522113 ]
7
8 While updating perf to work with Python3 and Python2 I noticed that the
9 stat-cpi script was dumping core.
10
11 $ perf stat -e cycles,instructions record -o /tmp/perf.data /bin/false
12
13 Performance counter stats for '/bin/false':
14
15 802,148 cycles
16
17 604,622 instructions 802,148 cycles
18 604,622 instructions
19
20 0.001445842 seconds time elapsed
21
22 $ perf script -i /tmp/perf.data -s scripts/python/stat-cpi.py
23 Segmentation fault (core dumped)
24 ...
25 ...
26 rblist=rblist@entry=0xb2a200 <rt_stat>,
27 new_entry=new_entry@entry=0x7ffcb755c310) at util/rblist.c:33
28 ctx=<optimized out>, type=<optimized out>, create=<optimized out>,
29 cpu=<optimized out>, evsel=<optimized out>) at util/stat-shadow.c:118
30 ctx=<optimized out>, type=<optimized out>, st=<optimized out>)
31 at util/stat-shadow.c:196
32 count=count@entry=727442, cpu=cpu@entry=0, st=0xb2a200 <rt_stat>)
33 at util/stat-shadow.c:239
34 config=config@entry=0xafeb40 <stat_config>,
35 counter=counter@entry=0x133c6e0) at util/stat.c:372
36 ...
37 ...
38
39 The issue is that since 1fcd03946b52 perf_stat__update_shadow_stats now calls
40 update_runtime_stat passing rt_stat rather than calling update_stats but
41 perf_stat__init_shadow_stats has never been called to initialize rt_stat in
42 the script path processing recorded stat data.
43
44 Since I can't see any reason why perf_stat__init_shadow_stats() is presently
45 initialized like it is in builtin-script.c::perf_sample__fprint_metric()
46 [4bd1bef8bba2f] I'm proposing it instead be initialized once in __cmd_script
47
48 Committer testing:
49
50 After applying the patch:
51
52 # perf script -i /tmp/perf.data -s tools/perf/scripts/python/stat-cpi.py
53 0.001970: cpu -1, thread -1 -> cpi 1.709079 (1075684/629394)
54 #
55
56 No segfault.
57
58 Signed-off-by: Tony Jones <tonyj@suse.de>
59 Reviewed-by: Jiri Olsa <jolsa@kernel.org>
60 Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
61 Tested-by: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
62 Cc: Andi Kleen <ak@linux.intel.com>
63 Cc: Jin Yao <yao.jin@linux.intel.com>
64 Fixes: 1fcd03946b52 ("perf stat: Update per-thread shadow stats")
65 Link: http://lkml.kernel.org/r/20190120191414.12925-1-tonyj@suse.de
66 Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
67 Signed-off-by: Sasha Levin <sashal@kernel.org>
68 ---
69 tools/perf/builtin-script.c | 7 ++-----
70 1 file changed, 2 insertions(+), 5 deletions(-)
71
72 diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
73 index 5c070a600233..d8791e0e5f75 100644
74 --- a/tools/perf/builtin-script.c
75 +++ b/tools/perf/builtin-script.c
76 @@ -1633,13 +1633,8 @@ static void perf_sample__fprint_metric(struct perf_script *script,
77 .force_header = false,
78 };
79 struct perf_evsel *ev2;
80 - static bool init;
81 u64 val;
82
83 - if (!init) {
84 - perf_stat__init_shadow_stats();
85 - init = true;
86 - }
87 if (!evsel->stats)
88 perf_evlist__alloc_stats(script->session->evlist, false);
89 if (evsel_script(evsel->leader)->gnum++ == 0)
90 @@ -2305,6 +2300,8 @@ static int __cmd_script(struct perf_script *script)
91
92 signal(SIGINT, sig_handler);
93
94 + perf_stat__init_shadow_stats();
95 +
96 /* override event processing functions */
97 if (script->show_task_events) {
98 script->tool.comm = process_comm_event;
99 --
100 2.19.1
101