* [PATCH bpf-next] selftests/bpf: run cgroup1_hierarchy test in own mount namespace
@ 2024-04-29 11:23 Viktor Malik
2024-04-29 23:20 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Viktor Malik @ 2024-04-29 11:23 UTC (permalink / raw)
To: bpf
Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Martin KaFai Lau, Eduard Zingerman, Song Liu, Yonghong Song,
John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
Mykola Lysenko, Shuah Khan, Yafang Shao, Viktor Malik
The cgroup1_hierarchy test uses setup_classid_environment to setup
cgroupv1 environment. The problem is that the environment is set in
/sys/fs/cgroup and therefore, if not run under an own mount namespace,
effectively deletes all system cgroups:
$ ls /sys/fs/cgroup | wc -l
27
$ sudo ./test_progs -t cgroup1_hierarchy
#41/1 cgroup1_hierarchy/test_cgroup1_hierarchy:OK
#41/2 cgroup1_hierarchy/test_root_cgid:OK
#41/3 cgroup1_hierarchy/test_invalid_level:OK
#41/4 cgroup1_hierarchy/test_invalid_cgid:OK
#41/5 cgroup1_hierarchy/test_invalid_hid:OK
#41/6 cgroup1_hierarchy/test_invalid_cgrp_name:OK
#41/7 cgroup1_hierarchy/test_invalid_cgrp_name2:OK
#41/8 cgroup1_hierarchy/test_sleepable_prog:OK
#41 cgroup1_hierarchy:OK
Summary: 1/8 PASSED, 0 SKIPPED, 0 FAILED
$ ls /sys/fs/cgroup | wc -l
1
To avoid this, run setup_cgroup_environment first which will create an
own mount namespace. This only affects the cgroupv1_hierarchy test as
all other cgroup1 test progs already run setup_cgroup_environment prior
to running setup_classid_environment.
Also add a comment to the header of setup_classid_environment to warn
against this invalid usage in future.
Fixes: 360769233cc9 ("selftests/bpf: Add selftests for cgroup1 hierarchy")
Signed-off-by: Viktor Malik <vmalik@redhat.com>
---
tools/testing/selftests/bpf/cgroup_helpers.c | 3 +++
tools/testing/selftests/bpf/prog_tests/cgroup1_hierarchy.c | 7 ++++++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/cgroup_helpers.c b/tools/testing/selftests/bpf/cgroup_helpers.c
index f2952a65dcc2..23bb9a9e6a7d 100644
--- a/tools/testing/selftests/bpf/cgroup_helpers.c
+++ b/tools/testing/selftests/bpf/cgroup_helpers.c
@@ -508,6 +508,9 @@ int cgroup_setup_and_join(const char *path) {
/**
* setup_classid_environment() - Setup the cgroupv1 net_cls environment
*
+ * This function should only be called in a custom mount namespace, e.g.
+ * created by running setup_cgroup_environment.
+ *
* After calling this function, cleanup_classid_environment should be called
* once testing is complete.
*
diff --git a/tools/testing/selftests/bpf/prog_tests/cgroup1_hierarchy.c b/tools/testing/selftests/bpf/prog_tests/cgroup1_hierarchy.c
index 74d6d7546f40..25332e596750 100644
--- a/tools/testing/selftests/bpf/prog_tests/cgroup1_hierarchy.c
+++ b/tools/testing/selftests/bpf/prog_tests/cgroup1_hierarchy.c
@@ -87,9 +87,12 @@ void test_cgroup1_hierarchy(void)
goto destroy;
/* Setup cgroup1 hierarchy */
+ err = setup_cgroup_environment();
+ if (!ASSERT_OK(err, "setup_cgroup_environment"))
+ goto destroy;
err = setup_classid_environment();
if (!ASSERT_OK(err, "setup_classid_environment"))
- goto destroy;
+ goto cleanup_cgroup;
err = join_classid();
if (!ASSERT_OK(err, "join_cgroup1"))
@@ -153,6 +156,8 @@ void test_cgroup1_hierarchy(void)
cleanup:
cleanup_classid_environment();
+cleanup_cgroup:
+ cleanup_cgroup_environment();
destroy:
test_cgroup1_hierarchy__destroy(skel);
}
--
2.44.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH bpf-next] selftests/bpf: run cgroup1_hierarchy test in own mount namespace
2024-04-29 11:23 [PATCH bpf-next] selftests/bpf: run cgroup1_hierarchy test in own mount namespace Viktor Malik
@ 2024-04-29 23:20 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-04-29 23:20 UTC (permalink / raw)
To: Viktor Malik
Cc: bpf, ast, daniel, andrii, martin.lau, eddyz87, song,
yonghong.song, john.fastabend, kpsingh, sdf, haoluo, jolsa,
mykolal, shuah, laoar.shao
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:
On Mon, 29 Apr 2024 13:23:11 +0200 you wrote:
> The cgroup1_hierarchy test uses setup_classid_environment to setup
> cgroupv1 environment. The problem is that the environment is set in
> /sys/fs/cgroup and therefore, if not run under an own mount namespace,
> effectively deletes all system cgroups:
>
> $ ls /sys/fs/cgroup | wc -l
> 27
> $ sudo ./test_progs -t cgroup1_hierarchy
> #41/1 cgroup1_hierarchy/test_cgroup1_hierarchy:OK
> #41/2 cgroup1_hierarchy/test_root_cgid:OK
> #41/3 cgroup1_hierarchy/test_invalid_level:OK
> #41/4 cgroup1_hierarchy/test_invalid_cgid:OK
> #41/5 cgroup1_hierarchy/test_invalid_hid:OK
> #41/6 cgroup1_hierarchy/test_invalid_cgrp_name:OK
> #41/7 cgroup1_hierarchy/test_invalid_cgrp_name2:OK
> #41/8 cgroup1_hierarchy/test_sleepable_prog:OK
> #41 cgroup1_hierarchy:OK
> Summary: 1/8 PASSED, 0 SKIPPED, 0 FAILED
> $ ls /sys/fs/cgroup | wc -l
> 1
>
> [...]
Here is the summary with links:
- [bpf-next] selftests/bpf: run cgroup1_hierarchy test in own mount namespace
https://git.kernel.org/bpf/bpf-next/c/19468ed51488
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] 2+ messages in thread
end of thread, other threads:[~2024-04-29 23:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-29 11:23 [PATCH bpf-next] selftests/bpf: run cgroup1_hierarchy test in own mount namespace Viktor Malik
2024-04-29 23:20 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).