From: Mykyta Yatsenko <mykyta.yatsenko5@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Martin Lau <kafai@meta.com>, Kernel Team <kernel-team@meta.com>,
Eduard <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Mykyta Yatsenko <yatsenko@meta.com>
Subject: Re: [PATCH bpf-next v6 1/6] bpf: Add sleepable support for raw tracepoint programs
Date: Tue, 24 Mar 2026 22:25:08 +0000 [thread overview]
Message-ID: <87y0jgj263.fsf@gmail.com> (raw)
In-Reply-To: <CAADnVQ+C6fJ1UpTzdYyJrookqjyOh1iGO9LqjwwFyRCf4W16+w@mail.gmail.com>
Alexei Starovoitov <alexei.starovoitov@gmail.com> writes:
> On Tue, Mar 24, 2026 at 12:03 PM Mykyta Yatsenko
> <mykyta.yatsenko5@gmail.com> wrote:
>>
>> From: Mykyta Yatsenko <yatsenko@meta.com>
>>
>> Rework __bpf_trace_run() to support sleepable BPF programs by using
>> explicit RCU flavor selection, following the uprobe_prog_run() pattern.
>>
>> For sleepable programs, use rcu_read_lock_tasks_trace() for lifetime
>> protection and add a might_fault() annotation. For non-sleepable
>> programs, use the regular rcu_read_lock(). Replace the combined
>> rcu_read_lock_dont_migrate() with separate rcu_read_lock()/
>> migrate_disable() calls, since sleepable programs need
>> rcu_read_lock_tasks_trace() instead of rcu_read_lock().
>>
>> Remove the preempt_disable_notrace/preempt_enable_notrace pair from
>> the faultable tracepoint BPF probe wrapper in bpf_probe.h, since
>> migration protection and RCU locking are now handled per-program
>> inside __bpf_trace_run().
>>
>> This prepares the runtime execution path for both BTF-based raw
>> tracepoints (tp_btf) and classic raw tracepoints (raw_tp) to support
>> sleepable BPF programs on faultable tracepoints (e.g. syscall
>> tracepoints). The verifier changes to allow loading sleepable
>> programs are in a subsequent patch.
>>
>> Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
>> ---
>> include/trace/bpf_probe.h | 2 --
>> kernel/trace/bpf_trace.c | 21 ++++++++++++++++++---
>> 2 files changed, 18 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..35ed53807cfd 100644
>> --- a/kernel/trace/bpf_trace.c
>> +++ b/kernel/trace/bpf_trace.c
>> @@ -2072,11 +2072,18 @@ void bpf_put_raw_tracepoint(struct bpf_raw_event_map *btp)
>> static __always_inline
>> void __bpf_trace_run(struct bpf_raw_tp_link *link, u64 *args)
>> {
>> + struct srcu_ctr __percpu *scp = NULL;
>> struct bpf_prog *prog = link->link.prog;
>> + bool sleepable = prog->sleepable;
>> struct bpf_run_ctx *old_run_ctx;
>> struct bpf_trace_run_ctx run_ctx;
>>
>> - rcu_read_lock_dont_migrate();
>> + if (sleepable)
>> + scp = rcu_read_lock_tasks_trace();
>> + else
>> + rcu_read_lock();
>> +
>> + migrate_disable();
>
> Pls don't sacrifice performance just to have common migrate_disable path.
>
>> if (unlikely(!bpf_prog_get_recursion_context(prog))) {
>> bpf_prog_inc_misses_counter(prog);
>> goto out;
>> @@ -2085,12 +2092,20 @@ 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 (sleepable)
>> + might_fault();
>
> why?
> might_fault() is there __BPF_DECLARE_TRACE_SYSCALL.
>
Agreed, thanks.
> pw-bot: cr
next prev parent reply other threads:[~2026-03-24 22:25 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-24 19:03 [PATCH bpf-next v6 0/6] bpf: Add support for sleepable tracepoint programs Mykyta Yatsenko
2026-03-24 19:03 ` [PATCH bpf-next v6 1/6] bpf: Add sleepable support for raw " Mykyta Yatsenko
2026-03-24 19:46 ` Alexei Starovoitov
2026-03-24 22:25 ` Mykyta Yatsenko [this message]
2026-03-24 19:03 ` [PATCH bpf-next v6 2/6] bpf: Rename bpf_prog_run_array_uprobe() to bpf_prog_run_array_sleepable() Mykyta Yatsenko
2026-03-24 19:03 ` [PATCH bpf-next v6 3/6] bpf: Add sleepable support for classic tracepoint programs Mykyta Yatsenko
2026-03-24 19:56 ` Alexei Starovoitov
2026-03-24 19:03 ` [PATCH bpf-next v6 4/6] bpf: Verifier support for sleepable " Mykyta Yatsenko
2026-03-24 19:03 ` [PATCH bpf-next v6 5/6] libbpf: Add section handlers for sleepable tracepoints Mykyta Yatsenko
2026-03-24 19:03 ` [PATCH bpf-next v6 6/6] selftests/bpf: Add tests for sleepable tracepoint programs Mykyta Yatsenko
2026-03-24 20:05 ` [PATCH bpf-next v6 0/6] bpf: Add support " Kumar Kartikeya Dwivedi
2026-03-24 22:20 ` Mykyta Yatsenko
2026-03-24 23:57 ` Alexei Starovoitov
2026-03-24 23:59 ` Alexei Starovoitov
-- strict thread matches above, loose matches on Subject: below --
2026-03-25 18:55 Mykyta Yatsenko
2026-03-25 18:55 ` [PATCH bpf-next v6 1/6] bpf: Add sleepable support for raw " Mykyta Yatsenko
2026-03-26 16:38 ` Kumar Kartikeya Dwivedi
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=87y0jgj263.fsf@gmail.com \
--to=mykyta.yatsenko5@gmail.com \
--cc=alexei.starovoitov@gmail.com \
--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=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