BPF List
 help / color / mirror / Atom feed
From: Andrea Righi <arighi@nvidia.com>
To: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Cc: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Martin KaFai Lau <martin.lau@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>, Tejun Heo <tj@kernel.org>,
	kkd@meta.com, kernel-team@meta.com
Subject: Re: [PATCH bpf-next v1 2/3] bpf: Add support for KF_RET_RCU flag
Date: Mon, 15 Sep 2025 10:02:56 +0200	[thread overview]
Message-ID: <aMfIMOF17vFVrfTt@gpd4> (raw)
In-Reply-To: <CAP01T74DSRE96FYRCMLghkFJdNPgi-PhoOycQ2fXyYhUF5ngBw@mail.gmail.com>

On Mon, Sep 15, 2025 at 09:13:15AM +0200, Kumar Kartikeya Dwivedi wrote:
> On Mon, 15 Sept 2025 at 08:14, Andrea Righi <arighi@nvidia.com> wrote:
> >
> > Hi Kumar,
> >
> > thanks for looking at this! Comment below.
> >
> > On Mon, Sep 15, 2025 at 02:47:30AM +0000, Kumar Kartikeya Dwivedi wrote:
> > > Add a kfunc annotation 'KF_RET_RCU' to signal that the return type must
> > > be marked MEM_RCU, to return objects that are RCU protected. Naturally,
> > > this must imply that the kfunc is invoked in an RCU critical section,
> > > and thus the presence of this flag implies the presence of the
> > > KF_RCU_PROTECTED flag. Upcoming kfunc scx_bpf_cpu_curr() [0] will be
> > > made to make use of this flag.
> >
> > I'm not sure we actually need two separate annotations, I can't think of a
> > case where KF_RCU_PROTECTED would be useful without also having KF_RET_RCU.
> >
> > What I mean is: if the kfunc is only meant to be called inside an RCU
> > critical section, but doesn't return an RCU-protected pointer, then we can
> > simply add rcu_read_lock/unlock() internally in the kfunc. And for kfuncs
> > that take RCU-protected arguments we already have KF_RCU.
> >
> > So it seems sufficient to have a single annotation that implements the
> > semantic "this kfunc returns an RCU-protected pointer".
> 
> Yeah, that seems reasonable in general, but we already have iterator
> APIs (bpf_iter_task_{new,next,destroy}()) that collectively require
> RCU CS to be open throughout the three calls. That's why I just
> cleaned up the internal logic for KF_RCU_PROTECTED and made KF_RET_RCU
> as what you're suggesting (i.e., fold KF_RCU_PROTECTED into it), which
> I assume will be most useful for the majority of kfuncs that are not
> iterators.

Right, my suggestion was to fold the KF_RET_RCU semantics into
KF_RCU_PROTECTED, even if the kfunc doesn't return anything (assuming it's
possible). Then annotate both iterators and kfuncs that require RCU as
KF_RCU_PROTECTED. This should handle both, right?

In any case, I don't have a strong opinion on that and I'm also happy with
KF_RCU_RET and KF_RCU_PROTECTED if it gives more flexibility.

Thanks,
-Andrea

  reply	other threads:[~2025-09-15  8:03 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-15  2:47 [PATCH bpf-next v1 0/3] Update KF_RCU_PROTECTED, add KF_RET_RCU Kumar Kartikeya Dwivedi
2025-09-15  2:47 ` [PATCH bpf-next v1 1/3] bpf: Enforce RCU protection for KF_RCU_PROTECTED Kumar Kartikeya Dwivedi
2025-09-15  2:47 ` [PATCH bpf-next v1 2/3] bpf: Add support for KF_RET_RCU flag Kumar Kartikeya Dwivedi
2025-09-15  6:14   ` Andrea Righi
2025-09-15  7:13     ` Kumar Kartikeya Dwivedi
2025-09-15  8:02       ` Andrea Righi [this message]
2025-09-15 17:55         ` Alexei Starovoitov
2025-09-17  2:18           ` Kumar Kartikeya Dwivedi
2025-09-15  2:47 ` [PATCH bpf-next v1 3/3] selftests/bpf: Add tests for KF_RET_RCU Kumar Kartikeya Dwivedi
2025-09-15 12:20 ` [PATCH bpf-next v1 0/3] Update KF_RCU_PROTECTED, add KF_RET_RCU Andrea Righi

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=aMfIMOF17vFVrfTt@gpd4 \
    --to=arighi@nvidia.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=kernel-team@meta.com \
    --cc=kkd@meta.com \
    --cc=martin.lau@kernel.org \
    --cc=memxor@gmail.com \
    --cc=tj@kernel.org \
    /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