hi, sending new version of batch attach support, previous post is in here [1]. The previous post could not assign multi trampoline on top of regular trampolines. This patchset is trying to address that, plus it has other fixes from last post. 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-27) that add support to attach BPF program to multiple functions The current functionality in nutshell: - allows to create 'multi trampoline' and use it to attach single program over multiple functions - it's possible to attach 'multi trampoline' on top of functions with attached trampoline - once 'multi trampoline' is created, the functions are locked and we: - do not allow to attach another 'multi trampoline' that intersects partially with already attached multi trampoline - do not allow to attach another standard trampoline on any function from 'multi trampoline' - allow to reuse 'multi trampoline' and attach another multi program in it These limitations are enforced to keep the implementation simple, because having multi trampolines to intersect would bring more complexity plus more ftrace direct API changes. It'd be probably possible allowing to attach another standard trampoline to 'multi trampoline' if needed. v4 other changes from previous review: - more detailed changelogs in several patches - removed 'ip' argument assumption in verifier code, because we now have bpf_get_func_ip helper - moved 'multi_func' under other bools in bpf.h [Yonghong] - used static linker in selftests [Andrii] - added more tests - added btf__find_by_glob_kind for simplified glob matching instead of the previous glibc glob matching [Andrii] - used '__ksym' instead of resolving test functions [Andrii] - I kept the single BPF_F_MULTI_FUNC flag instead of adding new multi prog type, because it'd be more complex - removed superfluous BPF_PROG_TYPE_TRACING/multi_func check from check_multi_prog_type [Yonghong] - kept link_create.iter_info_len as BPF_LINK_CREATE_LAST_FIELD [Yonghong] - define FTRACE_OPS_GRAPH_STUB 0 to make code look sane [Andrii] - removed BPF_LINK_UPDATE interface 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/20210605111034.1810858-1-jolsa@xxxxxxxxxx/ --- Jiri Olsa (25): 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: Add support to load multi func tracing program bpf: Add struct bpf_tramp_node layer bpf: Factor out bpf_trampoline_init function bpf: Factor out __bpf_trampoline_lookup function bpf: Factor out __bpf_trampoline_put function bpf: Change bpf_trampoline_get to return error pointer bpf, x64: Allow to use caller address from stack bpf: Add bpf_trampoline_multi_get/put functions bpf: Add multi trampoline attach support bpf, x64: Store properly return value for trampoline with multi func programs bpf: Attach multi trampoline with ftrace_ops libbpf: Add btf__find_by_glob_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: Add mixed multi func test selftests/bpf: Add attach multi func test selftests/bpf: Add ret_mod multi func 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/Makefile | 7 +++ arch/x86/boot/compressed/Makefile | 4 ++ 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 | 53 +++++++++++++++---- drivers/firmware/efi/libstub/Makefile | 3 ++ include/linux/bpf.h | 44 ++++++++++++++-- include/linux/ftrace.h | 22 ++++++++ include/uapi/linux/bpf.h | 12 +++++ kernel/bpf/core.c | 2 + kernel/bpf/syscall.c | 163 +++++++++++++++++++++++++++++++++++++++++++++++++++++---- kernel/bpf/trampoline.c | 400 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------- kernel/bpf/verifier.c | 7 +-- kernel/trace/fgraph.c | 6 ++- kernel/trace/ftrace.c | 214 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------- 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 | 8 +++ tools/lib/bpf/bpf.h | 6 ++- tools/lib/bpf/btf.c | 80 ++++++++++++++++++++++++++++ tools/lib/bpf/btf.h | 3 ++ tools/lib/bpf/libbpf.c | 72 +++++++++++++++++++++++++ tools/testing/selftests/bpf/Makefile | 8 ++- tools/testing/selftests/bpf/prog_tests/modify_return.c | 114 ++++++++++++++++++++++++++++++++++++++-- tools/testing/selftests/bpf/prog_tests/multi_attach_check_test.c | 115 ++++++++++++++++++++++++++++++++++++++++ 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/multi_attach_check.c | 36 +++++++++++++ tools/testing/selftests/bpf/progs/multi_attach_check_extra1.c | 12 +++++ tools/testing/selftests/bpf/progs/multi_attach_check_extra2.c | 12 +++++ tools/testing/selftests/bpf/progs/multi_check.c | 85 ++++++++++++++++++++++++++++++ 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 ++++++ 41 files changed, 1799 insertions(+), 165 deletions(-) create mode 100644 samples/ftrace/ftrace-direct-multi.c create mode 100644 tools/testing/selftests/bpf/prog_tests/multi_attach_check_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/multi_attach_check.c create mode 100644 tools/testing/selftests/bpf/progs/multi_attach_check_extra1.c create mode 100644 tools/testing/selftests/bpf/progs/multi_attach_check_extra2.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