From: Matt Bobrowski Date: Tue, 13 Jan 2026 08:39:48 +0000 (+0000) Subject: bpf: drop KF_ACQUIRE flag on BPF kfunc bpf_get_root_mem_cgroup() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e463b6de9da17995a2ddabf199cc00c65a8a5392;p=thirdparty%2Fkernel%2Flinux.git 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 Acked-by: Kumar Kartikeya Dwivedi Link: https://lore.kernel.org/r/20260113083949.2502978-2-mattbobrowski@google.com Signed-off-by: Alexei Starovoitov --- diff --git a/mm/bpf_memcontrol.c b/mm/bpf_memcontrol.c index 716df49d76477..f95cd5d16f4cd 100644 --- a/mm/bpf_memcontrol.c +++ b/mm/bpf_memcontrol.c @@ -13,12 +13,12 @@ __bpf_kfunc_start_defs(); /** * bpf_get_root_mem_cgroup - Returns a pointer to the root memory cgroup * - * The function has KF_ACQUIRE semantics, even though the root memory - * cgroup is never destroyed after being created and doesn't require - * reference counting. And it's perfectly safe to pass it to - * bpf_put_mem_cgroup() - * - * Return: A pointer to the root memory cgroup. + * Return: A pointer to the root memory cgroup. Notably, the pointer to the + * returned struct mem_cgroup is trusted by default, so it's perfectably + * acceptable to also pass this pointer into other BPF kfuncs (e.g., + * bpf_mem_cgroup_usage()). Additionally, this BPF kfunc does not make use of + * KF_ACQUIRE semantics, so there's no requirement for the BPF program to call + * bpf_put_mem_cgroup() on the pointer returned by this BPF kfunc. */ __bpf_kfunc struct mem_cgroup *bpf_get_root_mem_cgroup(void) { @@ -162,7 +162,7 @@ __bpf_kfunc void bpf_mem_cgroup_flush_stats(struct mem_cgroup *memcg) __bpf_kfunc_end_defs(); BTF_KFUNCS_START(bpf_memcontrol_kfuncs) -BTF_ID_FLAGS(func, bpf_get_root_mem_cgroup, KF_ACQUIRE | KF_RET_NULL) +BTF_ID_FLAGS(func, bpf_get_root_mem_cgroup, KF_RET_NULL) BTF_ID_FLAGS(func, bpf_get_mem_cgroup, KF_ACQUIRE | KF_RET_NULL | KF_RCU) BTF_ID_FLAGS(func, bpf_put_mem_cgroup, KF_RELEASE)