Skip to content

Commit 5439cfa

Browse files
Yonghong Songborkmann
Yonghong Song
authored andcommitted
selftests/bpf: Fix flaky cgroup_iter_sleepable subtest
Occasionally, with './test_progs -j' on my vm, I will hit the following failure: test_cgrp_local_storage:PASS:join_cgroup /cgrp_local_storage 0 nsec test_cgroup_iter_sleepable:PASS:skel_open 0 nsec test_cgroup_iter_sleepable:PASS:skel_load 0 nsec test_cgroup_iter_sleepable:PASS:attach_iter 0 nsec test_cgroup_iter_sleepable:PASS:iter_create 0 nsec test_cgroup_iter_sleepable:FAIL:cgroup_id unexpected cgroup_id: actual 1 != expected 2812 #48/5 cgrp_local_storage/cgroup_iter_sleepable:FAIL #48 cgrp_local_storage:FAIL Finally, I decided to do some investigation since the test is introduced by myself. It turns out the reason is due to cgroup_fd with value 0. In cgroup_iter, a cgroup_fd of value 0 means the root cgroup. /* from cgroup_iter.c */ if (fd) cgrp = cgroup_v1v2_get_from_fd(fd); else if (id) cgrp = cgroup_get_from_id(id); else /* walk the entire hierarchy by default. */ cgrp = cgroup_get_from_path("/"); That is why we got cgroup_id 1 instead of expected 2812. Why we got a cgroup_fd 0? Nobody should really touch 'stdin' (fd 0) in test_progs. I traced 'close' syscall with stack trace and found the root cause, which is a bug in bpf_obj_pinning.c. Basically, the code closed fd 0 although it should not. Fixing the bug in bpf_obj_pinning.c also resolved the above cgroup_iter_sleepable subtest failure. Fixes: 3b22f98 ("selftests/bpf: Add path_fd-based BPF_OBJ_PIN and BPF_OBJ_GET tests") Signed-off-by: Yonghong Song <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 9d0a67b commit 5439cfa

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/unistd.h>
99
#include <linux/mount.h>
1010
#include <sys/syscall.h>
11+
#include "bpf/libbpf_internal.h"
1112

1213
static inline int sys_fsopen(const char *fsname, unsigned flags)
1314
{
@@ -155,7 +156,7 @@ static void validate_pin(int map_fd, const char *map_name, int src_value,
155156
ASSERT_OK(err, "obj_pin");
156157

157158
/* cleanup */
158-
if (pin_opts.path_fd >= 0)
159+
if (path_kind == PATH_FD_REL && pin_opts.path_fd >= 0)
159160
close(pin_opts.path_fd);
160161
if (old_cwd[0])
161162
ASSERT_OK(chdir(old_cwd), "restore_cwd");
@@ -220,7 +221,7 @@ static void validate_get(int map_fd, const char *map_name, int src_value,
220221
goto cleanup;
221222

222223
/* cleanup */
223-
if (get_opts.path_fd >= 0)
224+
if (path_kind == PATH_FD_REL && get_opts.path_fd >= 0)
224225
close(get_opts.path_fd);
225226
if (old_cwd[0])
226227
ASSERT_OK(chdir(old_cwd), "restore_cwd");

0 commit comments

Comments
 (0)