From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>
Cc: linux-perf-users@vger.kernel.org, kvm@vger.kernel.org,
bpf@vger.kernel.org
Subject: Re: [RFC PATCH 11/16] perf report, script: Add host_ip, host_dso, and host_sym fields
Date: Tue, 01 Dec 2026 23:41:26 +0000 [thread overview]
Message-ID: <sashiko-outbox-244428@kernel.org> (raw)
In-Reply-To: <20261201232116.1988791-12-irogers@google.com>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] perf sort: double unmapping of host_ip in
hist_entry__host_sym_snprintf()
- [Medium] perf sort: strict weak ordering violation in
sort__host_sym_cmp()
- [Low] perf script: symoff and dsoff validation ignores host_sym and
host_dso
- [Low] perf hist: missing verbose width for unresolved
HISTC_HOST_SYMBOL
--
commit 976f06507181de924b5188635a7f011b6d5746e0
Author: Ian Rogers <irogers@google.com>
perf report, script: Add host_ip, host_dso, and host_sym fields
This commit records resolved host map, symbol, and address fields on
struct hist_entry and adds host_ip, host_dso, and host_sym sort keys and
output fields to perf report and perf script.
> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
> index b6691ebb1b4ef..f1f0e388d713e 100644
> --- a/tools/perf/builtin-script.c
> +++ b/tools/perf/builtin-script.c
[ ... ]
> @@ -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;
[Severity: Low]
Should evsel__check_attr() and perf_session__check_output_opt() also account
for HOST_SYM and HOST_DSO when validating SYMOFFSET and DSOFF?
evsel__check_attr() rejects PRINT_FIELD(SYMOFFSET) when !PRINT_FIELD(SYM), so
running perf script with -F -sym,+host_sym or -F host_sym,symoff fails with
-EINVAL. Likewise, perf_session__check_output_opt() unconditionally sets
PERF_OUTPUT_DSO whenever PERF_OUTPUT_DSOFF is requested, even if only
host_dso was selected.
> diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
> index 364754e9d12aa..50ecb65a354ad 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);
> + }
[Severity: Low]
Does the unresolved branch here and hists__sort_list_width() in
tools/perf/ui/hist.c miss the verbose address-and-origin prefix width for
HISTC_HOST_SYMBOL?
_hist_entry__sym_snprintf() prints the verbose prefix even when ms->sym is
NULL, and hists__sort_list_width() only checks hists__has(hists, sym) before
adding 3 + BITS_PER_LONG / 4. When running perf report -v sorted by
host_sym without sym, unresolved host symbols can overflow the calculated
column width and truncate the output line in hists__fprintf().
> diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
> index 58638ec9ae0ed..229b836479c45 100644
> --- a/tools/perf/util/sort.c
> +++ b/tools/perf/util/sort.c
[ ... ]
> +/* --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);
> +}
[Severity: Medium]
Does comparing sort__host_ip_cmp() before sort__host_dso_cmp() when both
symbols are NULL break comparator transitivity for the hists RB-tree?
When one entry has a symbol and the other does not, sort__host_sym_cmp()
orders them by host DSO first, whereas two unresolved entries are ordered by
unmapped host_ip across different DSOs. Three entries across DSOs liba.so
(sym == NULL, host_ip = 0x3000), libb.so (sym != NULL), and libc.so
(sym == NULL, host_ip = 0x1000) can then form a cycle A > B > C > A,
corrupting RB-tree lookups under --sort host_sym. In addition, if two
unresolved entries with different host_ms.map pointers share the same
unmapped host_ip, sort__host_sym_cmp() returns 0 and hists__findnew_entry()
overwrites he->host_ms.map in place without rebalancing the RB-tree.
> +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);
> +}
[Severity: Medium]
Doesn't calling map__unmap_ip() here cause _hist_entry__sym_snprintf() to
unmap ip a second time in verbose mode?
tools/perf/util/sort.c:_hist_entry__sym_snprintf() {
...
if (verbose > 0) {
struct dso *dso = map ? map__dso(map) : NULL;
char o = map ? dso__symtab_origin(dso) : '!';
u64 rip = ip;
if (dso && dso__kernel(dso) && dso__adjust_symbols(dso))
rip = map__unmap_ip(map, ip);
...
}
Because he->host_ip already holds al->host_addr when he->host_ms.map is
present (matching how he->ip holds al->addr in hist_entry__sym_snprintf()),
pre-unmapping ip when !he->host_ms.sym && he->host_ms.map causes adjusted
kernel and module DSOs to be unmapped twice under perf report -v, printing a
bogus address.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201232116.1988791-1-irogers@google.com?part=11
next prev parent reply other threads:[~2026-12-01 23:41 UTC|newest]
Thread overview: 23+ 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-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 [this message]
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
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=sashiko-outbox-244428@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=irogers@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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