[RFC PATCH v1 0/8] perf/core, perf/tools: Add PERF_SAMPLE_BUILD_ID_OFFSET support

Ian Rogers posted 8 patches 1 month, 3 weeks ago
include/linux/bpf.h                           |  13 +
include/uapi/linux/perf_event.h               |   4 +-
kernel/bpf/stackmap.c                         |   2 +-
kernel/events/core.c                          |  85 ++-
tools/include/uapi/linux/perf_event.h         |  30 +-
tools/lib/perf/include/perf/event.h           |  18 +-
.../arch/powerpc/util/skip-callchain-idx.c    |   4 +-
tools/perf/builtin-inject.c                   |  23 +-
tools/perf/builtin-record.c                   |   7 +
tools/perf/builtin-script.c                   |  49 +-
tools/perf/builtin-timechart.c                |   4 +-
tools/perf/builtin-trace.c                    |  12 +-
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         |  45 +-
tools/perf/tests/sample-parsing.c             |  37 +-
tools/perf/tests/shell/inject_bid_offset.sh   | 170 ++++++
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                    |   5 +-
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/event.c                       |  93 ++--
tools/perf/util/evsel.c                       |  35 ++
tools/perf/util/evsel.h                       |   3 +-
tools/perf/util/evsel_fprintf.c               |   2 +-
tools/perf/util/inject_bid_offset.c           | 504 ++++++++++++++++++
tools/perf/util/inject_bid_offset.h           |  21 +
tools/perf/util/intel-pt.c                    |  12 +-
tools/perf/util/machine.c                     | 106 ++--
tools/perf/util/maps.c                        |  29 +
tools/perf/util/maps.h                        |   2 +
tools/perf/util/perf_event_attr_fprintf.c     |   3 +-
tools/perf/util/python.c                      |  13 +-
tools/perf/util/record.h                      |   1 +
tools/perf/util/sample.h                      |  13 +
.../scripting-engines/trace-event-python.c    |  20 +-
tools/perf/util/synthetic-events.c            |  60 ++-
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 +-
50 files changed, 1473 insertions(+), 174 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
[RFC PATCH v1 0/8] perf/core, perf/tools: Add PERF_SAMPLE_BUILD_ID_OFFSET support
Posted by Ian Rogers 1 month, 3 weeks ago
This patch series introduces PERF_SAMPLE_BUILD_ID_OFFSET to the
perf_event UAPI and implements full support across both the kernel
and perf tools.

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 just facilitate Build ID and offset as a choice
for perf samples and the user can have the choice 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 say --synth=no.

The kernel support uses the existing build ID and offset support used
by BPF stack traces.

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 for the
purposes of testing without kernel support.

Series Overview:

- Patch 1: Factor struct perf_build_id into top-level header structure.
- Patch 2: Add PERF_SAMPLE_BUILD_ID_OFFSET to UAPI.
- Patch 3: Implement kernel-side sampling support in
           perf_output_sample() using stack_map_get_build_id_offset().
- Patch 4: Refactor perf tools thread__find_map and symbol lookup APIs
           to accept struct perf_sample.
- Patch 5: Add perf tools internal parsing and symbol resolution via
           Build ID + offset.
- Patch 6: Extend perf inject with --buildid-offset to convert sample
           files.
- Patch 7: Add --buildid-offset option to perf record.
- Patch 8: Add unit and shell test coverage (bid-offset test and
           inject_bid_offset.sh).

Testing & Verification:

The series was verified using QEMU hypervisor testing with kernel
builds and perf test.

Linux Plumbers Tracing Miniconference:

I submitted a proposal/abstract to talk about these changes to the
Tracing Micro Conference at Linux Plumbers Conference 2026 in Prague.

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                           |  13 +
 include/uapi/linux/perf_event.h               |   4 +-
 kernel/bpf/stackmap.c                         |   2 +-
 kernel/events/core.c                          |  85 ++-
 tools/include/uapi/linux/perf_event.h         |  30 +-
 tools/lib/perf/include/perf/event.h           |  18 +-
 .../arch/powerpc/util/skip-callchain-idx.c    |   4 +-
 tools/perf/builtin-inject.c                   |  23 +-
 tools/perf/builtin-record.c                   |   7 +
 tools/perf/builtin-script.c                   |  49 +-
 tools/perf/builtin-timechart.c                |   4 +-
 tools/perf/builtin-trace.c                    |  12 +-
 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         |  45 +-
 tools/perf/tests/sample-parsing.c             |  37 +-
 tools/perf/tests/shell/inject_bid_offset.sh   | 170 ++++++
 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                    |   5 +-
 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/event.c                       |  93 ++--
 tools/perf/util/evsel.c                       |  35 ++
 tools/perf/util/evsel.h                       |   3 +-
 tools/perf/util/evsel_fprintf.c               |   2 +-
 tools/perf/util/inject_bid_offset.c           | 504 ++++++++++++++++++
 tools/perf/util/inject_bid_offset.h           |  21 +
 tools/perf/util/intel-pt.c                    |  12 +-
 tools/perf/util/machine.c                     | 106 ++--
 tools/perf/util/maps.c                        |  29 +
 tools/perf/util/maps.h                        |   2 +
 tools/perf/util/perf_event_attr_fprintf.c     |   3 +-
 tools/perf/util/python.c                      |  13 +-
 tools/perf/util/record.h                      |   1 +
 tools/perf/util/sample.h                      |  13 +
 .../scripting-engines/trace-event-python.c    |  20 +-
 tools/perf/util/synthetic-events.c            |  60 ++-
 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 +-
 50 files changed, 1473 insertions(+), 174 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.55.0.679.g6767b8d81c-goog
