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 v3 0/2] Update KF_RCU_PROTECTED
Date: Wed, 17 Sep 2025 10:27:39 +0200	[thread overview]
Message-ID: <aMpw-yi-dmhox3h4@gpd4> (raw)
In-Reply-To: <20250917032755.4068726-1-memxor@gmail.com>

On Wed, Sep 17, 2025 at 03:27:53AM +0000, Kumar Kartikeya Dwivedi wrote:
> Currently, KF_RCU_PROTECTED only applies to iterator APIs and that too
> in a convoluted fashion: the presence of this flag on the kfunc is used
> to set MEM_RCU in iterator type, and the lack of RCU protection results
> in an error only later, once next() or destroy() methods are invoked on
> the iterator. While there is no bug, this is certainly a bit unintuitive,
> and makes the enforcement of the flag iterator specific.
> 
> In the interest of making this flag useful for other upcoming kfuncs,
> e.g. scx_bpf_cpu_curr() [0][1], add enforcement for invoking the kfunc
> in an RCU critical section in general.
> 
> In addition to this, the aforementioned kfunc also needs to return an
> RCU protected pointer, which currently has no generic kfunc flag or
> annotation. Add such a flag as well while we are at it.
> 
>   [0]: https://lore.kernel.org/all/20250903212311.369697-3-christian.loehle@arm.com
>   [1]: https://lore.kernel.org/all/20250909195709.92669-1-arighi@nvidia.com

Everything looks good from a sched_ext perspective.

I've also tested this with the new scx_bpf_cpu_curr() kfunc, marked as
KF_RCU_PROTECTED, and everything seems to work as expected.

Reviewed-by: Andrea Righi <arighi@nvidia.com>

Thanks,
-Andrea

> 
> Changelog:
> ----------
> v2 -> v3
> v2: https://lore.kernel.org/bpf/20250917032014.4060112-1-memxor@gmail.com
> 
>  * Add back lost hunk reworking documentation for KF_RCU_PROTECTED.
> 
> v1 -> v2
> v1: https://lore.kernel.org/bpf/20250915024731.1494251-1-memxor@gmail.com
> 
>  * Drop KF_RET_RCU and fold change into KF_RCU_PROTECTED. (Andrea, Alexei)
>  * Update tests for non-struct pointer return values with KF_RCU_PROTECTED.
> 
> Kumar Kartikeya Dwivedi (2):
>   bpf: Enforce RCU protection for KF_RCU_PROTECTED
>   selftests/bpf: Add tests for KF_RCU_PROTECTED
> 
>  Documentation/bpf/kfuncs.rst                  | 19 +++++++-
>  kernel/bpf/verifier.c                         | 10 ++++
>  .../selftests/bpf/progs/cgroup_read_xattr.c   |  2 +-
>  .../selftests/bpf/progs/iters_task_failure.c  |  4 +-
>  .../selftests/bpf/progs/iters_testmod.c       | 46 +++++++++++++++++++
>  .../selftests/bpf/test_kmods/bpf_testmod.c    | 12 +++++
>  .../bpf/test_kmods/bpf_testmod_kfunc.h        |  2 +
>  7 files changed, 91 insertions(+), 4 deletions(-)
> 
> 
> base-commit: b13448dd64e27752fad252cec7da1a50ab9f0b6f
> -- 
> 2.51.0
> 

  parent reply	other threads:[~2025-09-17  8:27 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-17  3:27 [PATCH bpf-next v3 0/2] Update KF_RCU_PROTECTED Kumar Kartikeya Dwivedi
2025-09-17  3:27 ` [PATCH bpf-next v3 1/2] bpf: Enforce RCU protection for KF_RCU_PROTECTED Kumar Kartikeya Dwivedi
2025-09-18 21:00   ` Eduard Zingerman
2025-09-18 21:37     ` Kumar Kartikeya Dwivedi
2025-09-18 21:47       ` Eduard Zingerman
2025-09-18 21:59         ` Kumar Kartikeya Dwivedi
2025-09-18 22:02           ` Eduard Zingerman
2025-09-17  3:27 ` [PATCH bpf-next v3 2/2] selftests/bpf: Add tests " Kumar Kartikeya Dwivedi
2025-09-18 21:34   ` Eduard Zingerman
2025-09-17  8:27 ` Andrea Righi [this message]
2025-09-17  8:42   ` [PATCH bpf-next v3 0/2] Update KF_RCU_PROTECTED Kumar Kartikeya Dwivedi
2025-09-18 22:40 ` patchwork-bot+netdevbpf

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=aMpw-yi-dmhox3h4@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