From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.200 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796167292; b=JiUw3319RubSPHatiIu2z4r7C8sRs/xq+//fMBZXom2915WrmdaWrQZxLKswsNqD9Rb5 qbQGKQxKg0smDZ+hxEXd5Ycm/MFW5snlKmERZDYfjCzD7/Hiz86txg/UuDSCMAc51DQpy /pOTBkE/BcvhIbAqJVyt3+MXa3Pha1kR0iIjcWwmt18Sxup+hVo7RMNby387ZHHcH6LEc FgVKO7yC9ntmPvEtaUcleqA+Zg9F7KhJqRnqlYQnX9352G8oVlgCrU9+G8pEZZZSSNb2z 03T/Ys7lB8YZJ83bXnZ7iEG6r55oBVyTrX03icYveNLvvwAalil5B6MKN5uLNjzlIMA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796167292; 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=ZPZqpbMYrA/Q6RuYjOUezms0frkbRXa4McyMmOrNk/U9MNdLmDg+ouxUyRH9OpPWSQWD Hxai9MzN3QNZPEDE6HKWgx9dAJXpKEbiRtzm1GiGZrNVlZuEzJIcH33TiEVsgbG0jbsNM upkqO0e1WrTAso0+Cea7/hx2gKw1eCddBghdWE3IwmmnaIcp1hR8hpwYaDkH/lJB6OoQI 092KYRZxOf3MaLa8XA5xEbXKn02DxZlZtWMzRxue/2YTzI4UCjwzzQkM9FK7S3AKnCnDU J0AARvX27l7V5/spHtV5wgc0VZz5sHwcxyKT83SeJTVtabYiK7qAKxwO9ssRvW4/lvg== 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.200 Received: from mail-dy1-f200.google.com (mail-dy1-f200.google.com [74.125.82.200]) (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 CA8DA606A33A for ; Tue, 1 Dec 2026 23:21:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CA8DA606A33A 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-f200.google.com with SMTP id 5a478bee46e88-386df943355so4124206eec.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=njofM66mXq9rclXEJ+AIFMBq4qYppKq+SDnfxh2SmAukl2Ub7L1qiPGpUz7cGRvPQE okPTAKR3YcPt71byhy3d3NdBmEwP47OTCQ5AN48wkHpOTu8GXD/JzD5eN5DBVuTTq3/F 8Afl3joxZljaE2PtHAZxkZKpFAY8V0msjMRP+tfJ+36gQqkFw8g3j4R+nxZl1nSGCNkb bghlTO9iNUsht4VOZpZqH85g7JtrtZ+iUu+p8B3krfvSQIlVxHo0SRN2511DzOUHUCD6 ftR4dha3mBOn6KmliuG2vyxs8WBav0icc7NsoONqcwA/OAJd8kMWV8uRQjKNDFTpZsD4 9BSQ== X-Forwarded-Encrypted: i=1; AL+hErGXbKKq5EyicqlNVxQMeqMCKd5OFrGpY2qvokmLJtphnUqOdf2FU7ztoWyQH9OGpJzk4s0=@vger.kernel.org X-Gm-Message-State: APuU4Z+H83X6pZmhbbABXUiPsz/yjvuec314L3wUuQKf+v9KfDri8BeX zntg+Tziq6ar/SHtQaUazcGJIQtJFeDh72DJnBj169J/tEMgkv0xVKWh2TylKrmxy6iBG5HAZEy 5fUu9egwfwQ== 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: bpf@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