Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

bpf: drop KF_ACQUIRE flag on BPF kfunc bpf_get_root_mem_cgroup()

With the BPF verifier now treating pointers to struct types returned
from BPF kfuncs as implicitly trusted by default, there is no need for
bpf_get_root_mem_cgroup() to be annotated with the KF_ACQUIRE flag.

bpf_get_root_mem_cgroup() does not acquire any references, but rather
simply returns a NULL pointer or a pointer to a struct mem_cgroup
object that is valid for the entire lifetime of the kernel.

This simplifies BPF programs using this kfunc by removing the
requirement to pair the call with bpf_put_mem_cgroup().

Signed-off-by: Matt Bobrowski <mattbobrowski@google.com>
Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20260113083949.2502978-2-mattbobrowski@google.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Matt Bobrowski and committed by
Alexei Starovoitov
e463b6de f8ade234

+7 -7
+7 -7
mm/bpf_memcontrol.c
··· 13 13 /** 14 14 * bpf_get_root_mem_cgroup - Returns a pointer to the root memory cgroup 15 15 * 16 - * The function has KF_ACQUIRE semantics, even though the root memory 17 - * cgroup is never destroyed after being created and doesn't require 18 - * reference counting. And it's perfectly safe to pass it to 19 - * bpf_put_mem_cgroup() 20 - * 21 - * Return: A pointer to the root memory cgroup. 16 + * Return: A pointer to the root memory cgroup. Notably, the pointer to the 17 + * returned struct mem_cgroup is trusted by default, so it's perfectably 18 + * acceptable to also pass this pointer into other BPF kfuncs (e.g., 19 + * bpf_mem_cgroup_usage()). Additionally, this BPF kfunc does not make use of 20 + * KF_ACQUIRE semantics, so there's no requirement for the BPF program to call 21 + * bpf_put_mem_cgroup() on the pointer returned by this BPF kfunc. 22 22 */ 23 23 __bpf_kfunc struct mem_cgroup *bpf_get_root_mem_cgroup(void) 24 24 { ··· 162 162 __bpf_kfunc_end_defs(); 163 163 164 164 BTF_KFUNCS_START(bpf_memcontrol_kfuncs) 165 - BTF_ID_FLAGS(func, bpf_get_root_mem_cgroup, KF_ACQUIRE | KF_RET_NULL) 165 + BTF_ID_FLAGS(func, bpf_get_root_mem_cgroup, KF_RET_NULL) 166 166 BTF_ID_FLAGS(func, bpf_get_mem_cgroup, KF_ACQUIRE | KF_RET_NULL | KF_RCU) 167 167 BTF_ID_FLAGS(func, bpf_put_mem_cgroup, KF_RELEASE) 168 168