diff options
author | Namhyung Kim <namhyung.kim@lge.com> | 2012-05-31 01:43:27 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-05-31 10:20:34 -0400 |
commit | 114067b69e7b2c691faace0e33db2f04096f668d (patch) | |
tree | 68e4e8e56fe448436a0efbdd03cd342768a32f0e | |
parent | 472606458f3e1ced5fe3cc5f04e90a6b5a4732cf (diff) |
perf tools: Check if callchain is corrupted
We faced segmentation fault on perf top -G at very high sampling rate
due to a corrupted callchain. While the root cause was not revealed (I
failed to figure it out), this patch tries to protect us from the
segfault on such cases.
Reported-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Namhyung Kim <namhyung.kim@lge.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Sunjin Yang <fan4326@gmail.com>
Link: http://lkml.kernel.org/r/1338443007-24857-2-git-send-email-namhyung.kim@lge.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | include/linux/perf_event.h | 4 | ||||
-rw-r--r-- | tools/perf/util/session.c | 14 |
2 files changed, 15 insertions, 3 deletions
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h index f32578634d9d..1817d4015e5f 100644 --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h | |||
@@ -555,6 +555,8 @@ enum perf_event_type { | |||
555 | PERF_RECORD_MAX, /* non-ABI */ | 555 | PERF_RECORD_MAX, /* non-ABI */ |
556 | }; | 556 | }; |
557 | 557 | ||
558 | #define PERF_MAX_STACK_DEPTH 255 | ||
559 | |||
558 | enum perf_callchain_context { | 560 | enum perf_callchain_context { |
559 | PERF_CONTEXT_HV = (__u64)-32, | 561 | PERF_CONTEXT_HV = (__u64)-32, |
560 | PERF_CONTEXT_KERNEL = (__u64)-128, | 562 | PERF_CONTEXT_KERNEL = (__u64)-128, |
@@ -609,8 +611,6 @@ struct perf_guest_info_callbacks { | |||
609 | #include <linux/sysfs.h> | 611 | #include <linux/sysfs.h> |
610 | #include <asm/local.h> | 612 | #include <asm/local.h> |
611 | 613 | ||
612 | #define PERF_MAX_STACK_DEPTH 255 | ||
613 | |||
614 | struct perf_callchain_entry { | 614 | struct perf_callchain_entry { |
615 | __u64 nr; | 615 | __u64 nr; |
616 | __u64 ip[PERF_MAX_STACK_DEPTH]; | 616 | __u64 ip[PERF_MAX_STACK_DEPTH]; |
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 3b6f8e460a31..04d1e33f4592 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c | |||
@@ -300,6 +300,11 @@ int machine__resolve_callchain(struct machine *self, | |||
300 | 300 | ||
301 | callchain_cursor_reset(&callchain_cursor); | 301 | callchain_cursor_reset(&callchain_cursor); |
302 | 302 | ||
303 | if (chain->nr > PERF_MAX_STACK_DEPTH) { | ||
304 | pr_warning("corrupted callchain. skipping...\n"); | ||
305 | return 0; | ||
306 | } | ||
307 | |||
303 | for (i = 0; i < chain->nr; i++) { | 308 | for (i = 0; i < chain->nr; i++) { |
304 | u64 ip; | 309 | u64 ip; |
305 | struct addr_location al; | 310 | struct addr_location al; |
@@ -318,7 +323,14 @@ int machine__resolve_callchain(struct machine *self, | |||
318 | case PERF_CONTEXT_USER: | 323 | case PERF_CONTEXT_USER: |
319 | cpumode = PERF_RECORD_MISC_USER; break; | 324 | cpumode = PERF_RECORD_MISC_USER; break; |
320 | default: | 325 | default: |
321 | break; | 326 | pr_debug("invalid callchain context: " |
327 | "%"PRId64"\n", (s64) ip); | ||
328 | /* | ||
329 | * It seems the callchain is corrupted. | ||
330 | * Discard all. | ||
331 | */ | ||
332 | callchain_cursor_reset(&callchain_cursor); | ||
333 | return 0; | ||
322 | } | 334 | } |
323 | continue; | 335 | continue; |
324 | } | 336 | } |