* [PATCH bpf-next] bpf: Revert "bpf: drop KF_ACQUIRE flag on BPF kfunc bpf_get_root_mem_cgroup()"
@ 2026-01-21 9:00 Matt Bobrowski
2026-01-21 17:50 ` patchwork-bot+netdevbpf
2026-01-21 18:47 ` Roman Gushchin
0 siblings, 2 replies; 3+ messages in thread
From: Matt Bobrowski @ 2026-01-21 9:00 UTC (permalink / raw)
To: bpf
Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Martin KaFai Lau, Eduard Zingerman, Song Liu, Yonghong Song,
ohn Fastabend, KP Singh, Stanislav Fomichev, Jiri Olsa,
Roman Gushchin, Matt Bobrowski
This reverts commit e463b6de9da1 ("bpf: drop KF_ACQUIRE flag on BPF
kfunc bpf_get_root_mem_cgroup()").
The original commit removed the KF_ACQUIRE flag from
bpf_get_root_mem_cgroup() under the assumption that it resulted in
simplified usage. This stemmed from the fact that
bpf_get_root_mem_cgroup() inherently returns a reference to an object
which technically isn't reference counted, therefore there is no
strong requirement to call a matching bpf_put_mem_cgroup() on the
returned reference.
Although technically correct, as per the arguments in the thread [0],
dropping the KF_ACQUIRE flag and losing reference tracking semantics
negatively impacted the usability of bpf_get_root_mem_cgroup() in
practice.
[0] https://lore.kernel.org/bpf/878qdx6yut.fsf@linux.dev/
Link: https://lore.kernel.org/bpf/CAADnVQ+6d1Lj4dteAv8u62d7kj3Ze5io6bqM0xeQd-UPk9ZgJQ@mail.gmail.com/
Signed-off-by: Matt Bobrowski <mattbobrowski@google.com>
---
mm/bpf_memcontrol.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/mm/bpf_memcontrol.c b/mm/bpf_memcontrol.c
index f95cd5d16f4c..716df49d7647 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
*
- * 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.
+ * 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.
*/
__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_RET_NULL)
+BTF_ID_FLAGS(func, bpf_get_root_mem_cgroup, KF_ACQUIRE | 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)
--
2.52.0.457.g6b5491de43-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next] bpf: Revert "bpf: drop KF_ACQUIRE flag on BPF kfunc bpf_get_root_mem_cgroup()"
2026-01-21 9:00 [PATCH bpf-next] bpf: Revert "bpf: drop KF_ACQUIRE flag on BPF kfunc bpf_get_root_mem_cgroup()" Matt Bobrowski
@ 2026-01-21 17:50 ` patchwork-bot+netdevbpf
2026-01-21 18:47 ` Roman Gushchin
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-01-21 17:50 UTC (permalink / raw)
To: Matt Bobrowski
Cc: bpf, ast, daniel, andrii, martin.lau, eddyz87, song,
yonghong.song, john.fastabend, kpsingh, sdf, jolsa,
roman.gushchin
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:
On Wed, 21 Jan 2026 09:00:01 +0000 you wrote:
> This reverts commit e463b6de9da1 ("bpf: drop KF_ACQUIRE flag on BPF
> kfunc bpf_get_root_mem_cgroup()").
>
> The original commit removed the KF_ACQUIRE flag from
> bpf_get_root_mem_cgroup() under the assumption that it resulted in
> simplified usage. This stemmed from the fact that
> bpf_get_root_mem_cgroup() inherently returns a reference to an object
> which technically isn't reference counted, therefore there is no
> strong requirement to call a matching bpf_put_mem_cgroup() on the
> returned reference.
>
> [...]
Here is the summary with links:
- [bpf-next] bpf: Revert "bpf: drop KF_ACQUIRE flag on BPF kfunc bpf_get_root_mem_cgroup()"
https://git.kernel.org/bpf/bpf-next/c/d0f5d4f8f328
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next] bpf: Revert "bpf: drop KF_ACQUIRE flag on BPF kfunc bpf_get_root_mem_cgroup()"
2026-01-21 9:00 [PATCH bpf-next] bpf: Revert "bpf: drop KF_ACQUIRE flag on BPF kfunc bpf_get_root_mem_cgroup()" Matt Bobrowski
2026-01-21 17:50 ` patchwork-bot+netdevbpf
@ 2026-01-21 18:47 ` Roman Gushchin
1 sibling, 0 replies; 3+ messages in thread
From: Roman Gushchin @ 2026-01-21 18:47 UTC (permalink / raw)
To: Matt Bobrowski
Cc: bpf, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Martin KaFai Lau, Eduard Zingerman, Song Liu, Yonghong Song,
ohn Fastabend, KP Singh, Stanislav Fomichev, Jiri Olsa
Matt Bobrowski <mattbobrowski@google.com> writes:
> This reverts commit e463b6de9da1 ("bpf: drop KF_ACQUIRE flag on BPF
> kfunc bpf_get_root_mem_cgroup()").
>
> The original commit removed the KF_ACQUIRE flag from
> bpf_get_root_mem_cgroup() under the assumption that it resulted in
> simplified usage. This stemmed from the fact that
> bpf_get_root_mem_cgroup() inherently returns a reference to an object
> which technically isn't reference counted, therefore there is no
> strong requirement to call a matching bpf_put_mem_cgroup() on the
> returned reference.
>
> Although technically correct, as per the arguments in the thread [0],
> dropping the KF_ACQUIRE flag and losing reference tracking semantics
> negatively impacted the usability of bpf_get_root_mem_cgroup() in
> practice.
>
> [0] https://lore.kernel.org/bpf/878qdx6yut.fsf@linux.dev/
>
> Link: https://lore.kernel.org/bpf/CAADnVQ+6d1Lj4dteAv8u62d7kj3Ze5io6bqM0xeQd-UPk9ZgJQ@mail.gmail.com/
> Signed-off-by: Matt Bobrowski <mattbobrowski@google.com>
Acked-by: Roman Gushchin <roman.gushchin@linux.dev>
Thanks, Matt!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-01-21 18:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-21 9:00 [PATCH bpf-next] bpf: Revert "bpf: drop KF_ACQUIRE flag on BPF kfunc bpf_get_root_mem_cgroup()" Matt Bobrowski
2026-01-21 17:50 ` patchwork-bot+netdevbpf
2026-01-21 18:47 ` Roman Gushchin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox