From: Puranjay Mohan <puranjay@kernel.org>
To: Mykyta Yatsenko <mykyta.yatsenko5@gmail.com>,
bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org,
daniel@iogearbox.net, kafai@meta.com, kernel-team@meta.com,
eddyz87@gmail.com
Cc: Mykyta Yatsenko <yatsenko@meta.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>
Subject: Re: [PATCH bpf-next v3 1/4] bpf: Add sleepable execution path for raw tracepoint programs
Date: Wed, 11 Mar 2026 23:39:52 +0000 [thread overview]
Message-ID: <m2jyvij5pz.fsf@kernel.org> (raw)
In-Reply-To: <20260311-sleepable_tracepoints-v3-1-3e9bbde5bd22@meta.com>
Mykyta Yatsenko <mykyta.yatsenko5@gmail.com> writes:
> From: Mykyta Yatsenko <yatsenko@meta.com>
>
> Modify __bpf_trace_run() to support both sleepable and non-sleepable
> BPF programs. When the program is sleepable:
>
> - Call might_fault() to annotate the faultable context
> - Use migrate_disable()/migrate_enable() instead of
> rcu_read_lock()/rcu_read_unlock() to allow sleeping while
> still protecting percpu data access
> - The outer rcu_tasks_trace lock is already held by the faultable
> tracepoint callback (__DECLARE_TRACE_SYSCALL), providing lifetime
> protection for the BPF program
>
> For non-sleepable programs, rcu_read_lock_dont_migrate() is replaced
> with explicit migrate_disable()/rcu_read_lock() pairing.
>
> Remove preempt_disable_notrace()/preempt_enable_notrace() from
> __BPF_DECLARE_TRACE_SYSCALL. Per-CPU protection and RCU locking are
> now managed per-program inside __bpf_trace_run().
>
> Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
> Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
Acked-by: Puranjay Mohan <puranjay@kernel.org>
> ---
> include/trace/bpf_probe.h | 2 --
> kernel/trace/bpf_trace.c | 13 ++++++++++---
> 2 files changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/include/trace/bpf_probe.h b/include/trace/bpf_probe.h
> index 9391d54d3f12..d1de8f9aa07f 100644
> --- a/include/trace/bpf_probe.h
> +++ b/include/trace/bpf_probe.h
> @@ -58,9 +58,7 @@ static notrace void \
> __bpf_trace_##call(void *__data, proto) \
> { \
> might_fault(); \
> - preempt_disable_notrace(); \
> CONCATENATE(bpf_trace_run, COUNT_ARGS(args))(__data, CAST_TO_U64(args)); \
> - preempt_enable_notrace(); \
> }
>
> #undef DECLARE_EVENT_SYSCALL_CLASS
> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> index 0b040a417442..3688a7e115d1 100644
> --- a/kernel/trace/bpf_trace.c
> +++ b/kernel/trace/bpf_trace.c
> @@ -2076,7 +2076,7 @@ void __bpf_trace_run(struct bpf_raw_tp_link *link, u64 *args)
> struct bpf_run_ctx *old_run_ctx;
> struct bpf_trace_run_ctx run_ctx;
>
> - rcu_read_lock_dont_migrate();
> + migrate_disable();
> if (unlikely(!bpf_prog_get_recursion_context(prog))) {
> bpf_prog_inc_misses_counter(prog);
> goto out;
> @@ -2085,12 +2085,19 @@ void __bpf_trace_run(struct bpf_raw_tp_link *link, u64 *args)
> run_ctx.bpf_cookie = link->cookie;
> old_run_ctx = bpf_set_run_ctx(&run_ctx.run_ctx);
>
> - (void) bpf_prog_run(prog, args);
> + if (prog->sleepable) {
> + might_fault();
> + (void)bpf_prog_run(prog, args);
> + } else {
> + rcu_read_lock();
> + (void)bpf_prog_run(prog, args);
> + rcu_read_unlock();
> + }
>
> bpf_reset_run_ctx(old_run_ctx);
> out:
> bpf_prog_put_recursion_context(prog);
> - rcu_read_unlock_migrate();
> + migrate_enable();
> }
>
> #define UNPACK(...) __VA_ARGS__
>
> --
> 2.52.0
next prev parent reply other threads:[~2026-03-11 23:39 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-11 18:22 [PATCH bpf-next v3 0/4] bpf: Add support for sleepable raw tracepoint programs Mykyta Yatsenko
2026-03-11 18:22 ` [PATCH bpf-next v3 1/4] bpf: Add sleepable execution path for " Mykyta Yatsenko
2026-03-11 19:25 ` Emil Tsalapatis
2026-03-11 23:39 ` Puranjay Mohan [this message]
2026-03-12 20:51 ` Andrii Nakryiko
2026-03-11 18:22 ` [PATCH bpf-next v3 2/4] bpf: Verifier support for sleepable " Mykyta Yatsenko
2026-03-11 18:49 ` Emil Tsalapatis
2026-03-11 18:53 ` bot+bpf-ci
2026-03-11 23:07 ` Kumar Kartikeya Dwivedi
2026-03-12 5:50 ` Leon Hwang
2026-03-12 6:21 ` Menglong Dong
2026-03-12 6:43 ` Leon Hwang
2026-03-11 23:08 ` Kumar Kartikeya Dwivedi
2026-03-11 23:40 ` Puranjay Mohan
2026-03-12 20:59 ` Andrii Nakryiko
2026-03-11 18:22 ` [PATCH bpf-next v3 3/4] libbpf: Add tp_btf.s section handler for sleepable raw tracepoints Mykyta Yatsenko
2026-03-11 18:54 ` Emil Tsalapatis
2026-03-11 23:40 ` Puranjay Mohan
2026-03-12 20:59 ` Andrii Nakryiko
2026-03-11 18:22 ` [PATCH bpf-next v3 4/4] selftests/bpf: Add tests for sleepable raw tracepoint programs Mykyta Yatsenko
2026-03-11 19:12 ` Emil Tsalapatis
2026-03-11 23:41 ` Puranjay Mohan
2026-03-12 21:03 ` 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=m2jyvij5pz.fsf@kernel.org \
--to=puranjay@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=kafai@meta.com \
--cc=kernel-team@meta.com \
--cc=memxor@gmail.com \
--cc=mykyta.yatsenko5@gmail.com \
--cc=yatsenko@meta.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