All of lore.kernel.org
 help / color / mirror / Atom feed
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 11/16] perf report, script: Add host_ip, host_dso, and host_sym fields
Date: Tue,  1 Dec 2026 15:21:11 -0800	[thread overview]
Message-ID: <20261201232116.1988791-12-irogers@google.com> (raw)
In-Reply-To: <20261201232116.1988791-1-irogers@google.com>

Store the resolved host_map, host_sym, host_addr, and raw_host_ip on
struct hist_entry and expose explicit host_ip, host_dso, and host_sym
sort keys in perf report as well as host_ip, host_sym, and host_dso
output fields in perf script.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/Documentation/perf-report.txt |   3 +
 tools/perf/Documentation/perf-script.txt |   4 +
 tools/perf/builtin-script.c              |  48 ++++++++++
 tools/perf/util/hist.c                   |  48 ++++++++++
 tools/perf/util/hist.h                   |   6 ++
 tools/perf/util/sort.c                   | 114 +++++++++++++++++++++++
 tools/perf/util/sort.h                   |   4 +
 7 files changed, 227 insertions(+)

diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
index e145124d6c9a..64466ccab9fd 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -156,6 +156,9 @@ OPTIONS
 	- p_stage_cyc: On powerpc, this presents the number of cycles spent in a
 	  pipeline stage. And currently supported only on powerpc.
 	- addr: (Full) virtual address of the sampled instruction
+	- host_ip: Host virtual address of the sampled instruction (recorded with --host-ip)
+	- host_dso: Host DSO mapped at host_ip
+	- host_sym / host_symbol: Host symbol resolved at host_ip
 	- retire_lat: On X86, this reports pipeline stall of this instruction compared
 	  to the previous instruction in cycles. And currently supported only on X86
 	- simd: Flags describing a SIMD operation. The architecture type can be Arm's
diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index f0228e784ced..ed66a6d23a68 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -169,6 +169,10 @@ OPTIONS
 	The cgroup fields requires sample having the cgroup id which is saved
 	when "--all-cgroups" option is passed to 'perf record'.
 
+	The host_ip, host_sym and host_dso fields display the host virtual IP
+	address, host symbol and host DSO resolved on the host machine when
+	recorded with 'perf record --host-ip'.
+
 	Finally, a user may not set fields to none for all event types.
 	i.e., -F "" is not allowed.
 
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index b6691ebb1b4e..f1f0e388d713 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -147,6 +147,9 @@ enum perf_output_field {
 	PERF_OUTPUT_DISASM          = 1ULL << 42,
 	PERF_OUTPUT_BRSTACKDISASM   = 1ULL << 43,
 	PERF_OUTPUT_BRCNTR          = 1ULL << 44,
+	PERF_OUTPUT_HOST_IP         = 1ULL << 45,
+	PERF_OUTPUT_HOST_SYM        = 1ULL << 46,
+	PERF_OUTPUT_HOST_DSO        = 1ULL << 47,
 };
 
 struct perf_script {
@@ -223,6 +226,9 @@ static struct output_option {
 	{.str = "retire_lat", .field = PERF_OUTPUT_RETIRE_LAT},
 	{.str = "brstackdisasm", .field = PERF_OUTPUT_BRSTACKDISASM},
 	{.str = "brcntr", .field = PERF_OUTPUT_BRCNTR},
+	{.str = "host_ip", .field = PERF_OUTPUT_HOST_IP},
+	{.str = "host_sym", .field = PERF_OUTPUT_HOST_SYM},
+	{.str = "host_dso", .field = PERF_OUTPUT_HOST_DSO},
 };
 
 enum {
@@ -595,6 +601,18 @@ static int evsel__check_attr(struct evsel *evsel, struct perf_session *session)
 	    evsel__check_stype(evsel, PERF_SAMPLE_WEIGHT_STRUCT, "WEIGHT_STRUCT", PERF_OUTPUT_RETIRE_LAT))
 		return -EINVAL;
 
+	if (PRINT_FIELD(HOST_IP) &&
+	    evsel__check_stype(evsel, PERF_SAMPLE_HOST_IP, "HOST_IP", PERF_OUTPUT_HOST_IP))
+		return -EINVAL;
+
+	if (PRINT_FIELD(HOST_SYM) &&
+	    evsel__check_stype(evsel, PERF_SAMPLE_HOST_IP, "HOST_IP", PERF_OUTPUT_HOST_SYM))
+		return -EINVAL;
+
+	if (PRINT_FIELD(HOST_DSO) &&
+	    evsel__check_stype(evsel, PERF_SAMPLE_HOST_IP, "HOST_IP", PERF_OUTPUT_HOST_DSO))
+		return -EINVAL;
+
 	return 0;
 }
 
