linux-riscv.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Menglong Dong <dongmenglong.8@bytedance.com>
To: andrii@kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev,
	eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev,
	john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com,
	haoluo@google.com, jolsa@kernel.org, agordeev@linux.ibm.com,
	borntraeger@linux.ibm.com, svens@linux.ibm.com,
	davem@davemloft.net, dsahern@kernel.org,
	dave.hansen@linux.intel.com, x86@kernel.org, rostedt@goodmis.org,
	mathieu.desnoyers@efficios.com, quentin@isovalent.com,
	bpf@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org,
	linux-s390@vger.kernel.org, netdev@vger.kernel.org,
	linux-trace-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org,
	linux-stm32@st-md-mailman.stormreply.com,
	Menglong Dong <dongmenglong.8@bytedance.com>
Subject: [PATCH bpf-next v2 0/9] bpf: make tracing program support multi-link
Date: Mon, 11 Mar 2024 17:35:17 +0800	[thread overview]
Message-ID: <20240311093526.1010158-1-dongmenglong.8@bytedance.com> (raw)

For now, the BPF program of type BPF_PROG_TYPE_TRACING is not allowed to
be attached to multiple hooks, and we have to create a BPF program for
each kernel function, for which we want to trace, even through all the
program have the same (or similar) logic. This can consume extra memory,
and make the program loading slow if we have plenty of kernel function to
trace.

In this series, we add the support to allow attaching a tracing BPF
program to multi hooks, which is similar to BPF_TRACE_KPROBE_MULTI.

In the 1st patch, we add the support to record index of the accessed
function args of the target for tracing program. Meanwhile, we add the
function btf_check_func_part_match() to compare the accessed function args
of two function prototype. This function will be used in the next commit.

In the 2nd patch, we refactor the struct modules_array to ptr_array, as
we need similar function to hold the target btf, target program and kernel
modules that we reference to in the following commit.

In the 3rd patch, we introduce the struct bpf_tramp_link_conn to be the
bridge between bpf_link and trampoline, as the releation between bpf_link
and trampoline is not one-to-one anymore.

In the 4th patch, we add the struct bpf_tramp_multi_link and
bpf_trampoline_multi_{link,unlink}_prog for multi-link of trampoline.

In the 5th patch, we add target btf to the function args of
bpf_check_attach_target(), then the caller can specify the btf to check.

The 6th patch is the main part to add multi-link supporting for tracing.
For now, only the following attach type is supported:

  BPF_TRACE_FENTRY_MULTI
  BPF_TRACE_FEXIT_MULTI
  BPF_MODIFY_RETURN_MULTI

The attach type of BPF_TRACE_RAW_TP has different link type, so we skip
this part in this series for now.

In the 7th and 8th patches, we add multi-link supporting of tracing to
libbpf. Note that we don't free btfs that we load after the bpf programs
are loaded into the kernel now if any programs of type tracing multi-link
existing, as we need to lookup the btf types during attaching.

In the 9th patch, we add the testcases for this series.

Changes since v1:
- According to the advice of Alexei, introduce multi-link for tracing
  instead of attaching a tracing program to multiple trampolines with
  creating multi instance of bpf_link.

Menglong Dong (9):
  bpf: tracing: add support to record and check the accessed args
  bpf: refactor the modules_array to ptr_array
  bpf: trampoline: introduce struct bpf_tramp_link_conn
  bpf: trampoline: introduce bpf_tramp_multi_link
  bpf: verifier: add btf to the function args of bpf_check_attach_target
  bpf: tracing: add multi-link support
  libbpf: don't free btf if program of multi-link tracing existing
  libbpf: add support for the multi-link of tracing
  selftests/bpf: add testcases for multi-link of tracing

 arch/arm64/net/bpf_jit_comp.c                 |   4 +-
 arch/riscv/net/bpf_jit_comp64.c               |   4 +-
 arch/s390/net/bpf_jit_comp.c                  |   4 +-
 arch/x86/net/bpf_jit_comp.c                   |   4 +-
 include/linux/bpf.h                           |  51 ++-
 include/linux/bpf_verifier.h                  |   1 +
 include/uapi/linux/bpf.h                      |  10 +
 kernel/bpf/bpf_struct_ops.c                   |   2 +-
 kernel/bpf/btf.c                              | 113 ++++-
 kernel/bpf/syscall.c                          | 425 +++++++++++++++++-
 kernel/bpf/trampoline.c                       |  97 +++-
 kernel/bpf/verifier.c                         |  24 +-
 kernel/trace/bpf_trace.c                      |  48 +-
 net/bpf/test_run.c                            |   3 +
 net/core/bpf_sk_storage.c                     |   2 +
 tools/bpf/bpftool/common.c                    |   3 +
 tools/include/uapi/linux/bpf.h                |  10 +
 tools/lib/bpf/bpf.c                           |  10 +
 tools/lib/bpf/bpf.h                           |   6 +
 tools/lib/bpf/libbpf.c                        | 215 ++++++++-
 tools/lib/bpf/libbpf.h                        |  16 +
 tools/lib/bpf/libbpf.map                      |   2 +
 .../selftests/bpf/bpf_testmod/bpf_testmod.c   |  49 ++
 .../bpf/prog_tests/tracing_multi_link.c       | 153 +++++++
 .../selftests/bpf/progs/tracing_multi_test.c  | 209 +++++++++
 25 files changed, 1366 insertions(+), 99 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/tracing_multi_link.c
 create mode 100644 tools/testing/selftests/bpf/progs/tracing_multi_test.c

