All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Tao Cui" <cui.tao@linux.dev>
Cc: hannes@cmpxchg.org, tj@kernel.org, mkoutny@suse.com, bpf@vger.kernel.org
Subject: Re: [RFC PATCH v2 2/5] selftests/bpf: add iocost cost model test
Date: Thu, 10 Sep 2026 13:12:04 +0000	[thread overview]
Message-ID: <20260910131204.E0F4A1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260910125817.223354-3-cui.tao@linux.dev>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The test fails to restore the system's global device state if `readback_model()` fails, causing a resource leak and polluting the system configuration.
- [Low] Usage of the deprecated CHECK() macro causes a build error due to a missing 'duration' variable, and violates subsystem guidelines.
--

commit 259f7c8970e8f40f2ac352cd5f7eefb63642bf71
Author: Tao Cui <cuitao@kylinos.cn>

selftests/bpf: add iocost cost model test

Add an example cost model implementing the full builtin linear HDD
formula at double cost, including flush pricing, and a runner which
registers it as a struct_ops and binds it to a device through
io.cost.model with "model=iocost_2x", verifying the readback and
restoring "model=linear" afterwards.

> 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..e9344b13fba98
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/iocost_model.c
> @@ -0,0 +1,193 @@
[ ... ]
> +static int bind_model(const char *dev, const char *name)
> +{
> +	char buf[300], got[64];
> +	int err;
> +
> +	snprintf(buf, sizeof(buf), "%s model=%s\n", dev, name);
> +	err = write_cost_model(buf);
> +	if (err) {
> +		CHECK(false, "write_model", "write model=%s: %s\n", name,
> +		      strerror(err));

[Severity: Low]
Does this code cause a build failure? The deprecated CHECK() macro requires a
'duration' variable in scope, which appears to be missing in bind_model().

Could we use the modern ASSERT_*() macros instead to avoid this build error
and adhere to current selftest guidelines? (This macro is also used further
down in this function).

> +		return -1;
> +	}
> +	err = readback_model(dev, got, sizeof(got));
> +	if (err || strcmp(got, name)) {
> +		CHECK(false, "readback_model", "got model=%s want %s\n",
> +		      err ? "(none)" : got, name);
> +		return -1;
> +	}

[Severity: Medium]
Does this early return fail to restore the global device state?

If readback_model() fails or returns a mismatched value, the function returns
early and skips the teardown logic below that restores the 'linear' model.

This leaves the test BPF program actively bound to the system's block device
via sysfs. Because the kernel block layer holds a reference to the active
model, the BPF program cannot be unloaded when destroying the skeleton,
altering system-wide block IO behavior indefinitely.

> +
> +	/* restore the builtin linear model; the write is checked too */
> +	snprintf(buf, sizeof(buf), "%s model=linear\n", dev);
> +	err = write_cost_model(buf);
> +	if (err) {
> +		CHECK(false, "restore_linear", "write model=linear: %s\n",
> +		      strerror(err));
> +		return -1;
> +	}
> +	return 0;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260910125817.223354-1-cui.tao@linux.dev?part=2

  reply	other threads:[~2026-09-10 13:12 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-10 12:58 [RFC PATCH v2 0/5] blk-iocost: BPF struct_ops cost model Tao Cui
2026-09-10 12:58 ` [RFC PATCH v2 1/5] blk-iocost: add BPF struct_ops cost model support Tao Cui
2026-09-10 13:17   ` sashiko-bot
2026-09-10 12:58 ` [RFC PATCH v2 2/5] selftests/bpf: add iocost cost model test Tao Cui
2026-09-10 13:12   ` sashiko-bot [this message]
2026-09-10 13:46   ` bot+bpf-ci
2026-09-10 12:58 ` [RFC PATCH v2 3/5] blk-iocost: add iocost_ioc_tick tracepoint for per-period device summary Tao Cui
2026-09-10 13:46   ` bot+bpf-ci
2026-09-10 12:58 ` [RFC PATCH v2 4/5] selftests/bpf: add multi-stream sequentiality example model Tao Cui
2026-09-10 13:10   ` sashiko-bot
2026-09-10 12:58 ` [RFC PATCH v2 5/5] docs: cgroup-v2: document io.cost model=<name> binding Tao Cui
2026-09-11  9:20 ` [RFC PATCH v2 0/5] 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=20260910131204.E0F4A1F000FF@smtp.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.