diff options
author | Krister Johansen <kjlx@templeofstupid.com> | 2017-01-06 01:23:31 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-01-31 14:19:06 -0500 |
commit | 9c68ae98c6f714ef573826cfc9055af1bd5e97b1 (patch) | |
tree | f87b3cf4812f70534c8cc2309c934d6ffab69bbc /tools | |
parent | c0621acf45a9d8c3b501633b5eca11495fff8f66 (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>
Diffstat (limited to 'tools')
-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 e16db30dfe40..aba953421a03 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c | |||
@@ -449,7 +449,7 @@ fill_node(struct callchain_node *node, struct callchain_cursor *cursor) | |||
449 | } | 449 | } |
450 | call->ip = cursor_node->ip; | 450 | call->ip = cursor_node->ip; |
451 | call->ms.sym = cursor_node->sym; | 451 | call->ms.sym = cursor_node->sym; |
452 | call->ms.map = cursor_node->map; | 452 | call->ms.map = map__get(cursor_node->map); |
453 | 453 | ||
454 | if (cursor_node->branch) { | 454 | if (cursor_node->branch) { |
455 | call->branch_count = 1; | 455 | call->branch_count = 1; |
@@ -489,6 +489,7 @@ add_child(struct callchain_node *parent, | |||
489 | 489 | ||
490 | list_for_each_entry_safe(call, tmp, &new->val, list) { | 490 | list_for_each_entry_safe(call, tmp, &new->val, list) { |
491 | list_del(&call->list); | 491 | list_del(&call->list); |
492 | map__zput(call->ms.map); | ||
492 | free(call); | 493 | free(call); |
493 | } | 494 | } |
494 | free(new); | 495 | free(new); |
@@ -773,6 +774,7 @@ merge_chain_branch(struct callchain_cursor *cursor, | |||
773 | list->ms.map, list->ms.sym, | 774 | list->ms.map, list->ms.sym, |
774 | false, NULL, 0, 0); | 775 | false, NULL, 0, 0); |
775 | list_del(&list->list); | 776 | list_del(&list->list); |
777 | map__zput(list->ms.map); | ||
776 | free(list); | 778 | free(list); |
777 | } | 779 | } |
778 | 780 | ||
@@ -823,7 +825,8 @@ int callchain_cursor_append(struct callchain_cursor *cursor, | |||
823 | } | 825 | } |
824 | 826 | ||
825 | node->ip = ip; | 827 | node->ip = ip; |
826 | node->map = map; | 828 | map__zput(node->map); |
829 | node->map = map__get(map); | ||
827 | node->sym = sym; | 830 | node->sym = sym; |
828 | node->branch = branch; | 831 | node->branch = branch; |
829 | node->nr_loop_iter = nr_loop_iter; | 832 | node->nr_loop_iter = nr_loop_iter; |
@@ -1154,11 +1157,13 @@ static void free_callchain_node(struct callchain_node *node) | |||
1154 | 1157 | ||
1155 | list_for_each_entry_safe(list, tmp, &node->parent_val, list) { | 1158 | list_for_each_entry_safe(list, tmp, &node->parent_val, list) { |
1156 | list_del(&list->list); | 1159 | list_del(&list->list); |
1160 | map__zput(list->ms.map); | ||
1157 | free(list); | 1161 | free(list); |
1158 | } | 1162 | } |
1159 | 1163 | ||
1160 | list_for_each_entry_safe(list, tmp, &node->val, list) { | 1164 | list_for_each_entry_safe(list, tmp, &node->val, list) { |
1161 | list_del(&list->list); | 1165 | list_del(&list->list); |
1166 | map__zput(list->ms.map); | ||
1162 | free(list); | 1167 | free(list); |
1163 | } | 1168 | } |
1164 | 1169 | ||
@@ -1222,6 +1227,7 @@ int callchain_node__make_parent_list(struct callchain_node *node) | |||
1222 | goto out; | 1227 | goto out; |
1223 | *new = *chain; | 1228 | *new = *chain; |
1224 | new->has_children = false; | 1229 | new->has_children = false; |
1230 | map__get(new->ms.map); | ||
1225 | list_add_tail(&new->list, &head); | 1231 | list_add_tail(&new->list, &head); |
1226 | } | 1232 | } |
1227 | parent = parent->parent; | 1233 | parent = parent->parent; |
@@ -1242,6 +1248,7 @@ int callchain_node__make_parent_list(struct callchain_node *node) | |||
1242 | out: | 1248 | out: |
1243 | list_for_each_entry_safe(chain, new, &head, list) { | 1249 | list_for_each_entry_safe(chain, new, &head, list) { |
1244 | list_del(&chain->list); | 1250 | list_del(&chain->list); |
1251 | map__zput(chain->ms.map); | ||
1245 | free(chain); | 1252 | free(chain); |
1246 | } | 1253 | } |
1247 | return -ENOMEM; | 1254 | 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 cff2e9041b15..32c6a939e4cc 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 | ||