Commit Graph

2 Commits

Author SHA1 Message Date
Viktor Malik 6d6f84610a
selftests/bpf: Fix flaky cgroup_iter_sleepable subtest
JIRA: https://issues.redhat.com/browse/RHEL-9957

commit 5439cfa7fe612e7d02d5a1234feda3fa6e483ba7
Author: Yonghong Song <yonghong.song@linux.dev>
Date:   Sun Aug 27 08:05:51 2023 -0700

    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: 3b22f98e5a05 ("selftests/bpf: Add path_fd-based BPF_OBJ_PIN and BPF_OBJ_GET tests")
    Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
    Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
    Link: https://lore.kernel.org/bpf/20230827150551.1743497-1-yonghong.song@linux.dev

Signed-off-by: Viktor Malik <vmalik@redhat.com>
2023-10-26 17:06:23 +02:00
Viktor Malik dfeeec0730
selftests/bpf: Add path_fd-based BPF_OBJ_PIN and BPF_OBJ_GET tests
JIRA: https://issues.redhat.com/browse/RHEL-9957

commit 3b22f98e5a05feee20699df0870dc5d47c9b61dd
Author: Andrii Nakryiko <andrii@kernel.org>
Date:   Tue May 23 10:00:13 2023 -0700

    selftests/bpf: Add path_fd-based BPF_OBJ_PIN and BPF_OBJ_GET tests
    
    Add a selftest demonstrating using detach-mounted BPF FS using new mount
    APIs, and pinning and getting BPF map using such mount. This
    demonstrates how something like container manager could setup BPF FS,
    pin and adjust all the necessary objects in it, all before exposing BPF
    FS to a particular mount namespace.
    
    Also add a few subtests validating all meaningful combinations of
    path_fd and pathname. We use mounted /sys/fs/bpf location for these.
    
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
    Link: https://lore.kernel.org/bpf/20230523170013.728457-5-andrii@kernel.org

Signed-off-by: Viktor Malik <vmalik@redhat.com>
2023-10-26 17:06:14 +02:00