perf/core, perf/tools: Add PERF_SAMPLE_BUILD_ID_OFFSET support
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v3 Latest19 patches 0 repliesNew
- v28 patches 0 repliesSuperseded
- v1 RFC8 patches 4 repliesSuperseded
Changes in v3 from the cover letter
- 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.
Patches in v3 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/19 | perf/core: Protect per-CPU callchain buffer across bpf_overflow_handler()kernel/ | +7 | 0 replies | |
| 2/19 | perf/uapi: Factor perf_build_id out into its own top-level structinclude/ | +13 | 0 replies | |
| 3/19 | perf/uapi: Add BUILD_ID_OFFSET sample types to UAPIinclude/ | +54 | 0 replies | |
| 4/19 | bpf: Export stack_map_get_build_id_offset() for perf eventsinclude/ kernel/ | +16 | 0 replies | |
| 5/19 | perf/core: Implement BUILD_ID_OFFSET and CALLCHAIN_BUILD_ID_OFFSET sample typesarch/ arch/ include/ +3 more | +385 | 0 replies | |
| 6/19 | perf/core: Support deferred unwinding for BUILD_ID_OFFSET sample typeskernel/ | +164 | 0 replies | |
| 7/19 | perf inject: Set ordered_events and ordering_requires_timestamps for --aslrtools/ tools/ | +3 | 0 replies | |
| 8/19 | perf session: Avoid double byte-swapping re-parsed deferred samplestools/ tools/ tools/ +1 more | +47 | 0 replies | |
| 9/19 | perf inject: Fix PERF_SAMPLE_READ layout and bounds checks in aslr_tool__process_sample()tools/ | +20 | 0 replies | |
| 10/19 | tools headers UAPI: Sync linux/perf_event.h for struct perf_build_idtools/ tools/ tools/ +4 more | +54 | 0 replies | |
| 11/19 | tools headers UAPI: Sync linux/perf_event.h for BUILD_ID_OFFSETtools/ tools/ | +81 | 0 replies | |
| 12/19 | perf: Refactor thread map and symbol APIs to take perf_sampletools/ tools/ tools/ +20 more | +224 | 0 replies | |
| 13/19 | perf maps: Add dsos__find_by_build_id() and maps__find_by_build_id()tools/ tools/ tools/ +1 more | +149 | 0 replies | |
| 14/19 | perf evsel: Parse, synthesize, and dump BUILD_ID_OFFSET sample typestools/ tools/ tools/ +5 more | +444 | 0 replies | |
| 15/19 | perf symbol: Resolve symbols and callchains using build ID and offsettools/ tools/ tools/ +3 more | +317 | 0 replies | |
| 16/19 | perf inject: Add --sample-buildids to convert samples to build ID + offsettools/ tools/ tools/ +2 more | +970 | 0 replies | |
| 17/19 | perf record: Add --buildid-offset optiontools/ tools/ tools/ +2 more | +65 | 0 replies | |
| 18/19 | perf test: Add BUILD_ID_OFFSET C unit teststools/ tools/ tools/ +3 more | +170 | 0 replies | |
| 19/19 | perf test: Add inject --sample-buildids and record --buildid-offset shell teststools/ tools/ | +253 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v3 yet.
Cover letter [PATCH v3 00/19] perf/core, perf/tools: Add PERF_SAMPLE_BUILD_ID_OFFSET support
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/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
[3] https://lore.kernel.org/linux-perf-users/[email protected]/
[4] https://lore.kernel.org/lkml/[email protected]/
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
Signature · 1 line
2.56.1.703.gf848ed807c-goog