All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf report: don't crash on invalid maps in `-g srcline` mode
@ 2017-05-09 20:50 Milian Wolff
  2017-05-10  6:04 ` Namhyung Kim
  2017-05-11 13:13 ` Paul Clarke
  0 siblings, 2 replies; 5+ messages in thread
From: Milian Wolff @ 2017-05-09 20:50 UTC (permalink / raw)
  To: Linux-kernel
  Cc: linux-perf-users, Milian Wolff, Arnaldo Carvalho de Melo,
	David Ahern, Namhyung Kim, Peter Zijlstra, Yao Jin

I just hit a segfault when doing `perf report -g srcline`.
Valgrind pointed me at this code as the culprit:

==8359== Invalid read of size 8
==8359==    at 0x3096D9: map__rip_2objdump (map.c:430)
==8359==    by 0x2FC1A3: match_chain_srcline (callchain.c:645)
==8359==    by 0x2FC1A3: match_chain (callchain.c:700)
==8359==    by 0x2FC1A3: append_chain (callchain.c:895)
==8359==    by 0x2FC1A3: append_chain_children (callchain.c:846)
==8359==    by 0x2FF719: callchain_append (callchain.c:944)
==8359==    by 0x2FF719: hist_entry__append_callchain (callchain.c:1058)
==8359==    by 0x32FA06: iter_add_single_cumulative_entry (hist.c:908)
==8359==    by 0x33195C: hist_entry_iter__add (hist.c:1050)
==8359==    by 0x258F65: process_sample_event (builtin-report.c:204)
==8359==    by 0x30D60C: perf_session__deliver_event (session.c:1310)
==8359==    by 0x30D60C: ordered_events__deliver_event (session.c:119)
==8359==    by 0x310D12: __ordered_events__flush (ordered-events.c:210)
==8359==    by 0x310D12: ordered_events__flush.part.3 (ordered-events.c:277)
==8359==    by 0x30DD3C: perf_session__process_user_event (session.c:1349)
==8359==    by 0x30DD3C: perf_session__process_event (session.c:1475)
==8359==    by 0x30FC3C: __perf_session__process_events (session.c:1867)
==8359==    by 0x30FC3C: perf_session__process_events (session.c:1921)
==8359==    by 0x25A985: __cmd_report (builtin-report.c:575)
==8359==    by 0x25A985: cmd_report (builtin-report.c:1054)
==8359==    by 0x2B9A80: run_builtin (perf.c:296)
==8359==  Address 0x70 is not stack'd, malloc'd or (recently) free'd

This patch fixes the issue.

Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Yao Jin <yao.jin@linux.intel.com>
Signed-off-by: Milian Wolff <milian.wolff@kdab.com>
---
 tools/perf/util/callchain.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
