Skip to content

RFC x86/ftrace/bpf: Add batch support for direct/tracing attach

Jiri Olsa bpf netdev 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v3 RFC Latest19 patches 56 repliesIn review

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/19x86/ftrace: Remove extra orig rax movearch/x86/kernel/ftrace_64.S+0 -10 replies
2/19x86/ftrace: Remove fault protection code in prepare_ftrace_returnarch/x86/kernel/ftrace.c+3 -350 replies
3/19x86/ftrace: Make function graph use ftrace directlyarch/x86/include/asm/ftrace.h arch/x86/kernel/ftrace.c arch/x86/kernel/ftrace_64.S +2 more+53 -363 replies
4/19tracing: Add trampoline/graph selftestkernel/trace/trace_selftest.c+48 -10 replies
5/19ftrace: Add ftrace_add_rec_direct functionkernel/trace/ftrace.c+36 -240 replies
6/19ftrace: Add multi direct register/unregister interfaceinclude/linux/ftrace.h kernel/trace/ftrace.c+118 -00 replies
7/19ftrace: Add multi direct modify interfaceinclude/linux/ftrace.h kernel/trace/ftrace.c+49 -00 replies
8/19ftrace/samples: Add multi direct interface test modulesamples/ftrace/Makefile samples/ftrace/ftrace-direct-multi.c+53 -00 replies
9/19bpf, x64: Allow to use caller address from stackarch/x86/net/bpf_jit_comp.c include/linux/bpf.h+14 -42 replies
10/19bpf: Allow to store caller's ip as argumentarch/x86/net/bpf_jit_comp.c include/linux/bpf.h+19 -46 replies
11/19bpf: Add support to load multi func tracing programinclude/linux/bpf.h include/uapi/linux/bpf.h kernel/bpf/btf.c +3 more+52 -63 replies
12/19bpf: Add bpf_trampoline_alloc functionkernel/bpf/trampoline.c+22 -120 replies
13/19bpf: Add support to link multi func tracing programinclude/linux/bpf.h include/uapi/linux/bpf.h kernel/bpf/syscall.c +2 more+237 -1413 replies
14/19libbpf: Add btf__find_by_pattern_kind functiontools/lib/bpf/btf.c tools/lib/bpf/btf.h+71 -03 replies
15/19libbpf: Add support to link multi func tracing programtools/lib/bpf/bpf.c tools/lib/bpf/bpf.h tools/lib/bpf/libbpf.c+85 -28 replies
16/19selftests/bpf: Add fentry multi func testtools/testing/selftests/bpf/multi_check.h tools/testing/selftests/bpf/prog_tests/fentry_multi_test.c tools/testing/selftests/bpf/progs/fentry_multi_test.c+113 -06 replies
17/19selftests/bpf: Add fexit multi func testtools/testing/selftests/bpf/prog_tests/fexit_multi_test.c tools/testing/selftests/bpf/progs/fexit_multi_test.c+64 -00 replies
18/19selftests/bpf: Add fentry/fexit multi func testtools/testing/selftests/bpf/prog_tests/fentry_fexit_multi_test.c tools/testing/selftests/bpf/progs/fentry_fexit_multi_test.c+80 -02 replies
19/19selftests/bpf: Temporary fix for fentry_fexit_multi_testtools/testing/selftests/bpf/multi_check.h tools/testing/selftests/bpf/progs/fentry_fexit_multi_test.c tools/testing/selftests/bpf/progs/fentry_multi_test.c +1 more+32 -240 replies

Reviews trailers per patch

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

Read the v3 thread

Cover letter [RFCv3 00/19] x86/ftrace/bpf: Add batch support for direct/tracing attach

hi,
saga continues.. ;-) previous post is in here [1]

After another discussion with Steven, he mentioned that if we fix the ftrace graph problem with direct functions, he'd be open to add batch interface for direct ftrace functions.

He already had prove of concept fix for that, which I took and broke up into several changes. I added the ftrace direct batch interface and bpf new interface on top of that.

It's not so many patches after all, so I thought having them all together will help the review, because they are all connected. However I can break this up into separate patchsets if necessary.

This patchset contains:

1) patches (1-4) that fix the ftrace graph tracing over the function with direct trampolines attached
2) patches (5-8) that add batch interface for ftrace direct function register/unregister/modify
3) patches (9-19) that add support to attach BPF program to multiple functions

In nutshell:

Ad 1) moves the graph tracing setup before the direct trampoline prepares the stack, so they don't clash

Ad 2) uses ftrace_ops interface to register direct function with all functions in ftrace_ops filter.

Ad 3) creates special program and trampoline type to allow attachment of multiple functions to single program.

