linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@infradead.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, Namhyung Kim <namhyung.kim@lge.com>,
	Namhyung Kim <namhyung@gmail.com>,
	Paul Mackerras <paulus@samba.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Sunjin Yang <fan4326@gmail.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 05/15] perf tools: Check if callchain is corrupted
Date: Fri,  1 Jun 2012 19:16:29 -0300	[thread overview]
Message-ID: <1338588999-32509-6-git-send-email-acme@infradead.org> (raw)
In-Reply-To: <1338588999-32509-1-git-send-email-acme@infradead.org>

From: Namhyung Kim <namhyung.kim@lge.com>

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>
---
 include/linux/perf_event.h |    4 ++--
 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 f325786..1817d40 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -555,6 +555,8 @@ enum perf_event_type {
 	PERF_RECORD_MAX,			/* non-ABI */
 };
 
+#define PERF_MAX_STACK_DEPTH		255
+
 enum perf_callchain_context {
 	PERF_CONTEXT_HV			= (__u64)-32,
 	PERF_CONTEXT_KERNEL		= (__u64)-128,
@@ -609,8 +611,6 @@ struct perf_guest_info_callbacks {
 #include <linux/sysfs.h>
 #include <asm/local.h>
 
-#define PERF_MAX_STACK_DEPTH		255
-
 struct perf_callchain_entry {
 	__u64				nr;
 	__u64				ip[PERF_MAX_STACK_DEPTH];
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 3b6f8e4..04d1e33 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -300,6 +300,11 @@ int machine__resolve_callchain(struct machine *self,
 
 	callchain_cursor_reset(&callchain_cursor);
 
+	if (chain->nr > PERF_MAX_STACK_DEPTH) {
+		pr_warning("corrupted callchain. skipping...\n");
+		return 0;
+	}
+
 	for (i = 0; i < chain->nr; i++) {
 		u64 ip;
 		struct addr_location al;
@@ -318,7 +323,14 @@ int machine__resolve_callchain(struct machine *self,
 			case PERF_CONTEXT_USER:
 				cpumode = PERF_RECORD_MISC_USER;	break;
 			default:
-				break;
+				pr_debug("invalid callchain context: "
+					 "%"PRId64"\n", (s64) ip);
+				/*
+				 * It seems the callchain is corrupted.
+				 * Discard all.
+				 */
+				callchain_cursor_reset(&callchain_cursor);
+				return 0;
 			}
 			continue;
 		}
-- 
1.7.1


  parent reply	other threads:[~2012-06-01 22:18 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-01 22:16 [GIT PULL 00/15] perf/urgent fixes Arnaldo Carvalho de Melo
2012-06-01 22:16 ` [PATCH 01/15] perf script: Fix regression in callchain dso name Arnaldo Carvalho de Melo
2012-06-01 22:16 ` [PATCH 02/15] perf tools: Fix make tarballs Arnaldo Carvalho de Melo
2012-06-01 22:16 ` [PATCH 03/15] perf tools: Fix pager on minimal-install embedded systems Arnaldo Carvalho de Melo
2012-06-01 22:16 ` [PATCH 04/15] perf callchain: Make callchain cursors TLS Arnaldo Carvalho de Melo
2012-06-01 22:16 ` Arnaldo Carvalho de Melo [this message]
2012-06-01 22:16 ` [PATCH 06/15] perf tools: Make --version show kernel version instead of pull req tag Arnaldo Carvalho de Melo
2012-06-01 22:16 ` [PATCH 07/15] perf tools: Update ioctl documentation for PERF_IOC_FLAG_GROUP Arnaldo Carvalho de Melo
2012-06-01 22:16 ` [PATCH 08/15] perf evlist: Pass third argument to ioctl explicitly Arnaldo Carvalho de Melo
2012-06-01 22:16 ` [PATCH 09/15] perf symbols: Handle different endians properly during symbol load Arnaldo Carvalho de Melo
2012-06-01 22:16 ` [PATCH 10/15] perf session: Handle endianity swap on sample_id_all header data Arnaldo Carvalho de Melo
2012-06-01 22:16 ` [PATCH 11/15] perf evsel: Fix 32 bit values endianity swap for sample_id_all header Arnaldo Carvalho de Melo
2012-06-01 22:16 ` [PATCH 12/15] perf symbols: Check for valid dso before creating map Arnaldo Carvalho de Melo
2012-06-01 22:16 ` [PATCH 13/15] perf uprobes: Remove unnecessary check before strlist__delete Arnaldo Carvalho de Melo
2012-06-01 22:16 ` [PATCH 14/15] perf: Remove duplicate invocation on perf_event_for_each Arnaldo Carvalho de Melo
2012-06-01 22:16 ` [PATCH 15/15] perf tool: Build fix, remove duplicate declarations Arnaldo Carvalho de Melo
2012-06-01 22:45 ` [GIT PULL 00/15] perf/urgent fixes David Ahern
2012-06-01 23:08   ` Arnaldo Carvalho de Melo
2012-06-06  6:50 ` Ingo Molnar
2012-06-06 22:50   ` David Ahern
2012-06-07  2:19     ` Namhyung Kim
2012-06-07  3:52   ` David Ahern
2012-06-07 16:09     ` Arnaldo Carvalho de Melo
2012-06-07 16:11       ` Steven Rostedt
2012-06-07 16:43         ` Arnaldo Carvalho de Melo
2012-06-07 16:55         ` Borislav Petkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1338588999-32509-6-git-send-email-acme@infradead.org \
    --to=acme@infradead.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=fan4326@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung.kim@lge.com \
    --cc=namhyung@gmail.com \
    --cc=paulus@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).