From: Ian Rogers <irogers@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>
Cc: Marc Zyngier <maz@kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
linux-perf-users@vger.kernel.org, kvm@vger.kernel.org,
bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
Ian Rogers <irogers@google.com>
Subject: [RFC PATCH 10/16] perf symbol: Support host IP resolution and guest fallback symbolization
Date: Tue, 1 Dec 2026 15:21:10 -0800 [thread overview]
Message-ID: <20261201232116.1988791-11-irogers@google.com> (raw)
In-Reply-To: <20261201232116.1988791-1-irogers@google.com>
Store resolved host mapping state (host_map, host_sym, host_addr,
raw_host_ip) in struct addr_location and resolve sample->host_ip against
machines->host in machine__resolve().
When a guest sample cannot be symbolized in the guest machine,
automatically fall back to the resolved host mapping and symbol (and
clear HIST_FILTER__GUEST when perf_host or perf_guest is active), so
guest code backed by host DAX or file-backed mappings symbolizes
transparently without guest symbol state.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/addr_location.c | 7 ++++
tools/perf/util/addr_location.h | 4 +++
tools/perf/util/event.c | 58 +++++++++++++++++++++++++++++++--
3 files changed, 67 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/addr_location.c b/tools/perf/util/addr_location.c
index 57e8217a00f9..ca0380260ee6 100644
--- a/tools/perf/util/addr_location.c
+++ b/tools/perf/util/addr_location.c
@@ -9,8 +9,12 @@ void addr_location__init(struct addr_location *al)
al->thread = NULL;
al->map = NULL;
al->sym = NULL;
+ al->host_map = NULL;
+ al->host_sym = NULL;
al->srcline = NULL;
al->addr = 0;
+ al->host_addr = 0;
+ al->raw_host_ip = 0;
al->level = 0;
al->filtered = 0;
al->cpumode = 0;
@@ -28,6 +32,7 @@ void addr_location__init(struct addr_location *al)
void addr_location__exit(struct addr_location *al)
{
map__zput(al->map);
+ map__zput(al->host_map);
thread__zput(al->thread);
}
@@ -35,7 +40,9 @@ void addr_location__copy(struct addr_location *dst, struct addr_location *src)
{
thread__put(dst->thread);
map__put(dst->map);
+ map__put(dst->host_map);
*dst = *src;
dst->thread = thread__get(src->thread);
dst->map = map__get(src->map);
+ dst->host_map = map__get(src->host_map);
}
diff --git a/tools/perf/util/addr_location.h b/tools/perf/util/addr_location.h
index fdc4d3f3a68b..d4148d7df998 100644
--- a/tools/perf/util/addr_location.h
+++ b/tools/perf/util/addr_location.h
@@ -13,8 +13,12 @@ struct addr_location {
struct thread *thread;
struct map *map;
struct symbol *sym;
+ struct map *host_map;
+ struct symbol *host_sym;
const char *srcline;
u64 addr;
+ u64 host_addr;
+ u64 raw_host_ip;
char level;
u8 cpumode;
u16 filtered;
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index ea75816d126a..96d88d88ba06 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -808,6 +808,11 @@ int machine__resolve(struct machine *machine, struct addr_location *al,
struct thread *thread;
struct dso *dso;
+ map__zput(al->host_map);
+ al->host_sym = NULL;
+ al->host_addr = 0;
+ al->raw_host_ip = sample->host_ip;
+
if (symbol_conf.guest_code && !machine__is_host(machine))
thread = machine__findnew_guest_code(machine, sample->pid);
else
@@ -862,6 +867,57 @@ int machine__resolve(struct machine *machine, struct addr_location *al,
*/
al->latency = sample->period * 1000 / al->parallelism;
+ if (al->map)
+ al->sym = map__find_symbol(al->map, al->addr);
+
+ if (sample->host_ip) {
+ struct machine *host_machine = machine__is_host(machine) ?
+ machine : (machine->machines ? &machine->machines->host : NULL);
+
+ if (host_machine) {
+ struct thread *host_thread = machine__findnew_thread(host_machine,
+ sample->pid,
+ sample->tid);
+ struct maps *host_maps = NULL;
+ bool load_host_map = false;
+
+ if (machine__kernel_ip(host_machine, sample->host_ip)) {
+ host_maps = machine__kernel_maps(host_machine);
+ load_host_map = !symbol_conf.lazy_load_kernel_maps;
+ } else if (host_thread) {
+ host_maps = thread__maps(host_thread);
+ }
+
+ if (host_maps) {
+ al->host_map = maps__find(host_maps, sample->host_ip);
+ if (al->host_map) {
+ if (load_host_map)
+ map__load(al->host_map);
+ al->host_addr = map__map_ip(al->host_map,
+ sample->host_ip);
+ al->host_sym = map__find_symbol(al->host_map,
+ al->host_addr);
+ }
+ }
+ thread__put(host_thread);
+ }
+
+ if ((sample->cpumode == PERF_RECORD_MISC_GUEST_USER ||
+ sample->cpumode == PERF_RECORD_MISC_GUEST_KERNEL) &&
+ !al->sym && al->host_map && (al->host_sym || !al->map)) {
+ map__zput(al->map);
+ al->map = map__get(al->host_map);
+ al->addr = al->host_addr;
+ al->sym = al->host_sym;
+ dso = map__dso(al->map);
+ if (perf_host || perf_guest) {
+ al->filtered &= ~(1 << HIST_FILTER__GUEST);
+ al->level = (sample->cpumode == PERF_RECORD_MISC_GUEST_KERNEL) ?
+ 'g' : 'u';
+ }
+ }
+ }
+
if (al->map) {
if (symbol_conf.dso_list &&
(!dso || !(strlist__has_entry(symbol_conf.dso_list,
@@ -871,8 +927,6 @@ int machine__resolve(struct machine *machine, struct addr_location *al,
dso__long_name(dso)))))) {
al->filtered |= (1 << HIST_FILTER__DSO);
}
-
- al->sym = map__find_symbol(al->map, al->addr);
} else if (symbol_conf.dso_list) {
al->filtered |= (1 << HIST_FILTER__DSO);
}
--
2.56.1.915.g69d5ec7298-goog
next prev parent reply other threads:[~2026-12-01 23:21 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 23:21 [RFC PATCH 00/16] perf, kvm: Add PERF_SAMPLE_HOST_IP for host-side guest symbolization Ian Rogers
2026-12-01 23:21 ` [RFC PATCH 01/16] perf/core: Add PERF_SAMPLE_HOST_IP sample format Ian Rogers
2026-12-01 23:21 ` [RFC PATCH 02/16] perf/core, bpf: Support BPF filtering of mmap_data events Ian Rogers
2026-12-01 23:21 ` [RFC PATCH 03/16] KVM: Add NMI-safe guest-to-host IP translation infrastructure Ian Rogers
2026-12-01 23:40 ` sashiko-bot
2026-12-01 23:21 ` [RFC PATCH 04/16] KVM: x86: Implement kvm_arch_vcpu_get_ip_gpa() Ian Rogers
2026-12-01 23:21 ` [RFC PATCH 05/16] KVM: arm64: " Ian Rogers
2026-12-01 23:41 ` sashiko-bot
2026-12-01 23:21 ` [RFC PATCH 06/16] KVM: riscv: " Ian Rogers
2026-12-01 23:21 ` [RFC PATCH 07/16] KVM: loongarch: " Ian Rogers
2026-12-01 23:21 ` [RFC PATCH 08/16] tools headers UAPI: Sync linux/perf_event.h with the kernel sources Ian Rogers
2026-12-01 23:21 ` [RFC PATCH 09/16] perf tools: Add PERF_SAMPLE_HOST_IP parsing, synthesis, and record --host-ip Ian Rogers
2026-12-01 23:36 ` sashiko-bot
2026-12-01 23:21 ` Ian Rogers [this message]
2026-12-01 23:21 ` [RFC PATCH 11/16] perf report, script: Add host_ip, host_dso, and host_sym fields Ian Rogers
2026-12-01 23:41 ` sashiko-bot
2026-12-01 23:21 ` [RFC PATCH 12/16] perf record: Synthesize hypervisor file-backed data mappings for --host-ip Ian Rogers
2026-12-01 23:21 ` [RFC PATCH 13/16] perf record: Filter runtime hypervisor data mmaps with BPF " Ian Rogers
2026-12-01 23:43 ` sashiko-bot
2026-12-01 23:21 ` [RFC PATCH 14/16] perf bpf-filter: Support host_ip in BPF sample filters Ian Rogers
2026-12-01 23:21 ` [RFC PATCH 15/16] perf aslr: Anonymize sampled host_ip values Ian Rogers
2026-12-01 23:21 ` [RFC PATCH 16/16] perf test: Add PERF_SAMPLE_HOST_IP symbolization, sorting, and ASLR tests Ian Rogers
2026-12-01 23:40 ` sashiko-bot
2026-12-01 23:43 ` [RFC PATCH 00/16] perf, kvm: Add PERF_SAMPLE_HOST_IP for host-side guest symbolization sashiko-bot
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=20261201232116.1988791-11-irogers@google.com \
--to=irogers@google.com \
--cc=acme@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=maz@kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=seanjc@google.com \
/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