There're more detailed desriptions in related changelogs.

I have working bpftrace multi attachment code on top this. I briefly checked retsnoop and I think it could use the new API as well.

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]/

---
Jiri Olsa (17):
x86/ftrace: Remove extra orig rax move
tracing: Add trampoline/graph selftest
ftrace: Add ftrace_add_rec_direct function
ftrace: Add multi direct register/unregister interface
ftrace: Add multi direct modify interface ftrace/samples: Add multi direct interface test module bpf, x64: Allow to use caller address from stack
bpf: Allow to store caller's ip as argument
bpf: Add support to load multi func tracing program
bpf: Add bpf_trampoline_alloc function
bpf: Add support to link multi func tracing program
libbpf: Add btf__find_by_pattern_kind function
libbpf: Add support to link multi func tracing program selftests/bpf: Add fentry multi func test selftests/bpf: Add fexit multi func test selftests/bpf: Add fentry/fexit multi func test selftests/bpf: Temporary fix for fentry_fexit_multi_test

Steven Rostedt (VMware) (2):
x86/ftrace: Remove fault protection code in prepare_ftrace_return x86/ftrace: Make function graph use ftrace directly

 arch/x86/include/asm/ftrace.h                                    |   9 ++++--
 arch/x86/kernel/ftrace.c                                         |  71 ++++++++++++++++++++++-----------------------
 arch/x86/kernel/ftrace_64.S                                      |  30 +------------------
 arch/x86/net/bpf_jit_comp.c                                      |  31 ++++++++++++++------
 include/linux/bpf.h                                              |  14 +++++++++
 include/linux/ftrace.h                                           |  22 ++++++++++++++
 include/uapi/linux/bpf.h                                         |  12 ++++++++
 kernel/bpf/btf.c                                                 |   5 ++++
 kernel/bpf/syscall.c                                             | 220 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 kernel/bpf/trampoline.c                                          |  83 ++++++++++++++++++++++++++++++++++++++---------------
 kernel/bpf/verifier.c                                            |   3 +-
 kernel/trace/fgraph.c                                            |   8 ++++--
 kernel/trace/ftrace.c                                            | 211 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------
 kernel/trace/trace_selftest.c                                    |  49 ++++++++++++++++++++++++++++++-
 samples/ftrace/Makefile                                          |   1 +
 samples/ftrace/ftrace-direct-multi.c                             |  52 +++++++++++++++++++++++++++++++++
 tools/include/uapi/linux/bpf.h                                   |  12 ++++++++
 tools/lib/bpf/bpf.c                                              |  11 ++++++-
 tools/lib/bpf/bpf.h                                              |   4 ++-
 tools/lib/bpf/btf.c                                              |  68 +++++++++++++++++++++++++++++++++++++++++++
 tools/lib/bpf/btf.h                                              |   3 ++
 tools/lib/bpf/libbpf.c                                           |  72 ++++++++++++++++++++++++++++++++++++++++++++++
 tools/testing/selftests/bpf/multi_check.h                        |  53 ++++++++++++++++++++++++++++++++++
 tools/testing/selftests/bpf/prog_tests/fentry_fexit_multi_test.c |  52 +++++++++++++++++++++++++++++++++
 tools/testing/selftests/bpf/prog_tests/fentry_multi_test.c       |  43 +++++++++++++++++++++++++++
 tools/testing/selftests/bpf/prog_tests/fexit_multi_test.c        |  44 ++++++++++++++++++++++++++++
 tools/testing/selftests/bpf/progs/fentry_fexit_multi_test.c      |  31 ++++++++++++++++++++
 tools/testing/selftests/bpf/progs/fentry_multi_test.c            |  20 +++++++++++++
 tools/testing/selftests/bpf/progs/fexit_multi_test.c             |  22 ++++++++++++++
 29 files changed, 1121 insertions(+), 135 deletions(-)
 create mode 100644 samples/ftrace/ftrace-direct-multi.c
 create mode 100644 tools/testing/selftests/bpf/multi_check.h
 create mode 100644 tools/testing/selftests/bpf/prog_tests/fentry_fexit_multi_test.c
 create mode 100644 tools/testing/selftests/bpf/prog_tests/fentry_multi_test.c
 create mode 100644 tools/testing/selftests/bpf/prog_tests/fexit_multi_test.c
 create mode 100644 tools/testing/selftests/bpf/progs/fentry_fexit_multi_test.c
 create mode 100644 tools/testing/selftests/bpf/progs/fentry_multi_test.c
 create mode 100644 tools/testing/selftests/bpf/progs/fexit_multi_test.c