All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>, linux-perf-users@vger.kernel.org
Subject: Re: [PATCH 4/6] perf synthetic-events: Use PROCMAP_QUERY to synthesize mmap events
Date: Fri, 04 Dec 2026 01:25:35 +0000	[thread overview]
Message-ID: <sashiko-outbox-248885@kernel.org> (raw)
In-Reply-To: <20261204010452.1937224-5-irogers@google.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] perf: PROCMAP_QUERY requests build IDs for non-regular device
  VMAs
- [Medium] perf: backwards addr on retry in
  synth_mmap2_state__procmap_query_pass()
- [Low] perf: synth_mmap2_state__procmap_query_pass() skips timeout
  check
--

commit b2c1ada3a9050c0e1eaf2b8ff80a88664c6a6487
Author: Ian Rogers <irogers@google.com>

perf synthetic-events: Use PROCMAP_QUERY to synthesize mmap events

This commit switches MMAP2 event synthesis to use the PROCMAP_QUERY ioctl
on /proc/<pid>/task/<pid>/maps when supported, keeping the text parser as
a fallback.  It also asks the kernel for build IDs on DSO cache misses to
avoid opening ELF files from userspace.

Link: https://lore.kernel.org/lkml/20261202124341.GA677025@noisy.programming.kicks-ass.net/

> diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c
> index 445199d7bbd46..3ad482f9115a9 100644
> --- a/tools/perf/util/synthetic-events.c
> +++ b/tools/perf/util/synthetic-events.c

[ ... ]

> +static int synth_mmap2_state__procmap_query_pass(struct synth_mmap2_state *state, int fd,
> +						 __u64 query_flags, bool skip_readable,
> +						 bool *first)
> +{
> +	union perf_event *event = state->event;
> +	char *name = event->mmap2.filename;
> +	const u32 name_size = sizeof(event->mmap2.filename) - state->machine->id_hdr_size;
> +	__u64 addr = 0;
> +
> +	while (true) {
> +		struct synth_mmap2_vma vma = { .bid = { .size = 0, }, };
> +		struct procmap_query q;
> +		bool want_name = !skip_readable;
> +		bool name_too_long = false;
> +		int ret;
> +retry:

[ ... ]

> +		if (skip_readable && (q.vma_flags & PROCMAP_QUERY_VMA_READABLE)) {
> +			addr = q.vma_end;
> +			continue;
> +		}

[Severity: Low]
Does skipping readable VMAs here bypass the --proc-map-timeout check?

The only check against state->timeout is inside
synth_mmap2_state__process_vma(), which this continue skips.  On a process
with many readable executable VMAs during data mmap synthesis, the second
pass can keep issuing PROCMAP_QUERY ioctls past the timeout without warning
or setting PERF_RECORD_MISC_PROC_MAP_PARSE_TIMEOUT.

> +		if (!want_name) {
> +			/* A wanted VMA, query it again to get its name. */
> +			want_name = true;
> +			addr = q.vma_start;
> +			goto retry;
> +		}

[Severity: Medium]
Can moving addr backwards to q.vma_start here trap perf in an infinite loop
when a target process concurrently modifies its VMAs?

PROCMAP_QUERY_COVERING_OR_NEXT_VMA returns a covering VMA even when
vma_start is below addr.  If an unprivileged target process alternates
mprotect() on the prefix [base, mid) of a contiguous region [base, end)
between PROT_READ|PROT_EXEC and PROT_EXEC while perf is in Pass 2:

perf (Pass 2, addr = mid)                 target process
ioctl(PROCMAP_QUERY, mid)
  -> covering VMA [base, end), --x
want_name = true
addr = q.vma_start (base)
goto retry
                                          mprotect([base, mid), r-x)
ioctl(PROCMAP_QUERY, base)
  -> VMA [base, mid), r-x
skip_readable matches:
  addr = q.vma_end (mid)
  continue (resets want_name = false)  <-- repeats forever
                                          mprotect([base, mid), --x)

Because neither goto retry nor the skip_readable continue checks
state->timeout, perf can spin indefinitely and bypass --proc-map-timeout
during system-wide data mmap recording.  Retrying at the original addr (or
ensuring addr never moves backwards) would preserve forward progress.

[ ... ]

> +		/*
> +		 * Get the build ID of wanted file backed VMAs. Other VMAs
> +		 * have no build ID, or are unwanted and skipped.
> +		 */
> +		if (!symbol_conf.no_buildid_mmap2 && q.inode && name[0] == '/' &&
> +		    ((vma.prot & PROT_EXEC) || (state->mmap_data && (vma.prot & PROT_READ))) &&
> +		    (!state->hugetlbfs_mnt_len ||
> +		     strncmp(name, state->hugetlbfs_mnt, state->hugetlbfs_mnt_len)))
> +			synth_mmap2_state__vma_build_id(state, fd, &q, name, &vma);

[Severity: Medium]
Can this request build IDs from the kernel for non-regular files such as
mapped character devices?

Previously, filename__read_build_id() checked is_regular_file() before
opening a mapped path, skipping device files.  With mmap_data enabled,
readable mappings like /dev/dri/renderD128 satisfy the check above, miss
the DSO build ID cache, and cause synth_mmap2_state__vma_build_id() to
issue PROCMAP_QUERY with build_id_size set.

In the kernel, do_procmap_query() passes vma->vm_file straight to
build_id_parse_file() -> __kernel_read(), triggering ratelimited "kernel
read not supported" warnings in dmesg for device files without read_iter
(or with both read and read_iter).  On 6.11-6.18 kernels lacking commit
777a8560fd29 ("lib/buildid: use __kernel_read() for sleepable context"),
querying build IDs on mapped device files without read_folio causes a
kernel NULL pointer dereference in filemap_read_folio().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204010452.1937224-1-irogers@google.com?part=4

  reply	other threads:[~2026-12-04  1:25 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  1:04 [PATCH 0/6] perf synthetic-events: Use PROCMAP_QUERY for mmap synthesis Ian Rogers
2026-12-04  1:04 ` [PATCH 1/6] perf machine: Fix leak when creating host kernel maps fails Ian Rogers
2026-12-04  1:04 ` [PATCH 2/6] perf synthetic-events: Fix race on DSO build IDs when synthesizing Ian Rogers
2026-12-04  1:04 ` [PATCH 3/6] perf bench synthesize: Initialize symbols so build IDs can be read Ian Rogers
2026-12-04  1:04 ` [PATCH 4/6] perf synthetic-events: Use PROCMAP_QUERY to synthesize mmap events Ian Rogers
2026-12-04  1:25   ` sashiko-bot [this message]
2026-12-04  1:04 ` [PATCH 5/6] perf bench synthesize: Add --procmap-query option Ian Rogers
2026-12-04  1:04 ` [PATCH 6/6] perf test: Add test comparing PROCMAP_QUERY and /proc/pid/maps synthesis Ian Rogers
2026-12-04  1:25 ` [PATCH 0/6] perf synthetic-events: Use PROCMAP_QUERY for mmap synthesis 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-248885@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=irogers@google.com \
    --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 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.