-- 
2.39.2


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

             reply	other threads:[~2024-03-11  9:34 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-11  9:35 Menglong Dong [this message]
2024-03-11  9:35 ` [PATCH bpf-next v2 1/9] bpf: tracing: add support to record and check the accessed args Menglong Dong
2024-03-12  1:46   ` Alexei Starovoitov
2024-03-12  2:01     ` [External] " 梦龙董
2024-03-12  2:09       ` Alexei Starovoitov
2024-03-12  2:42         ` 梦龙董
2024-03-12  2:49           ` 梦龙董
2024-03-12 16:42           ` Alexei Starovoitov
2024-03-13  1:53             ` 梦龙董
2024-03-14  0:25               ` Alexei Starovoitov
2024-03-14  6:27                 ` Jiri Olsa
2024-03-15  8:17                   ` 梦龙董
2024-03-15  8:00                 ` 梦龙董
2024-03-28 14:43                   ` 梦龙董
2024-03-28 15:13                     ` Steven Rostedt
2024-03-28 23:17                       ` Alexei Starovoitov
2024-03-30  3:36                         ` 梦龙董
2024-03-29 23:28                       ` Andrii Nakryiko
2024-03-29 23:28                         ` Andrii Nakryiko
2024-03-29 23:28                         ` Andrii Nakryiko
2024-03-30  4:16                         ` 梦龙董
2024-03-30 12:27                         ` Steven Rostedt
2024-03-30 17:52                           ` Jiri Olsa
2024-03-31  2:34                             ` Andrii Nakryiko
2024-03-31  2:34                               ` Andrii Nakryiko
2024-03-31  2:34                               ` Andrii Nakryiko
2024-03-30  3:18                       ` 梦龙董
2024-03-30 19:37                         ` Steven Rostedt
2024-04-01  2:28                           ` 梦龙董
2024-04-01 15:59                             ` Steven Rostedt
2024-03-11  9:35 ` [PATCH bpf-next v2 2/9] bpf: refactor the modules_array to ptr_array Menglong Dong
2024-03-12  1:48   ` Alexei Starovoitov
2024-03-12  1:53     ` [External] " 梦龙董
2024-03-11  9:35 ` [PATCH bpf-next v2 3/9] bpf: trampoline: introduce struct bpf_tramp_link_conn Menglong Dong
2024-03-11  9:35 ` [PATCH bpf-next v2 4/9] bpf: trampoline: introduce bpf_tramp_multi_link Menglong Dong
2024-03-11  9:35 ` [PATCH bpf-next v2 5/9] bpf: verifier: add btf to the function args of bpf_check_attach_target Menglong Dong
2024-03-12  1:51   ` Alexei Starovoitov
2024-03-12  3:13     ` [External] " 梦龙董
2024-03-11  9:35 ` [PATCH bpf-next v2 6/9] bpf: tracing: add multi-link support Menglong Dong
2024-03-11 18:59   ` kernel test robot
2024-03-11 21:36   ` kernel test robot
2024-03-11  9:35 ` [PATCH bpf-next v2 7/9] libbpf: don't free btf if program of multi-link tracing existing Menglong Dong
2024-03-12  1:55   ` Alexei Starovoitov
2024-03-12  2:05     ` [External] " 梦龙董
2024-03-12  2:13       ` Alexei Starovoitov
2024-03-12  2:56         ` 梦龙董
2024-03-11  9:35 ` [PATCH bpf-next v2 8/9] libbpf: add support for the multi-link of tracing Menglong Dong
2024-03-11 15:29   ` Quentin Monnet
2024-03-12  1:43     ` [External] " 梦龙董
2024-03-12  1:56   ` Alexei Starovoitov
2024-03-12  2:44     ` [External] " 梦龙董
2024-03-12 16:11       ` Alexei Starovoitov
2024-03-13  1:14         ` 梦龙董
2024-03-11  9:35 ` [PATCH bpf-next v2 9/9] selftests/bpf: add testcases for " Menglong Dong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240311093526.1010158-1-dongmenglong.8@bytedance.com \
    --to=dongmenglong.8@bytedance.com \
    --cc=agordeev@linux.ibm.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=borntraeger@linux.ibm.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=dave.hansen@linux.intel.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=netdev@vger.kernel.org \
    --cc=quentin@isovalent.com \
    --cc=rostedt@goodmis.org \
    --cc=sdf@google.com \
    --cc=song@kernel.org \
    --cc=svens@linux.ibm.com \
    --cc=x86@kernel.org \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).