aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorKrister Johansen <kjlx@templeofstupid.com>2017-01-06 01:23:31 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-03-12 00:41:47 -0500
commit11a4d644d6d84a34a393a389d5efd4e036b04a62 (patch)
tree793dc6c63b83a7b774bed66aeb6858586d4c4cb7 /tools/perf
parent65013a93b6c335bd166c911d73c47ff4bcbdb8be (diff)
perf callchain: Reference count maps
commit aa33b9b9a2ebb00d33c83a5312d4fbf2d5aeba36 upstream. If dso__load_kcore frees all of the existing maps, but one has already been attached to a callchain cursor node, then we can get a SIGSEGV in any function that happens to try to use this invalid cursor. Use the existing map refcount mechanism to forestall cleanup of a map until the cursor iterates past the node. Signed-off-by: Krister Johansen <kjlx@templeofstupid.com> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Fixes: 84c2cafa2889 ("perf tools: Reference count struct map") Link: http://lkml.kernel.org/r/20170106062331.GB2707@templeofstupid.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/util/callchain.c11
-rw-r--r--tools/perf/util/callchain.h6
-rw-r--r--tools/perf/util/hist.c7
3 files changed, 22 insertions, 2 deletions
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c
index ae58b493af45..ecf6236f3b5f 100644
--- a/tools/perf/util/callchain.c
+++ b/tools/perf/util/callchain.c
@@ -437,7 +437,7 @@ fill_node(struct callchain_node *node, struct callchain_cursor *cursor)
437 } 437 }
438 call->ip = cursor_node->ip; 438 call->ip = cursor_node->ip;
439 call->ms.sym = cursor_node->sym; 439 call->ms.sym = cursor_node->sym;
440 call->ms.map = cursor_node->map; 440 call->ms.map = map__get(cursor_node->map);
441 list_add_tail(&call->list, &node->val); 441 list_add_tail(&call->list, &node->val);
442 442
443 callchain_cursor_advance(cursor); 443 callchain_cursor_advance(cursor);
@@ -462,6 +462,7 @@ add_child(struct callchain_node *parent,
462 462
463 list_for_each_entry_safe(call, tmp, &new->val, list) { 463 list_for_each_entry_safe(call, tmp, &new->val, list) {
464 list_del(&call->list); 464 list_del(&call->list);
465 map__zput(call->ms.map);
465 free(call); 466 free(call);
466 } 467 }
467 free(new); 468 free(new);
@@ -730,6 +731,7 @@ merge_chain_branch(struct callchain_cursor *cursor,
730 callchain_cursor_append(cursor, list->ip, 731 callchain_cursor_append(cursor, list->ip,
731 list->ms.map, list->ms.sym); 732 list->ms.map, list->ms.sym);
732 list_del(&list->list); 733 list_del(&list->list);
734 map__zput(list->ms.map);
733 free(list); 735 free(list);
734 } 736 }
735 737
@@ -778,7 +780,8 @@ int callchain_cursor_append(struct callchain_cursor *cursor,
778 } 780 }
779 781
780 node->ip = ip; 782 node->ip = ip;
781 node->map = map; 783 map__zput(node->map);
784 node->map = map__get(map);
782 node->sym = sym; 785 node->sym = sym;
783 786
784 cursor->nr++; 787 cursor->nr++;
@@ -945,11 +948,13 @@ static void free_callchain_node(struct callchain_node *node)
945 948
946 list_for_each_entry_safe(list, tmp, &node->parent_val, list) { 949 list_for_each_entry_safe(list, tmp, &node->parent_val, list) {
947 list_del(&list->list); 950 list_del(&list->list);
951 map__zput(list->ms.map);
948 free(list); 952 free(list);
949 } 953 }
950 954
951 list_for_each_entry_safe(list, tmp, &node->val, list) { 955 list_for_each_entry_safe(list, tmp, &node->val, list) {
952 list_del(&list->list); 956 list_del(&list->list);
957 map__zput(list->ms.map);
953 free(list); 958 free(list);
954 } 959 }
955 960
@@ -1013,6 +1018,7 @@ int callchain_node__make_parent_list(struct callchain_node *node)
1013 goto out; 1018 goto out;
1014 *new = *chain; 1019 *new = *chain;
1015 new->has_children = false; 1020 new->has_children = false;
1021 map__get(new->ms.map);
1016 list_add_tail(&new->list, &head); 1022 list_add_tail(&new->list, &head);
1017 } 1023 }
1018 parent = parent->parent; 1024 parent = parent->parent;
@@ -1033,6 +1039,7 @@ int callchain_node__make_parent_list(struct callchain_node *node)
1033out: 1039out:
1034 list_for_each_entry_safe(chain, new, &head, list) { 1040 list_for_each_entry_safe(chain, new, &head, list) {
1035 list_del(&chain->list); 1041 list_del(&chain->list);
1042 map__zput(chain->ms.map);
1036 free(chain); 1043 free(chain);
1037 } 1044 }
1038 return -ENOMEM; 1045 return -ENOMEM;
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h
index 47cfd1080975..b7cbabb3931f 100644
--- a/tools/perf/util/callchain.h
+++ b/tools/perf/util/callchain.h
@@ -5,6 +5,7 @@
5#include <linux/list.h> 5#include <linux/list.h>
6#include <linux/rbtree.h> 6#include <linux/rbtree.h>
7#include "event.h" 7#include "event.h"
8#include "map.h"
8#include "symbol.h" 9#include "symbol.h"
9 10
10#define HELP_PAD "\t\t\t\t" 11#define HELP_PAD "\t\t\t\t"
@@ -174,8 +175,13 @@ int callchain_merge(struct callchain_cursor *cursor,
174 */ 175 */
175static inline void callchain_cursor_reset(struct callchain_cursor *cursor) 176static inline void callchain_cursor_reset(struct callchain_cursor *cursor)
176{ 177{
178 struct callchain_cursor_node *node;
179
177 cursor->nr = 0; 180 cursor->nr = 0;
178 cursor->last = &cursor->first; 181 cursor->last = &cursor->first;
182
183 for (node = cursor->first; node != NULL; node = node->next)
184 map__zput(node->map);
179} 185}
180 186
181int callchain_cursor_append(struct callchain_cursor *cursor, u64 ip, 187int callchain_cursor_append(struct callchain_cursor *cursor, u64 ip,
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index a69f027368ef..10849a079026 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -1,6 +1,7 @@
1#include "util.h" 1#include "util.h"
2#include "build-id.h" 2#include "build-id.h"
3#include "hist.h" 3#include "hist.h"
4#include "map.h"
4#include "session.h" 5#include "session.h"
5#include "sort.h" 6#include "sort.h"
6#include "evlist.h" 7#include "evlist.h"
@@ -1019,6 +1020,10 @@ int hist_entry_iter__add(struct hist_entry_iter *iter, struct addr_location *al,
1019 int max_stack_depth, void *arg) 1020 int max_stack_depth, void *arg)
1020{ 1021{
1021 int err, err2; 1022 int err, err2;
1023 struct map *alm = NULL;
1024
1025 if (al && al->map)
1026 alm = map__get(al->map);
1022 1027
1023 err = sample__resolve_callchain(iter->sample, &callchain_cursor, &iter->parent, 1028 err = sample__resolve_callchain(iter->sample, &callchain_cursor, &iter->parent,
1024 iter->evsel, al, max_stack_depth); 1029 iter->evsel, al, max_stack_depth);
@@ -1058,6 +1063,8 @@ out:
1058 if (!err) 1063 if (!err)
1059 err = err2; 1064 err = err2;
1060 1065
1066 map__put(alm);
1067
1061 return err; 1068 return err;
1062} 1069}
1063 1070