[PATCH bpf-next v4 0/2] selftests/bpf: Add tests for memcg kfuncs

From: listout

Date: Tue Oct 13 2026 - 16:47:48 EST


From: Brahmajit Das <bdas@xxxxxxx>

bpf_get_root_mem_cgroup(), bpf_mem_cgroup_usage(),
bpf_mem_cgroup_memory_events() and bpf_proactive_reclaim() have no
selftest coverage. Patch 2 adds a memcg_kfuncs test for them, plus
verifier tests for their acquire/release, NULL and program type rules.

Patch 1 moves the alloc_pagecache() helper from arena_memcg to
cgroup_helpers so the new test can share it instead of carrying a copy.

Tested on bpf-next with vmtest.sh (x86_64): all memcg_kfuncs and
memcg_kfuncs_failure subtests pass, and arena_memcg still passes.
---
v3 -> v4:
- Move alloc_pagecache() to cgroup_helpers.c and share it with
arena_memcg instead of duplicating it (new patch 1). (CI review)

v2 -> v3:
- Drop the upper bound on the bpf_proactive_reclaim() result; only the
request is clamped and reclaim may overshoot. Fix the commit message
accordingly. (CI review)
- Print the reason before skipping. (CI review)

v1 -> v2:
- Also check that negative indices are rejected by
bpf_mem_cgroup_memory_events() and bpf_mem_cgroup_vm_events() (Sashiko)

v3: https://lore.kernel.org/bpf/20261013171211.1661726-1-listout@xxxxxxxxxxx/
v2: https://lore.kernel.org/bpf/20261013151621.1526699-1-listout@xxxxxxxxxxx/
v1: https://lore.kernel.org/bpf/20261013143853.1379307-1-listout@xxxxxxxxxxx/

Brahmajit Das (2):
selftests/bpf: Move alloc_pagecache() to cgroup_helpers
selftests/bpf: Add tests for memcg kfuncs

tools/testing/selftests/bpf/cgroup_helpers.c | 34 +++
tools/testing/selftests/bpf/cgroup_helpers.h | 1 +
.../selftests/bpf/prog_tests/arena_memcg.c | 34 ---
.../selftests/bpf/prog_tests/memcg_kfuncs.c | 273 ++++++++++++++++++
.../selftests/bpf/progs/memcg_kfuncs.c | 106 +++++++
.../bpf/progs/memcg_kfuncs_failure.c | 54 ++++
6 files changed, 468 insertions(+), 34 deletions(-)
create mode 100644 tools/testing/selftests/bpf/prog_tests/memcg_kfuncs.c
create mode 100644 tools/testing/selftests/bpf/progs/memcg_kfuncs.c
create mode 100644 tools/testing/selftests/bpf/progs/memcg_kfuncs_failure.c

--
2.56.0