Re: [PATCH v14 26/39] selftests/sched: Test the root domain of a task in deadline_bw_test

From: sashiko-bot

Date: Thu Dec 03 2026 - 12:25:27 EST


Thank you for your contribution! Sashiko AI review found 11 potential
issues to consider:
- [Low] selftests/sched: stack buffer overflow in rebuild_record_taken()
- [Low] selftests/sched: unchecked buffer truncation in
partition_invalidate_refused()
- [Low] selftests/sched: unclosed ack[1] pipe end hangs two partition
tests
- [Low] selftests/sched: inverted tell flag in partition_swap_accepted()
- [Low] selftests/sched: unpinned migration window causes flaky
deadline_bw_test cases
- [Low] selftests/sched: silent or misleading KSFT_SKIP returns in
deadline_bw_test
- [Low] selftests/sched: wrong isolcpus count comment and cs_setup()
duplication
- [Low] selftests/sched: missing ext_switched_all() check before hotplug
with server
- [Low] selftests/sched: woken_on() accepts negative task_cpu_of() error
as valid CPU
- [Low] selftests/sched: no_admission_affinity_moves() restores sysctl
before 0-lag
- [Low] selftests/sched: hotplug_no_admission_pinned() restores sysctl
before 0-lag
--

commit 771f314a11047ea4b849341ab0c81a8587315b6a
Author: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>

selftests/sched: Test the root domain of a task in deadline_bw_test

This commit adds 40 test cases to deadline_bw_test covering CPU hotplug,
cpuset partition changes, and root domain accounting for SCHED_DEADLINE
tasks with and without isolcpus=domain.

> diff --git a/tools/testing/selftests/sched/deadline/deadline_bw_test.c b/tools/testing/selftests/sched/deadline/deadline_bw_test.c
> index f50d45dd57994..8c2a2ccb3c600 100644
> --- a/tools/testing/selftests/sched/deadline/deadline_bw_test.c
> +++ b/tools/testing/selftests/sched/deadline/deadline_bw_test.c

[ ... ]

> @@ -45,7 +46,7 @@
> *
> * The test needs root, deadline admission control and 3 housekeeping
> * CPUs. Some cases need 4. Most also need the cgroup v2 cpuset
> - * controller. Some need debugfs or CPU hotplug. Five need
> + * controller. Some need debugfs or CPU hotplug. Twenty-nine need
> * isolcpus="domain" at boot.
> */

[Severity: Low]
Should this say thirty-one rather than twenty-nine, given the five existing
cases plus the 26 new cases that require isolcpus=domain?

Two other small cleanups in the added code: fallback_case() declares a local
cg_q that shadows the file-scope cg_q and duplicates the cgroup setup and
teardown from cs_setup()/cs_cleanup(); and hotplug_partition_invalid_refused()
leaves cs_n[0] non-zero if snprintf() truncates before jumping to out:,
unlike hotplug_sibling_partition_refused() which clears cs_d[0] = 0.

[ ... ]

> + snprintf(path, sizeof(path), "%s/cgroup.subtree_control", root);
> + if (read_file(path, buf, sizeof(buf)))
> + return KSFT_SKIP;
> + if (!strstr(buf, "cpuset")) {
> + if (write_file(root, "cgroup.subtree_control", "+cpuset"))
> + return KSFT_SKIP;
> + added = 1;
> + }

[Severity: Low]
Should these early KSFT_SKIP returns print a skip reason? cs_setup() also
returns -1 without logging, so the roughly 20 new cases calling it (as well
as partition_grows_child_valid() and hotplug_top_last_refused()) skip
silently when prerequisites are missing.

In addition, partition_shrink_moves_refused(),
partition_shrink_isolated_moves_refused(), partition_invalidate_refused(),
and partition_child_invalidate_refused() combine their CPU-count check with
cs_setup(), printing a misleading CPU-count message when cs_setup() fails.
Most new cases also initialize ret = KSFT_SKIP and only switch to KSFT_FAIL
after pipe(fd), so a pipe() error jumps to out: and silently skips instead
of failing.

[ ... ]

> +out:
> + reap(pid);
> + if (write_file("/proc/sys/kernel", "sched_rt_runtime_us", saved)) {
> + ksft_print_msg("admission control cannot be turned on again\n");
> + return KSFT_FAIL;
> + }
> + sleep_ns(3 * PERIOD);

[Severity: Low]
Can restoring /proc/sys/kernel/sched_rt_runtime_us before sleep_ns(3 * PERIOD)
fail with -EBUSY?

While the killed spinning task's 0-lag timer still holds its bandwidth in
dl_b->total_bw, sched_dl_global_validate() rejects the write if
new_bw * cpus < dl_b->total_bw. That returns KSFT_FAIL immediately and
leaves global admission control disabled (-1) for the remaining test cases
and after the test exits. Waiting 3 * PERIOD before restoring
sched_rt_runtime_us avoids this.

[Severity: Low]
In commit "selftests/sched: Test the root domain rebuild in deadline_bw_test"
earlier in this series, does hotplug_no_admission_pinned() have the same
ordering problem? Its out: path restores sched_rt_runtime_us immediately
after reaping the spinning 50% deadline task and before sleep_ns(3 * PERIOD),
which can fail with -EBUSY and leave admission control at -1 for all
subsequent cases.

[ ... ]

> + err = enter(cs_c, pid);
> + cpu = task_cpu_of(pid);
> + if (bw <= 0 || def != def0 || err || cpu != fb_h) {
> + ksft_print_msg("a deadline task adds %lld, %lld to total_bw, in C: %s, on CPU %d\n",
> + def - def0, bw, strerror(-err), cpu);
> + goto out;
> + }

