Re: [RFC PATCH v14 3/4] selftests/bpf: add iocost cost model test
From: bot+bpf-ci
Date: Wed Nov 18 2026 - 08:49:24 EST
> selftests/bpf: add iocost cost model test
TL;DR: In the iocost selftest, the setns() unwind on the skip path may reset
test_progs' cwd to "/" (and possibly leave a chroot), so later unrelated tests
could fail with -ENOENT when null_blk is unavailable.
> diff --git a/tools/testing/selftests/bpf/prog_tests/iocost_model.c b/tools/testing/selftests/bpf/prog_tests/iocost_model.c
> new file mode 100644
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/iocost_model.c
[ ... ]
> +static bool iocost_test_env(void)
> +{
[ ... ]
> + /*
> + * Isolate the configfs and cgroup mounts from the host. A
> + * failed setup unwinds the namespace so that a later retry does
> + * not stack private namespaces.
> + */
> + orig_ns = open("/proc/self/ns/mnt", O_RDONLY);
> + if (unshare(CLONE_NEWNS) ||
> + mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL)) {
> + printf("%s:SKIP:cannot make mounts private: %s\n",
> + __func__, strerror(errno));
> + test__skip();
> + goto out;
> + }
> + mkdir("/sys/kernel/config", 0755);
> + (void)mount("none", "/sys/kernel/config", "configfs", 0, NULL);
> + SYS_NOFAIL("modprobe null_blk nr_devices=0");
> + if (access("/sys/kernel/config/nullb", W_OK)) {
> + printf("%s:SKIP:needs null_blk with configfs support\n",
> + __func__);
> + test__skip();
> + goto out;
> + }
> +
> + ready = true;
> + ok = true;
> +
> +out:
> + if (orig_ns >= 0) {
> + if (!ok)
> + setns(orig_ns, CLONE_NEWNS);
> + close(orig_ns);
> + }
> + return ok;
> +}
When a prerequisite check fails after unshare(CLONE_NEWNS), for example
when access("/sys/kernel/config/nullb", W_OK) fails because null_blk is
not built, not installed, or modprobe is missing, this goes back with
setns(orig_ns, CLONE_NEWNS).
Can this change the cwd of the test_progs process? mntns_install() in
fs/namespace.c ends with:
/* Update the pwd and root */
set_fs_pwd(fs, &root);
set_fs_root(fs, &root);
unshare() keeps the cwd, so only this skip path moves the process to "/".
The serial tests run in the test_progs main process, so the new cwd
persists for every test that runs afterwards. Many of those open objects
by cwd-relative path, for example serial_test_kfree_skb() loading
"./test_pkt_access.bpf.o", select_reuseport.c opening
"test_select_reuseport_kern.bpf.o", and l4lb_all.c using "test_l4lb.bpf.o".
The flavored runners also lose the chdir() done by cd_flavor_subdir().
So on a kernel with the iocost BPF support but no usable null_blk, would
the iocost tests report SKIP and then unrelated tests fail with -ENOENT?
If test_progs runs inside a chroot, does the root reset also leave the
chroot?
The comment says the unwind exists "so that a later retry does not stack
private namespaces", but serial_test_iocost_model() and
serial_test_iocost_model_streams() call cgroup_setup_and_join(), and
setup_cgroup_environment() calls unshare(CLONE_NEWNS) every time, so
namespaces stack regardless.
Would it work to drop the setns() unwind and cache the failure in a
static, or to save the cwd with open(".", O_RDONLY | O_DIRECTORY) before
unshare() and fchdir() back to it after setns()?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/44312765238