index 9ab68682c6d0..295f0846fd84 100644
--- a/tools/perf/util/callchain.c
+++ b/tools/perf/util/callchain.c
@@ -642,13 +642,22 @@ static enum match_result match_chain_strings(const char *left,
 static enum match_result match_chain_srcline(struct callchain_cursor_node *node,
 					     struct callchain_list *cnode)
 {
-	char *left = get_srcline(cnode->ms.map->dso,
-				 map__rip_2objdump(cnode->ms.map, cnode->ip),
-				 cnode->ms.sym, true, false);
-	char *right = get_srcline(node->map->dso,
-				  map__rip_2objdump(node->map, node->ip),
-				  node->sym, true, false);
-	enum match_result ret = match_chain_strings(left, right);
+	char *left = NULL;
+	char *right = NULL;
+	enum match_result ret = MATCH_ERROR;
+
+	if (!node->map || !cnode->ms.map)
+		return ret;
+
+	left = get_srcline(cnode->ms.map->dso,
+			   map__rip_2objdump(cnode->ms.map, cnode->ip),
+			   cnode->ms.sym, true, false);
+
+	right = get_srcline(node->map->dso,
+			    map__rip_2objdump(node->map, node->ip),
+			    node->sym, true, false);
+
+	ret = match_chain_strings(left, right);
 
 	free_srcline(left);
 	free_srcline(right);
-- 
2.12.2

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] perf report: don't crash on invalid maps in `-g srcline` mode
  2017-05-09 20:50 [PATCH] perf report: don't crash on invalid maps in `-g srcline` mode Milian Wolff
@ 2017-05-10  6:04 ` Namhyung Kim
  2017-05-12 10:23   ` Milian Wolff
  2017-05-11 13:13 ` Paul Clarke
  1 sibling, 1 reply; 5+ messages in thread
From: Namhyung Kim @ 2017-05-10  6:04 UTC (permalink / raw)
  To: Milian Wolff
  Cc: Linux-kernel, linux-perf-users, Arnaldo Carvalho de Melo,
	David Ahern, Peter Zijlstra, Yao Jin, kernel-team

On Tue, May 09, 2017 at 10:50:46PM +0200, Milian Wolff wrote:
> I just hit a segfault when doing `perf report -g srcline`.
> Valgrind pointed me at this code as the culprit:
> 
> ==8359== Invalid read of size 8
> ==8359==    at 0x3096D9: map__rip_2objdump (map.c:430)
> ==8359==    by 0x2FC1A3: match_chain_srcline (callchain.c:645)
> ==8359==    by 0x2FC1A3: match_chain (callchain.c:700)
> ==8359==    by 0x2FC1A3: append_chain (callchain.c:895)
> ==8359==    by 0x2FC1A3: append_chain_children (callchain.c:846)
> ==8359==    by 0x2FF719: callchain_append (callchain.c:944)
> ==8359==    by 0x2FF719: hist_entry__append_callchain (callchain.c:1058)
> ==8359==    by 0x32FA06: iter_add_single_cumulative_entry (hist.c:908)
> ==8359==    by 0x33195C: hist_entry_iter__add (hist.c:1050)
> ==8359==    by 0x258F65: process_sample_event (builtin-report.c:204)
> ==8359==    by 0x30D60C: perf_session__deliver_event (session.c:1310)
> ==8359==    by 0x30D60C: ordered_events__deliver_event (session.c:119)
> ==8359==    by 0x310D12: __ordered_events__flush (ordered-events.c:210)
> ==8359==    by 0x310D12: ordered_events__flush.part.3 (ordered-events.c:277)
> ==8359==    by 0x30DD3C: perf_session__process_user_event (session.c:1349)
> ==8359==    by 0x30DD3C: perf_session__process_event (session.c:1475)
> ==8359==    by 0x30FC3C: __perf_session__process_events (session.c:1867)
> ==8359==    by 0x30FC3C: perf_session__process_events (session.c:1921)
> ==8359==    by 0x25A985: __cmd_report (builtin-report.c:575)
> ==8359==    by 0x25A985: cmd_report (builtin-report.c:1054)
> ==8359==    by 0x2B9A80: run_builtin (perf.c:296)
> ==8359==  Address 0x70 is not stack'd, malloc'd or (recently) free'd
> 
> This patch fixes the issue.
> 
> Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
> Cc: David Ahern <dsahern@gmail.com>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
> Cc: Yao Jin <yao.jin@linux.intel.com>
> Signed-off-by: Milian Wolff <milian.wolff@kdab.com>
> ---
>  tools/perf/util/callchain.c | 23 ++++++++++++++++-------
>  1 file changed, 16 insertions(+), 7 deletions(-)
> 
> diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
> index 9ab68682c6d0..295f0846fd84 100644
> --- a/tools/perf/util/callchain.c
> +++ b/tools/perf/util/callchain.c
> @@ -642,13 +642,22 @@ static enum match_result match_chain_strings(const char *left,
>  static enum match_result match_chain_srcline(struct callchain_cursor_node *node,
>  					     struct callchain_list *cnode)
>  {
> -	char *left = get_srcline(cnode->ms.map->dso,
> -				 map__rip_2objdump(cnode->ms.map, cnode->ip),
> -				 cnode->ms.sym, true, false);
> -	char *right = get_srcline(node->map->dso,
> -				  map__rip_2objdump(node->map, node->ip),
> -				  node->sym, true, false);
> -	enum match_result ret = match_chain_strings(left, right);
> +	char *left = NULL;
> +	char *right = NULL;
> +	enum match_result ret = MATCH_ERROR;
> +
> +	if (!node->map || !cnode->ms.map)
> +		return ret;

This makes it fall back to function/address matching below if one of
srcline is not available.  But it'll just show many "??:0" entries
IMHO.  Maybe we can use same logic in util/sort.c:cmp_null instead..

Thanks,
Namhyung


> +
> +	left = get_srcline(cnode->ms.map->dso,
> +			   map__rip_2objdump(cnode->ms.map, cnode->ip),
> +			   cnode->ms.sym, true, false);
> +
> +	right = get_srcline(node->map->dso,
> +			    map__rip_2objdump(node->map, node->ip),
> +			    node->sym, true, false);
> +
> +	ret = match_chain_strings(left, right);
>  
>  	free_srcline(left);
>  	free_srcline(right);
> -- 
> 2.12.2
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] perf report: don't crash on invalid maps in `-g srcline` mode
  2017-05-09 20:50 [PATCH] perf report: don't crash on invalid maps in `-g srcline` mode Milian Wolff
  2017-05-10  6:04 ` Namhyung Kim
@ 2017-05-11 13:13 ` Paul Clarke
  1 sibling, 0 replies; 5+ messages in thread
From: Paul Clarke @ 2017-05-11 13:13 UTC (permalink / raw)
  To: Milian Wolff, Linux-kernel
  Cc: linux-perf-users, Arnaldo Carvalho de Melo, David Ahern,
	Namhyung Kim, Peter Zijlstra, Yao Jin

On 05/09/2017 03:50 PM, Milian Wolff wrote:
> diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
> index 9ab68682c6d0..295f0846fd84 100644
> --- a/tools/perf/util/callchain.c
> +++ b/tools/perf/util/callchain.c
> @@ -642,13 +642,22 @@ static enum match_result match_chain_strings(const char *left,
>  static enum match_result match_chain_srcline(struct callchain_cursor_node *node,
>  					     struct callchain_list *cnode)
>  {
> -	char *left = get_srcline(cnode->ms.map->dso,
> -				 map__rip_2objdump(cnode->ms.map, cnode->ip),
> -				 cnode->ms.sym, true, false);
> -	char *right = get_srcline(node->map->dso,
> -				  map__rip_2objdump(node->map, node->ip),
> -				  node->sym, true, false);
> -	enum match_result ret = match_chain_strings(left, right);
> +	char *left = NULL;
> +	char *right = NULL;

nit: the above two initializations are unnecessary.

> +	enum match_result ret = MATCH_ERROR;
> +
> +	if (!node->map || !cnode->ms.map)
> +		return ret;
> +
> +	left = get_srcline(cnode->ms.map->dso,
> +			   map__rip_2objdump(cnode->ms.map, cnode->ip),
> +			   cnode->ms.sym, true, false);
> +
> +	right = get_srcline(node->map->dso,
> +			    map__rip_2objdump(node->map, node->ip),
> +			    node->sym, true, false);
> +
> +	ret = match_chain_strings(left, right);
> 
>  	free_srcline(left);
>  	free_srcline(right);

PC

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] perf report: don't crash on invalid maps in `-g srcline` mode
  2017-05-10  6:04 ` Namhyung Kim
@ 2017-05-12 10:23   ` Milian Wolff
  2017-05-12 12:19     ` Namhyung Kim
  0 siblings, 1 reply; 5+ messages in thread
From: Milian Wolff @ 2017-05-12 10:23 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Linux-kernel, linux-perf-users, Arnaldo Carvalho de Melo,
	David Ahern, Peter Zijlstra, Yao Jin, kernel-team

[-- Attachment #1: Type: text/plain, Size: 1613 bytes --]

On Mittwoch, 10. Mai 2017 08:04:23 CEST Namhyung Kim wrote:
> On Tue, May 09, 2017 at 10:50:46PM +0200, Milian Wolff wrote:

<snip>

> > diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
> > index 9ab68682c6d0..295f0846fd84 100644
> > --- a/tools/perf/util/callchain.c
> > +++ b/tools/perf/util/callchain.c
> > @@ -642,13 +642,22 @@ static enum match_result match_chain_strings(const
> > char *left,> 
> >  static enum match_result match_chain_srcline(struct callchain_cursor_node
> >  *node,>  
> >  					     struct callchain_list *cnode)
> >  
> >  {
> > 
> > -	char *left = get_srcline(cnode->ms.map->dso,
> > -				 map__rip_2objdump(cnode->ms.map, cnode->ip),
> > -				 cnode->ms.sym, true, false);
> > -	char *right = get_srcline(node->map->dso,
> > -				  map__rip_2objdump(node->map, node->ip),
> > -				  node->sym, true, false);
> > -	enum match_result ret = match_chain_strings(left, right);
> > +	char *left = NULL;
> > +	char *right = NULL;
> > +	enum match_result ret = MATCH_ERROR;
> > +
> > +	if (!node->map || !cnode->ms.map)
> > +		return ret;
> 
> This makes it fall back to function/address matching below if one of
> srcline is not available.  But it'll just show many "??:0" entries
> IMHO.  Maybe we can use same logic in util/sort.c:cmp_null instead..

Yes, that could be done but I think it's not directly related to the patch/fix 
at hand. Would it be OK if I change this behavior in a separate patch?

Thanks
-- 
Milian Wolff | milian.wolff@kdab.com | Software Engineer
KDAB (Deutschland) GmbH&Co KG, a KDAB Group company
Tel: +49-30-521325470
KDAB - The Qt Experts

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5903 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] perf report: don't crash on invalid maps in `-g srcline` mode
  2017-05-12 10:23   ` Milian Wolff
@ 2017-05-12 12:19     ` Namhyung Kim
  0 siblings, 0 replies; 5+ messages in thread
From: Namhyung Kim @ 2017-05-12 12:19 UTC (permalink / raw)
  To: Milian Wolff
  Cc: Linux-kernel, linux-perf-users, Arnaldo Carvalho de Melo,
	David Ahern, Peter Zijlstra, Yao Jin, kernel-team

On Fri, May 12, 2017 at 12:23:06PM +0200, Milian Wolff wrote:
> On Mittwoch, 10. Mai 2017 08:04:23 CEST Namhyung Kim wrote:
> > On Tue, May 09, 2017 at 10:50:46PM +0200, Milian Wolff wrote:
> 
> <snip>
> 
> > > diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
> > > index 9ab68682c6d0..295f0846fd84 100644
> > > --- a/tools/perf/util/callchain.c
> > > +++ b/tools/perf/util/callchain.c
> > > @@ -642,13 +642,22 @@ static enum match_result match_chain_strings(const
> > > char *left,> 
> > >  static enum match_result match_chain_srcline(struct callchain_cursor_node
> > >  *node,>  
> > >  					     struct callchain_list *cnode)
> > >  
> > >  {
> > > 
> > > -	char *left = get_srcline(cnode->ms.map->dso,
> > > -				 map__rip_2objdump(cnode->ms.map, cnode->ip),
> > > -				 cnode->ms.sym, true, false);
> > > -	char *right = get_srcline(node->map->dso,
> > > -				  map__rip_2objdump(node->map, node->ip),
> > > -				  node->sym, true, false);
> > > -	enum match_result ret = match_chain_strings(left, right);
> > > +	char *left = NULL;
> > > +	char *right = NULL;
> > > +	enum match_result ret = MATCH_ERROR;
> > > +
> > > +	if (!node->map || !cnode->ms.map)
> > > +		return ret;
> > 
> > This makes it fall back to function/address matching below if one of
> > srcline is not available.  But it'll just show many "??:0" entries
> > IMHO.  Maybe we can use same logic in util/sort.c:cmp_null instead..
> 
> Yes, that could be done but I think it's not directly related to the patch/fix 
> at hand. Would it be OK if I change this behavior in a separate patch?

I'm OK with that.

Thanks,
Namhyung

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-05-12 12:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-09 20:50 [PATCH] perf report: don't crash on invalid maps in `-g srcline` mode Milian Wolff
2017-05-10  6:04 ` Namhyung Kim
2017-05-12 10:23   ` Milian Wolff
2017-05-12 12:19     ` Namhyung Kim
2017-05-11 13:13 ` Paul Clarke

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.