]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
selftests/bpf: Add a test for bpf_cgroup_from_id lookup in non-root cgns
authorKumar Kartikeya Dwivedi <memxor@gmail.com>
Mon, 15 Sep 2025 03:26:18 +0000 (03:26 +0000)
committerAlexei Starovoitov <ast@kernel.org>
Mon, 15 Sep 2025 17:53:15 +0000 (10:53 -0700)
commita8250d167c0cf6b98ccb5168fb2daf2859679d72
tree8cf0583f633fa911f1969bb356b8009c571051a0
parent2c895133950646f45e5cf3900b168c952c8dbee8
selftests/bpf: Add a test for bpf_cgroup_from_id lookup in non-root cgns

Make sure that we only switch the cgroup namespace and enter a new
cgroup in a child process separate from test_progs, to not mess up the
environment for subsequent tests.

To remove this cgroup, we need to wait for the child to exit, and then
rmdir its cgroup. If the read call fails, or waitpid succeeds, we know
the child exited (read call would fail when the last pipe end is closed,
otherwise waitpid waits until exit(2) is called). We then invoke a newly
introduced remove_cgroup_pid() helper, that identifies cgroup path using
the passed in pid of the now dead child, instead of using the current
process pid (getpid()).

Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20250915032618.1551762-3-memxor@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/cgroup_helpers.c
tools/testing/selftests/bpf/cgroup_helpers.h
tools/testing/selftests/bpf/prog_tests/cgrp_kfunc.c
tools/testing/selftests/bpf/progs/cgrp_kfunc_success.c