Skip to content

Relax tracing prog recursive attach rules

Dmitrii Dolgov bpf stable 12 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. v12 Latest4 patches 6 repliesApplied 4/4
  2. v114 patches 7 repliesSuperseded
  3. v104 patches 5 repliesSuperseded
Earlier versions · 9
VersionPostedPatchesRepliesStatus
v94 patches7 repliesSuperseded
v84 patches3 repliesSuperseded
v74 patches6 repliesSuperseded
v64 patches2 repliesSuperseded
v54 patches2 repliesSuperseded
v43 patches14 repliesSuperseded
v33 patches0 repliesSuperseded
v2 RFC1 patch10 repliesSuperseded
v1 RFC1 patch3 repliesSuperseded

Patches in v12 All 4 applied

#Subject and filesSizeRepliesApplied
1/4bpf: Relax tracing prog recursive attach rulesinclude/linux/bpf.h kernel/bpf/syscall.c kernel/bpf/verifier.c+48 -150 repliesApplied
2/4selftests/bpf: Add test for recursive attachment of tracing progstools/testing/selftests/bpf/prog_tests/recursive_attach.c tools/testing/selftests/bpf/progs/fentry_recursive.c tools/testing/selftests/bpf/progs/fentry_recursive_target.c+140 -05 repliesApplied
3/4bpf: Fix re-attachment branch in bpf_tracing_prog_attachkernel/bpf/syscall.c+9 -00 repliesApplied
4/4selftests/bpf: Test re-attachment fix for bpf_tracing_prog_attachtools/testing/selftests/bpf/prog_tests/recursive_attach.c tools/testing/selftests/bpf/progs/fentry_recursive_target.c+54 -01 replyApplied

Reviews trailers per patch

All 4 patches have a Reviewed-by or Acked-by.

PatchJiri OlsaSong Liu
1/4A-b A-b
2/4A-b A-b
3/4A-b A-b
4/4A-b A-b

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

Read the v12 thread

Cover letter [PATCH bpf-next v12 0/4] Relax tracing prog recursive attach rules

Currently, it's not allowed to attach an fentry/fexit prog to another fentry/fexit. At the same time it's not uncommon to see a tracing program with lots of logic in use, and the attachment limitation prevents usage of fentry/fexit for performance analysis (e.g. with "bpftool prog profile" command) in this case. An example could be falcosecurity libs project that uses tp_btf tracing programs for offloading certain part of logic into tail-called programs, but the use-case is still generic enough -- a tracing program could be complicated and heavy enough to warrant its profiling, yet frustratingly it's not possible to do so use best tooling for that.

Following the corresponding discussion [1], the reason for that is to avoid tracing progs call cycles without introducing more complex solutions. But currently it seems impossible to load and attach tracing programs in a way that will form such a cycle. Replace "no same type" requirement with verification that no more than one level of attachment nesting is allowed. In this way only one fentry/fexit program could be attached to another fentry/fexit to cover profiling use case, and still no cycle could be formed.

The series contains a test for recursive attachment, as well as a fix + test for an issue in re-attachment branch of bpf_tracing_prog_attach. When preparing the test for the main change set, I've stumbled upon the possibility to construct a sequence of events when attach_btf would be NULL while computing a trampoline key. It doesn't look like this issue is triggered by the main change, because the reproduces doesn't actually need to have an fentry attachment chain.

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

Dmitrii Dolgov (3):
bpf: Relax tracing prog recursive attach rules selftests/bpf: Add test for recursive attachment of tracing progs selftests/bpf: Test re-attachment fix for bpf_tracing_prog_attach

Jiri Olsa (1):
bpf: Fix re-attachment branch in bpf_tracing_prog_attach

 include/linux/bpf.h                           |   1 +
 kernel/bpf/syscall.c                          |  32 +++-
 kernel/bpf/verifier.c                         |  39 +++--
 .../bpf/prog_tests/recursive_attach.c         | 151 ++++++++++++++++++
 .../selftests/bpf/progs/fentry_recursive.c    |  16 ++
 .../bpf/progs/fentry_recursive_target.c       |  27 ++++
 6 files changed, 251 insertions(+), 15 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/recursive_attach.c
 create mode 100644 tools/testing/selftests/bpf/progs/fentry_recursive.c
 create mode 100644 tools/testing/selftests/bpf/progs/fentry_recursive_target.c

base-commit: 40d0eb0259ae77ace3e81d7454d1068c38bc95c2

Signature · 1 line
2.41.0