From: Mike Bazov via B4 Relay <devnull+mikeba.sentinelone.com@kernel.org>
To: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>
Cc: Martin KaFai Lau <martin.lau@linux.dev>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Jiri Olsa <jolsa@kernel.org>,
John Fastabend <john.fastabend@gmail.com>,
Emil Tsalapatis <emil@etsalapatis.com>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
JP Kobryn <jp.kobryn@linux.dev>,
linux-trace-kernel@vger.kernel.org,
linux-kernel@vger.kernel.org,
Mike Bazov <mikeba@sentinelone.com>
Subject: [PATCH bpf-next v4 3/6] bpf: Link the async run context without writing to it
Date: Mon, 30 Nov 2026 13:54:03 +0200 [thread overview]
Message-ID: <20261130-bpf-preempt-v2-r2-v4-3-bd28389dfd64@sentinelone.com> (raw)
In-Reply-To: <20261130-bpf-preempt-v2-r2-v4-0-bd28389dfd64@sentinelone.com>
From: Mike Bazov <mikeba@sentinelone.com>
bpf_run_async_cb() links bpf_async_run_ctx with bpf_set_run_ctx(). All
CPUs share that one frame. The next patch makes bpf_set_run_ctx() write
the outer frame into the frame it links, so callbacks that run on two
CPUs at once would overwrite each other's link, and a program that runs
inside a callback would follow it into another task's stack.
Set current->bpf_ctx directly instead, so that the frame is never
written. No functional change.
Signed-off-by: Mike Bazov <mikeba@sentinelone.com>
---
kernel/bpf/helpers.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
index f7ff82548f38..7156b4f41f43 100644
--- a/kernel/bpf/helpers.c
+++ b/kernel/bpf/helpers.c
@@ -1228,9 +1228,11 @@ struct bpf_run_ctx bpf_async_run_ctx;
static void bpf_run_async_cb(struct bpf_prog *prog, bpf_callback_t callback_fn,
struct bpf_map *map, void *key, void *value)
{
- struct bpf_run_ctx *old_ctx = bpf_set_run_ctx(&bpf_async_run_ctx);
+ struct bpf_run_ctx *old_ctx = READ_ONCE(current->bpf_ctx);
struct bpf_timed_may_goto saved;
+ /* All CPUs share bpf_async_run_ctx, so link it without writing to it */
+ WRITE_ONCE(current->bpf_ctx, &bpf_async_run_ctx);
bpf_timed_may_goto_save(prog, &saved);
callback_fn((u64)(long)map, (u64)(long)key, (u64)(long)value, 0, 0);
bpf_timed_may_goto_restore(prog, &saved);
--
2.43.0
next prev parent reply other threads:[~2026-11-30 11:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 11:54 [PATCH bpf-next v4 0/6] bpf: Check recursion per task for preemptible programs Mike Bazov via B4 Relay
2026-11-30 11:54 ` [PATCH bpf-next v4 1/6] bpf: Avoid per-CPU private stack in preemptible tracing progs Mike Bazov via B4 Relay
2026-11-30 11:54 ` [PATCH bpf-next v4 2/6] bpf: Mark programs that keep per-CPU state Mike Bazov via B4 Relay
2026-11-30 11:54 ` Mike Bazov via B4 Relay [this message]
2026-11-30 11:54 ` [PATCH bpf-next v4 4/6] bpf: Check program recursion per task via bpf_ctx Mike Bazov via B4 Relay
2026-11-30 11:54 ` [PATCH bpf-next v4 5/6] bpf: Remove the per-CPU recursion counter of programs Mike Bazov via B4 Relay
2026-11-30 11:54 ` [PATCH bpf-next v4 6/6] selftests/bpf: Add preemption recursion test for tracing programs Mike Bazov via B4 Relay
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=20261130-bpf-preempt-v2-r2-v4-3-bd28389dfd64@sentinelone.com \
--to=devnull+mikeba.sentinelone.com@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=jp.kobryn@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=mathieu.desnoyers@efficios.com \
--cc=memxor@gmail.com \
--cc=mhiramat@kernel.org \
--cc=mikeba@sentinelone.com \
--cc=rostedt@goodmis.org \
--cc=song@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
all inboxes | Powered by JetHome®