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=1796167309; b=hs2Oo+vUwW6D66d83uGLW6cEXCzZPfd4RBTojESsds+f0W+QbLEZvgQlaGMdnZSGLoPj vsp8bemBpQYUUwIFII/sIuyEyha0tzJ5/I6+LoPwwNEJKF+iuPOTZe/QnvJhnt+86Zzxc x8a6C86nDtepTT49WrnnY3198LlLoNp0UkkdRVTzQk9kwMnpZq9wR6NUEezysusjSS4Ww s5ev0M8LPE4w8VfiHTH4A4Godz0H9vZGnph/pzFYFJHRVoXEZGdeRunLEa5k4F71VCtId ONLWEnpjVJ4qi659w8kZx5NwRgoyM8irD5Lk62ndKDxRU3k0Qgwv+wPiAzlPFgV3dOg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796167309; 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=cVA6L0IWzwc1A4cmR2XO2kpLPOmtpqE/6dgVK9ypfx4=; b=E+Yb3KNFyzBTVrRcU3unNk53+DDa1QwJR1TAZnU/LNg1QvwNJOKWucPGSd1bWg1LSez/ /tIVLHu/KV9NYb+jgR1/XgrGmcHvopVqxqgAHQWZcvFmhcBXRQqiOvJ32vV0UVqAqo8ya NkX6/yAPLBKj52GB8aEuNo1OoXIO83NC1OisbcK77h55V7E+xYRdP2QThSkTR+cUikQ2R bLwTws2e9DHgTZlRc+a2GgduUcEyTW+0zy1Mgm8rpVfXOBwXD1Tu8/FtmbzHwMU0vGE/G eoWtNol0qou8ZjCbq66IsY+n9lhw+6gV1WRKW+yu4QRuF6P7f5Pazbn0IZYTR0+nEWA== 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=XpqXeDib; 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 BB5E660A5BCE for ; Tue, 1 Dec 2026 23:21:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BB5E660A5BCE 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=XpqXeDib Received: by mail-dy1-f197.google.com with SMTP id 5a478bee46e88-341eff9e381so18069063eec.1 for ; Tue, 01 Dec 2026 15:21:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796167308; x=1796772108; 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=cVA6L0IWzwc1A4cmR2XO2kpLPOmtpqE/6dgVK9ypfx4=; b=XpqXeDib/6xC3gYr3nzYRFk/JXhPzqJ59A3jyVzNO/RyVXzO1i+8d0bBlEhIbUuZfC F2NSUxP9A/CjJgZ2M3Li8P6D6tlhVP5NBPipBd6lQiSwDMg6v5mAr3YQ1RoXkt9yZEEZ +fXAqhutWPbeuUAU2aHgWINegxakzDuj6NgehgwUQAKupwMQVJlZHr8R3nfKh+XYiRRZ SLYsyJA1XOTcPxzWqjF1PegNBwUhfvIbzSHkiy4/K5vQn6JBm4nYBBdGujdj+lKnmDpj l9nEcpkjPWMpIy5kaValIevI5IGwToXVMBafRGAnY7SXc5gXPQMn6gRo7tHNYkyK3N15 nOGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796167308; x=1796772108; 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=cVA6L0IWzwc1A4cmR2XO2kpLPOmtpqE/6dgVK9ypfx4=; b=qag8VBOeB9HdOxuYR+mUOF2WRphOVgY3B4pSTQ1XLYla7A0mvff2aYr1J6XgY0JaqO BgdbKrJFPwn577PTF3tf0Jda+1xxBJw784vhyWz9m6gVAZ6nOsT+Ci/88+pAgE4FWGVa qOKStqcJQTg23buqkPDmhvvNcOPFY+KodYTTkk6plpM/Mrq9NaKUjSgzA4qAouo+4wnM SbrU2fNkg+mM3xVq7N6jk6NZuEeVDmblNIKt7wtyRnQydGIx+5Os2mCanYK6gHOb/rx+ bGfvEAKZVn1WcPPipVX8+zKyaT4T4Hg02n25WyOisYaXqOIGdfIIa16pgQKNowD2DQ/m Z+jQ== X-Forwarded-Encrypted: i=1; AL+hErGmQfbYLuJowMWfqD79hk6/bk4ZOh+ySh6S+vS49VGMJ7Wf8EstUJUpQXR36q1o1X+H8qjIO2XHHcgPpXM=@vger.kernel.org X-Gm-Message-State: APuU4Z9ZcUUI9pHRBe9cn7c3LqtZ2S7Y2PBSsMlWbURLXEJa01YbDEUr iPgMb8tdlOy+z6ih2TfD7gQBWt6qNW/GhjTKFBvdyzWNkNiyfDvsX+PAkGBtVsJRWepDxxXuF/3 18HrWPssLMA== X-Received: from dyay19.prod.google.com ([2002:a05:693c:62d3:b0:386:9fbb:9f3e]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:2419:b0:367:185e:867a with SMTP id 5a478bee46e88-38571027a5dmr41107540eec.38.1796167307397; Tue, 01 Dec 2026 15:21:47 -0800 (PST) Date: Tue, 1 Dec 2026 15:21:09 -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-10-irogers@google.com> Subject: [RFC PATCH 09/16] perf tools: Add PERF_SAMPLE_HOST_IP parsing, synthesis, and record --host-ip 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 core userspace plumbing for PERF_SAMPLE_HOST_IP: - Add host_ip to struct perf_sample and wire __evsel__parse_sample(), perf_event__sample_event_size(), perf_event__synthesize_sample(), dump_sample(), and perf_event_attr__fprintf() (placing PERF_SAMPLE_HOST_IP right after PERF_SAMPLE_CODE_PAGE_SIZE and before PERF_SAMPLE_AUX). - Add --host-ip to perf record (and perf kvm record) to request PERF_SAMPLE_HOST_IP on non-dummy events, probe kernel support in evsel__detect_missing_features(), and report a helpful message in evsel__open_strerror(). - Mark host DSOs hit via sample->host_ip in build_id__mark_dso_hit() so perf record --host-ip caches their build-ids. - Update the sample-parsing test to cover PERF_SAMPLE_HOST_IP (standalone, combined with all sample bits, and truncated bounds checking). Signed-off-by: Ian Rogers --- tools/perf/Documentation/perf-record.txt | 7 ++++++ tools/perf/builtin-record.c | 2 ++ tools/perf/tests/sample-parsing.c | 7 +++++- tools/perf/util/build-id.c | 27 +++++++++++++++++++++++ tools/perf/util/evsel.c | 22 ++++++++++++++++++ tools/perf/util/evsel.h | 1 + tools/perf/util/perf_event_attr_fprintf.c | 3 ++- tools/perf/util/record.h | 1 + tools/perf/util/sample.h | 2 ++ tools/perf/util/session.c | 3 +++ tools/perf/util/synthetic-events.c | 8 +++++++ 11 files changed, 81 insertions(+), 2 deletions(-) diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt index 2351f7b4f5fc..fb3029f82a08 100644 --- a/tools/perf/Documentation/perf-record.txt +++ b/tools/perf/Documentation/perf-record.txt @@ -534,6 +534,13 @@ sets are allowed like -I. --running-time:: Record running and enabled time for read events (:S) +--host-ip:: +Record host virtual IP addresses alongside sampled instruction addresses +(PERF_SAMPLE_HOST_IP). When profiling virtual machines with direct-access (DAX) +or file-backed hypervisor mappings, this allows host mappings to symbolize guest +samples without requiring guest symbol information, and filters non-executable +hypervisor file mappings via BPF when supported. + -k:: --clockid:: Sets the clock id to use for the various time fields in the perf_event_type diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 085d3648a30a..4ff929191211 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -3546,6 +3546,8 @@ static struct option __record_options[] = { "Record the sampled data address data page size"), OPT_BOOLEAN(0, "code-page-size", &record.opts.sample_code_page_size, "Record the sampled code address (ip) page size"), + OPT_BOOLEAN(0, "host-ip", &record.opts.sample_host_ip, + "Record host virtual IP addresses for sampled instructions"), OPT_BOOLEAN(0, "sample-mem-info", &record.opts.sample_data_src, "Record the data source for memory operations"), OPT_BOOLEAN(0, "sample-cpu", &record.opts.sample_cpu, "Record the sample cpu"), diff --git a/tools/perf/tests/sample-parsing.c b/tools/perf/tests/sample-parsing.c index acbd353d3588..9c04eaba813d 100644 --- a/tools/perf/tests/sample-parsing.c +++ b/tools/perf/tests/sample-parsing.c @@ -209,6 +209,9 @@ static bool samples_same(struct perf_sample *s1, if (type & PERF_SAMPLE_CODE_PAGE_SIZE) COMP(code_page_size); + if (type & PERF_SAMPLE_HOST_IP) + COMP(host_ip); + if (type & PERF_SAMPLE_AUX) { COMP(aux_sample.size); if (memcmp(s1->aux_sample.data, s2->aux_sample.data, @@ -295,6 +298,7 @@ static int do_test(u64 sample_type, u64 sample_regs, u64 read_format) .size = sizeof(aux_data), .data = (void *)aux_data, }, + .host_ip = 119, }; struct sample_read_value values[] = {{1, 5, 0}, {9, 3, 0}, {2, 7, 0}, {6, 4, 1},}; struct sample_read_value packed_values[ARRAY_SIZE(values)]; @@ -554,6 +558,7 @@ static int test_truncated_u64_fields(void) PERF_SAMPLE_CGROUP, PERF_SAMPLE_DATA_PAGE_SIZE, PERF_SAMPLE_CODE_PAGE_SIZE, + PERF_SAMPLE_HOST_IP, }; for (size_t i = 0; i < ARRAY_SIZE(types); i++) { @@ -606,7 +611,7 @@ static int test__sample_parsing(struct test_suite *test __maybe_unused, int subt * were added. Please actually update the test rather than just change * the condition below. */ - if (PERF_SAMPLE_MAX > PERF_SAMPLE_WEIGHT_STRUCT << 1) { + if (PERF_SAMPLE_MAX > PERF_SAMPLE_HOST_IP << 1) { pr_debug("sample format has changed, some new PERF_SAMPLE_ bit was introduced - test needs updating\n"); return -1; } diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index 02233ef0eaff..cc5ce39ddacd 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -74,6 +74,33 @@ int build_id__mark_dso_hit(const struct perf_tool *tool __maybe_unused, addr_location__exit(&al); + 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; + + if (machine__kernel_ip(host_machine, sample->host_ip)) + host_maps = machine__kernel_maps(host_machine); + else if (host_thread) + host_maps = thread__maps(host_thread); + + if (host_maps) { + struct map *host_map = maps__find(host_maps, sample->host_ip); + + if (host_map) { + dso__set_hit(map__dso(host_map)); + map__put(host_map); + } + } + thread__put(host_thread); + } + } + sample__for_each_callchain_node(thread, sample, PERF_MAX_STACK_DEPTH, /*symbols=*/false, mark_dso_hit_callback, /*data=*/NULL); diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 90269b8d1745..5950a383eff4 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1769,6 +1769,9 @@ void evsel__config(struct evsel *evsel, const struct record_opts *opts, if (opts->sample_code_page_size) evsel__set_sample_bit(evsel, CODE_PAGE_SIZE); + if (opts->sample_host_ip && !evsel__is_dummy_event(evsel)) + evsel__set_sample_bit(evsel, HOST_IP); + if (opts->record_switch_events) attr->context_switch = track; @@ -2825,6 +2828,13 @@ static bool evsel__detect_missing_features(struct evsel *evsel, struct perf_cpu /* Please add new feature detection here. */ + attr.sample_type = PERF_SAMPLE_HOST_IP; + if (has_attr_feature(&attr, /*flags=*/0)) + goto found; + perf_missing_features.host_ip = true; + pr_debug2_peo("Kernel has no PERF_SAMPLE_HOST_IP support\n"); + attr.sample_type = 0; + attr.defer_callchain = true; if (has_attr_feature(&attr, /*flags=*/0)) goto found; @@ -3898,6 +3908,13 @@ int __evsel__parse_sample(struct evsel *evsel, union perf_event *event, array++; } + data->host_ip = 0; + if (type & PERF_SAMPLE_HOST_IP) { + OVERFLOW_CHECK_u64(array); + data->host_ip = *array; + array++; + } + if (type & PERF_SAMPLE_AUX) { OVERFLOW_CHECK_u64(array); sz = *array++; @@ -4677,6 +4694,11 @@ int evsel__open_strerror(struct evsel *evsel, struct target *target, size - printed); break; case EINVAL: + if ((evsel->core.attr.sample_type & PERF_SAMPLE_HOST_IP) && + perf_missing_features.host_ip) { + return scnprintf(msg, size, + "Asking for the host IP isn't supported by this kernel."); + } if (evsel->core.attr.sample_type & PERF_SAMPLE_CODE_PAGE_SIZE && perf_missing_features.code_page_size) return scnprintf(msg, size, "Asking for the code page size isn't supported by this kernel."); if (evsel->core.attr.sample_type & PERF_SAMPLE_DATA_PAGE_SIZE && perf_missing_features.data_page_size) diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 53f3641b66e1..ce38cea0f729 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -236,6 +236,7 @@ struct perf_missing_features { bool aux_action; bool inherit_sample_read; bool defer_callchain; + bool host_ip; }; extern struct perf_missing_features perf_missing_features; diff --git a/tools/perf/util/perf_event_attr_fprintf.c b/tools/perf/util/perf_event_attr_fprintf.c index 2e8be9a357dc..492dcc04bd99 100644 --- a/tools/perf/util/perf_event_attr_fprintf.c +++ b/tools/perf/util/perf_event_attr_fprintf.c @@ -40,7 +40,7 @@ static void __p_sample_type(char *buf, size_t size, u64 value) bit_name(IDENTIFIER), bit_name(REGS_INTR), bit_name(DATA_SRC), bit_name(WEIGHT), bit_name(PHYS_ADDR), bit_name(AUX), bit_name(CGROUP), bit_name(DATA_PAGE_SIZE), bit_name(CODE_PAGE_SIZE), - bit_name(WEIGHT_STRUCT), + bit_name(WEIGHT_STRUCT), bit_name(HOST_IP), { .name = NULL, } }; #undef bit_name @@ -384,6 +384,7 @@ int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr, PRINT_ATTRf_bf(sigtrap, p_unsigned); PRINT_ATTRf_bf(defer_callchain, p_unsigned); PRINT_ATTRf_bf(defer_output, p_unsigned); + PRINT_ATTRf_bf(mmap_bpf, p_unsigned); } PRINT_ATTRn("{ wakeup_events, wakeup_watermark }", wakeup_events, p_unsigned, false); diff --git a/tools/perf/util/record.h b/tools/perf/util/record.h index 411bb7276ad7..99f20019dbf8 100644 --- a/tools/perf/util/record.h +++ b/tools/perf/util/record.h @@ -23,6 +23,7 @@ struct record_opts { bool sample_phys_addr; bool sample_data_page_size; bool sample_code_page_size; + bool sample_host_ip; bool sample_weight; bool sample_time; bool sample_time_set; diff --git a/tools/perf/util/sample.h b/tools/perf/util/sample.h index cb4b16654876..c27f21db45e1 100644 --- a/tools/perf/util/sample.h +++ b/tools/perf/util/sample.h @@ -163,6 +163,8 @@ struct perf_sample { u64 code_page_size; /** @cgroup: The sample event PERF_SAMPLE_CGROUP value. */ u64 cgroup; + /** @host_ip: The sample event PERF_SAMPLE_HOST_IP value. */ + u64 host_ip; /** @file_offset: Byte offset of this event in the perf.data file. */ u64 file_offset; /** @flags: Extra flag data from auxiliary events like intel-pt. */ diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 56a5e57ec512..f143ffbd7f8b 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1734,6 +1734,9 @@ static void dump_sample(struct machine *machine, union perf_event *event, if (sample_type & PERF_SAMPLE_CODE_PAGE_SIZE) printf(" .. code page size: %s\n", get_page_size_name(sample->code_page_size, str)); + if (sample_type & PERF_SAMPLE_HOST_IP) + printf(" .. host_ip: %#" PRIx64 "\n", sample->host_ip); + if (sample_type & PERF_SAMPLE_TRANSACTION) printf("... transaction: %" PRIx64 "\n", sample->transaction); diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c index b9dbd105cdc3..92e9b086b1b3 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -1704,6 +1704,9 @@ size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type, if (type & PERF_SAMPLE_CODE_PAGE_SIZE) result += sizeof(u64); + if (type & PERF_SAMPLE_HOST_IP) + result += sizeof(u64); + if (type & PERF_SAMPLE_AUX) { result += sizeof(u64); result += sample->aux_sample.size; @@ -1958,6 +1961,11 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type, u64 read_fo array++; } + if (type & PERF_SAMPLE_HOST_IP) { + *array = sample->host_ip; + array++; + } + if (type & PERF_SAMPLE_AUX) { sz = sample->aux_sample.size; *array++ = sz; -- 2.56.1.915.g69d5ec7298-goog