All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ian Rogers" <irogers@google.com>
Cc: linux-perf-users@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH v4 16/19] perf inject: Add --sample-buildids to convert samples to build ID + offset
Date: Wed, 25 Nov 2026 01:18:14 +0000	[thread overview]
Message-ID: <sashiko-outbox-232322@kernel.org> (raw)
In-Reply-To: <20261125005108.1020003-17-irogers@google.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] perf inject: repeated dso__read_build_id() calls on DSOs
  without build ID
- [Medium] perf inject: redundant O(K*M) build-ID map scans in
  inject_bid_offset_tool__sample()
--

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

perf inject: Add --sample-buildids to convert samples to build ID + offset

This commit adds the --sample-buildids (-S) option to perf inject to drop
user-space MMAP events and rewrite sample IPs and callchains into build
IDs and file offsets.

> diff --git a/tools/perf/util/inject_bid_offset.c b/tools/perf/util/inject_bid_offset.c
> new file mode 100644
> index 0000000000000..c6f80f2a95321
> --- /dev/null
> +++ b/tools/perf/util/inject_bid_offset.c

[ ... ]

> +static void perf_event__inject_sample_buildid_array(struct thread *thread,
> +						    u64 ip, u8 cpumode,
> +						    __u64 *array)
> +{
> +	struct perf_build_id bid = { .size = 0 };
> +	u64 offset = ip;
> +	struct addr_location al;
> +	struct dso *dso;
> +	const struct build_id *dso_bid;
> +
> +	struct perf_sample ps = { .ip = ip, .cpumode = cpumode };
> +
> +	addr_location__init(&al);
> +
> +	if (!thread ||
> +	    (cpumode != PERF_RECORD_MISC_USER &&
> +	     cpumode != PERF_RECORD_MISC_GUEST_USER))
> +		goto write_bid;
> +
> +	if (!thread__find_map(thread, &ps, &al))
> +		goto write_bid;
> +
> +	dso = al.map ? dso__get(map__dso(al.map)) : NULL;
> +	if (!dso)
> +		goto write_bid;
> +	if (!dso__has_build_id(dso))
> +		dso__read_build_id(dso);
> +	dso_bid = dso__bid(dso);
> +	if (!dso_bid || dso_bid->size == 0 ||
> +	    map__mapping_type(al.map) != MAPPING_TYPE__DSO) {
> +		dso__put(dso);
> +		goto write_bid;
> +	}

[Severity: Medium]
Does calling dso__read_build_id() here cause repeated filesystem open()
and mount-namespace setns() syscalls on every sample IP and callchain
frame that hits a DSO without a build ID?

Both inject_bid_offset_tool__sample() and
inject_bid_offset_tool__callchain_deferred() already call mark_dso_hit()
first, which attempts dso__read_build_id() once per DSO tracked in
ibo->synthesized_dsos.  When a mapping has no build ID (such as an
anonymous mapping or a binary built without a build ID),
dso__has_build_id() stays false, so this check re-runs
dso__read_build_id() on every hit, even before checking
map__mapping_type(al.map) != MAPPING_TYPE__DSO.

[ ... ]

> +	ev->sample.header.size = (u16)(out - (u8 *)ev);
> +
> +	orig_sample_size = evsel->sample_size;
> +	if (perf_event__rewrite_attr_for_build_id_offset(&evsel->core.attr)) {
> +		ret = -EFAULT;
> +		goto out_put;
> +	}
> +	evsel->sample_size = __evsel__sample_size(evsel->core.attr.sample_type);
> +	perf_sample__init(&new_sample, /*all=*/true);
> +	ret = __evsel__parse_sample(evsel, ev, &new_sample, /*needs_swap=*/false);
> +	if (!ret) {
> +		new_sample.evsel = evsel;
> +		ret = ibo->tool.delegate->sample(ibo->tool.delegate, ev,
> +						 &new_sample, machine);
> +	}

[Severity: Medium]
Does delegating the rewritten sample to perf_event__repipe_sample() trigger
redundant build-ID map scans via build_id__mark_dso_hit()?

mark_dso_hit() has already resolved the virtual addresses by binary search
and marked the hit DSOs.  Passing new_sample to perf_event__repipe_sample()
runs build_id__mark_dso_hit() on the converted BUILD_ID_OFFSET sample,
which resolves the sample IP and every callchain frame through
maps__find_by_build_id(), performing a linear scan across all thread
mappings for each frame just to mark the same DSOs hit again.

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

  reply	other threads:[~2026-11-25  1:18 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  0:50 [PATCH v4 00/19] perf/core, perf/tools: Add PERF_SAMPLE_BUILD_ID_OFFSET support Ian Rogers
2026-11-25  0:50 ` [PATCH v4 01/19] perf/core: Protect per-CPU callchain buffer across bpf_overflow_handler() Ian Rogers
2026-11-25  0:50 ` [PATCH v4 02/19] perf/uapi: Factor perf_build_id out into its own top-level struct Ian Rogers
2026-11-25 13:17   ` Peter Zijlstra
2026-11-30 19:34     ` Ian Rogers
2026-11-25  0:50 ` [PATCH v4 03/19] perf/uapi: Add BUILD_ID_OFFSET sample types to UAPI Ian Rogers
2026-11-25 13:25   ` Peter Zijlstra
2026-11-25 21:45     ` Namhyung Kim
2026-11-30 19:38       ` Ian Rogers
2026-12-01  8:14         ` Peter Zijlstra
2026-12-01 17:10           ` Ian Rogers
2026-12-01  8:10       ` Peter Zijlstra
2026-11-25  0:50 ` [PATCH v4 04/19] bpf: Export stack_map_get_build_id_offset() for perf events Ian Rogers
2026-11-25  0:50 ` [PATCH v4 05/19] perf/core: Implement BUILD_ID_OFFSET and CALLCHAIN_BUILD_ID_OFFSET sample types Ian Rogers
2026-11-25  1:19   ` sashiko-bot
2026-11-25  0:50 ` [PATCH v4 06/19] perf/core: Support deferred unwinding for BUILD_ID_OFFSET " Ian Rogers
2026-11-25  0:50 ` [PATCH v4 07/19] perf inject: Set ordered_events and ordering_requires_timestamps for --aslr Ian Rogers
2026-11-25  0:50 ` [PATCH v4 08/19] perf session: Avoid double byte-swapping re-parsed deferred samples Ian Rogers
2026-11-25  1:12   ` sashiko-bot
2026-11-25  0:50 ` [PATCH v4 09/19] perf inject: Fix PERF_SAMPLE_READ layout and bounds checks in aslr_tool__process_sample() Ian Rogers
2026-11-25  0:50 ` [PATCH v4 10/19] tools headers UAPI: Sync linux/perf_event.h for struct perf_build_id Ian Rogers
2026-11-25  0:51 ` [PATCH v4 11/19] tools headers UAPI: Sync linux/perf_event.h for BUILD_ID_OFFSET Ian Rogers
2026-11-25  0:51 ` [PATCH v4 12/19] perf: Refactor thread map and symbol APIs to take perf_sample Ian Rogers
2026-11-25  0:51 ` [PATCH v4 13/19] perf maps: Add dsos__find_by_build_id() and maps__find_by_build_id() Ian Rogers
2026-11-25  0:51 ` [PATCH v4 14/19] perf evsel: Parse, synthesize, and dump BUILD_ID_OFFSET sample types Ian Rogers
2026-11-25  0:51 ` [PATCH v4 15/19] perf symbol: Resolve symbols and callchains using build ID and offset Ian Rogers
2026-11-25  0:51 ` [PATCH v4 16/19] perf inject: Add --sample-buildids to convert samples to build ID + offset Ian Rogers
2026-11-25  1:18   ` sashiko-bot [this message]
2026-11-25  0:51 ` [PATCH v4 17/19] perf record: Add --buildid-offset option Ian Rogers
2026-11-25  1:19   ` sashiko-bot
2026-11-25  0:51 ` [PATCH v4 18/19] perf test: Add BUILD_ID_OFFSET C unit tests Ian Rogers
2026-11-25  0:51 ` [PATCH v4 19/19] perf test: Add inject --sample-buildids and record --buildid-offset shell tests Ian Rogers
2026-11-25  1:19 ` [PATCH v4 00/19] perf/core, perf/tools: Add PERF_SAMPLE_BUILD_ID_OFFSET support 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-232322@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.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.