From: sashiko-bot@kernel.org
To: "Tao Cui" <cui.tao@linux.dev>
Cc: 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: Wed, 18 Nov 2026 13:41:08 +0000 [thread overview]
Message-ID: <sashiko-outbox-221050@kernel.org> (raw)
In-Reply-To: <20261118131029.797007-4-cui.tao@linux.dev>
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
- [Low] selftests/bpf: open_nullb_dev() callers check -errno instead of
fd
--
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.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118131029.797007-1-cui.tao@linux.dev?part=3
next prev parent reply other threads:[~2026-11-18 13:41 UTC|newest]
Thread overview: 9+ 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-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 [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
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=sashiko-outbox-221050@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=cui.tao@linux.dev \
--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.