Commit 1c249565 authored by Krister Johansen's avatar Krister Johansen Committed by Arnaldo Carvalho de Melo

perf symbols: Symbol lookup with kcore can fail if multiple segments match stext

This problem was encountered on an arm64 system with a lot of memory.
Without kernel debug symbols installed, and with both kcore and kallsyms
available, perf managed to get confused and returned "unknown" for all
of the kernel symbols that it tried to look up.

On this system, stext fell within the vmalloc segment.  The kcore symbol
matching code tries to find the first segment that contains stext and
uses that to replace the segment generated from just the kallsyms
information.  In this case, however, there were two: a very large
vmalloc segment, and the text segment.  This caused perf to get confused
because multiple overlapping segments were inserted into the RB tree
that holds the discovered segments.  However, that alone wasn't
sufficient to cause the problem. Even when we could find the segment,
the offsets were adjusted in such a way that the newly generated symbols
didn't line up with the instruction addresses in the trace.  The most
obvious solution would be to consult which segment type is text from
kcore, but this information is not exposed to users.

Instead, select the smallest matching segment that contains stext
instead of the first matching segment.  This allows us to match the text
segment instead of vmalloc, if one is contained within the other.
Reviewed-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
Signed-off-by: default avatarKrister Johansen <kjlx@templeofstupid.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Reaver <me@davidreaver.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/20230125183418.GD1963@templeofstupid.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 3980ee9a
...@@ -1377,10 +1377,23 @@ static int dso__load_kcore(struct dso *dso, struct map *map, ...@@ -1377,10 +1377,23 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
/* Find the kernel map using the '_stext' symbol */ /* Find the kernel map using the '_stext' symbol */
if (!kallsyms__get_function_start(kallsyms_filename, "_stext", &stext)) { if (!kallsyms__get_function_start(kallsyms_filename, "_stext", &stext)) {
u64 replacement_size = 0;
list_for_each_entry(new_map, &md.maps, node) { list_for_each_entry(new_map, &md.maps, node) {
if (stext >= new_map->start && stext < new_map->end) { u64 new_size = new_map->end - new_map->start;
if (!(stext >= new_map->start && stext < new_map->end))
continue;
/*
* On some architectures, ARM64 for example, the kernel
* text can get allocated inside of the vmalloc segment.
* Select the smallest matching segment, in case stext
* falls within more than one in the list.
*/
if (!replacement_map || new_size < replacement_size) {
replacement_map = new_map; replacement_map = new_map;
break; replacement_size = new_size;
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment