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 01/16] perf/core: Add PERF_SAMPLE_HOST_IP sample format
Date: Tue, 1 Dec 2026 15:21:01 -0800 [thread overview]
Message-ID: <20261201232116.1988791-2-irogers@google.com> (raw)
In-Reply-To: <20261201232116.1988791-1-irogers@google.com>
Add PERF_SAMPLE_HOST_IP (1U << 25) to enum perf_event_sample_format so
that samples can record a host virtual instruction pointer alongside
PERF_SAMPLE_IP.
When sampling a guest (should_sample_guest()), PERF_SAMPLE_HOST_IP
invokes an optional ->get_host_ip() callback on
perf_guest_info_callbacks to translate the guest instruction pointer
into the corresponding host virtual address in the hypervisor process,
allowing host-side file-backed/DAX mappings to symbolize guest code
without guest symbol state. When not in guest context and
!attr.exclude_host, it records perf_instruction_pointer().
Ensure __perf_event_header_size() accounts for sizeof(data->host_ip),
respect exclude_kernel on skidded guest-kernel samples and exclude_host
on skidded host samples, and keep ->get_host_ip() optional so
hypervisors such as Xen default safely to returning 0.
Signed-off-by: Ian Rogers <irogers@google.com>
---
include/linux/perf_event.h | 9 +++++++++
include/uapi/linux/perf_event.h | 4 +++-
kernel/events/core.c | 24 ++++++++++++++++++++++++
3 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index b52348eca6ef..8ce5383e4b0a 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -1329,6 +1329,7 @@ struct perf_sample_data {
* perf_{prepare,output}_sample().
*/
u64 ip;
+ u64 host_ip;
struct perf_callchain_entry *callchain;
struct perf_raw_record *raw;
struct perf_branch_stack *br_stack;
@@ -1683,6 +1684,7 @@ extern void perf_event_bpf_event(struct bpf_prog *prog,
struct perf_guest_info_callbacks {
unsigned int (*state)(void);
unsigned long (*get_ip)(void);
+ unsigned long (*get_host_ip)(void);
unsigned int (*handle_intel_pt_intr)(void);
void (*handle_mediated_pmi)(void);
@@ -1694,6 +1696,7 @@ extern struct perf_guest_info_callbacks __rcu *perf_guest_cbs;
DECLARE_STATIC_CALL(__perf_guest_state, *perf_guest_cbs->state);
DECLARE_STATIC_CALL(__perf_guest_get_ip, *perf_guest_cbs->get_ip);
+DECLARE_STATIC_CALL(__perf_guest_get_host_ip, *perf_guest_cbs->get_host_ip);
DECLARE_STATIC_CALL(__perf_guest_handle_intel_pt_intr, *perf_guest_cbs->handle_intel_pt_intr);
DECLARE_STATIC_CALL(__perf_guest_handle_mediated_pmi, *perf_guest_cbs->handle_mediated_pmi);
@@ -1707,6 +1710,11 @@ static inline unsigned long perf_guest_get_ip(void)
return static_call(__perf_guest_get_ip)();
}
+static inline unsigned long perf_guest_get_host_ip(void)
+{
+ return static_call(__perf_guest_get_host_ip)();
+}
+
static inline unsigned int perf_guest_handle_intel_pt_intr(void)
{
return static_call(__perf_guest_handle_intel_pt_intr)();
@@ -1724,6 +1732,7 @@ extern void perf_unregister_guest_info_callbacks(struct perf_guest_info_callback
static inline unsigned int perf_guest_state(void) { return 0; }
static inline unsigned long perf_guest_get_ip(void) { return 0; }
+static inline unsigned long perf_guest_get_host_ip(void) { return 0; }
static inline unsigned int perf_guest_handle_intel_pt_intr(void) { return 0; }
#endif /* !CONFIG_GUEST_PERF_EVENTS */
diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index c49fc76292f7..75ed8e968d30 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -165,8 +165,9 @@ enum perf_event_sample_format {
PERF_SAMPLE_DATA_PAGE_SIZE = 1U << 22,
PERF_SAMPLE_CODE_PAGE_SIZE = 1U << 23,
PERF_SAMPLE_WEIGHT_STRUCT = 1U << 24,
+ PERF_SAMPLE_HOST_IP = 1U << 25,
- PERF_SAMPLE_MAX = 1U << 25, /* non-ABI */
+ PERF_SAMPLE_MAX = 1U << 26, /* non-ABI */
};
#define PERF_SAMPLE_WEIGHT_TYPE (PERF_SAMPLE_WEIGHT | PERF_SAMPLE_WEIGHT_STRUCT)
@@ -1093,6 +1094,7 @@ enum perf_event_type {
* { u64 cgroup;} && PERF_SAMPLE_CGROUP
* { u64 data_page_size;} && PERF_SAMPLE_DATA_PAGE_SIZE
* { u64 code_page_size;} && PERF_SAMPLE_CODE_PAGE_SIZE
+ * { u64 host_ip;} && PERF_SAMPLE_HOST_IP
* { u64 size;
* char data[size]; } && PERF_SAMPLE_AUX
* };
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 526c486d1647..6da956ceead0 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -2103,6 +2103,9 @@ static void __perf_event_header_size(struct perf_event *event, u64 sample_type)
if (sample_type & PERF_SAMPLE_CODE_PAGE_SIZE)
size += sizeof(data->code_page_size);
+ if (sample_type & PERF_SAMPLE_HOST_IP)
+ size += sizeof(data->host_ip);
+
event->header_size = size;
}
@@ -7804,6 +7807,7 @@ struct perf_guest_info_callbacks __rcu *perf_guest_cbs;
DEFINE_STATIC_CALL_RET0(__perf_guest_state, *perf_guest_cbs->state);
DEFINE_STATIC_CALL_RET0(__perf_guest_get_ip, *perf_guest_cbs->get_ip);
+DEFINE_STATIC_CALL_RET0(__perf_guest_get_host_ip, *perf_guest_cbs->get_host_ip);
DEFINE_STATIC_CALL_RET0(__perf_guest_handle_intel_pt_intr, *perf_guest_cbs->handle_intel_pt_intr);
DEFINE_STATIC_CALL_RET0(__perf_guest_handle_mediated_pmi, *perf_guest_cbs->handle_mediated_pmi);
@@ -7816,6 +7820,10 @@ void perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
static_call_update(__perf_guest_state, cbs->state);
static_call_update(__perf_guest_get_ip, cbs->get_ip);
+ /* Implementing ->get_host_ip is optional. */
+ if (cbs->get_host_ip)
+ static_call_update(__perf_guest_get_host_ip, cbs->get_host_ip);
+
/* Implementing ->handle_intel_pt_intr is optional. */
if (cbs->handle_intel_pt_intr)
static_call_update(__perf_guest_handle_intel_pt_intr,
@@ -7835,6 +7843,7 @@ void perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
rcu_assign_pointer(perf_guest_cbs, NULL);
static_call_update(__perf_guest_state, (void *)&__static_call_return0);
static_call_update(__perf_guest_get_ip, (void *)&__static_call_return0);
+ static_call_update(__perf_guest_get_host_ip, (void *)&__static_call_return0);
static_call_update(__perf_guest_handle_intel_pt_intr, (void *)&__static_call_return0);
static_call_update(__perf_guest_handle_mediated_pmi, (void *)&__static_call_return0);
synchronize_rcu();
@@ -8595,6 +8604,9 @@ void perf_output_sample(struct perf_output_handle *handle,
if (sample_type & PERF_SAMPLE_CODE_PAGE_SIZE)
perf_output_put(handle, data->code_page_size);
+ if (sample_type & PERF_SAMPLE_HOST_IP)
+ perf_output_put(handle, data->host_ip);
+
if (sample_type & PERF_SAMPLE_AUX) {
perf_output_put(handle, data->aux_size);
@@ -8838,6 +8850,18 @@ void perf_prepare_sample(struct perf_sample_data *data,
data->sample_flags |= PERF_SAMPLE_IP;
}
+ if (filtered_sample_type & PERF_SAMPLE_HOST_IP) {
+ data->host_ip = 0;
+ if (should_sample_guest(event)) {
+ if (!event->attr.exclude_kernel ||
+ (perf_guest_state() & PERF_GUEST_USER))
+ data->host_ip = perf_guest_get_host_ip();
+ } else if (!event->attr.exclude_host) {
+ data->host_ip = perf_instruction_pointer(event, regs);
+ }
+ data->sample_flags |= PERF_SAMPLE_HOST_IP;
+ }
+
if (filtered_sample_type & PERF_SAMPLE_CALLCHAIN)
perf_sample_save_callchain(data, event, regs);
--
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 ` Ian Rogers [this message]
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 ` [RFC PATCH 10/16] perf symbol: Support host IP resolution and guest fallback symbolization Ian Rogers
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-2-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