mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
To: Namhyung Kim <namhyung.kim@lge.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Paul Mackerras <paulus@samba.org>, Ingo Molnar <mingo@redhat.com>,
	Namhyung Kim <namhyung@gmail.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Sunjin Yang <fan4326@gmail.com>
Subject: Re: [PATCH/RFC 2/2] perf tools: Check callchain is corrupted
Date: Thu, 31 May 2012 10:45:57 -0300	[thread overview]
Message-ID: <20120531134557.GB13591@infradead.org> (raw)
In-Reply-To: <1338443007-24857-2-git-send-email-namhyung.kim@lge.com>

Em Thu, May 31, 2012 at 02:43:27PM +0900, Namhyung Kim escreveu:
> 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.

Capping the callchain lenght may even be a feature, not a consistency
check, but I don't know how long, for consistency checking, we should
consider too much, as there are cases of loooong callchains.

Ingo? Peter?

- Arnaldo
 
> Reported-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> Signed-off-by: Namhyung Kim <namhyung.kim@lge.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 8adf70e9e3cc..0430ea6054ef 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 a7de2acac460..fa14e60ed459 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.10.1

  reply	other threads:[~2012-05-31 13:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-31  5:43 [PATCH 1/2] perf callchain: Make callchain cursors TLS Namhyung Kim
2012-05-31  5:43 ` [PATCH/RFC 2/2] perf tools: Check callchain is corrupted Namhyung Kim
2012-05-31 13:45   ` Arnaldo Carvalho de Melo [this message]
2012-05-31 14:04     ` Namhyung Kim
2012-05-31 14:31       ` Arnaldo Carvalho de Melo
2012-06-01 17:52   ` Zachary Landau
2012-06-06  7:01   ` [tip:perf/urgent] perf tools: Check if " tip-bot for Namhyung Kim
2012-06-01 17:50 ` [PATCH 1/2] perf callchain: Make callchain cursors TLS Zachary Landau
2012-06-06  7:00 ` [tip:perf/urgent] " tip-bot for Namhyung Kim

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=20120531134557.GB13591@infradead.org \
    --to=acme@ghostprotocols.net \
    --cc=a.p.zijlstra@chello.nl \
    --cc=fan4326@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --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

all inboxes | Powered by JetHome®