]> git.ipfire.org Git - thirdparty/linux.git/commit
mm: introduce BPF kfuncs to deal with memcg pointers
authorRoman Gushchin <roman.gushchin@linux.dev>
Tue, 23 Dec 2025 04:41:52 +0000 (20:41 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 23 Dec 2025 06:20:21 +0000 (22:20 -0800)
commit5904db9891f80f84283648121e2d8c8a506296a8
treeb7389ef8a704b6fe02bcad742a74001bf5a9b3f9
parent4221de8c410e7adb1114a4374c78fa4269175343
mm: introduce BPF kfuncs to deal with memcg pointers

To effectively operate with memory cgroups in BPF there is a need
to convert css pointers to memcg pointers. A simple container_of
cast which is used in the kernel code can't be used in BPF because
from the verifier's point of view that's a out-of-bounds memory access.

Introduce helper get/put kfuncs which can be used to get
a refcounted memcg pointer from the css pointer:
  - bpf_get_mem_cgroup,
  - bpf_put_mem_cgroup.

bpf_get_mem_cgroup() can take both memcg's css and the corresponding
cgroup's "self" css. It allows it to be used with the existing cgroup
iterator which iterates over cgroup tree, not memcg tree.

Signed-off-by: Roman Gushchin <roman.gushchin@linux.dev>
Link: https://lore.kernel.org/r/20251223044156.208250-3-roman.gushchin@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
mm/Makefile
mm/bpf_memcontrol.c [new file with mode: 0644]