From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796311958; b=hKDCi3Glh7IfOUG8fuLi3sif1fVuYefJY3UcXIqAOA9YHvb1lUeNWrO9f9IjiT5dwz35 VcZzYhDzsYpAN1dkTKoDRWRsUmKC93B430ujtApt77qBI0lSyH+bemNd1zlt3bWLqahRM HMU+c5xHrBCvqZ+bZo9uIe0JZTc5PoREupPfAGkkNv+h3HA1360+EkcoZ4dNniOPAU9km 4Uk1Z+EEby69ucUqvomNlYNlSub19KWRXiezzm5sYSleRHrp/ckya79jroruxkObFApAO M5Q8ot91TRKz2z/xvcMWIhioArzJ4/4N81PRCR5FSFjC/l8y6+38eSOikiKzU8+r4yA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796311958; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=2g4qJSHTU8EiaD6khfj8aMgLHrz/N7VxSOunhmhhKOY=; b=IAOBvdu+UrFyL9Z1yzlZNEpYRq8/VAIzZvSJQOAmWooSTPxeBn1nz+E/AJs5aCmhRjC1 Qk5NHqFmz0dPTMUkErGCPyJHlVEClhCRiPMCH9F9D2/T1NAm1EDqyk9XQ2uqTwHLK8Kkd YRoUN6wn/0TldL5hZCAqkz/SiRmzHLsV/qsrWl1iR0OCqjEGJj2ouvVJ75GhMgDTqKay6 0ZS1xa3SJlPHnHJn8/6lpmrrGWbAH8WxYISXWRxNd9TdVQVxl8QFJ/g1LVtd2S19eN5dt nak0gt527iw7+VlcVe8GJkYakaxkJBlgli+v0Xkqr3H8FkGNJhN0X+vDYemcKhfk/6Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="ZCCl/XNu"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6068606A322 for ; Thu, 3 Dec 2026 15:32:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ZCCl/XNu Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2AE621F000C1; Thu, 3 Dec 2026 15:32:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796311958; bh=2g4qJSHTU8EiaD6khfj8aMgLHrz/N7VxSOunhmhhKOY=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=ZCCl/XNuGDXv3qoQkXAdFzTuAG9x7TbLnuOCjyCIzikzNaKoMFUwM44GM6f6VO0Xl ZFweux89VaNT/eJn2GJsoDO2CYJO4gC16Brr1WB1p/EELIP1uY2lhm/H5nPnwksnpK bCKLlGehFhtZx+tMPdCn/iU9OT7FMHTQtVonlEpLq5zwPODgIVPqNYQfuQXXJl33sw vy77hK5fGdWqTugyEnjx1AbpcpJs78iaEPiyV//IExM9oflloeMY8lfdQNBfS1aSmE fjn9MlbCe3lk21MdhqXOuSbQrR+QKAykJNA0koCkHkNyhHI/uWt5kKq5SUr6VV+tgA mRQbmOha/Pdxw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v15 3/4] selftests/bpf: add iocost cost model test Reply-To: sashiko-reviews@lists.linux.dev To: "Tao Cui" Cc: bpf@vger.kernel.org, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com In-Reply-To: <20261203150338.2625598-4-cui.tao@linux.dev> References: <20261203150338.2625598-1-cui.tao@linux.dev> <20261203150338.2625598-4-cui.tao@linux.dev> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 15:32:37 +0000 X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 10 potential issues to consider: - [Medium] selftests/bpf: iocost_test_env() skips all tests when CONFIG_KALLSYMS_ALL=3Dn - [Low] selftests/bpf: contradictory ASSERT_OK() and test__skip() in iocost_model.c - [Low] selftests/bpf: mount ns pollution and close(-1) in iocost_test_env() - [Low] selftests/bpf: file_contains() duplicates libbpf BTF and kallsyms helpers - [Low] selftests/bpf: duplicate write and rollback code in iocost_model.c - [Low] selftests/bpf: unconditional close(orig_cwd) in iocost_test_env() - [Low] selftests/bpf: fixed sleep(3) calls stall serial iocost tests for 6s - [Low] selftests/bpf: open_nullb_dev() leaks manually created /dev nodes - [Low] selftests/bpf: udev TOCTOU race on mknod() in open_nullb_dev() - [Low] selftests/bpf: unpaired cleanup_cgroup_environment() on setup failure -- commit 1da50772d61bfc9d55dc63e068869c415d99ec21 Author: Tao Cui selftests/bpf: add iocost cost model test This commit adds two BPF struct_ops iocost cost model examples and serial selftests that attach them to configfs-created null_blk devices to test model switching, IO pricing, tracepoint observation, and device removal. > diff --git a/tools/testing/selftests/bpf/prog_tests/iocost_model.c b/tool= s/testing/selftests/bpf/prog_tests/iocost_model.c > new file mode 100644 > index 0000000000000..11bcb33a1eb5e > --- /dev/null > +++ b/tools/testing/selftests/bpf/prog_tests/iocost_model.c > @@ -0,0 +1,1021 @@ [ ... ] > +static int file_contains(const char *path, const char *needle) > +{ [ ... ] > +static int iocost_bpf_supported(void) > +{ > + static int cached =3D -1; > + > + if (cached >=3D 0) > + return cached; > + > + cached =3D file_contains("/sys/kernel/btf/vmlinux", > + "bpf_struct_ops_iocost_model_ops"); > + return cached; > +} [Severity: Low] Can file_contains() be dropped in favor of the existing BTF and kallsyms helpers? Probing /sys/kernel/btf/vmlinux by slurping raw bytes with memmem() duplicates btf__load_vmlinux_btf() and btf__find_by_name_kind(..., BTF_KIND_STRUCT). Similarly, the /proc/kallsyms lookup in iocost_test_env() reads the entire file into heap memory on every test invocation instead of reusing kallsyms_find() from trace_helpers.h. [ ... ] > + if (unlink(path) && errno !=3D ENOENT) > + return -errno; > + if (mknod(path, S_IFBLK | 0600, dev)) > + return -errno; [Severity: Low] Can udev racing between unlink() and mknod() cause open_nullb_dev() to fail with -EEXIST? If udev processes the KOBJ_ADD uevent and creates /dev/ after the initial open() or unlink() and before mknod(), mknod() fails with EEXIST and the test fails its ASSERT_GE() instead of retrying open() and validating fstat(). > + fd =3D open(path, flags); > + if (fd < 0) > + unlink(path); > + return fd; > +} [Severity: Low] Does open_nullb_dev() leak manually created /dev/ nodes on systems without devtmpfs or udev? iocost_test_env() does not mount a private /dev, and when mknod() succeeds neither the callers nor nullb_remove() unlink the node on teardown, leaving a stale block device node in /dev. [ ... ] > + if (!ready) { > + orig_cwd =3D open(".", O_RDONLY | O_DIRECTORY); > + orig_ns =3D open("/proc/self/ns/mnt", O_RDONLY); > + if (unshare(CLONE_NEWNS) || > + mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL)) { [Severity: Low] Does iocost_test_env() leave the main test_progs process in a modified mount namespace for all later serial tests? All serial_test_* functions run sequentially in the main test_progs process, and on success orig_ns is closed without restoring it, leaving /sys/fs/cgro= up and /sys/kernel/config altered for subsequent tests. Both serial_test_iocost_model() and serial_test_iocost_model_streams() already call cgroup_setup_and_join(), which calls unshare(CLONE_NEWNS) per test anyway. [ ... ] > + /* > + * the tp_btf attach goes through the raw-tracepoint syscall and > + * needs no tracefs mount; probe the tracepoint by its kallsyms > + * entry instead. A probe error skips like an absent tracepoint: > + * transient failures are retried on the next run. > + */ > + if (file_contains("/proc/kallsyms", > + "__tracepoint_iocost_ioc_tick") <=3D 0) { > + printf("%s:SKIP:needs the iocost_ioc_tick tracepoint\n", > + __func__); > + test__skip(); > + goto out; > + } [Severity: Medium] Does this skip all three iocost tests on kernels built with CONFIG_KALLSYMS_ALL=3Dn? __DEFINE_TRACE_EXT() places __tracepoint_iocost_ioc_tick in the __tracepoints data section, which scripts/kallsyms.c omits unless --all-symbols (CONFIG_KALLSYMS_ALL) is enabled, and tools/testing/selftests/bpf/config does not enable CONFIG_KALLSYMS_ALL. Probing vmlinux BTF for btf_trace_iocost_ioc_tick (or /proc/kallsyms for the text symbol __traceiter_iocost_ioc_tick) works regardless of CONFIG_KALLSYMS_ALL. [ ... ] > +out: > + if (!ok) > + ready =3D false; > + if (orig_ns >=3D 0) { > + if (!ok) > + setns(orig_ns, CLONE_NEWNS); > + close(orig_ns); > + } > + if (orig_cwd >=3D 0) > + fchdir(orig_cwd); > + close(orig_cwd); > + return ok; > +} [Severity: Low] Are braces missing around the orig_cwd >=3D 0 block? As written, close(orig_cwd) runs unconditionally, calling close(-1) on every invocation after initialization or when open(".") fails, and fchdir(orig_cw= d) runs even on the success path where setns() was not called. [ ... ] > +static int write_cost_model(const char *dev, const char *what) > +{ > + char buf[128]; > + FILE *fp; > + int err =3D 0; > + > + snprintf(buf, sizeof(buf), "%s %s", dev, what); > + fp =3D fopen("/sys/fs/cgroup/io.cost.model", "w"); > + if (!fp) > + return errno ? -errno : -EACCES; > + if (fwrite(buf, 1, strlen(buf), fp) !=3D strlen(buf)) > + err =3D ferror(fp) ? (errno ? -errno : -EIO) : -EIO; > + if (fclose(fp) && !err) > + err =3D -errno; > + return err; > +} [Severity: Low] Can write_cost_model() delegate to write_file("/sys/fs/cgroup/io.cost.model= ", buf) instead of duplicating the fopen/fwrite/fclose error handling? Similarly, in nullb_create(), the error path after read_file_token() duplicates the power-off and rmdir sequence at the err_rmdir label directly below it instead of using goto err_rmdir. [ ... ] > + /* > + * the usage stat is flushed by the iocost timer, give > + * the current period a chance to end before reading > + */ > + sleep(3); > + ASSERT_OK(read_cost_usage("/iocost_pairing", > + dev, &u2), "cost_usage_post"); > + ASSERT_GT(u2, u1, "cost_charged"); > + ASSERT_GT(skel->bss->ioc_ticks, 0, "tick_seen"); [Severity: Low] Can this and the matching sleep(3) in serial_test_iocost_model_streams() poll with a bounded deadline instead of sleeping for 6 seconds total? All serial_test_* functions run sequentially on the main test_progs thread after parallel workers finish, so unconditional sleeps extend the overall critical-path runtime. On non-rotational null_blk (AUTOP_SSD_DFL), ioc_refresh_period_us() uses a 50 ms period (and MAX_PERIOD is 1 s), so polling read_cost_usage() and skel->bss->ioc_ticks up to a 3-second deadline would typically finish in ~50-100 ms. [ ... ] > + cg =3D cgroup_setup_and_join("/iocost_ms"); > + if (!ASSERT_GE(cg, 0, "setup_cg_ms")) { > + iocost_ms__destroy(skel); > + nullb_remove(IOCOST_NULLB); > + cleanup_cgroup_environment(); > + return; > + } [Severity: Low] Should cleanup_cgroup_environment() be omitted when cgroup_setup_and_join() fails? cgroup_setup_and_join() either fails before mounting /mnt or calls cleanup_cgroup_environment() itself before returning an error, so calling it again runs join_cgroup_from_top("/mnt") on an unmounted /mnt and logs spurious errors (serial_test_iocost_model() omits it on the same path). [ ... ] > + if (!ASSERT_OK(posix_memalign(&iobuf, 4096, 4096), > + "memalign_iobuf")) { > + printf("%s:SKIP:cannot allocate the aligned IO buffer\n", > + __func__); > + test__skip(); > + } else { [Severity: Low] Should this branch either fail via ASSERT_OK() or skip via test__skip(), rather than doing both? When posix_memalign() fails, ASSERT_OK() increments test_state->error_cnt and test__skip() increments test_state->skip_cnt; test_progs.c then reports the test as failed while also adding it to the summary skip count. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203150338.2625= 598-1-cui.tao@linux.dev?part=3D3