From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.197 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796167293; b=gNB3b1EiY7gkXWZlW3OOvFwQlapoWVGqBWlQkKq2v3OVcTnKGGJIs+2XnSOGtP3zYneE GYO5H+EUqAlS0NhJ9Qc6oIqNF2RWxYNRiQyGy0NCyheVGU43zZLTqOXfNtddLThbrOVyl zYola0ybF8iGV9nuBZ2bvoxYuZn8HNu1+lnHUrx+egVNmuheVUFvkhc5HLNZrSr9NIvoo M7tSzNFvrjkI30aSaQ40vGjNSW9RcPWJg7IgQ/x6EpEkTvyILSoe+B3BJeHGYOZe1nxE5 3Vim7+evawAb9XQTT6SJqlvIGyuobydXSS5nMa1hi3vcMru0gD0oVAhhjRjensbQdfg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796167293; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:X-Mailer:Message-ID:Subject:From:To:Cc: Content-Type; bh=tLzo1+/lHSbRGMPAu0xFWHgomdgE5Zx5vsljkZVSL+c=; b=hhUN6LObdW3nGPImj+Hb8w3yspSkRIVZxmOmN/3M0GJZ3YPIEY2RghCq7V65IERJFkyY 9bcUfu1e0FPvv4w5hELPWRV/RPz6BwoMwUN8s7k0h1b1U3KqTOm38KuMb/s5Zj/T84RBe 6eh9M9PEVX4FU7uuKpuZSVTUQUHxOJXIdhE3S8oWqWvbIUu651wgx4Ss2H94gDEWQznmx uTNc/qtW7JLCUIheBrKuaWixkwLO0hC2zPeWPslcEV5ReA1Mxhy3SkAuvt4Vydn8VeQ+9 ikPevuEfiBucuuNbu1XruTKI+quX78BY9a6mf6spfQf4Ffmk/UYYcsOU3k1LZkVXMQw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=iSDNAJRG; arc=none smtp.remote-ip=74.125.82.197 Received: from mail-dy1-f197.google.com (mail-dy1-f197.google.com [74.125.82.197]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD216606A33E for ; Tue, 1 Dec 2026 23:21:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DD216606A33E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=iSDNAJRG Received: by mail-dy1-f197.google.com with SMTP id 5a478bee46e88-386df943355so4124207eec.1 for ; Tue, 01 Dec 2026 15:21:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796167291; x=1796772091; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=tLzo1+/lHSbRGMPAu0xFWHgomdgE5Zx5vsljkZVSL+c=; b=iSDNAJRGgM7cylDuoXDbK4m3YNmeQsaa0a4OMSHbiudS6/T7T0FdLdaY5ywhIgCta1 hKh5DWEudF1HOKx8QooDp50KFwc4eyLTEED+StB0exOuo8Ke75CLx9/KFroen6cQVOgg UYwnaG6Bsi5HY9mBwekkRm9ns0jf6U1L5vLnXQpaSDFwAKp/3CsUD0Aqo8avECQ3SBER WbX6XK1YOafhfr7zmXaQ31DHN4AgqCIznGiH+dIV4ByCyY3jPatuCA4Zw3SpkYM8LgxO D0d9A1evAaaM11z/pZmk6WZTLE6o2gGHnyr6fpbd4XiqSgzRVyr5uDtRxLy3BuoYQI5F +umA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796167291; x=1796772091; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=tLzo1+/lHSbRGMPAu0xFWHgomdgE5Zx5vsljkZVSL+c=; b=MRo9PraA8RH3VN1J4OM6ik3lHus+K898uRpuAf4n97tIoVB4uYMAyVbyspYwH8Fws/ KWKlEFp3fmehD90eGr4qGNSpWHZLjavmTgvdQVQ6gJ1E5n8fZkMtRcHamhR8aaS4Ezz9 honaDkNR2XyzIG3zSzz0CJ0qGutRSw6m2uG41jlida/Pu05RUx7wbfD+k0Ggdvi6sq3m cm1QDBdLqXBtiVldCoQeUIB5fcxBwZPnPe5kK1sWiuL3jcrieaNZQKLJzqFdKrMAPTmY c5czIAiFrqoCM/xo8LycK5yBYa13v7422hGzHBKDVtq+zEGKshfSrYQcO+VVPl3qSXwD 7O6Q== X-Forwarded-Encrypted: i=1; AL+hErG/wFutD2Pb51YismOFgcUjTRF7sOZDTiBHSu6BW/g1EBWEW2c/P1EDJiAzWKiHUkGn/rH52tp1EN0qMZ8=@vger.kernel.org X-Gm-Message-State: APuU4Z+Byrl4cAwg7NlPQJVlABetk5aeTV6rgyTXuPhhyXz6cqoyv8x7 +sID0EHDtyEfHTCi6EltyKuGSTT2vubm+dAVdSsFl6VMioSp2EsZFYSTRY0p+MZpN2mByJcwYpi yMm8yWn09Bw== X-Received: from dlbrl22.prod.google.com ([2002:a05:7022:f516:b0:195:8b4e:20b7]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:701a:8459:20b0:1ab:90a8:87a2 with SMTP id a92af1059eb24-1b5524b0f73mr35291960c88.11.1796167290739; Tue, 01 Dec 2026 15:21:30 -0800 (PST) Date: Tue, 1 Dec 2026 15:21:01 -0800 In-Reply-To: <20261201232116.1988791-1-irogers@google.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261201232116.1988791-1-irogers@google.com> X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog Message-ID: <20261201232116.1988791-2-irogers@google.com> Subject: [RFC PATCH 01/16] perf/core: Add PERF_SAMPLE_HOST_IP sample format From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Sean Christopherson , Paolo Bonzini Cc: Marc Zyngier , Alexei Starovoitov , linux-perf-users@vger.kernel.org, kvm@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Ian Rogers Content-Type: text/plain; charset="UTF-8" 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 --- 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