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

From: Jiri Olsa <[email-masked]>
Date: Thu, 18 Nov 2021 12:24:26 +0100

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-masked]/
Cc: Steven Rostedt <[email-masked]>
---
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