@@ -2745,6 +2763,36 @@ static void process_event(struct perf_script *script,
 				    symbol_conf.bt_stop_list, fp);
 	}
 
+	if (PRINT_FIELD(HOST_IP) || PRINT_FIELD(HOST_SYM) || PRINT_FIELD(HOST_DSO)) {
+		struct perf_sample host_sample = *sample;
+		struct addr_location host_al;
+		unsigned int host_opts = 0;
+
+		if (PRINT_FIELD(HOST_IP))
+			host_opts |= EVSEL__PRINT_IP;
+		if (PRINT_FIELD(HOST_SYM))
+			host_opts |= EVSEL__PRINT_SYM;
+		if (PRINT_FIELD(HOST_DSO))
+			host_opts |= EVSEL__PRINT_DSO;
+		if (PRINT_FIELD(DSOFF))
+			host_opts |= EVSEL__PRINT_DSOFF;
+		if (PRINT_FIELD(SYMOFFSET))
+			host_opts |= EVSEL__PRINT_SYMOFFSET;
+		if (output[type].print_ip_opts & EVSEL__PRINT_UNKNOWN_AS_ADDR)
+			host_opts |= EVSEL__PRINT_UNKNOWN_AS_ADDR;
+
+		host_sample.ip = sample->host_ip;
+		addr_location__init(&host_al);
+		host_al.map = map__get(al->host_map);
+		host_al.sym = al->host_sym;
+		host_al.addr = al->host_map ? al->host_addr : sample->host_ip;
+
+		fputc(' ', fp);
+		sample__fprintf_sym(&host_sample, &host_al, 0, host_opts,
+				    NULL, NULL, fp);
+		addr_location__exit(&host_al);
+	}
+
 	if (PRINT_FIELD(IREGS)) {
 		perf_sample__fprintf_iregs(sample, attr,
 					   thread__e_machine(thread, machine, &e_flags),
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 364754e9d12a..50ecb65a354a 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -119,6 +119,24 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
 		hists__new_col_len(hists, HISTC_DSO, len);
 	}
 
+	if (h->host_ms.sym) {
+		symlen = h->host_ms.sym->namelen + 4;
+		if (verbose > 0)
+			symlen += BITS_PER_LONG / 4 + 2 + 3;
+		hists__new_col_len(hists, HISTC_HOST_SYMBOL, symlen);
+	} else {
+		symlen = unresolved_col_width + 4 + 2;
+		hists__new_col_len(hists, HISTC_HOST_SYMBOL, symlen);
+		hists__set_unres_dso_col_len(hists, HISTC_HOST_DSO);
+	}
+
+	if (h->host_ms.map) {
+		len = dso__name_len(map__dso(h->host_ms.map));
+		hists__new_col_len(hists, HISTC_HOST_DSO, len);
+	}
+
+	hists__new_col_len(hists, HISTC_HOST_IP, BITS_PER_LONG / 4 + 2);
+
 	if (h->parent)
 		hists__new_col_len(hists, HISTC_PARENT, h->parent->namelen);
 
@@ -543,6 +561,8 @@ static int hist_entry__init(struct hist_entry *he,
 
 	he->ms.thread = thread__get(he->ms.thread);
 	he->ms.map = map__get(he->ms.map);
+	he->host_ms.thread = thread__get(he->host_ms.thread);
+	he->host_ms.map = map__get(he->host_ms.map);
 
 	if (he->branch_info) {
 		/*
@@ -616,6 +636,7 @@ static int hist_entry__init(struct hist_entry *he,
 	if (he->mem_info)
 		mem_info__zput(he->mem_info);
 err:
+	map_symbol__exit(&he->host_ms);
 	map_symbol__exit(&he->ms);
 	zfree(&he->stat_acc);
 	return -ENOMEM;
@@ -734,6 +755,20 @@ static struct hist_entry *hists__findnew_entry(struct hists *hists,
 				map__put(he->ms.map);
 				he->ms.map = map__get(entry->ms.map);
 			}
+			if (hists__has(hists, host_sym) &&
+			    entry->host_ms.map &&
+			    he->host_ms.map != entry->host_ms.map) {
+				if (he->host_ms.sym) {
+					u64 addr = he->host_ms.sym->start;
+
+					he->host_ms.sym =
+						map__find_symbol(entry->host_ms.map, addr);
+				}
+
+				map__put(he->host_ms.map);
+				he->host_ms.map = map__get(entry->host_ms.map);
+				he->host_ip = entry->host_ip;
+			}
 			goto out;
 		}
 
@@ -819,11 +854,17 @@ __hists__add_entry(struct hists *hists,
 			.map	= al->map,
 			.sym	= al->sym,
 		},
+		.host_ms = {
+			.thread	= al->thread,
+			.map	= al->host_map,
+			.sym	= al->host_sym,
+		},
 		.srcline = (char *) al->srcline,
 		.socket	 = al->socket,
 		.cpu	 = al->cpu,
 		.cpumode = al->cpumode,
 		.ip	 = al->addr,
+		.host_ip = al->host_map ? al->host_addr : al->raw_host_ip,
 		.level	 = al->level,
 		.code_page_size = sample->code_page_size,
 		.parallelism	= al->parallelism,
@@ -1236,11 +1277,17 @@ iter_add_next_cumulative_entry(struct hist_entry_iter *iter,
 		.thread = al->thread,
 		.comm = thread__comm(al->thread),
 		.ip = al->addr,
+		.host_ip = al->host_map ? al->host_addr : al->raw_host_ip,
 		.ms = {
 			.thread = al->thread,
 			.map = al->map,
 			.sym = al->sym,
 		},
+		.host_ms = {
+			.thread = al->thread,
+			.map = al->host_map,
+			.sym = al->host_sym,
+		},
 		.srcline = (char *) al->srcline,
 		.parent = iter->parent,
 		.raw_data = sample->raw_data,
@@ -1467,6 +1514,7 @@ void hist_entry__delete(struct hist_entry *he)
 	}
 
 	thread__zput(he->thread);
+	map_symbol__exit(&he->host_ms);
 	map_symbol__exit(&he->ms);
 
 	if (he->branch_info) {
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index 0d08011aebce..263b349b9597 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -97,6 +97,9 @@ enum hist_column {
 	HISTC_CALLCHAIN_BRANCH_PREDICTED,
 	HISTC_CALLCHAIN_BRANCH_ABORT,
 	HISTC_CALLCHAIN_BRANCH_CYCLES,
+	HISTC_HOST_IP,
+	HISTC_HOST_DSO,
+	HISTC_HOST_SYMBOL,
 	HISTC_NR_COLS, /* Last entry */
 };
 
@@ -247,11 +250,13 @@ struct hist_entry {
 	struct he_stat		*stat_acc;
 	struct he_mem_stat	*mem_stat;
 	struct map_symbol	ms;
+	struct map_symbol	host_ms;
 	struct thread		*thread;
 	struct comm		*comm;
 	struct namespace_id	cgroup_id;
 	u64			cgroup;
 	u64			ip;
+	u64			host_ip;
 	u64			transaction;
 	u64			code_page_size;
 	u64			weight;
@@ -532,6 +537,7 @@ struct perf_hpp_list {
 	int need_collapse;
 	int parent;
 	int sym;
+	int host_sym;
 	int dso;
 	int socket;
 	int thread;
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index 58638ec9ae0e..229b836479c4 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -2476,6 +2476,111 @@ static struct sort_entry sort_addr = {
 	.se_width_idx	= HISTC_ADDR,
 };
 
+/* --sort host_ip */
+
+static int64_t
+sort__host_ip_cmp(struct hist_entry *left, struct hist_entry *right)
+{
+	u64 left_ip = left->host_ip;
+	u64 right_ip = right->host_ip;
+	struct map *left_map = left->host_ms.map;
+	struct map *right_map = right->host_ms.map;
+
+	if (left_map)
+		left_ip = map__unmap_ip(left_map, left_ip);
+	if (right_map)
+		right_ip = map__unmap_ip(right_map, right_ip);
+
+	return _sort__addr_cmp(left_ip, right_ip);
+}
+
+static int hist_entry__host_ip_snprintf(struct hist_entry *he, char *bf,
+					size_t size, unsigned int width)
+{
+	u64 ip = he->host_ip;
+	struct map *map = he->host_ms.map;
+
+	if (map)
+		ip = map__unmap_ip(map, ip);
+
+	return repsep_snprintf(bf, size, "%-#*llx", width, ip);
+}
+
+static struct sort_entry sort_host_ip = {
+	.se_header	= "Host IP",
+	.se_cmp		= sort__host_ip_cmp,
+	.se_snprintf	= hist_entry__host_ip_snprintf,
+	.se_width_idx	= HISTC_HOST_IP,
+};
+
+/* --sort host_dso */
+
+static int64_t
+sort__host_dso_cmp(struct hist_entry *left, struct hist_entry *right)
+{
+	return _sort__dso_cmp(right->host_ms.map, left->host_ms.map);
+}
+
+static int hist_entry__host_dso_snprintf(struct hist_entry *he, char *bf,
+					 size_t size, unsigned int width)
+{
+	return _hist_entry__dso_snprintf(he->host_ms.map, bf, size, width);
+}
+
+static struct sort_entry sort_host_dso = {
+	.se_header	= "Host Shared Object",
+	.se_cmp		= sort__host_dso_cmp,
+	.se_snprintf	= hist_entry__host_dso_snprintf,
+	.se_width_idx	= HISTC_HOST_DSO,
+};
+
+/* --sort host_sym */
+
+static int64_t
+sort__host_sym_cmp(struct hist_entry *left, struct hist_entry *right)
+{
+	int64_t ret;
+
+	if (!left->host_ms.sym && !right->host_ms.sym)
+		return sort__host_ip_cmp(left, right);
+
+	ret = sort__host_dso_cmp(left, right);
+	if (ret != 0)
+		return ret;
+
+	return _sort__sym_cmp(left->host_ms.sym, right->host_ms.sym);
+}
+
+static int64_t
+sort__host_sym_sort(struct hist_entry *left, struct hist_entry *right)
+{
+	if (!left->host_ms.sym || !right->host_ms.sym)
+		return cmp_null(left->host_ms.sym, right->host_ms.sym);
+
+	return strcmp(right->host_ms.sym->name, left->host_ms.sym->name);
+}
+
+static int hist_entry__host_sym_snprintf(struct hist_entry *he, char *bf,
+					 size_t size, unsigned int width)
+{
+	struct dso *dso = he->host_ms.map ? map__dso(he->host_ms.map) : NULL;
+	char level = (dso && dso__kernel(dso)) ? 'k' : '.';
+	u64 ip = he->host_ip;
+
+	if (!he->host_ms.sym && he->host_ms.map)
+		ip = map__unmap_ip(he->host_ms.map, ip);
+
+	return _hist_entry__sym_snprintf(&he->host_ms, ip, level, bf, size, width);
+}
+
+static struct sort_entry sort_host_sym = {
+	.se_header	= "Host Symbol",
+	.se_cmp		= sort__host_sym_cmp,
+	.se_sort	= sort__host_sym_sort,
+	.se_snprintf	= hist_entry__host_sym_snprintf,
+	.se_width_idx	= HISTC_HOST_SYMBOL,
+};
+
 /* --sort type */
 
 struct annotated_data_type unknown_type = {
@@ -2757,6 +2862,10 @@ static struct sort_dimension common_sort_dimensions[] = {
 	DIM(SORT_SYM_OFFSET, "symoff", sort_sym_offset),
 	DIM(SORT_ANNOTATE_DATA_TYPE_CACHELINE, "typecln", sort_type_cacheline),
 	DIM(SORT_PARALLELISM, "parallelism", sort_parallelism),
+	DIM(SORT_HOST_IP, "host_ip", sort_host_ip),
+	DIM(SORT_HOST_DSO, "host_dso", sort_host_dso),
+	DIM(SORT_HOST_SYM, "host_sym", sort_host_sym),
+	DIM(SORT_HOST_SYMBOL, "host_symbol", sort_host_sym),
 };
 
 #undef DIM
@@ -3712,6 +3821,10 @@ static int __sort_dimension__update(struct sort_dimension *sd,
 
 	} else if (sd->entry == &sort_sym_offset) {
 		list->sym = 1;
+	} else if (sd->entry == &sort_host_sym) {
+		list->host_sym = 1;
+		if (sort__mode == SORT_MODE__DIFF)
+			sd->entry->se_collapse = sort__host_sym_sort;
 	} else if (sd->entry == &sort_dso) {
 		list->dso = 1;
 	} else if (sd->entry == &sort_socket) {
@@ -4453,6 +4566,7 @@ void reset_output_field(void)
 	perf_hpp_list.need_collapse = 0;
 	perf_hpp_list.parent = 0;
 	perf_hpp_list.sym = 0;
+	perf_hpp_list.host_sym = 0;
 	perf_hpp_list.dso = 0;
 
 	field_order = NULL;
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index c962e77e4b93..db6f541a82a2 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h
@@ -76,6 +76,10 @@ enum sort_type {
 	SORT_ANNOTATE_DATA_TYPE_CACHELINE,
 	SORT_PARALLELISM,
 	SORT_TGID,
+	SORT_HOST_IP,
+	SORT_HOST_DSO,
+	SORT_HOST_SYM,
+	SORT_HOST_SYMBOL,
 
 	/* branch stack specific sort keys */
 	__SORT_BRANCH_STACK,
-- 
2.56.1.915.g69d5ec7298-goog


  parent reply	other threads:[~2026-12-01 23:21 UTC|newest]

Thread overview: 25+ 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-02  8:29   ` Christian Borntraeger
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 ` Ian Rogers [this message]
2026-12-01 23:41   ` [RFC PATCH 11/16] perf report, script: Add host_ip, host_dso, and host_sym fields 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-12-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.