stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	patches@lists.linux.dev, Adrian Hunter <adrian.hunter@intel.com>,
	Krister Johansen <kjlx@templeofstupid.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	David Reaver <me@davidreaver.com>,
	Ian Rogers <irogers@google.com>, Jiri Olsa <jolsa@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Michael Petlan <mpetlan@redhat.com>,
	Namhyung Kim <namhyung@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 5.15 13/15] perf symbols: Symbol lookup with kcore can fail if multiple segments match stext
Date: Mon,  3 Jul 2023 20:54:58 +0200	[thread overview]
Message-ID: <20230703184519.254046765@linuxfoundation.org> (raw)
In-Reply-To: <20230703184518.896751186@linuxfoundation.org>

From: Krister Johansen <kjlx@templeofstupid.com>

commit 1c249565426e3a9940102c0ba9f63914f7cda73d upstream.

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: Adrian Hunter <adrian.hunter@intel.com>
Signed-off-by: Krister 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.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Krister Johansen <kjlx@templeofstupid.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 tools/perf/util/symbol.c |   17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -1357,10 +1357,23 @@ static int dso__load_kcore(struct dso *d
 
 	/* Find the kernel map using the '_stext' symbol */
 	if (!kallsyms__get_function_start(kallsyms_filename, "_stext", &stext)) {
+		u64 replacement_size = 0;
+
 		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;
-				break;
+				replacement_size = new_size;
 			}
 		}
 	}



  parent reply	other threads:[~2023-07-03 18:57 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-03 18:54 [PATCH 5.15 00/15] 5.15.120-rc1 review Greg Kroah-Hartman
2023-07-03 18:54 ` [PATCH 5.15 01/15] mptcp: fix possible divide by zero in recvmsg() Greg Kroah-Hartman
2023-07-03 18:54 ` [PATCH 5.15 02/15] mptcp: consolidate fallback and non fallback state machine Greg Kroah-Hartman
2023-07-03 18:54 ` [PATCH 5.15 03/15] mm, hwpoison: try to recover from copy-on write faults Greg Kroah-Hartman
2023-07-03 18:54 ` [PATCH 5.15 04/15] mm, hwpoison: when copy-on-write hits poison, take page offline Greg Kroah-Hartman
2023-07-03 18:54 ` [PATCH 5.15 05/15] drm/amdgpu: Set vmbo destroy after pt bo is created Greg Kroah-Hartman
2023-07-03 18:54 ` [PATCH 5.15 06/15] x86/microcode/AMD: Load late on both threads too Greg Kroah-Hartman
2023-07-03 18:54 ` [PATCH 5.15 07/15] x86/smp: Use dedicated cache-line for mwait_play_dead() Greg Kroah-Hartman
2023-07-03 18:54 ` [PATCH 5.15 08/15] can: isotp: isotp_sendmsg(): fix return error fix on TX path Greg Kroah-Hartman
2023-07-03 18:54 ` [PATCH 5.15 09/15] bpf: ensure main program has an extable Greg Kroah-Hartman
2023-07-03 18:54 ` [PATCH 5.15 10/15] HID: wacom: Use ktime_t rather than int when dealing with timestamps Greg Kroah-Hartman
2023-07-03 18:54 ` [PATCH 5.15 11/15] HID: logitech-hidpp: add HIDPP_QUIRK_DELAYED_INIT for the T651 Greg Kroah-Hartman
2023-07-03 18:54 ` [PATCH 5.15 12/15] Revert "thermal/drivers/mediatek: Use devm_of_iomap to avoid resource leak in mtk_thermal_probe" Greg Kroah-Hartman
2023-07-03 18:54 ` Greg Kroah-Hartman [this message]
2023-07-03 18:54 ` [PATCH 5.15 14/15] scripts/tags.sh: Resolve gtags empty index generation Greg Kroah-Hartman
2023-07-03 18:55 ` [PATCH 5.15 15/15] drm/amdgpu: Validate VM ioctl flags Greg Kroah-Hartman
2023-07-04  7:00 ` [PATCH 5.15 00/15] 5.15.120-rc1 review Naresh Kamboju
2023-07-04  7:16   ` Helge Deller
2023-07-04  7:31     ` Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230703184519.254046765@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=kjlx@templeofstupid.com \
    --cc=mark.rutland@arm.com \
    --cc=me@davidreaver.com \
    --cc=mpetlan@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=patches@lists.linux.dev \
    --cc=peterz@infradead.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).