Skip to content

Commit a3bd642

Browse files
viktormalikKernel Patches Daemon
authored and
Kernel Patches Daemon
committed
selftests/bpf: run cgroup1_hierarchy test in own mount namespace
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: 3607692 ("selftests/bpf: Add selftests for cgroup1 hierarchy") Signed-off-by: Viktor Malik <[email protected]>
1 parent c70be35 commit a3bd642

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

tools/testing/selftests/bpf/cgroup_helpers.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,9 @@ int cgroup_setup_and_join(const char *path) {
508508
/**
509509
* setup_classid_environment() - Setup the cgroupv1 net_cls environment
510510
*
511+
* This function should only be called in a custom mount namespace, e.g.
512+
* created by running setup_cgroup_environment.
513+
*
511514
* After calling this function, cleanup_classid_environment should be called
512515
* once testing is complete.
513516
*

tools/testing/selftests/bpf/prog_tests/cgroup1_hierarchy.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,12 @@ void test_cgroup1_hierarchy(void)
8787
goto destroy;
8888

8989
/* Setup cgroup1 hierarchy */
90+
err = setup_cgroup_environment();
91+
if (!ASSERT_OK(err, "setup_cgroup_environment"))
92+
goto destroy;
9093
err = setup_classid_environment();
9194
if (!ASSERT_OK(err, "setup_classid_environment"))
92-
goto destroy;
95+
goto cleanup_cgroup;
9396

9497
err = join_classid();
9598
if (!ASSERT_OK(err, "join_cgroup1"))
@@ -153,6 +156,8 @@ void test_cgroup1_hierarchy(void)
153156

154157
cleanup:
155158
cleanup_classid_environment();
159+
cleanup_cgroup:
160+
cleanup_cgroup_environment();
156161
destroy:
157162
test_cgroup1_hierarchy__destroy(skel);
158163
}

0 commit comments

Comments
 (0)