mirror-linux/tools
Kumar Kartikeya Dwivedi 1512231b6c bpf: Enforce RCU protection for KF_RCU_PROTECTED
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.

This would also mean that iterator APIs using KF_RCU_PROTECTED will
error out earlier, instead of throwing an error for lack of RCU CS
protection when next() or destroy() methods are invoked.

In addition to this, if the kfuncs tagged KF_RCU_PROTECTED return a
pointer value, ensure that this pointer value is only usable in an RCU
critical section. There might be edge cases where the return value is
special and doesn't need to imply MEM_RCU semantics, but in general, the
assumption should hold for the majority of kfuncs, and we can revisit
things if necessary later.

  [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

Tested-by: Andrea Righi <arighi@nvidia.com>
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/r/20250917032755.4068726-2-memxor@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2025-09-18 15:36:17 -07:00
..
accounting tools/getdelays: add backward compatibility for taskstats version 2025-08-02 12:01:41 -07:00
arch ARM: 2025-08-29 13:54:26 -07:00
bootconfig bootconfig: Fix negative seeks on 32-bit with LFS enabled 2025-08-21 08:16:31 +09:00
bpf bpftool: Search for tracefs at /sys/kernel/tracing first 2025-09-15 10:10:28 -07:00
build
certs
cgroup
counter
crypto
debugging
firewire
firmware
gpio tools: gpio: remove the include directory on make clean 2025-09-04 16:29:28 +02:00
hv
iio
include perf-tools fixes for v6.17-rc4 2025-08-27 19:18:51 -07:00
kvm/kvm_stat
laptop
leds
lib libbpf: Remove unused args in parse_usdt_note 2025-09-04 11:35:44 -07:00
memory-model
mm
net tools: ynl-gen: fix nested array counting 2025-09-03 15:18:34 -07:00
objtool objtool/LoongArch: Get table size correctly if LTO is enabled 2025-08-20 22:23:15 +08:00
pcmcia
perf perf symbol-elf: Add support for the block argument for libbfd 2025-09-04 16:37:35 -07:00
power cpupower: Allow control of boost feature on non-x86 based systems with boost support. 2025-08-15 10:49:14 -06:00
rcu
sched
sched_ext
scripts tools headers: Sync syscall tables with the kernel source 2025-08-18 13:49:25 -07:00
sound
spi
testing bpf: Enforce RCU protection for KF_RCU_PROTECTED 2025-09-18 15:36:17 -07:00
thermal
time
tracing rtla: Check pkg-config install 2025-08-19 20:32:54 -04:00
usb
verification rv: Add opid per-cpu monitor 2025-07-28 16:47:35 -04:00
virtio
wmi
workqueue
writeback
Makefile