From: Jiri Olsa <jolsa@kernel.org>
To: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>
Cc: bpf@vger.kernel.org, Martin KaFai Lau <kafai@fb.com>,
Song Liu <songliubraving@fb.com>, Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@chromium.org>,
Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
"Masami Hiramatsu (Google)" <mhiramat@kernel.org>,
Viktor Malik <vmalik@redhat.com>
Subject: [PATCH RFC bpf-next 3/4] libbpf: Add return_prog_fd to kprobe multi opts
Date: Wed, 7 Feb 2024 16:35:49 +0100 [thread overview]
Message-ID: <20240207153550.856536-4-jolsa@kernel.org> (raw)
In-Reply-To: <20240207153550.856536-1-jolsa@kernel.org>
Adding support to specify return prog file descriptor in struct
bpf_kprobe_multi_opts.
When the return_prog bool is set true the return_prog_fd is used
as bpf program to be executed for the return probe.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
tools/lib/bpf/bpf.c | 1 +
tools/lib/bpf/bpf.h | 1 +
tools/lib/bpf/libbpf.c | 5 +++++
tools/lib/bpf/libbpf.h | 6 +++++-
4 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index 97ec005c3c47..9f296957bd30 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -771,6 +771,7 @@ int bpf_link_create(int prog_fd, int target_fd,
attr.link_create.kprobe_multi.syms = ptr_to_u64(OPTS_GET(opts, kprobe_multi.syms, 0));
attr.link_create.kprobe_multi.addrs = ptr_to_u64(OPTS_GET(opts, kprobe_multi.addrs, 0));
attr.link_create.kprobe_multi.cookies = ptr_to_u64(OPTS_GET(opts, kprobe_multi.cookies, 0));
+ attr.link_create.kprobe_multi.return_prog_fd = OPTS_GET(opts, kprobe_multi.return_prog_fd, 0);
if (!OPTS_ZEROED(opts, kprobe_multi))
return libbpf_err(-EINVAL);
break;
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
index f866e98b2436..e04a14134a21 100644
--- a/tools/lib/bpf/bpf.h
+++ b/tools/lib/bpf/bpf.h
@@ -399,6 +399,7 @@ struct bpf_link_create_opts {
const char **syms;
const unsigned long *addrs;
const __u64 *cookies;
+ __u32 return_prog_fd;
} kprobe_multi;
struct {
__u32 flags;
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 01f407591a92..022a68b9fe83 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -11073,6 +11073,11 @@ bpf_program__attach_kprobe_multi_opts(const struct bpf_program *prog,
lopts.kprobe_multi.cnt = cnt;
lopts.kprobe_multi.flags = retprobe ? BPF_F_KPROBE_MULTI_RETURN : 0;
+ if (OPTS_GET(opts, return_prog, false)) {
+ lopts.kprobe_multi.return_prog_fd = OPTS_GET(opts, return_prog_fd, 0);
+ lopts.kprobe_multi.flags |= BPF_F_KPROBE_MULTI_RETURN_PROG;
+ }
+
link = calloc(1, sizeof(*link));
if (!link) {
err = -ENOMEM;
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 5723cbbfcc41..d77b953009d6 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -539,10 +539,14 @@ struct bpf_kprobe_multi_opts {
size_t cnt;
/* create return kprobes */
bool retprobe;
+ /* attach return program (specified by return_prog_fd file descriptor) */
+ bool return_prog;
+ /* return program fd */
+ int return_prog_fd;
size_t :0;
};
-#define bpf_kprobe_multi_opts__last_field retprobe
+#define bpf_kprobe_multi_opts__last_field return_prog_fd
LIBBPF_API struct bpf_link *
bpf_program__attach_kprobe_multi_opts(const struct bpf_program *prog,
--
2.43.0
next prev parent reply other threads:[~2024-02-07 15:36 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-07 15:35 [PATCH RFC bpf-next 0/4] bpf: Add support to attach return prog in kprobe multi Jiri Olsa
2024-02-07 15:35 ` [PATCH RFC bpf-next 1/4] fprobe: Add entry/exit callbacks types Jiri Olsa
2024-02-13 15:35 ` Masami Hiramatsu
2024-02-15 9:08 ` Jiri Olsa
2024-02-07 15:35 ` [PATCH RFC bpf-next 2/4] bpf: Add return prog to kprobe multi Jiri Olsa
2024-02-08 19:05 ` Alexei Starovoitov
2024-02-10 15:29 ` Jiri Olsa
2024-02-07 15:35 ` Jiri Olsa [this message]
2024-02-07 15:35 ` [PATCH RFC bpf-next 4/4] selftests/bpf: Add kprobe multi return prog test Jiri Olsa
2024-02-08 19:35 ` [PATCH RFC bpf-next 0/4] bpf: Add support to attach return prog in kprobe multi Andrii Nakryiko
2024-02-10 15:31 ` Jiri Olsa
2024-02-13 4:06 ` Andrii Nakryiko
2024-02-13 12:09 ` Jiri Olsa
2024-02-13 18:20 ` Andrii Nakryiko
2024-02-13 21:09 ` Jiri Olsa
2024-02-14 20:55 ` Jiri Olsa
2024-02-15 16:27 ` Steven Rostedt
2024-02-16 15:03 ` Jiri Olsa
2024-02-19 11:20 ` Viktor Malik
2024-02-19 12:43 ` Jiri Olsa
2024-02-23 9:32 ` Jiri Olsa
2024-02-29 0:43 ` Andrii Nakryiko
2024-02-29 1:25 ` Andrii Nakryiko
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=20240207153550.856536-4-jolsa@kernel.org \
--to=jolsa@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@chromium.org \
--cc=mhiramat@kernel.org \
--cc=sdf@google.com \
--cc=songliubraving@fb.com \
--cc=vmalik@redhat.com \
--cc=yhs@fb.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.