Skip to content

RFC libbpf: Add support for dynamic tracepoints

Yafang Shao bpf netdev 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 RFC Latest2 patches 3 repliesIn review
  2. v1 RFC2 patches 8 repliesSuperseded

Changes in v2 from the cover letter

- Use a new SEC("kprobe/SUBSYSTEM/PROBE") instead (Jiri)

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2libbpf: Add support for dynamic tracepointtools/lib/bpf/libbpf.c+28 -10 replies
2/2selftests/bpf: Add selftest for dynamic tracepointtools/testing/selftests/bpf/prog_tests/test_dynamic_tp.c tools/testing/selftests/bpf/progs/dynamic_tp.c+91 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [RFC PATCH v2 0/2] libbpf: Add support for dynamic tracepoints

The primary goal of this change is to enable tracing of inlined kernel functions with BPF programs.

Dynamic tracepoints can be created using tools like perf-probe, debugfs, or similar utilities. For example:

  $ perf probe -a 'tcp_listendrop sk'
  $ ls /sys/kernel/debug/tracing/events/probe/tcp_listendrop/
  enable  filter  format  hist  id  trigger

Here, tcp_listendrop() is an example of an inlined kernel function.

While these dynamic tracepoints are functional, they cannot be easily attached to BPF programs. For instance, attempting to use them with bpftrace results in the following error:

  $ bpftrace -l 'tracepoint:probe:*'
  tracepoint:probe:tcp_listendrop
  $ bpftrace -e 'tracepoint:probe:tcp_listendrop {print(comm)}'
  Attaching 1 probe...
  ioctl(PERF_EVENT_IOC_SET_BPF): Invalid argument
  ERROR: Error attaching probe: tracepoint:probe:tcp_listendrop

The issue lies in how these dynamic tracepoints are implemented: despite being exposed as tracepoints, they remain kprobe events internally. As a result, loading them as a tracepoint program fails. Instead, they must be loaded as kprobe programs.

This change introduces support for such use cases in libbpf by adding a new section: SEC("kprobe/SUBSYSTEM/PROBE")

- Future work
Extend support for dynamic tracepoints in bpftrace.

Changes:
v1->v2:
- Use a new SEC("kprobe/SUBSYSTEM/PROBE") instead (Jiri)

v1: https://lore.kernel.org/bpf/[email protected]/

Yafang Shao (2):
libbpf: Add support for dynamic tracepoint selftests/bpf: Add selftest for dynamic tracepoint

 tools/lib/bpf/libbpf.c                        | 29 ++++++++-
 .../bpf/prog_tests/test_dynamic_tp.c          | 64 +++++++++++++++++++
 .../testing/selftests/bpf/progs/dynamic_tp.c  | 27 ++++++++
 3 files changed, 119 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/test_dynamic_tp.c
 create mode 100644 tools/testing/selftests/bpf/progs/dynamic_tp.c
Signature · 1 line
2.43.5