From: Tao Cui <cui.tao@linux.dev>
To: sashiko-reviews@lists.linux.dev
Cc: cui.tao@linux.dev, bpf@vger.kernel.org, tj@kernel.org,
hannes@cmpxchg.org, mkoutny@suse.com
Subject: Re: [RFC PATCH v14 3/4] selftests/bpf: add iocost cost model test
Date: Tue, 24 Nov 2026 21:06:56 +0800 [thread overview]
Message-ID: <e0df6f55-aae9-4abd-8434-f6b75e42a972@linux.dev> (raw)
In-Reply-To: <sashiko-outbox-221050@kernel.org>
Hello,
在 2026/11/18 21:41, sashiko-bot@kernel.org 写道:
> Thank you for your contribution! Sashiko AI review found 2 potential
> issues to consider:
> - [Medium] selftests/bpf: iocost_test_env() hardcodes /sys/fs/cgroup
> without mounting
Right, the tests access /sys/fs/cgroup without mounting anything there,
so they depend on the host's mount state and would see the tmpfs that
setup_classid_environment() leaves behind. The next posting mounts
cgroup2 at /sys/fs/cgroup inside the private mount namespace that
iocost_test_env() creates, tolerating EBUSY, and skips the tests when
the mount fails.
> - [Low] selftests/bpf: open_nullb_dev() callers check -errno instead of
> fd
That's a real gap. open_nullb_dev() can return -1 with errno unset,
and the callers then pass 0 to ASSERT_OK() and keep using fd -1. The
next posting returns a proper negative error code from the helper and
checks the fd itself with ASSERT_GE(devfd, 0).
And another one:
bpf-ci points this, the setns() unwind on the skip path may reset test_progs' cwd to "/"
Right, mntns_install() sets the pwd to the root of the new namespace on
the way back, so a skip moves the process to "/". The next posting
saves the cwd before unshare() and fchdir()s back to it after setns().
Thanks,
Tao
> --
>
> commit 7c8a11566574f6e4224eb8a8a97b22da0b3eb991
> Author: Tao Cui <cuitao@kylinos.cn>
>
> selftests/bpf: add iocost cost model test
>
> This commit adds two BPF struct_ops iocost cost models and selftests that
> attach them to a configfs-created null_blk device and verify model
> selection, IO pricing, tracepoint firing, and device removal.
>
>> 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
>> index 0000000000000..0fbaeb7c5b7ef
>> --- /dev/null
>> +++ b/tools/testing/selftests/bpf/prog_tests/iocost_model.c
> [ ... ]
>> +/* open the nullb device node, creating it manually when udev hasn't */
>> +static int open_nullb_dev(const char *name, int flags)
>> +{
>> + char path[32], syspath[64], devtok[32];
>> + unsigned int maj, min;
>> + dev_t dev;
>> + struct stat st;
>> + int fd;
>> +
>> + snprintf(syspath, sizeof(syspath), "/sys/block/%s/dev", name);
>> + if (read_file_token(syspath, devtok, sizeof(devtok)) ||
>> + sscanf(devtok, "%u:%u", &maj, &min) != 2)
>> + return -1;
>> + dev = makedev(maj, min);
>> +
>> + snprintf(path, sizeof(path), "/dev/%s", name);
>> + fd = open(path, flags);
>> + if (fd >= 0 && fstat(fd, &st) == 0 && S_ISBLK(st.st_mode) &&
>> + st.st_rdev == dev)
>> + return fd;
>> + if (fd >= 0) {
>> + /* a stale node from a previous run, drop and recreate */
>> + close(fd);
>> + fd = -1;
>> + }
>> + if (unlink(path) && errno != ENOENT)
>> + return -1;
>> + if (mknod(path, S_IFBLK | 0600, dev))
>> + return -1;
>> + fd = open(path, flags);
>> + if (fd < 0)
>> + unlink(path);
>> + return fd;
>> +}
>
> [Severity: Low]
> Can ASSERT_OK(devfd < 0 ? -errno : 0, ...) in serial_test_iocost_model()
> and serial_test_iocost_model_streams() pass when open_nullb_dev() fails?
>
> If read_file_token() hits EOF without setting errno, sscanf() fails to
> match two tokens, or unlink(path) succeeds and leaves errno at 0 after
> the second open() fails, open_nullb_dev() returns -1 with errno == 0.
> The callers then pass 0 to ASSERT_OK() and proceed to call
> posix_fadvise(), read(), pread(), and close() on fd -1. Using
> ASSERT_OK_FD(devfd, ...) in the callers (or returning a negative error
> code from open_nullb_dev()) would catch any failure directly.
>
> [ ... ]
>> +static bool iocost_test_env(void)
>> +{
>> + static bool ready;
>> + struct statfs sf;
>> + int orig_ns = -1, supported;
>> + bool ok = false;
>> +
>> + if (geteuid() != 0) {
>> + printf("%s:SKIP:needs root\n", __func__);
>> + test__skip();
>> + return false;
>> + }
>> +
>> + if (statfs("/sys/fs/cgroup", &sf) ||
>> + sf.f_type != CGROUP2_SUPER_MAGIC) {
>> + printf("%s:SKIP:needs cgroup v2 at /sys/fs/cgroup\n",
>> + __func__);
>> + test__skip();
>> + return false;
>> + }
> [ ... ]
>> + /*
>> + * 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);
>
> [Severity: Medium]
> Will all three iocost tests skip when /sys/fs/cgroup is not already a
> cgroup2 mount or after an earlier cgroup v1 test runs in the same
> test_progs process?
>
> iocost_test_env(), cgroupfs_has_controller(), readback_model(),
> write_cost_model(), and the io.cost.qos writes all access /sys/fs/cgroup
> directly without mounting cgroup2 there, while cgroup_setup_and_join() in
> tools/testing/selftests/bpf/cgroup_helpers.c mounts cgroup2 at /mnt
> (CGROUP_MOUNT_PATH). In addition, setup_classid_environment() in
> cgroup_helpers.c mounts tmpfs at /sys/fs/cgroup (CGROUP_MOUNT_DFLT) and
> cleanup_classid_environment() leaves that tmpfs mounted:
>
> tools/testing/selftests/bpf/cgroup_helpers.c:setup_classid_environment() {
> ...
> if (mount("tmpfs", CGROUP_MOUNT_DFLT, "tmpfs", 0, NULL) &&
> errno != EBUSY) {
> log_err("mount cgroup base");
> return 1;
> }
> ...
> }
>
> When a test using setup_classid_environment() runs before
> serial_test_iocost_model*, statfs("/sys/fs/cgroup", &sf) sees TMPFS_MAGIC
> instead of CGROUP2_SUPER_MAGIC and skips the tests. Using the cgroup2
> mount managed by cgroup_helpers.c (via get_root_cgroup() or
> write_cgroup_file("", ...) / read_cgroup_file("", ...)), or mounting
> cgroup2 inside the private mount namespace created by iocost_test_env(),
> would avoid relying on the host's /sys/fs/cgroup mount state.
>
next prev parent reply other threads:[~2026-11-24 13:07 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 13:10 [RFC PATCH v14 0/4] blk-iocost: BPF struct_ops cost model Tao Cui
2026-11-18 13:10 ` [RFC PATCH v14 1/4] blk-iocost: add BPF struct_ops cost model support Tao Cui
2026-11-29 19:10 ` Tejun Heo
2026-11-30 10:14 ` Tao Cui
2026-11-18 13:10 ` [RFC PATCH v14 2/4] blk-iocost: add iocost_ioc_tick tracepoint for per-period device summary Tao Cui
2026-11-18 13:49 ` bot+bpf-ci
2026-11-18 13:10 ` [RFC PATCH v14 3/4] selftests/bpf: add iocost cost model test Tao Cui
2026-11-18 13:41 ` sashiko-bot
2026-11-24 13:06 ` Tao Cui [this message]
2026-11-18 13:49 ` bot+bpf-ci
2026-11-18 13:10 ` [RFC PATCH v14 4/4] docs: cgroup-v2: document the iocost BPF cost model attachment Tao Cui
2026-11-18 13:17 ` [RFC PATCH v14 0/4] blk-iocost: BPF struct_ops cost model Tao Cui
2026-11-29 2:17 ` Tao Cui
2026-12-01 13:26 ` Tao Cui
2026-12-01 15:04 ` Tejun Heo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e0df6f55-aae9-4abd-8434-f6b75e42a972@linux.dev \
--to=cui.tao@linux.dev \
--cc=bpf@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=mkoutny@suse.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.