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>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
James Clark <james.clark@linaro.org>
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
Leo Yan <leo.yan@linux.dev>, Dmitry Vyukov <dvyukov@google.com>,
"Steinar H . Gunderson" <sesse@google.com>,
Stephen Brennan <stephen.s.brennan@oracle.com>,
Thomas Falcon <thomas.falcon@intel.com>,
linux-perf-users@vger.kernel.org, bpf@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v3 00/19] perf/core, perf/tools: Add PERF_SAMPLE_BUILD_ID_OFFSET support
Date: Sun, 15 Nov 2026 23:43:55 -0800 [thread overview]
Message-ID: <20261116074414.3174737-1-irogers@google.com> (raw)
This patch series introduces PERF_SAMPLE_BUILD_ID_OFFSET and
PERF_SAMPLE_CALLCHAIN_BUILD_ID_OFFSET to the perf_event UAPI and
implements full support across both the kernel and perf tools. It
builds on earlier work making build IDs the default and improving build
ID handling in perf [1].
Based on linux-next (next-20261113) merged with perf-tools-next
(b7ff10b9ddec), which combines the tip, bpf-next, and perf-tools-next
trees including the prerequisite deferred-output perf/core fixes [4]
and standalone perf tool fixes.
Background & Motivation:
In order for perf to translate virtual addresses of samples into
symbols a file and offset within the file are needed. During event
synthesis perf will create mmap events to facilitate the translation
of a virtual address to a file and offset by modelling the address
space of a process. By directly recording in a sample the Build ID of
a file and the offset within it, no synthesis is necessary. The Build
ID and offset as a pair are larger than a virtual address, so there is
a trade-off between synthesis cost and extra size for samples. These
changes facilitate Build ID and offset as a choice for perf samples so
the user can choose to use it when they believe it is advantageous.
In practice perf still needs to map a build ID to a file, so by
default this change keeps synthesis to allow this. It is expected a
user that knows their build IDs, say through debuginfod, will disable
this option with --synth=no.
For callchains (PERF_SAMPLE_CALLCHAIN_BUILD_ID_OFFSET and
PERF_RECORD_CALLCHAIN_DEFERRED with PERF_RECORD_MISC_MMAP_BUILD_ID),
unique build IDs are deduplicated into a compact variable-length table
(up to 254 unique build IDs per record) and referenced by a 1-based
index in the top byte alongside a 56-bit file offset for user frames,
while non-user callchain addresses and context markers are preserved
unmodified across architectures.
The kernel support uses the existing build ID and offset support used
by BPF stack traces (stack_map_get_build_id_offset()). When
attr.defer_callchain is enabled (the default for `perf record
--buildid-offset`), user-space build ID and offset resolution is
deferred to a task_work callback where page faults are permitted, with
resolved entries emitted via PERF_RECORD_CALLCHAIN_DEFERRED.
The Build ID and offset samples inherently don't leak ASLR
information. As with the ASLR remapping work in perf inject, support
is added to migrate virtual addresses to Build ID and offset (`perf
inject --sample-buildids`) for testing and conversion without kernel
support.
Series Organization:
- Patch 1: Pre-existing kernel perf/core fix for per-CPU callchain
buffer protection across bpf_overflow_handler().
- Patches 2-6: Kernel UAPI, BPF helper export, and perf/core synchronous
and deferred BUILD_ID_OFFSET / CALLCHAIN_BUILD_ID_OFFSET support.
- Patches 7-9: Pre-existing perf tool fixes uncovered during
development and review.
- Patches 10-19: Tool UAPI header sync, perf parsing/synthesis/symbol
resolution, `perf inject --sample-buildids`, `perf record
--buildid-offset`, man page updates, and C/shell test coverage.
v3:
- Rebased onto linux-next (next-20261113) + perf-tools-next, dropping
the prerequisite perf/core [4] and perf tool fixes that were merged
upstream, and addressed review feedback on v2 [3] as well as findings
from Sashiko AI review (with AI coding assistant help refactoring and
verifying fixes against kernel/perf builds, checkpatch.pl, and
`perf test`):
- Split larger kernel and tool patches into smaller logical commits
and separated pre-existing kernel and perf tool bug fixes into
standalone commits with Fixes: tags at the start of the kernel and
tool sections.
- Changed PERF_SAMPLE_CALLCHAIN_BUILD_ID_OFFSET and build-ID
PERF_RECORD_CALLCHAIN_DEFERRED to deduplicate build IDs into a
compact packed table + 8-bit index / 56-bit file offset array,
keeping non-user addresses lossless across all architectures.
- Preserved source-level API compatibility in libperf's
`struct perf_record_mmap2` union by retaining `build_id_size` and
`build_id[]` alongside `struct perf_build_id bid`.
- Fixed per-CPU callchain buffer protection across
bpf_overflow_handler(), deferred output build-ID accounting and
single-IP clamping, and deferred callchain u16 header.size clamping.
- Isolated user vs kernel DSO/map build-ID lookups, handled vDSO and
kcore names when synthesizing build IDs in `perf inject
--sample-buildids`, aligned sample payload walking with
__evsel__parse_sample(), and fixed cross-endian deferred sample
re-parsing and Python event copying.
- Documented `--sample-buildids` in perf-inject.txt and
`--buildid-offset` in perf-record.txt.
v2:
- Addressed review feedback from Namhyung Kim and Sashiko AI on v1 [2]:
- Extended the deferred callchain unwind infrastructure
(attr.defer_callchain / PERF_RECORD_CALLCHAIN_DEFERRED) to support
deferred user-space build ID and offset resolution in task_work
context where page faults are allowed, avoiding NMI-time page fault
limitations and per-CPU irq_work contention.
- Batched in-place user callchain resolution into a single
stack_map_get_build_id_offset() call and skipped kernel frames.
- Defined struct perf_build_id and struct perf_sample_build_id_offset
consistently across UAPI and libperf headers, with a fallback for
__DECLARE_FLEX_ARRAY.
- Added reference-counted tracking (nr_build_id_offset_events and
nr_callchain_build_id_offset_events) and clamped callchain frame
counts in perf_prepare_sample() and perf_callchain_deferred_output()
to prevent u16 header.size overflows.
- Added cross-endian byte-swapping support for
PERF_SAMPLE_BUILD_ID_OFFSET, PERF_SAMPLE_CALLCHAIN_BUILD_ID_OFFSET,
and PERF_RECORD_CALLCHAIN_DEFERRED.
- Fixed perf_record_mmap2 union field preservation when build ID
synthesis fails, callchain context marker tracking in perf inject,
and per-event callgraph configuration in `perf record
--buildid-offset`.
[1] https://lore.kernel.org/lkml/20250424061943.1321025-1-irogers@google.com/
[2] https://lore.kernel.org/lkml/20260807071818.718751-1-irogers@google.com/
[3] https://lore.kernel.org/linux-perf-users/20261002173848.3228217-1-irogers@google.com/
[4] https://lore.kernel.org/lkml/20261025215508.1237480-1-irogers@google.com/
Ian Rogers (19):
perf/core: Protect per-CPU callchain buffer across
bpf_overflow_handler()
perf/uapi: Factor perf_build_id out into its own top-level struct
perf/uapi: Add BUILD_ID_OFFSET sample types to UAPI
bpf: Export stack_map_get_build_id_offset() for perf events
perf/core: Implement BUILD_ID_OFFSET and CALLCHAIN_BUILD_ID_OFFSET
sample types
perf/core: Support deferred unwinding for BUILD_ID_OFFSET sample types
perf inject: Set ordered_events and ordering_requires_timestamps for
--aslr
perf session: Avoid double byte-swapping re-parsed deferred samples
perf inject: Fix PERF_SAMPLE_READ layout and bounds checks in
aslr_tool__process_sample()
tools headers UAPI: Sync linux/perf_event.h for struct perf_build_id
tools headers UAPI: Sync linux/perf_event.h for BUILD_ID_OFFSET
perf: Refactor thread map and symbol APIs to take perf_sample
perf maps: Add dsos__find_by_build_id() and maps__find_by_build_id()
perf evsel: Parse, synthesize, and dump BUILD_ID_OFFSET sample types
perf symbol: Resolve symbols and callchains using build ID and offset
perf inject: Add --sample-buildids to convert samples to build ID +
offset
perf record: Add --buildid-offset option
perf test: Add BUILD_ID_OFFSET C unit tests
perf test: Add inject --sample-buildids and record --buildid-offset
shell tests
arch/powerpc/perf/core-book3s.c | 10 +-
arch/s390/kernel/perf_cpum_sf.c | 7 +-
include/linux/bpf.h | 14 +
include/linux/perf_event.h | 43 +-
include/uapi/linux/perf_event.h | 72 +-
kernel/bpf/stackmap.c | 10 +-
kernel/events/callchain.c | 206 +++-
kernel/events/core.c | 310 +++++-
tools/include/uapi/linux/perf_event.h | 72 +-
tools/lib/perf/include/perf/event.h | 43 +-
tools/perf/Documentation/perf-inject.txt | 8 +
tools/perf/Documentation/perf-record.txt | 6 +
.../arch/powerpc/util/skip-callchain-idx.c | 4 +-
tools/perf/builtin-inject.c | 80 +-
tools/perf/builtin-record.c | 22 +-
tools/perf/builtin-report.c | 6 +-
tools/perf/builtin-script.c | 75 +-
tools/perf/builtin-timechart.c | 5 +-
tools/perf/builtin-trace.c | 10 +-
tools/perf/tests/Build | 1 +
tools/perf/tests/bid-offset.c | 61 ++
tools/perf/tests/builtin-test.c | 1 +
tools/perf/tests/code-reading.c | 6 +-
tools/perf/tests/mmap-thread-lookup.c | 58 +-
tools/perf/tests/sample-parsing.c | 60 +-
tools/perf/tests/shell/inject_bid_offset.sh | 179 ++++
tools/perf/tests/shell/record.sh | 74 ++
tools/perf/tests/tests.h | 1 +
tools/perf/util/Build | 1 +
tools/perf/util/annotate-data.c | 5 +-
tools/perf/util/aslr.c | 142 ++-
tools/perf/util/build-id.c | 2 +-
tools/perf/util/callchain.c | 153 ++-
tools/perf/util/capstone.c | 4 +-
tools/perf/util/cs-etm.c | 10 +-
tools/perf/util/data-convert-json.c | 4 +-
tools/perf/util/debug.c | 6 +-
tools/perf/util/dlfilter.c | 8 +-
tools/perf/util/dsos.c | 68 ++
tools/perf/util/dsos.h | 6 +
tools/perf/util/event.c | 89 +-
tools/perf/util/evlist.c | 38 +-
tools/perf/util/evlist.h | 2 +
tools/perf/util/evsel.c | 180 +++-
tools/perf/util/evsel.h | 3 +-
tools/perf/util/evsel_fprintf.c | 9 +-
tools/perf/util/inject_bid_offset.c | 882 ++++++++++++++++++
tools/perf/util/inject_bid_offset.h | 15 +
tools/perf/util/intel-pt.c | 24 +-
tools/perf/util/machine.c | 194 +++-
tools/perf/util/maps.c | 73 ++
tools/perf/util/maps.h | 2 +
tools/perf/util/perf_event_attr_fprintf.c | 3 +-
tools/perf/util/python.c | 43 +-
tools/perf/util/record.c | 22 +
tools/perf/util/record.h | 1 +
tools/perf/util/sample.c | 84 ++
tools/perf/util/sample.h | 39 +
tools/perf/util/session.c | 140 ++-
tools/perf/util/synthetic-events.c | 77 +-
tools/perf/util/thread.c | 11 +-
tools/perf/util/thread.h | 14 +-
tools/perf/util/unwind-libdw.c | 7 +-
tools/perf/util/unwind-libunwind.c | 8 +-
64 files changed, 3433 insertions(+), 380 deletions(-)
create mode 100644 tools/perf/tests/bid-offset.c
create mode 100755 tools/perf/tests/shell/inject_bid_offset.sh
create mode 100644 tools/perf/util/inject_bid_offset.c
create mode 100644 tools/perf/util/inject_bid_offset.h
--
2.56.1.703.gf848ed807c-goog
next reply other threads:[~2026-11-16 7:45 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 7:43 Ian Rogers [this message]
2026-11-16 7:43 ` [PATCH v3 01/19] perf/core: Protect per-CPU callchain buffer across bpf_overflow_handler() Ian Rogers
2026-11-16 7:43 ` [PATCH v3 02/19] perf/uapi: Factor perf_build_id out into its own top-level struct Ian Rogers
2026-11-16 7:43 ` [PATCH v3 03/19] perf/uapi: Add BUILD_ID_OFFSET sample types to UAPI Ian Rogers
2026-11-16 7:43 ` [PATCH v3 04/19] bpf: Export stack_map_get_build_id_offset() for perf events Ian Rogers
2026-11-16 7:44 ` [PATCH v3 05/19] perf/core: Implement BUILD_ID_OFFSET and CALLCHAIN_BUILD_ID_OFFSET sample types Ian Rogers
2026-11-16 7:44 ` [PATCH v3 06/19] perf/core: Support deferred unwinding for BUILD_ID_OFFSET " Ian Rogers
2026-11-16 7:44 ` [PATCH v3 07/19] perf inject: Set ordered_events and ordering_requires_timestamps for --aslr Ian Rogers
2026-11-16 7:44 ` [PATCH v3 08/19] perf session: Avoid double byte-swapping re-parsed deferred samples Ian Rogers
2026-11-16 7:44 ` [PATCH v3 09/19] perf inject: Fix PERF_SAMPLE_READ layout and bounds checks in aslr_tool__process_sample() Ian Rogers
2026-11-16 7:44 ` [PATCH v3 10/19] tools headers UAPI: Sync linux/perf_event.h for struct perf_build_id Ian Rogers
2026-11-16 7:44 ` [PATCH v3 11/19] tools headers UAPI: Sync linux/perf_event.h for BUILD_ID_OFFSET Ian Rogers
2026-11-16 7:44 ` [PATCH v3 12/19] perf: Refactor thread map and symbol APIs to take perf_sample Ian Rogers
2026-11-16 7:44 ` [PATCH v3 13/19] perf maps: Add dsos__find_by_build_id() and maps__find_by_build_id() Ian Rogers
2026-11-16 7:44 ` [PATCH v3 14/19] perf evsel: Parse, synthesize, and dump BUILD_ID_OFFSET sample types Ian Rogers
2026-11-16 7:44 ` [PATCH v3 15/19] perf symbol: Resolve symbols and callchains using build ID and offset Ian Rogers
2026-11-16 7:44 ` [PATCH v3 16/19] perf inject: Add --sample-buildids to convert samples to build ID + offset Ian Rogers
2026-11-16 7:44 ` [PATCH v3 17/19] perf record: Add --buildid-offset option Ian Rogers
2026-11-16 7:44 ` [PATCH v3 18/19] perf test: Add BUILD_ID_OFFSET C unit tests Ian Rogers
2026-11-16 7:44 ` [PATCH v3 19/19] perf test: Add inject --sample-buildids and record --buildid-offset shell tests Ian Rogers
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=20261116074414.3174737-1-irogers@google.com \
--to=irogers@google.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=dvyukov@google.com \
--cc=eddyz87@gmail.com \
--cc=ihor.solodrai@linux.dev \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=leo.yan@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=martin.lau@linux.dev \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=sesse@google.com \
--cc=song@kernel.org \
--cc=stephen.s.brennan@oracle.com \
--cc=thomas.falcon@intel.com \
--cc=yonghong.song@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
all inboxes | Powered by JetHome®