diff options
author | Krister Johansen <kjlx@templeofstupid.com> | 2017-01-06 01:23:31 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-02-02 09:39:09 -0500 |
commit | aa33b9b9a2ebb00d33c83a5312d4fbf2d5aeba36 (patch) | |
tree | bb0805b62c31bfee44ae018eac68214c0e40d1e1 | |
parent | a1c9f97f0b64e6337d9cfcc08c134450934fdd90 (diff) |
perf callchain: Reference count maps
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>
Cc: stable@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>
-rw-r--r-- | tools/perf/util/callchain.c | 11 | ||||
-rw-r--r-- | tools/perf/util/callchain.h | 6 | ||||
-rw-r--r-- | tools/perf/util/hist.c | 7 |
3 files changed, 22 insertions, 2 deletions
diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index 42922512c1c6..8b610dd9e2f6 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 | 441 | ||
442 | if (cursor_node->branch) { | 442 | if (cursor_node->branch) { |
443 | call->branch_count = 1; | 443 | call->branch_count = 1; |
@@ -477,6 +477,7 @@ add_child(struct callchain_node *parent, | |||
477 | 477 | ||
478 | list_for_each_entry_safe(call, tmp, &new->val, list) { | 478 | list_for_each_entry_safe(call, tmp, &new->val, list) { |
479 | list_del(&call->list); | 479 | list_del(&call->list); |
480 | map__zput(call->ms.map); | ||
480 | free(call); | 481 | free(call); |
481 | } | 482 | } |
482 | free(new); | 483 | free(new); |
@@ -761,6 +762,7 @@ merge_chain_branch(struct callchain_cursor *cursor, | |||
761 | list->ms.map, list->ms.sym, | 762 | list->ms.map, list->ms.sym, |
762 | false, NULL, 0, 0); | 763 | false, NULL, 0, 0); |
763 | list_del(&list->list); | 764 | list_del(&list->list); |
765 | map__zput(list->ms.map); | ||
764 | free(list); | 766 | free(list); |
765 | } | 767 | } |
766 | 768 | ||
@@ -811,7 +813,8 @@ int callchain_cursor_append(struct callchain_cursor *cursor, | |||
811 | } | 813 | } |
812 | 814 | ||
813 | node->ip = ip; | 815 | node->ip = ip; |
814 | node->map = map; | 816 | map__zput(node->map); |
817 | node->map = map__get(map); | ||
815 | node->sym = sym; | 818 | node->sym = sym; |
816 | node->branch = branch; | 819 | node->branch = branch; |
817 | node->nr_loop_iter = nr_loop_iter; | 820 | node->nr_loop_iter = nr_loop_iter; |
@@ -1142,11 +1145,13 @@ static void free_callchain_node(struct callchain_node *node) | |||
1142 | 1145 | ||
1143 | list_for_each_entry_safe(list, tmp, &node->parent_val, list) { | 1146 | list_for_each_entry_safe(list, tmp, &node->parent_val, list) { |
1144 | list_del(&list->list); | 1147 | list_del(&list->list); |
1148 | map__zput(list->ms.map); | ||
1145 | free(list); | 1149 | free(list); |
1146 | } | 1150 | } |
1147 | 1151 | ||
1148 | list_for_each_entry_safe(list, tmp, &node->val, list) { | 1152 | list_for_each_entry_safe(list, tmp, &node->val, list) { |
1149 | list_del(&list->list); | 1153 | list_del(&list->list); |
1154 | map__zput(list->ms.map); | ||
1150 | free(list); | 1155 | free(list); |
1151 | } | 1156 | } |
1152 | 1157 | ||
@@ -1210,6 +1215,7 @@ int callchain_node__make_parent_list(struct callchain_node *node) | |||
1210 | goto out; | 1215 | goto out; |
1211 | *new = *chain; | 1216 | *new = *chain; |
1212 | new->has_children = false; | 1217 | new->has_children = false; |
1218 | map__get(new->ms.map); | ||
1213 | list_add_tail(&new->list, &head); | 1219 | list_add_tail(&new->list, &head); |
1214 | } | 1220 | } |
1215 | parent = parent->parent; | 1221 | parent = parent->parent; |
@@ -1230,6 +1236,7 @@ int callchain_node__make_parent_list(struct callchain_node *node) | |||
1230 | out: | 1236 | out: |
1231 | list_for_each_entry_safe(chain, new, &head, list) { | 1237 | list_for_each_entry_safe(chain, new, &head, list) { |
1232 | list_del(&chain->list); | 1238 | list_del(&chain->list); |
1239 | map__zput(chain->ms.map); | ||
1233 | free(chain); | 1240 | free(chain); |
1234 | } | 1241 | } |
1235 | return -ENOMEM; | 1242 | return -ENOMEM; |
diff --git a/tools/perf/util/callchain.h b/tools/perf/util/callchain.h index 35c8e379530f..4f4b60f1558a 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" |
@@ -184,8 +185,13 @@ int callchain_merge(struct callchain_cursor *cursor, | |||
184 | */ | 185 | */ |
185 | static inline void callchain_cursor_reset(struct callchain_cursor *cursor) | 186 | static inline void callchain_cursor_reset(struct callchain_cursor *cursor) |
186 | { | 187 | { |
188 | struct callchain_cursor_node *node; | ||
189 | |||
187 | cursor->nr = 0; | 190 | cursor->nr = 0; |
188 | cursor->last = &cursor->first; | 191 | cursor->last = &cursor->first; |
192 | |||
193 | for (node = cursor->first; node != NULL; node = node->next) | ||
194 | map__zput(node->map); | ||
189 | } | 195 | } |
190 | 196 | ||
191 | int callchain_cursor_append(struct callchain_cursor *cursor, u64 ip, | 197 | int callchain_cursor_append(struct callchain_cursor *cursor, u64 ip, |
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c index 6770a9645609..7d1b7d33e644 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 | ||