Skip to content

RFC bpf: Add batch support for attaching trampolines

Jiri Olsa bpf netdev 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v5 RFC Latest29 patches 19 repliesIn review

Changes in v5 from the cover letter

- ftrace new direct batch api got merged, so it's not longer part of this patchset (thanks Steven!), adding just few small related fixes
- added code that allows attach trampolines on top of each other as per previous version comments
- fixed btf__find_by_glob_kind as per Andrii's comments
- added new selftest to check on the trampoline's splitting
- added in bpf_arg/bpf_ret_value helpers with tests

Patches in v5 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/29ftrace: Use direct_ops hash in unregister_ftrace_directkernel/trace/ftrace.c+3 -10 replies
2/29ftrace: Add cleanup to unregister_ftrace_direct_multikernel/trace/ftrace.c+4 -00 replies
3/29ftrace: Add ftrace_set_filter_ips functioninclude/linux/ftrace.h kernel/trace/ftrace.c+47 -90 replies
4/29bpf: Factor bpf_check_attach_target functionkernel/bpf/verifier.c+59 -200 replies
5/29bpf: Add bpf_check_attach_model functioninclude/linux/bpf_verifier.h kernel/bpf/verifier.c+33 -00 replies
6/29bpf: Add bpf_arg/bpf_ret_value helpers for tracing programsarch/x86/net/bpf_jit_comp.c include/uapi/linux/bpf.h kernel/bpf/verifier.c +2 more+122 -79 replies
7/29bpf, x64: Allow to use caller address from stackarch/x86/net/bpf_jit_comp.c include/linux/bpf.h+14 -42 replies
8/29bpf: Keep active attached trampoline in bpf_proginclude/linux/bpf.h kernel/bpf/syscall.c+30 -52 replies
9/29bpf: Add support to load multi func tracing programinclude/linux/bpf.h include/uapi/linux/bpf.h kernel/bpf/syscall.c +2 more+47 -66 replies
10/29bpf: Add bpf_trampoline_id objectinclude/linux/bpf.h include/linux/bpf_verifier.h kernel/bpf/syscall.c +2 more+99 -410 replies
11/29bpf: Add addr to bpf_trampoline_id objectinclude/linux/bpf.h kernel/bpf/trampoline.c+11 -110 replies
12/29bpf: Add struct bpf_tramp_node layerinclude/linux/bpf.h kernel/bpf/core.c kernel/bpf/syscall.c +1 more+25 -170 replies
13/29bpf: Add bpf_tramp_attach layer for trampoline attachmentinclude/linux/bpf.h kernel/bpf/core.c kernel/bpf/syscall.c +2 more+156 -650 replies
14/29bpf: Add support to store multiple ids in bpf_tramp_id objectinclude/linux/bpf.h kernel/bpf/syscall.c kernel/bpf/trampoline.c +1 more+39 -140 replies
15/29bpf: Add support to store multiple addrs in bpf_tramp_id objectinclude/linux/bpf.h kernel/bpf/syscall.c kernel/bpf/trampoline.c +1 more+15 -110 replies
16/29bpf: Add bpf_tramp_id_single functioninclude/linux/bpf.h kernel/bpf/syscall.c kernel/bpf/trampoline.c +1 more+18 -190 replies
17/29bpf: Resolve id in bpf_tramp_id_singleinclude/linux/bpf.h kernel/bpf/syscall.c kernel/bpf/trampoline.c +1 more+24 -220 replies
18/29bpf: Add refcount_t to struct bpf_tramp_idinclude/linux/bpf.h kernel/bpf/syscall.c kernel/bpf/trampoline.c +1 more+18 -50 replies
19/29bpf: Add support to attach trampolines with multiple IDsinclude/linux/bpf.h kernel/bpf/trampoline.c+674 -550 replies
20/29bpf: Add support for tracing multi linkinclude/uapi/linux/bpf.h kernel/bpf/syscall.c kernel/kallsyms.c +1 more+263 -10 replies
21/29libbpf: Add btf__find_by_glob_kind functiontools/lib/bpf/btf.c tools/lib/bpf/btf.h+80 -00 replies
22/29libbpf: Add support to link multi func tracing programtools/lib/bpf/bpf.c tools/lib/bpf/bpf.h tools/lib/bpf/libbpf.c+78 -10 replies
23/29selftests/bpf: Add bpf_arg/bpf_ret_value testtools/testing/selftests/bpf/prog_tests/args_test.c tools/testing/selftests/bpf/progs/args_test.c+64 -00 replies
24/29selftests/bpf: Add fentry multi func testtools/testing/selftests/bpf/Makefile tools/testing/selftests/bpf/prog_tests/multi_fentry_test.c tools/testing/selftests/bpf/progs/multi_check.c +1 more+113 -10 replies
25/29selftests/bpf: Add fexit multi func testtools/testing/selftests/bpf/Makefile tools/testing/selftests/bpf/prog_tests/multi_fexit_test.c tools/testing/selftests/bpf/progs/multi_check.c +1 more+76 -10 replies
26/29selftests/bpf: Add fentry/fexit multi func testtools/testing/selftests/bpf/Makefile tools/testing/selftests/bpf/prog_tests/multi_fentry_fexit_test.c tools/testing/selftests/bpf/progs/multi_fentry_fexit.c+63 -10 replies
27/29selftests/bpf: Add mixed multi func testtools/testing/selftests/bpf/Makefile tools/testing/selftests/bpf/prog_tests/multi_mixed_test.c tools/testing/selftests/bpf/progs/multi_mixed.c+79 -10 replies
28/29selftests/bpf: Add ret_mod multi func testtools/testing/selftests/bpf/prog_tests/modify_return.c tools/testing/selftests/bpf/progs/multi_modify_return.c+128 -30 replies
29/29selftests/bpf: Add attach multi func testtools/testing/selftests/bpf/Makefile tools/testing/selftests/bpf/prog_tests/multi_attach_test.c tools/testing/selftests/bpf/progs/multi_attach.c+284 -10 replies

