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@xxxxxxx [1]: https://lore.kernel.org/all/20250909195709.92669-1-arighi@xxxxxxxxxx Kumar Kartikeya Dwivedi (3): bpf: Enforce RCU protection for KF_RCU_PROTECTED bpf: Add support for KF_RET_RCU flag selftests/bpf: Add tests for KF_RET_RCU Documentation/bpf/kfuncs.rst | 24 +++++++++++++++++-- include/linux/btf.h | 1 + kernel/bpf/verifier.c | 12 ++++++++++ .../selftests/bpf/progs/cgroup_read_xattr.c | 2 +- .../selftests/bpf/progs/iters_task_failure.c | 4 ++-- .../selftests/bpf/progs/iters_testmod.c | 23 ++++++++++++++++++ .../selftests/bpf/test_kmods/bpf_testmod.c | 6 +++++ .../bpf/test_kmods/bpf_testmod_kfunc.h | 1 + 8 files changed, 68 insertions(+), 5 deletions(-) base-commit: a578b54a8ad282dd739e4d1f4e8352fc8ac1c4a0 -- 2.51.0