Skip to content

libbpf: extend [ku]probe and syscall argument tracing support

Andrii Nakryiko bpf 1 version Applied

Status from this message: This series was applied to bpf/bpf-next.git (master)

Get series with b4
b4 am [email protected]

Versions newest first

  1. v2 Latest25 patches 0 repliesApplied 25/25

Changes in v2 from the cover letter

- switched from mmap() to splice() syscall (Ilya);
- updated ABI spec link for s390x (Ilya);
- added a bunch of Tested-by and acks tags, thank you;
- dropped direct CCs because vger/patchworks blocked v1 patches, probably due to too long CC list.

Patches in v2 All 25 applied

#Subject and filesSizeRepliesApplied
1/25libbpf: add support for fetching up to 8 arguments in kprobestools/lib/bpf/bpf_tracing.h+37 -40 repliesApplied
2/25libbpf: add 6th argument support for x86-64 in bpf_tracing.htools/lib/bpf/bpf_tracing.h+6 -00 repliesApplied
3/25libbpf: fix arm and arm64 specs in bpf_tracing.htools/lib/bpf/bpf_tracing.h+11 -10 repliesApplied
4/25libbpf: complete mips spec in bpf_tracing.htools/lib/bpf/bpf_tracing.h+8 -00 repliesApplied
5/25libbpf: complete powerpc spec in bpf_tracing.htools/lib/bpf/bpf_tracing.h+8 -00 repliesApplied
6/25libbpf: complete sparc spec in bpf_tracing.htools/lib/bpf/bpf_tracing.h+5 -00 repliesApplied
7/25libbpf: complete riscv arch spec in bpf_tracing.htools/lib/bpf/bpf_tracing.h+7 -00 repliesApplied
8/25libbpf: fix and complete ARC spec in bpf_tracing.htools/lib/bpf/bpf_tracing.h+9 -10 repliesApplied
9/25libbpf: complete LoongArch (loongarch) spec in bpf_tracing.htools/lib/bpf/bpf_tracing.h+7 -10 repliesApplied
10/25libbpf: add BPF_UPROBE and BPF_URETPROBE macro aliasestools/lib/bpf/bpf_tracing.h+7 -00 repliesApplied
11/25selftests/bpf: validate arch-specific argument registers limitstools/testing/selftests/bpf/prog_tests/uprobe_autoattach.c tools/testing/selftests/bpf/progs/bpf_misc.h tools/testing/selftests/bpf/progs/test_uprobe_autoattach.c+99 -70 repliesApplied
12/25libbpf: improve syscall tracing support in bpf_tracing.htools/lib/bpf/bpf_tracing.h+58 -130 repliesApplied
13/25libbpf: define x86-64 syscall regs spec in bpf_tracing.htools/lib/bpf/bpf_tracing.h+19 -60 repliesApplied
14/25libbpf: define i386 syscall regs spec in bpf_tracing.htools/lib/bpf/bpf_tracing.h+8 -00 repliesApplied
15/25libbpf: define s390x syscall regs spec in bpf_tracing.htools/lib/bpf/bpf_tracing.h+15 -20 repliesApplied
16/25libbpf: define arm syscall regs spec in bpf_tracing.htools/lib/bpf/bpf_tracing.h+8 -00 repliesApplied
17/25libbpf: define arm64 syscall regs spec in bpf_tracing.htools/lib/bpf/bpf_tracing.h+11 -20 repliesApplied
18/25libbpf: define mips syscall regs spec in bpf_tracing.htools/lib/bpf/bpf_tracing.h+8 -00 repliesApplied
19/25libbpf: define powerpc syscall regs spec in bpf_tracing.htools/lib/bpf/bpf_tracing.h+13 -20 repliesApplied
20/25libbpf: define sparc syscall regs spec in bpf_tracing.htools/lib/bpf/bpf_tracing.h+8 -00 repliesApplied
21/25libbpf: define riscv syscall regs spec in bpf_tracing.htools/lib/bpf/bpf_tracing.h+10 -20 repliesApplied
22/25libbpf: define arc syscall regs spec in bpf_tracing.htools/lib/bpf/bpf_tracing.h+10 -20 repliesApplied
23/25libbpf: define loongarch syscall regs spec in bpf_tracing.htools/lib/bpf/bpf_tracing.h+10 -20 repliesApplied
24/25selftests/bpf: add 6-argument syscall tracing testtools/testing/selftests/bpf/prog_tests/test_bpf_syscall_macro.c tools/testing/selftests/bpf/progs/bpf_syscall_macro.c+43 -00 repliesApplied
25/25libbpf: clean up now not needed __PT_PARM{1-6}_SYSCALL_REG defaultstools/lib/bpf/bpf_tracing.h+0 -180 repliesApplied

Reviews trailers per patch

