From: Ian Rogers <irogers@google.com>
To: irogers@google.com, acme@kernel.org, adrian.hunter@intel.com,
mingo@redhat.com, namhyung@kernel.org, peterz@infradead.org
Cc: ak@linux.intel.com, alexander.shishkin@linux.intel.com,
atrajeev@linux.ibm.com, dvyukov@google.com, fzczx123@gmail.com,
james.clark@linaro.org, jolsa@kernel.org, kjain@linux.ibm.com,
krzysztof.m.lopatowski@gmail.com, leo.yan@arm.com,
lihuafei1@huawei.com, linux-kernel@vger.kernel.org,
linux-perf-users@vger.kernel.org, linux@treblig.org,
m.liska@foxlink.cz, mark.rutland@arm.com, martin.liska@hey.com,
mpetlan@redhat.com, quic_zhonhan@quicinc.com,
scclevenger@os.amperecomputing.com, sesse@google.com,
stephen.s.brennan@oracle.com, thomas.falcon@intel.com,
yangyicong@hisilicon.com
Subject: [PATCH v2 0/8] perf/core, perf/tools: Add PERF_SAMPLE_BUILD_ID_OFFSET support
Date: Fri, 2 Oct 2026 10:38:33 -0700 [thread overview]
Message-ID: <20261002173848.3228217-1-irogers@google.com> (raw)
In-Reply-To: <20250424061943.1321025-1-irogers@google.com>
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].
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 much 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.
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.
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/
Ian Rogers (8):
perf event: Factor build_id out into its own top-level struct
perf/core: Add BUILD_ID_OFFSET to UAPI
perf/core: Implement BUILD_ID_OFFSET sample type
perf: Refactor thread map and symbol APIs to take perf_sample
perf tools: Internal support for BUILD_ID_OFFSET
perf inject: Extend perf inject to support bid_offset conversion
perf record: Add --buildid-offset option
perf tests: Add build_id_offset test coverage
include/linux/bpf.h | 14 +
include/linux/perf_event.h | 1 +
include/uapi/linux/perf_event.h | 53 +-
kernel/bpf/stackmap.c | 4 +-
kernel/events/core.c | 298 +++++++-
tools/include/uapi/linux/perf_event.h | 53 +-
tools/lib/perf/include/perf/event.h | 51 +-
.../arch/powerpc/util/skip-callchain-idx.c | 4 +-
tools/perf/builtin-inject.c | 75 +-
tools/perf/builtin-record.c | 2 +
tools/perf/builtin-report.c | 6 +-
tools/perf/builtin-script.c | 56 +-
tools/perf/builtin-timechart.c | 5 +-
tools/perf/builtin-trace.c | 10 +-
tools/perf/tests/Build | 1 +
tools/perf/tests/bid-offset.c | 60 ++
tools/perf/tests/builtin-test.c | 1 +
tools/perf/tests/code-reading.c | 4 +-
tools/perf/tests/mmap-thread-lookup.c | 51 +-
tools/perf/tests/sample-parsing.c | 68 +-
tools/perf/tests/shell/inject_bid_offset.sh | 175 +++++
tools/perf/tests/shell/record.sh | 69 ++
tools/perf/tests/tests.h | 1 +
tools/perf/util/Build | 1 +
tools/perf/util/annotate-data.c | 5 +-
tools/perf/util/aslr.c | 16 +-
tools/perf/util/build-id.c | 2 +-
tools/perf/util/callchain.c | 93 ++-
tools/perf/util/capstone.c | 4 +-
tools/perf/util/cs-etm.c | 4 +-
tools/perf/util/data-convert-json.c | 4 +-
tools/perf/util/debug.c | 4 +-
tools/perf/util/dlfilter.c | 8 +-
tools/perf/util/dsos.c | 27 +
tools/perf/util/dsos.h | 2 +
tools/perf/util/event.c | 88 ++-
tools/perf/util/evsel.c | 169 ++++-
tools/perf/util/evsel.h | 3 +-
tools/perf/util/evsel_fprintf.c | 9 +-
tools/perf/util/inject_bid_offset.c | 680 ++++++++++++++++++
tools/perf/util/inject_bid_offset.h | 15 +
tools/perf/util/intel-pt.c | 14 +-
tools/perf/util/machine.c | 140 +++-
tools/perf/util/maps.c | 59 ++
tools/perf/util/maps.h | 2 +
tools/perf/util/perf_event_attr_fprintf.c | 3 +-
tools/perf/util/python.c | 26 +-
tools/perf/util/record.h | 1 +
tools/perf/util/sample.c | 9 +
tools/perf/util/sample.h | 28 +
tools/perf/util/session.c | 86 ++-
tools/perf/util/synthetic-events.c | 64 +-
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 +-
56 files changed, 2418 insertions(+), 250 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.0.rc1.315.gc6ed9934b7-goog
next prev parent reply other threads:[~2026-10-02 17:39 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-24 6:19 [PATCH v1 0/5] perf: Default use of build IDs and improvements Ian Rogers
2025-04-24 6:19 ` [PATCH v1 1/5] perf build-id: Reduce size of "size" variable Ian Rogers
2025-04-24 6:19 ` [PATCH v1 2/5] perf build-id: Truncate to avoid overflowing the build_id data Ian Rogers
2025-04-24 6:19 ` [PATCH v1 3/5] perf build-id: Change sprintf functions to snprintf Ian Rogers
2025-04-24 6:19 ` [PATCH v1 4/5] perf dso: Move build_id to dso_id Ian Rogers
2025-04-24 6:19 ` [PATCH v1 5/5] perf record: Make --buildid-mmap the default Ian Rogers
2025-04-24 7:20 ` Ian Rogers
2025-04-25 14:45 ` Arnaldo Carvalho de Melo
2025-04-25 14:59 ` Arnaldo Carvalho de Melo
2025-04-25 16:03 ` Ian Rogers
2026-10-02 17:38 ` Ian Rogers [this message]
2026-10-02 17:38 ` [PATCH v2 1/8] perf event: Factor build_id out into its own top-level struct Ian Rogers
2026-10-02 17:38 ` [PATCH v2 2/8] perf/core: Add BUILD_ID_OFFSET to UAPI Ian Rogers
2026-10-02 17:38 ` [PATCH v2 3/8] perf/core: Implement BUILD_ID_OFFSET sample type Ian Rogers
2026-10-02 17:38 ` [PATCH v2 4/8] perf: Refactor thread map and symbol APIs to take perf_sample Ian Rogers
2026-10-02 17:38 ` [PATCH v2 5/8] perf tools: Internal support for BUILD_ID_OFFSET Ian Rogers
2026-10-02 17:38 ` [PATCH v2 6/8] perf inject: Extend perf inject to support bid_offset conversion Ian Rogers
2026-10-02 17:38 ` [PATCH v2 7/8] perf record: Add --buildid-offset option Ian Rogers
2026-10-02 17:38 ` [PATCH v2 8/8] perf tests: Add build_id_offset test coverage 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=20261002173848.3228217-1-irogers@google.com \
--to=irogers@google.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=ak@linux.intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=atrajeev@linux.ibm.com \
--cc=dvyukov@google.com \
--cc=fzczx123@gmail.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=kjain@linux.ibm.com \
--cc=krzysztof.m.lopatowski@gmail.com \
--cc=leo.yan@arm.com \
--cc=lihuafei1@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux@treblig.org \
--cc=m.liska@foxlink.cz \
--cc=mark.rutland@arm.com \
--cc=martin.liska@hey.com \
--cc=mingo@redhat.com \
--cc=mpetlan@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=quic_zhonhan@quicinc.com \
--cc=scclevenger@os.amperecomputing.com \
--cc=sesse@google.com \
--cc=stephen.s.brennan@oracle.com \
--cc=thomas.falcon@intel.com \
--cc=yangyicong@hisilicon.com \
/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®