Skip to content

Add SEC("ksyscall") support

Andrii Nakryiko bpf 2 versions – 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 · linked by author and title

  1. v2 Latest5 patches 3 repliesApplied 5/5
  2. v15 patches 12 repliesSuperseded

Changes in v2 from the cover letter

- normalize extern variable-related warn and debug message formats (Alan);

Patches in v2 All 5 applied

#Subject and filesSizeRepliesApplied
1/5libbpf: generalize virtual __kconfig externs and use it for USDTtools/lib/bpf/libbpf.c tools/lib/bpf/usdt.bpf.h+66 -450 repliesApplied
2/5selftests/bpf: add test of __weak unknown virtual __kconfig externtools/testing/selftests/bpf/prog_tests/core_extern.c tools/testing/selftests/bpf/progs/test_core_extern.c+10 -100 repliesApplied
3/5libbpf: improve BPF_KPROBE_SYSCALL macro and rename it to BPF_KSYSCALLtools/lib/bpf/bpf_tracing.h tools/lib/bpf/libbpf.c+40 -130 repliesApplied
4/5libbpf: add ksyscall/kretsyscall sections support for syscall kprobestools/lib/bpf/libbpf.c tools/lib/bpf/libbpf.h tools/lib/bpf/libbpf.map +1 more+157 -90 repliesApplied
5/5selftests/bpf: use BPF_KSYSCALL and SEC("ksyscall") in selfteststools/testing/selftests/bpf/progs/bpf_syscall_macro.c tools/testing/selftests/bpf/progs/test_attach_probe.c tools/testing/selftests/bpf/progs/test_probe_user.c+16 -322 repliesApplied

Reviews trailers per patch

1 of 5 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchAlan MaguireStanislav Fomichev
SeriesR-b
1/5T-b R-b
2/5T-b
3/5T-b
4/5T-b
5/5T-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 bpf-next 0/5] Add SEC("ksyscall") support

Add SEC("ksyscall")/SEC("kretsyscall") sections and corresponding bpf_program__attach_ksyscall() API that simplifies tracing kernel syscalls through kprobe mechanism. Kprobing syscalls isn't trivial due to varying syscall handler names in the kernel and various ways syscall argument are passed, depending on kernel architecture and configuration. SEC("ksyscall") allows user to not care about such details and just get access to syscall input arguments, while libbpf takes care of necessary feature detection logic.

There are still more quirks that are not straightforward to hide completely (see comments about mmap(), clone() and compat syscalls), so in such more advanced scenarios user might need to fall back to plain SEC("kprobe") approach, but for absolute majority of users SEC("ksyscall") is a big improvement.

As part of this patch set libbpf adds two more virtual __kconfig externs, in addition to existing LINUX_KERNEL_VERSION: LINUX_HAS_BPF_COOKIE and LINUX_HAS_SYSCALL_WRAPPER, which let's libbpf-provided BPF-side code minimize external dependencies and assumptions and let's user-space part of libbpf to perform all the feature detection logic. This benefits USDT support code, which now doesn't depend on BPF CO-RE for its functionality.

v1->v2:
- normalize extern variable-related warn and debug message formats (Alan);
rfc->v1:
- drop dependency on kallsyms and speed up SYSCALL_WRAPPER detection (Alexei);
- drop dependency on /proc/config.gz in bpf_tracing.h (Yaniv);
- add doc comment and ephasize mmap(), clone() and compat quirks that are

    not supported (Ilya);

- use mechanism similar to LINUX_KERNEL_VERSION to also improve USDT code.

Andrii Nakryiko (5):
libbpf: generalize virtual __kconfig externs and use it for USDT selftests/bpf: add test of __weak unknown virtual __kconfig extern
libbpf: improve BPF_KPROBE_SYSCALL macro and rename it to BPF_KSYSCALL
libbpf: add ksyscall/kretsyscall sections support for syscall kprobes selftests/bpf: use BPF_KSYSCALL and SEC("ksyscall") in selftests

 tools/lib/bpf/bpf_tracing.h                   |  51 +++--
 tools/lib/bpf/libbpf.c                        | 214 ++++++++++++++----
 tools/lib/bpf/libbpf.h                        |  46 ++++
 tools/lib/bpf/libbpf.map                      |   1 +
 tools/lib/bpf/libbpf_internal.h               |   2 +
 tools/lib/bpf/usdt.bpf.h                      |  16 +-
 .../selftests/bpf/prog_tests/core_extern.c    |  17 +-
 .../selftests/bpf/progs/bpf_syscall_macro.c   |   6 +-
 .../selftests/bpf/progs/test_attach_probe.c   |  15 +-
 .../selftests/bpf/progs/test_core_extern.c    |   3 +
 .../selftests/bpf/progs/test_probe_user.c     |  27 +--
 11 files changed, 289 insertions(+), 109 deletions(-)
Signature · 1 line
2.30.2