Skip to contentSkip to conversation

perf tools: Fix segfault in cumulative.callchain report

RFC/PATCH Jiri Olsa 5 participants 6 messages Jun 15, 2014 – Jun 25, 2014 perf events

lore
Share & tools
lore

Jiri Olsa

author reviewer
#0 lore raw

heya,
not completely sure this is what we want to do, but have no streght to dive into annotation code ;-)

thanks,
jirka

---
When cumulative callchain mode is on, we could get samples with with no actual hits. This breaks the assumption of the annotation code, that each sample has annotation counts allocated and leads to segfault.

Fixing this by additional checks for annotation stats.

Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Corey Ashford <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 tools/perf/ui/browsers/hists.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
tools/perf/ui/browsers/hists.c +16 -5
index 52c03fb..04a229a 100644
@@ -17,6 +17,7 @@
 #include "../util.h"
 #include "../ui.h"
 #include "map.h"
+#include "annotate.h"
 
 struct hist_browser {
 	struct ui_browser   b;
@@ -1593,13 +1594,18 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
 					 bi->to.sym->name) > 0)
 				annotate_t = nr_options++;
 		} else {
-
 			if (browser->selection != NULL &&
 			    browser->selection->sym != NULL &&
-			    !browser->selection->map->dso->annotate_warned &&
-				asprintf(&options[nr_options], "Annotate %s",
-					 browser->selection->sym->name) > 0)
-				annotate = nr_options++;
+			    !browser->selection->map->dso->annotate_warned) {
+				struct annotation *notes;
+
+				notes = symbol__annotation(browser->selection->sym);
+
+				if (notes->src &&
+				    asprintf(&options[nr_options], "Annotate %s",
+						 browser->selection->sym->name) > 0)
+					annotate = nr_options++;
+			}
 		}
 
 		if (thread != NULL &&
@@ -1656,6 +1662,7 @@ retry_popup_menu:
 
 		if (choice == annotate || choice == annotate_t || choice == annotate_f) {
 			struct hist_entry *he;
+			struct annotation *notes;
 			int err;
 do_annotate:
 			if (!objdump_path && perf_session_env__lookup_objdump(env))
@@ -1679,6 +1686,10 @@ do_annotate:
 				he->ms.map = he->branch_info->to.map;
 			}
 
+			notes = symbol__annotation(he->ms.sym);
+			if (!notes->src)
+				continue;
+
 			/*
 			 * Don't let this be freed, say, by hists__decay_entry.
 			 */
Signature · 1 line
1.8.3.1
maintainer
#1 lore raw

Hi Jiri,

2014-06-15 (일), 10:35 +0200, Jiri Olsa:

Quoted 3 lines

heya,
not completely sure this is what we want to do, but have no streght to dive into annotation code ;-)

Currently, cumulative entries do not accounts annotation info so annotation only works for normal entries. I'm not sure we should support it or not, but anyway it also needs some updates on the annotation code IMHO.

So I'm okay with disabling annotation on pure cumulative entries.

Thanks,
Namhyung

Quoted 77 lines

---
When cumulative callchain mode is on, we could get samples with with no actual hits. This breaks the assumption of the annotation code, that each sample has annotation counts allocated and leads to segfault.

Fixing this by additional checks for annotation stats.

Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Corey Ashford <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 tools/perf/ui/browsers/hists.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
tools/perf/ui/browsers/hists.c +16 -5
index 52c03fb..04a229a 100644
@@ -17,6 +17,7 @@
 #include "../util.h"
 #include "../ui.h"
 #include "map.h"
+#include "annotate.h"
 
 struct hist_browser {
 	struct ui_browser   b;
@@ -1593,13 +1594,18 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
 					 bi->to.sym->name) > 0)
 				annotate_t = nr_options++;
 		} else {
-
 			if (browser->selection != NULL &&
 			    browser->selection->sym != NULL &&
-			    !browser->selection->map->dso->annotate_warned &&
-				asprintf(&options[nr_options], "Annotate %s",
-					 browser->selection->sym->name) > 0)
-				annotate = nr_options++;
+			    !browser->selection->map->dso->annotate_warned) {
+				struct annotation *notes;
+
+				notes = symbol__annotation(browser->selection->sym);
+
+				if (notes->src &&
+				    asprintf(&options[nr_options], "Annotate %s",
+						 browser->selection->sym->name) > 0)
+					annotate = nr_options++;
+			}
 		}
 
 		if (thread != NULL &&
@@ -1656,6 +1662,7 @@ retry_popup_menu:
 
 		if (choice == annotate || choice == annotate_t || choice == annotate_f) {
 			struct hist_entry *he;
+			struct annotation *notes;
 			int err;
 do_annotate:
 			if (!objdump_path && perf_session_env__lookup_objdump(env))
@@ -1679,6 +1686,10 @@ do_annotate:
 				he->ms.map = he->branch_info->to.map;
 			}
 
+			notes = symbol__annotation(he->ms.sym);
+			if (!notes->src)
+				continue;
+
 			/*
 			 * Don't let this be freed, say, by hists__decay_entry.
 			 */
#2 lore raw
Quoted 7 lines · Namhyung Kim

Hi Jiri,

2014-06-15 (일), 10:35 +0200, Jiri Olsa:

Quoted 3 lines

heya,
not completely sure this is what we want to do, but have no streght to dive into annotation code ;-)