[Severity: Low]
Can hotplug_nested_refused() fail spuriously if the child migrates off fb_h
before sleeping?

task_from() widens the child's affinity to all CPUs before calling
set_deadline() and blocking in read(), so preemption or load balancing can
move it to another CPU before it sleeps, and enter() does not migrate a
sleeping task's CPU. Unlike fallback_case(), which treats sleeping off fb_h
as KSFT_SKIP, hotplug_nested_refused(), hotplug_dead_accepted(),
partition_takes_fallback_refused(), partition_swap_refused(),
partition_refused_no_warn(), and hotplug_asleep_setattr() all return
KSFT_FAIL in that case.

[ ... ]

> + c = 'x';
> + if (enter(cs_b, pid) || write(go[1], &c, 1) != 1 || read(ack[0], &c, 1) != 1) {
> + ksft_print_msg("the task never ran in B\n");
> + goto out;
> + }

[Severity: Low]
Can read(ack[0], &c, 1) block forever if the child exits before writing to
ack[1]?

The parent keeps ack[1] open until out:, so if the child terminates early
(for example if read(go[0], &c, 1) fails and it calls _exit(1)), the kernel
never delivers EOF on ack[0] and the test hangs until the harness timeout.
hotplug_top_last_refused() has the same unclosed ack[1] before
read(ack[0], &c, 1). Closing ack[1] and go[0] in the parent right after
fork_child() avoids the hang.

[ ... ]

> + if (ic < 0 || x < 0 || !cpu_hotpluggable(x) || !server_found || cs_setup()) {
> + ksft_print_msg("needs isolcpus=\"domain\", 2 housekeeping CPUs, CPU hotplug, fair server files\n");
> + return KSFT_SKIP;
> + }

[Severity: Low]
Should hotplug_isolated_partition_falls_back() also skip when
ext_switched_all() is true, like hotplug_server() and
hotplug_server_refused()?

Because it reads server_get() and checks totals_check() across
cpu_online(x, 0), a CPU hotplug that terminates a sched_ext switch_all=1
scheduler switches accounting from ext_server back to fair_server and causes
a spurious failure.

[ ... ]

> + snprintf(buf, sizeof(buf), "%d", h2);
> + if (write_file(cs_q, "cpuset.cpus", buf) || partition_has(cs_q, "invalid", 1) ||
> + fallback_wake(fd[1], pid))
> + goto out;

[Severity: Low]
Is the tell flag in partition_has(cs_q, "invalid", 1) inverted?

partition_has() only prints cpuset.cpus.partition when the substring is
absent and tell is non-zero, so this logs a spurious message on every
passing run when Q is "root", stays silent if Q becomes invalid, and omits
checking that Q remains "root". Using !partition_has(cs_q, "root", 1) ||
partition_has(cs_q, "invalid", 0) matches the other valid-partition checks.

[ ... ]

> + /* Q has every housekeeping CPU but A, B and D. */
> + for (i = n = 0; i < ncpus - 3; i++)
> + n += snprintf(buf + n, sizeof(buf) - n, "%s%d", n ? "," : "",
> + online[i]);

[ ... ]

> + for (i = 1, n = 0; i < ncpus - 3; i++)
> + n += snprintf(buf + n, sizeof(buf) - n, "%d,", online[i]);
> + snprintf(buf + n, sizeof(buf) - n, "%d", d);

[Severity: Low]
Can these snprintf() loops overflow buf[4096] on the stack?

Because snprintf() returns the untruncated length, on a large-CPU system
where the formatted CPU list exceeds 4095 bytes, n grows past sizeof(buf)
and sizeof(buf) - n underflows size_t on the next iteration or the trailing
snprintf(), writing past buf on the stack. Guarding both loops with
n < (int)sizeof(buf) and skipping when n >= (int)sizeof(buf) (as
mask_grows_refused() does) prevents the overflow.

[ ... ]

> + cpu = task_cpu_of(pid);
> + if (want_isol ? !is_isol(cpu) : want >= 0 ? cpu != want : is_isol(cpu)) {
> + ksft_print_msg("woken on CPU %d\n", cpu);
> + return -1;
> + }
> + return 0;

[Severity: Low]
Does woken_on() accept a -1 error from task_cpu_of() as a valid housekeeping
CPU? When called with want_isol == 0 and want < 0 (as in
partition_shrink_isolated_moves_refused()), cpu == -1 makes is_isol(-1)
return 0, so woken_on() returns 0 instead of -1. Checking cpu < 0 first
avoids this.

[ ... ]

> + for (i = 0; i < ncpus && n < (int)sizeof(buf); i++)
> + n += snprintf(buf + n, sizeof(buf) - n, "%s%d", i ? "," : "", online[i]);
> + for (i = 0; i < nisol && n < (int)sizeof(buf); i++)
> + n += snprintf(buf + n, sizeof(buf) - n, ",%d", isol[i]);
> + err = write_file(cs_q, "cpuset.cpus", buf);

[Severity: Low]
Should partition_invalidate_refused() check n >= (int)sizeof(buf) before
calling write_file()?

On a host with roughly 540 or more online CPUs, the formatted CPU list
truncates at 2048 bytes and write_file() receives a partial or malformed
list, causing a spurious KSFT_FAIL instead of skipping.

--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796296313.git.mathieu.desnoyers@xxxxxxxxxxxx?part=26