Reviews trailers per patch

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

Read the v5 thread

Cover letter [RFC bpf-next v5 00/29] bpf: Add batch support for attaching trampolines

hi,
sending new version of batch attach support, previous post is in here [1].

As discussed in previous post adding this version is adding generic approach to attach program to multiple functions, meaning you are now able to attach multiple trampolines on top of each other with no limitations, which was not possible in previous version.

v5 changes:
- ftrace new direct batch api got merged, so it's not longer part of this patchset (thanks Steven!), adding just few small related fixes
- added code that allows attach trampolines on top of each other as per previous version comments
- fixed btf__find_by_glob_kind as per Andrii's comments
- added new selftest to check on the trampoline's splitting
- added in bpf_arg/bpf_ret_value helpers with tests

I'm not completely sure about the approach, because it was quite difficult to debug/finalize, but I can't think of anything better for now.. so sending this as RFC ;)

Also available at:
https://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
bpf/batch

thanks,
jirka

[1] https://lore.kernel.org/bpf/[email protected]/
Cc: Steven Rostedt <[email protected]>
---
Jiri Olsa (29):
ftrace: Use direct_ops hash in unregister_ftrace_direct
ftrace: Add cleanup to unregister_ftrace_direct_multi
ftrace: Add ftrace_set_filter_ips function
bpf: Factor bpf_check_attach_target function
bpf: Add bpf_check_attach_model function
bpf: Add bpf_arg/bpf_ret_value helpers for tracing programs bpf, x64: Allow to use caller address from stack
bpf: Keep active attached trampoline in bpf_prog
bpf: Add support to load multi func tracing program
bpf: Add bpf_trampoline_id object
bpf: Add addr to bpf_trampoline_id object
bpf: Add struct bpf_tramp_node layer
bpf: Add bpf_tramp_attach layer for trampoline attachment
bpf: Add support to store multiple ids in bpf_tramp_id object
bpf: Add support to store multiple addrs in bpf_tramp_id object
bpf: Add bpf_tramp_id_single function
bpf: Resolve id in bpf_tramp_id_single
bpf: Add refcount_t to struct bpf_tramp_id
bpf: Add support to attach trampolines with multiple IDs
bpf: Add support for tracing multi link
libbpf: Add btf__find_by_glob_kind function
libbpf: Add support to link multi func tracing program selftests/bpf: Add bpf_arg/bpf_ret_value test selftests/bpf: Add fentry multi func test selftests/bpf: Add fexit multi func test selftests/bpf: Add fentry/fexit multi func test selftests/bpf: Add mixed multi func test selftests/bpf: Add ret_mod multi func test selftests/bpf: Add attach multi func test

 arch/x86/net/bpf_jit_comp.c                                      |  31 ++-
 include/linux/bpf.h                                              |  76 +++++--
 include/linux/bpf_verifier.h                                     |  23 +--
 include/linux/ftrace.h                                           |   3 +
 include/uapi/linux/bpf.h                                         |  26 +++
 kernel/bpf/core.c                                                |   4 +-
 kernel/bpf/syscall.c                                             | 379 +++++++++++++++++++++++++++++++----
 kernel/bpf/trampoline.c                                          | 926 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
 kernel/bpf/verifier.c                                            | 173 +++++++++++++---
 kernel/kallsyms.c                                                |   2 +-
 kernel/trace/bpf_trace.c                                         |  38 +++-
 kernel/trace/ftrace.c                                            |  61 +++++-
 tools/include/uapi/linux/bpf.h                                   |  26 +++
 tools/lib/bpf/bpf.c                                              |   7 +
 tools/lib/bpf/bpf.h                                              |   6 +-
 tools/lib/bpf/btf.c                                              |  77 ++++++++
 tools/lib/bpf/btf.h                                              |   3 +
 tools/lib/bpf/libbpf.c                                           |  66 +++++++
 tools/testing/selftests/bpf/Makefile                             |  10 +-
 tools/testing/selftests/bpf/prog_tests/args_test.c               |  34 ++++
 tools/testing/selftests/bpf/prog_tests/modify_return.c           | 114 ++++++++++-
 tools/testing/selftests/bpf/prog_tests/multi_attach_test.c       | 176 +++++++++++++++++
 tools/testing/selftests/bpf/prog_tests/multi_fentry_fexit_test.c |  32 +++
 tools/testing/selftests/bpf/prog_tests/multi_fentry_test.c       |  30 +++
 tools/testing/selftests/bpf/prog_tests/multi_fexit_test.c        |  31 +++
 tools/testing/selftests/bpf/prog_tests/multi_mixed_test.c        |  34 ++++
 tools/testing/selftests/bpf/progs/args_test.c                    |  30 +++
 tools/testing/selftests/bpf/progs/multi_attach.c                 | 105 ++++++++++
 tools/testing/selftests/bpf/progs/multi_check.c                  |  86 ++++++++
 tools/testing/selftests/bpf/progs/multi_fentry.c                 |  17 ++
 tools/testing/selftests/bpf/progs/multi_fentry_fexit.c           |  28 +++
 tools/testing/selftests/bpf/progs/multi_fexit.c                  |  20 ++
 tools/testing/selftests/bpf/progs/multi_mixed.c                  |  43 ++++
 tools/testing/selftests/bpf/progs/multi_modify_return.c          |  17 ++
 34 files changed, 2539 insertions(+), 195 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/args_test.c
 create mode 100644 tools/testing/selftests/bpf/prog_tests/multi_attach_test.c
 create mode 100644 tools/testing/selftests/bpf/prog_tests/multi_fentry_fexit_test.c
 create mode 100644 tools/testing/selftests/bpf/prog_tests/multi_fentry_test.c
 create mode 100644 tools/testing/selftests/bpf/prog_tests/multi_fexit_test.c
 create mode 100644 tools/testing/selftests/bpf/prog_tests/multi_mixed_test.c
 create mode 100644 tools/testing/selftests/bpf/progs/args_test.c
 create mode 100644 tools/testing/selftests/bpf/progs/multi_attach.c
 create mode 100644 tools/testing/selftests/bpf/progs/multi_check.c
 create mode 100644 tools/testing/selftests/bpf/progs/multi_fentry.c
 create mode 100644 tools/testing/selftests/bpf/progs/multi_fentry_fexit.c
 create mode 100644 tools/testing/selftests/bpf/progs/multi_fexit.c
 create mode 100644 tools/testing/selftests/bpf/progs/multi_mixed.c
 create mode 100644 tools/testing/selftests/bpf/progs/multi_modify_return.c