public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Russell King (Oracle)" <linux@armlinux.org.uk>
To: Arnaldo Carvalho de Melo <acme@kernel.org>, Jiri Olsa <jolsa@redhat.com>
Cc: linux-kernel@vger.kernel.org
Subject: perf-kvm unable to resolve guest kernel symbols
Date: Wed, 26 May 2021 19:31:30 +0100	[thread overview]
Message-ID: <20210526183130.GK30436@shell.armlinux.org.uk> (raw)

Hi,

While attempting to use "perf kvm --guestkallsyms=g-kallsyms report",
I have found that perf 5.13-rc2 fails to convert IP values to symbols.

After spending a while debugging, what I've found is:

1) perf_session__new() will not read the gust kernel symbols in this
   case (data is non-NULL, and is open read-only.) The comments say
   that symbol reading will be deferred to the MMAP and MMAP2 events.

2) all of the MMAP and MMAP2 events seem to be for
   PERF_RECORD_MISC_KERNEL and PERF_RECORD_MISC_USER. There are none
   for PERF_RECORD_MISC_GUEST_KERNEL.

I have found that disabling the checks in perf_session__new() mentioned
in (1) allows the command above to give me symbolic information. As I
don't know the code all that well, I'm not sure if this is a correct
fix, or whether the problem lies in the "perf kvm record" side - that
depends whether there are supposed to be MMAP/MMAP2 events for the
guest kernel.

Below is the debug diff I've been using so far... (building out of the
kernel tree.) The change to tools/perf/util/session.c seems to be what
has fixed the problem for me, but I don't think this is the correct
fix.

diff -ur -x '*.o' -x '*.cmd' perf-5.13.0-rc2.orig/tools/perf/util/machine.c perf-5.13.0-rc2/tools/perf/util/machine.c
--- perf-5.13.0-rc2.orig/tools/perf/util/machine.c	2021-05-19 15:04:47.000000000 +0100
+++ perf-5.13.0-rc2/tools/perf/util/machine.c	2021-05-20 14:41:55.425771482 +0100
@@ -1234,7 +1234,7 @@
 	char path[PATH_MAX];
 	pid_t pid;
 	char *endp;
-
+printf("machines__create_guest_kernel_maps: %s\n", symbol_conf.default_guest_kallsyms);
 	if (symbol_conf.default_guest_vmlinux_name ||
 	    symbol_conf.default_guest_modules ||
 	    symbol_conf.default_guest_kallsyms) {
@@ -1293,7 +1293,7 @@
 int machines__create_kernel_maps(struct machines *machines, pid_t pid)
 {
 	struct machine *machine = machines__findnew(machines, pid);
-
+printf("machines__create_kernel_maps: %p\n", machine);
 	if (machine == NULL)
 		return -1;
 
@@ -1763,7 +1763,7 @@
 		bid = &__bid;
 		build_id__init(bid, event->mmap2.build_id, event->mmap2.build_id_size);
 	}
-
+printf("%s: cpumode %d\n", "machine__process_mmap2_event", sample->cpumode);
 	if (sample->cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
 	    sample->cpumode == PERF_RECORD_MISC_KERNEL) {
 		struct extra_kernel_map xm = {
@@ -1821,6 +1821,7 @@
 	if (dump_trace)
 		perf_event__fprintf_mmap(event, stdout);
 
+printf("%s: cpumode %d\n", "machine__process_mmap_event", sample->cpumode);
 	if (sample->cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
 	    sample->cpumode == PERF_RECORD_MISC_KERNEL) {
 		struct extra_kernel_map xm = {
diff -ur -x '*.o' -x '*.cmd' perf-5.13.0-rc2.orig/tools/perf/util/session.c perf-5.13.0-rc2/tools/perf/util/session.c
--- perf-5.13.0-rc2.orig/tools/perf/util/session.c	2021-05-19 15:04:47.000000000 +0100
+++ perf-5.13.0-rc2/tools/perf/util/session.c	2021-05-20 12:17:31.251730384 +0100
@@ -243,14 +243,14 @@
 	session->machines.host.single_address_space =
 		perf_env__single_address_space(session->machines.host.env);
 
-	if (!data || perf_data__is_write(data)) {
+//	if (!data || perf_data__is_write(data)) {
 		/*
 		 * In O_RDONLY mode this will be performed when reading the
 		 * kernel MMAP event, in perf_event__process_mmap().
 		 */
 		if (perf_session__create_kernel_maps(session) < 0)
 			pr_warning("Cannot read kernel map\n");
-	}
+//	}
 
 	/*
 	 * In pipe-mode, evlist is empty until PERF_RECORD_HEADER_ATTR is

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!

                 reply	other threads:[~2021-05-26 18:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20210526183130.GK30436@shell.armlinux.org.uk \
    --to=linux@armlinux.org.uk \
    --cc=acme@kernel.org \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@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