linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@kernel.org>
To: Oleg Nesterov <oleg@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	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@fomichev.me>, Hao Luo <haoluo@google.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: [PATCHv6 bpf-next 06/16] bpf: Add support for uprobe multi session context
Date: Thu, 10 Oct 2024 22:09:47 +0200	[thread overview]
Message-ID: <20241010200957.2750179-7-jolsa@kernel.org> (raw)
In-Reply-To: <20241010200957.2750179-1-jolsa@kernel.org>

Placing bpf_session_run_ctx layer in between bpf_run_ctx and
bpf_uprobe_multi_run_ctx, so the session data can be retrieved
from uprobe_multi link.

Plus granting session kfuncs access to uprobe session programs.

Acked-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 kernel/trace/bpf_trace.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 5f10994376d0..01868039d7bc 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -3098,7 +3098,7 @@ struct bpf_uprobe_multi_link {
 };
 
 struct bpf_uprobe_multi_run_ctx {
-	struct bpf_run_ctx run_ctx;
+	struct bpf_session_run_ctx session_ctx;
 	unsigned long entry_ip;
 	struct bpf_uprobe *uprobe;
 };
@@ -3211,16 +3211,22 @@ static const struct bpf_link_ops bpf_uprobe_multi_link_lops = {
 
 static int uprobe_prog_run(struct bpf_uprobe *uprobe,
 			   unsigned long entry_ip,
-			   struct pt_regs *regs)
+			   struct pt_regs *regs,
+			   bool is_return, void *data)
 {
 	struct bpf_uprobe_multi_link *link = uprobe->link;
 	struct bpf_uprobe_multi_run_ctx run_ctx = {
+		.session_ctx = {
+			.is_return = is_return,
+			.data = data,
+		},
 		.entry_ip = entry_ip,
 		.uprobe = uprobe,
 	};
 	struct bpf_prog *prog = link->link.prog;
 	bool sleepable = prog->sleepable;
 	struct bpf_run_ctx *old_run_ctx;
+	int err;
 
 	if (link->task && !same_thread_group(current, link->task))
 		return 0;
@@ -3232,8 +3238,8 @@ static int uprobe_prog_run(struct bpf_uprobe *uprobe,
 
 	migrate_disable();
 
-	old_run_ctx = bpf_set_run_ctx(&run_ctx.run_ctx);
-	bpf_prog_run(link->link.prog, regs);
+	old_run_ctx = bpf_set_run_ctx(&run_ctx.session_ctx.run_ctx);
+	err = bpf_prog_run(link->link.prog, regs);
 	bpf_reset_run_ctx(old_run_ctx);
 
 	migrate_enable();
@@ -3242,7 +3248,7 @@ static int uprobe_prog_run(struct bpf_uprobe *uprobe,
 		rcu_read_unlock_trace();
 	else
 		rcu_read_unlock();
-	return 0;
+	return err;
 }
 
 static bool
@@ -3262,7 +3268,7 @@ uprobe_multi_link_handler(struct uprobe_consumer *con, struct pt_regs *regs,
 	int ret;
 
 	uprobe = container_of(con, struct bpf_uprobe, consumer);
-	ret = uprobe_prog_run(uprobe, instruction_pointer(regs), regs);
+	ret = uprobe_prog_run(uprobe, instruction_pointer(regs), regs, false, data);
 	if (uprobe->session)
 		return ret ? UPROBE_HANDLER_IGNORE : 0;
 	return 0;
@@ -3275,7 +3281,7 @@ uprobe_multi_link_ret_handler(struct uprobe_consumer *con, unsigned long func, s
 	struct bpf_uprobe *uprobe;
 
 	uprobe = container_of(con, struct bpf_uprobe, consumer);
-	uprobe_prog_run(uprobe, func, regs);
+	uprobe_prog_run(uprobe, func, regs, true, data);
 	return 0;
 }
 
@@ -3283,7 +3289,8 @@ static u64 bpf_uprobe_multi_entry_ip(struct bpf_run_ctx *ctx)
 {
 	struct bpf_uprobe_multi_run_ctx *run_ctx;
 
-	run_ctx = container_of(current->bpf_ctx, struct bpf_uprobe_multi_run_ctx, run_ctx);
+	run_ctx = container_of(current->bpf_ctx, struct bpf_uprobe_multi_run_ctx,
+			       session_ctx.run_ctx);
 	return run_ctx->entry_ip;
 }
 
@@ -3291,7 +3298,8 @@ static u64 bpf_uprobe_multi_cookie(struct bpf_run_ctx *ctx)
 {
 	struct bpf_uprobe_multi_run_ctx *run_ctx;
 
-	run_ctx = container_of(current->bpf_ctx, struct bpf_uprobe_multi_run_ctx, run_ctx);
+	run_ctx = container_of(current->bpf_ctx, struct bpf_uprobe_multi_run_ctx,
+			       session_ctx.run_ctx);
 	return run_ctx->uprobe->cookie;
 }
 
@@ -3485,7 +3493,7 @@ static int bpf_kprobe_multi_filter(const struct bpf_prog *prog, u32 kfunc_id)
 	if (!btf_id_set8_contains(&kprobe_multi_kfunc_set_ids, kfunc_id))
 		return 0;
 
-	if (!is_kprobe_session(prog))
+	if (!is_kprobe_session(prog) && !is_uprobe_session(prog))
 		return -EACCES;
 
 	return 0;
-- 
2.46.2


  parent reply	other threads:[~2024-10-10 20:11 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-10 20:09 [PATCHv6 bpf-next,perf/core 00/16] uprobe, bpf: Add session support Jiri Olsa
2024-10-10 20:09 ` [PATCHv6 perf/core 01/16] uprobe: Add data pointer to consumer handlers Jiri Olsa
2024-10-15 22:24   ` Masami Hiramatsu
2024-10-16  6:41     ` Jiri Olsa
2024-10-10 20:09 ` [PATCHv6 perf/core 02/16] uprobe: Add support for session consumer Jiri Olsa
2024-10-11 11:27   ` Oleg Nesterov
2024-10-16  0:07   ` Masami Hiramatsu
2024-10-10 20:09 ` [PATCHv6 bpf-next 03/16] bpf: Allow return values 0 and 1 for kprobe session Jiri Olsa
2024-10-11  2:19   ` Andrii Nakryiko
2024-10-10 20:09 ` [PATCHv6 bpf-next 04/16] bpf: Force uprobe bpf program to always return 0 Jiri Olsa
2024-10-11  2:20   ` Andrii Nakryiko
2024-10-10 20:09 ` [PATCHv6 bpf-next 05/16] bpf: Add support for uprobe multi session attach Jiri Olsa
2024-10-10 20:09 ` Jiri Olsa [this message]
2024-10-10 20:09 ` [PATCHv6 bpf-next 07/16] libbpf: " Jiri Olsa
2024-10-11  2:21   ` Andrii Nakryiko
2024-10-10 20:09 ` [PATCHv6 bpf-next 08/16] selftests/bpf: Add uprobe session test Jiri Olsa
2024-10-11  2:22   ` Andrii Nakryiko
2024-10-10 20:09 ` [PATCHv6 bpf-next 09/16] selftests/bpf: Add uprobe session cookie test Jiri Olsa
2024-10-10 20:09 ` [PATCHv6 bpf-next 10/16] selftests/bpf: Add uprobe session recursive test Jiri Olsa
2024-10-10 20:09 ` [PATCHv6 bpf-next 11/16] selftests/bpf: Add uprobe session verifier test for return value Jiri Olsa
2024-10-11  2:23   ` Andrii Nakryiko
2024-10-10 20:09 ` [PATCHv6 bpf-next 12/16] selftests/bpf: Add kprobe " Jiri Olsa
2024-10-11  2:24   ` Andrii Nakryiko
2024-10-10 20:09 ` [PATCHv6 bpf-next 13/16] selftests/bpf: Add uprobe session single consumer test Jiri Olsa
2024-10-11  2:25   ` Andrii Nakryiko
2024-10-11 11:33     ` Jiri Olsa
2024-10-10 20:09 ` [PATCHv6 bpf-next 14/16] selftests/bpf: Scale down uprobe multi " Jiri Olsa
2024-10-11  2:27   ` Andrii Nakryiko
2024-10-11 11:36     ` Jiri Olsa
2024-10-10 20:09 ` [PATCHv6 bpf-next 15/16] selftests/bpf: Add uprobe sessions to " Jiri Olsa
2024-10-11  2:30   ` Andrii Nakryiko
2024-10-11 11:36     ` Jiri Olsa
2024-10-10 20:09 ` [PATCHv6 bpf-next 16/16] selftests/bpf: Add threads " Jiri Olsa
2024-10-11  2:35   ` 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=20241010200957.2750179-7-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=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=oleg@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=sdf@fomichev.me \
    --cc=songliubraving@fb.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 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).