From: Peter Zijlstra <peterz@infradead.org>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: 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, memxor@gmail.com, rostedt@goodmis.org,
Mykyta Yatsenko <yatsenko@meta.com>
Subject: Re: [PATCH bpf-next v11 2/6] bpf: Add bpf_prog_run_array_sleepable()
Date: Thu, 23 Apr 2026 12:00:42 +0200 [thread overview]
Message-ID: <20260423100042.GC3126523@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <DHZ4I3RWVVCU.16XRZX1HPFI8K@gmail.com>
On Tue, Apr 21, 2026 at 01:42:25PM -0700, Alexei Starovoitov wrote:
> > +static __always_inline u32
> > +bpf_prog_run_array_sleepable(const struct bpf_prog_array *array,
> > + const void *ctx, bpf_prog_run_fn run_prog)
> > +{
> > + const struct bpf_prog_array_item *item;
> > + struct bpf_prog *prog;
> > + struct bpf_run_ctx *old_run_ctx;
> > + struct bpf_trace_run_ctx run_ctx;
> > + u32 ret = 1;
> > +
> > + might_fault();
> > + RCU_LOCKDEP_WARN(!rcu_read_lock_trace_held(), "no rcu lock held");
>
> The only caller of this function is in the next patch trace_call_bpf_faultable()
> that does
> + might_fault();
> + guard(rcu_tasks_trace)();
>
> imo above two lines are redunant.
> We can defensive programming when another caller appears.
>
> > +
> > + if (unlikely(!array))
> > + return ret;
> > +
> > + migrate_disable();
> > +
> > + run_ctx.is_uprobe = false;
> > +
> > + old_run_ctx = bpf_set_run_ctx(&run_ctx.run_ctx);
> > + item = &array->items[0];
> > + while ((prog = READ_ONCE(item->prog))) {
> > + /* Skip dummy_bpf_prog placeholder (len == 0) */
> > + if (unlikely(!prog->len)) {
> > + item++;
> > + continue;
> > + }
> > +
> > + if (!prog->sleepable)
> > + rcu_read_lock();
> > +
> > + if (unlikely(!bpf_prog_get_recursion_context(prog))) {
> > + bpf_prog_inc_misses_counter(prog);
> > + bpf_prog_put_recursion_context(prog);
> > + if (!prog->sleepable)
> > + rcu_read_unlock();
>
> Why grab rcu_read_lock() and undo it?
> imo it would be cleaner and faster to do
> bpf_prog_get_recursion_context() here ...
>
> > + item++;
> > + continue;
> > + }
> > +
> > + run_ctx.bpf_cookie = item->bpf_cookie;
> > + ret &= run_prog(prog, ctx);
>
> ... and then here:
> if (!prog->sleepable) {
> guard(rcu)();
> ret &= run_prog(prog, ctx);
> } else {
> ret &= run_prog(prog, ctx);
> }
Right, but the whole thing is called bpf_prog_run_array_sleepable(), why
are we doing silly things like this instead of hard assuming things
are sleepable and calling it a day?
next prev parent reply other threads:[~2026-04-23 10:00 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-21 17:14 [PATCH bpf-next v11 0/6] bpf: Add support for sleepable tracepoint programs Mykyta Yatsenko
2026-04-21 17:14 ` [PATCH bpf-next v11 1/6] bpf: Add sleepable support for raw " Mykyta Yatsenko
2026-04-23 9:56 ` Peter Zijlstra
2026-04-23 12:39 ` Mykyta Yatsenko
2026-04-23 14:04 ` Steven Rostedt
2026-04-23 14:11 ` Kumar Kartikeya Dwivedi
2026-04-21 17:14 ` [PATCH bpf-next v11 2/6] bpf: Add bpf_prog_run_array_sleepable() Mykyta Yatsenko
2026-04-21 20:42 ` Alexei Starovoitov
2026-04-21 23:16 ` Mykyta Yatsenko
2026-04-23 10:00 ` Peter Zijlstra [this message]
2026-04-23 9:59 ` Peter Zijlstra
2026-04-21 17:14 ` [PATCH bpf-next v11 3/6] bpf: Add sleepable support for classic tracepoint programs Mykyta Yatsenko
2026-04-22 15:58 ` Steven Rostedt
2026-04-21 17:14 ` [PATCH bpf-next v11 4/6] bpf: Verifier support for sleepable " Mykyta Yatsenko
2026-04-21 17:14 ` [PATCH bpf-next v11 5/6] libbpf: Add section handlers for sleepable tracepoints Mykyta Yatsenko
2026-04-21 17:14 ` [PATCH bpf-next v11 6/6] selftests/bpf: Add tests for sleepable tracepoint programs Mykyta Yatsenko
2026-04-21 18:06 ` bot+bpf-ci
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=20260423100042.GC3126523@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--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=mykyta.yatsenko5@gmail.com \
--cc=rostedt@goodmis.org \
--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