Quoted 6 lines

Currently, cumulative entries do not accounts annotation info so annotation only works for normal entries. I'm not sure we should support it or not, but anyway it also needs some updates on the annotation code IMHO.

So I'm okay with disabling annotation on pure cumulative entries.

is that an ack? ;-)

thanks,
jirka

maintainer Acked-by
#3 lore raw

2014-06-15 (일), 18:34 +0200, Jiri Olsa:

Quoted 8 lines · Namhyung Kim
Quoted 7 lines

Hi Jiri,

2014-06-15 (일), 10:35 +0200, Jiri Olsa:

Quoted 3 lines

heya,
not completely sure this is what we want to do, but have no streght to dive into annotation code ;-)

Quoted 8 lines
Quoted 6 lines

Currently, cumulative entries do not accounts annotation info so annotation only works for normal entries. I'm not sure we should support it or not, but anyway it also needs some updates on the annotation code IMHO.

So I'm okay with disabling annotation on pure cumulative entries.

is that an ack? ;-)

Yep,

Thanks,
Namhyung

maintainer Acked-by
#4 lore raw

Em Mon, Jun 16, 2014 at 10:14:22PM +0900, Namhyung Kim escreveu:

Quoted 13 lines

2014-06-15 (일), 18:34 +0200, Jiri Olsa:

Quoted 11 lines · Namhyung Kim
Quoted 10 lines

2014-06-15 (일), 10:35 +0200, Jiri Olsa:

Quoted 2 lines

not completely sure this is what we want to do, but have no streght to dive into annotation code ;-)

Currently, cumulative entries do not accounts annotation info so annotation only works for normal entries. I'm not sure we should support it or not, but anyway it also needs some updates on the annotation code IMHO.

So I'm okay with disabling annotation on pure cumulative entries.

Quoted 7 lines
Quoted 1 line

is that an ack? ;-)

Yep,

From a quick look, this looks sane, i.e. only offering annotation for

symbols where samples were taken.

Otherwise we would have to figure out which samples came thru the specific point in the callchain selected, which, as Namhyung mentioned, requires more thinking and coding.

- Arnaldo

#5 lore raw
In reply to Jiri Olsa
perf tools: Fix segfault in cumulative.callchain report
Commit-ID:  d755330c5e0658d8056242b5b81e2f44ed7a96d8
Gitweb:     http://git.kernel.org/tip/d755330c5e0658d8056242b5b81e2f44ed7a96d8
Author:     Jiri Olsa <[email protected]>
AuthorDate: Sun, 15 Jun 2014 10:22:15 +0200
Committer:  Jiri Olsa <[email protected]>
CommitDate: Fri, 20 Jun 2014 09:34:18 +0200

perf tools: Fix segfault in cumulative.callchain report

When cumulative callchain mode is on, we could get samples with with no actual hits. This breaks the assumption of the annotation code, that each sample has annotation counts allocated and leads to segfault.

Fixing this by additional checks for annotation stats.

Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Corey Ashford <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 tools/perf/ui/browsers/hists.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
tools/perf/ui/browsers/hists.c +16 -5
index 52c03fb..04a229a 100644
@@ -17,6 +17,7 @@
 #include "../util.h"
 #include "../ui.h"
 #include "map.h"
+#include "annotate.h"
 
 struct hist_browser {
 	struct ui_browser   b;
@@ -1593,13 +1594,18 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
 					 bi->to.sym->name) > 0)
 				annotate_t = nr_options++;
 		} else {
-
 			if (browser->selection != NULL &&
 			    browser->selection->sym != NULL &&
-			    !browser->selection->map->dso->annotate_warned &&
-				asprintf(&options[nr_options], "Annotate %s",
-					 browser->selection->sym->name) > 0)
-				annotate = nr_options++;
+			    !browser->selection->map->dso->annotate_warned) {
+				struct annotation *notes;
+
+				notes = symbol__annotation(browser->selection->sym);
+
+				if (notes->src &&
+				    asprintf(&options[nr_options], "Annotate %s",
+						 browser->selection->sym->name) > 0)
+					annotate = nr_options++;
+			}
 		}
 
 		if (thread != NULL &&
@@ -1656,6 +1662,7 @@ retry_popup_menu:
 
 		if (choice == annotate || choice == annotate_t || choice == annotate_f) {
 			struct hist_entry *he;
+			struct annotation *notes;
 			int err;
 do_annotate:
 			if (!objdump_path && perf_session_env__lookup_objdump(env))
@@ -1679,6 +1686,10 @@ do_annotate:
 				he->ms.map = he->branch_info->to.map;
 			}
 
+			notes = symbol__annotation(he->ms.sym);
+			if (!notes->src)
+				continue;
+
 			/*
 			 * Don't let this be freed, say, by hists__decay_entry.
 			 */