Re: [RFC PATCH v1 0/8] perf/core, perf/tools: Add PERF_SAMPLE_BUILD_ID_OFFSET support
Posted by Peter Zijlstra 1 month, 3 weeks ago
On Fri, Aug 07, 2026 at 12:18:10AM -0700, Ian Rogers wrote:
> This patch series introduces PERF_SAMPLE_BUILD_ID_OFFSET to the
> perf_event UAPI and implements full support across both the kernel
> and perf tools.
> 
> 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 just facilitate Build ID and offset as a choice
> for perf samples and the user can have the choice 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 say --synth=no.
> 
> The kernel support uses the existing build ID and offset support used
> by BPF stack traces.

That is still a giant stinking mess that needs to cleaned up.
Re: [RFC PATCH v1 0/8] perf/core, perf/tools: Add PERF_SAMPLE_BUILD_ID_OFFSET support
Posted by Namhyung Kim 1 month ago
Hello,

On Fri, Aug 07, 2026 at 01:18:18PM +0200, Peter Zijlstra wrote:
> On Fri, Aug 07, 2026 at 12:18:10AM -0700, Ian Rogers wrote:
> > This patch series introduces PERF_SAMPLE_BUILD_ID_OFFSET to the
> > perf_event UAPI and implements full support across both the kernel
> > and perf tools.
> > 
> > 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 just facilitate Build ID and offset as a choice
> > for perf samples and the user can have the choice 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 say --synth=no.
> > 
> > The kernel support uses the existing build ID and offset support used
> > by BPF stack traces.
> 
> That is still a giant stinking mess that needs to cleaned up.

Then we can discuss how we want to handle that as well. :)

I think this work would be useful on large systems with lots of tasks.
I've got reports it took too long on synthesis and timed out.  Also it's
racy and easy to miss new tasks..

So I think it's a good option to explore and maybe we can make default
once it turns out working great.  But I'm afraid it may need some kind
of optimization to handle multiple addresses like in callchains/LBRs.

Thanks,
Namhyung
Re: [RFC PATCH v1 0/8] perf/core, perf/tools: Add PERF_SAMPLE_BUILD_ID_OFFSET support
Posted by Namhyung Kim 3 days, 8 hours ago
On Wed, Aug 26, 2026 at 04:19:57PM -0700, Namhyung Kim wrote:
> Hello,
> 
> On Fri, Aug 07, 2026 at 01:18:18PM +0200, Peter Zijlstra wrote:
> > On Fri, Aug 07, 2026 at 12:18:10AM -0700, Ian Rogers wrote:
> > > This patch series introduces PERF_SAMPLE_BUILD_ID_OFFSET to the
> > > perf_event UAPI and implements full support across both the kernel
> > > and perf tools.
> > > 
> > > 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 just facilitate Build ID and offset as a choice
> > > for perf samples and the user can have the choice 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 say --synth=no.
> > > 
> > > The kernel support uses the existing build ID and offset support used
> > > by BPF stack traces.
> > 
> > That is still a giant stinking mess that needs to cleaned up.
> 
> Then we can discuss how we want to handle that as well. :)
> 
> I think this work would be useful on large systems with lots of tasks.
> I've got reports it took too long on synthesis and timed out.  Also it's
> racy and easy to miss new tasks..
> 
> So I think it's a good option to explore and maybe we can make default
> once it turns out working great.  But I'm afraid it may need some kind
> of optimization to handle multiple addresses like in callchains/LBRs.

One more thought.

Maybe it's not a good idea to traverse the VMA tree in NMI.  Can it use
the deferred unwind framework to do that later?  We could extend it for
non-callchain data like IP and BRANCH_STACKs for user space.

Thanks,
Namhyung
Re: [RFC PATCH v1 0/8] perf/core, perf/tools: Add PERF_SAMPLE_BUILD_ID_OFFSET support
Posted by Ian Rogers 3 days, 8 hours ago
On Fri, Sep 25, 2026 at 8:03 PM Namhyung Kim <namhyung@kernel.org> wrote:
>
> On Wed, Aug 26, 2026 at 04:19:57PM -0700, Namhyung Kim wrote:
> > Hello,
> >
> > On Fri, Aug 07, 2026 at 01:18:18PM +0200, Peter Zijlstra wrote:
> > > On Fri, Aug 07, 2026 at 12:18:10AM -0700, Ian Rogers wrote:
> > > > This patch series introduces PERF_SAMPLE_BUILD_ID_OFFSET to the
> > > > perf_event UAPI and implements full support across both the kernel
> > > > and perf tools.
> > > >
> > > > 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 just facilitate Build ID and offset as a choice
> > > > for perf samples and the user can have the choice 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 say --synth=no.
> > > >
> > > > The kernel support uses the existing build ID and offset support used
> > > > by BPF stack traces.
> > >
> > > That is still a giant stinking mess that needs to cleaned up.
> >
> > Then we can discuss how we want to handle that as well. :)
> >
> > I think this work would be useful on large systems with lots of tasks.
> > I've got reports it took too long on synthesis and timed out.  Also it's
> > racy and easy to miss new tasks..
> >
> > So I think it's a good option to explore and maybe we can make default
> > once it turns out working great.  But I'm afraid it may need some kind
> > of optimization to handle multiple addresses like in callchains/LBRs.
>
> One more thought.
>
> Maybe it's not a good idea to traverse the VMA tree in NMI.  Can it use
> the deferred unwind framework to do that later?  We could extend it for
> non-callchain data like IP and BRANCH_STACKs for user space.

Thanks Namhyung! I will incorporate this in v2.

Ian

> Thanks,
> Namhyung
>