1 of 25 patches has a Reviewed-by or Acked-by.

PatchAlan MaguireIlya LeoshkevichPu Lehui
1/25T-b T-b
2/25
3/25T-b
4/25
5/25
6/25
7/25T-b
8/25
9/25
10/25
11/25T-b T-b
12/25T-b
13/25
14/25
15/25A-b T-b
16/25
17/25T-b
18/25
19/25
20/25
21/25T-b
22/25
23/25
24/25T-b T-b
25/25

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v2 thread

Cover letter [PATCH v2 bpf-next 00/25] libbpf: extend [ku]probe and syscall argument tracing support

This patch set fixes and extends libbpf's bpf_tracing.h support for tracing arguments of kprobes/uprobes, and syscall as a special case.

Depending on the architecture, anywhere between 3 and 8 arguments can be passed to a function in registers (so relevant to kprobes and uprobes), but before this patch set libbpf's macros in bpf_tracing.h only supported up to 5 arguments, which is limiting in practice. This patch set extends bpf_tracing.h to support up to 8 arguments, if architecture allows. This includes explicit PT_REGS_PARMx() macro family, as well as BPF_KPROBE() macro.

Now, with tracing syscall arguments situation is sometimes quite different. For a lot of architectures syscall argument passing through registers differs from function call sequence at least a little. For i386 it differs *a lot*. This patch set addresses this issue across all currently supported architectures and hopefully fixes existing issues. syscall(2) manpage defines that either 6 or 7 arguments can be supported, depending on architecture, so libbpf defines 6 or 7 registers per architecture to be used to fetch syscall arguments.

Also, BPF_UPROBE and BPF_URETPROBE are introduced as part of this patch set. They are aliases for BPF_KPROBE and BPF_KRETPROBE (as mechanics of argument fetching of kernel functions and user-space functions are identical), but it allows BPF users to have less confusing BPF-side code when working with uprobes.

For both sets of changes selftests are extended to test these new register definitions to architecture-defined limits. Unfortunately I don't have ability to test it on all architectures, and BPF CI only tests 3 architecture (x86-64, arm64, and s390x), so it would be greatly appreciated if people with access to architectures other than above 3 helped review and test changes.

v1->v2:
- switched from mmap() to splice() syscall (Ilya);
- updated ABI spec link for s390x (Ilya);
- added a bunch of Tested-by and acks tags, thank you;
- dropped direct CCs because vger/patchworks blocked v1 patches, probably due to too long CC list.

Andrii Nakryiko (25):
libbpf: add support for fetching up to 8 arguments in kprobes
libbpf: add 6th argument support for x86-64 in bpf_tracing.h
libbpf: fix arm and arm64 specs in bpf_tracing.h
libbpf: complete mips spec in bpf_tracing.h
libbpf: complete powerpc spec in bpf_tracing.h
libbpf: complete sparc spec in bpf_tracing.h
libbpf: complete riscv arch spec in bpf_tracing.h
libbpf: fix and complete ARC spec in bpf_tracing.h
libbpf: complete LoongArch (loongarch) spec in bpf_tracing.h
libbpf: add BPF_UPROBE and BPF_URETPROBE macro aliases selftests/bpf: validate arch-specific argument registers limits
libbpf: improve syscall tracing support in bpf_tracing.h
libbpf: define x86-64 syscall regs spec in bpf_tracing.h
libbpf: define i386 syscall regs spec in bpf_tracing.h
libbpf: define s390x syscall regs spec in bpf_tracing.h
libbpf: define arm syscall regs spec in bpf_tracing.h
libbpf: define arm64 syscall regs spec in bpf_tracing.h
libbpf: define mips syscall regs spec in bpf_tracing.h
libbpf: define powerpc syscall regs spec in bpf_tracing.h
libbpf: define sparc syscall regs spec in bpf_tracing.h
libbpf: define riscv syscall regs spec in bpf_tracing.h
libbpf: define arc syscall regs spec in bpf_tracing.h
libbpf: define loongarch syscall regs spec in bpf_tracing.h selftests/bpf: add 6-argument syscall tracing test
libbpf: clean up now not needed __PT_PARM{1-6}_SYSCALL_REG defaults

 tools/lib/bpf/bpf_tracing.h                   | 303 +++++++++++++++---
 .../bpf/prog_tests/test_bpf_syscall_macro.c   |  17 +
 .../bpf/prog_tests/uprobe_autoattach.c        |  33 +-
 tools/testing/selftests/bpf/progs/bpf_misc.h  |  25 ++
 .../selftests/bpf/progs/bpf_syscall_macro.c   |  26 ++
 .../bpf/progs/test_uprobe_autoattach.c        |  48 ++-
 6 files changed, 407 insertions(+), 45 deletions(-)
Signature · 1 line
2.30.2