History

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.

Namhyung Kim committed 14 years ago

Commit 114067b1 parent 47260642 files · +15 −3Browse files

Unified · Split

2 files
  1. include/linux/perf_event.h +2 −2
  2. tools/perf/util/session.c +13 −1
include/linux/perf_event.h+2−2
@@ -555,6 +555,8 @@ enum perf_event_type { · 554 unmodified lines
555555 PERF_RECORD_MAX, /* non-ABI */
556556 };
557557
558+#define PERF_MAX_STACK_DEPTH 255
559+
558560 enum perf_callchain_context {
559561 PERF_CONTEXT_HV = (__u64)-32,
560562 PERF_CONTEXT_KERNEL = (__u64)-128,
@@ -609,8 +611,6 @@ struct perf_guest_info_callbacks { · 48 unmodified lines
609611 #include <linux/sysfs.h>
610612 #include <asm/local.h>
611613
612−#define PERF_MAX_STACK_DEPTH 255
613−
614614 struct perf_callchain_entry {
615615 __u64 nr;
616616 __u64 ip[PERF_MAX_STACK_DEPTH];
tools/perf/util/session.c+13−1
@@ -300,6 +300,11 @@ int machine__resolve_callchain(struct machine *self, · 299 unmodified lines
300300
301301 callchain_cursor_reset(&callchain_cursor);
302302
303+ if (chain->nr > PERF_MAX_STACK_DEPTH) {
304+ pr_warning("corrupted callchain. skipping...\n");
305+ return 0;
306+ }
307+
303308 for (i = 0; i < chain->nr; i++) {
304309 u64 ip;
305310 struct addr_location al;
@@ -318,7 +323,14 @@ int machine__resolve_callchain(struct machine *self, · 12 unmodified lines
318323 case PERF_CONTEXT_USER:
319324 cpumode = PERF_RECORD_MISC_USER; break;
320325 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;
322334 }
323335 continue;
324336 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t