Re: [PATCH v8 05/33] selftests/sched: Test SCHED_DEADLINE bandwidth across a root domain rebuild

From: sashiko-bot

Date: Thu Nov 19 2026 - 15:29:36 EST


Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] selftests/sched: missing isolated/sparse CPU handling and
code duplication
- [Low] selftests/sched: missing 0-lag wait on early exit in
test_rebuild()
- [Low] selftests/sched: undersized path buffer in make_partition()
- [Low] selftests/sched: missing PR_SET_PDEATHSIG in departing() and
sleeper()
--

commit 61b9ca4442ef766ed51f3c6ad77a1ac959261741
Author: Mathieu Desnoyers <mathieu.desnoyers@xxxxxxxxxxxx>

selftests/sched: Test SCHED_DEADLINE bandwidth across a root domain rebuild

This commit adds the deadline_rebuild_test selftest to verify that
SCHED_DEADLINE bandwidth of tasks that exit or leave the policy before
their 0-lag time is preserved across cpuset partition root domain
rebuilds.

> diff --git a/tools/testing/selftests/sched/deadline/deadline_rebuild_test.c b/tools/testing/selftests/sched/deadline/deadline_rebuild_test.c
> new file mode 100644
> index 0000000000000..714a0ff03f1b9
> --- /dev/null
> +++ b/tools/testing/selftests/sched/deadline/deadline_rebuild_test.c
> @@ -0,0 +1,497 @@

[ ... ]

> +/* Make @cg a partition root of CPU @cpu alone. Return 0, or -1 on error. */
> +static int make_partition(const char *cg, int cpu)
> +{
> + char path[PATH_MAX], buf[32];
> +
> + if (mkdir(cg, 0755) && errno != EEXIST)
> + return -1;
> + snprintf(buf, sizeof(buf), "%d", cpu);
> + if (write_file(cg, "cpuset.cpus", buf) || write_file(cg, "cpuset.cpus.partition", "root"))
> + return -1;
> + snprintf(path, sizeof(path), "%s/cpuset.cpus.partition", cg);
> + if (read_file(path, buf, sizeof(buf)) || strcmp(buf, "root\n"))
> + return -1;
> + return 0;
> +}

[Severity: Low]
Can snprintf() truncate path[] here and trigger a -Wformat-truncation
warning when make_partition() is inlined with cg_p or cg_q (which are
sized PATH_MAX)? Sizing path[] to PATH_MAX + 32, as main() does for
cgroup.subtree_control, avoids the truncation warning.

[ ... ]

> +static pid_t departing(const char *cg, enum depart how, int fd[2])
> +{
> + pid_t pid = fork();
> +
> + if (pid < 0)
> + ksft_print_msg("fork: %s\n", strerror(errno));
> + if (!pid) {
> + uint64_t t0;
> +
> + close(fd[0]);
> + if (cg && enter(cg, getpid()))
> + _exit(2);
> + if (set_deadline(0, 400 * NSEC_PER_MSEC))
> + _exit(3);
> + t0 = cpu_time_ns();
> + while (cpu_time_ns() - t0 < 380 * NSEC_PER_MSEC)
> + ;
> + if (how == DIES)
> + _exit(0);
> + if (set_other(0) || write(fd[1], "x", 1) != 1)
> + _exit(4);
> + for (;;)
> + pause();
> + }

[ ... ]

> +static pid_t sleeper(const char *cg)
> +{
> + int fd[2];
> + pid_t pid;
> + char c;
> +
> + if (pipe(fd))
> + return -1;
> + pid = fork();
> + if (pid < 0)
> + ksft_print_msg("fork: %s\n", strerror(errno));
> + if (!pid) {
> + close(fd[0]);
> + if (enter(cg, getpid()) || write(fd[1], "x", 1) != 1)
> + _exit(1);
> + for (;;)
> + pause();
> + }

[Severity: Low]
If the test runner is killed by a signal or kselftest timeout while
children from departing() or sleeper() are alive, will those children stay
blocked in pause() inside cg_p holding SCHED_DEADLINE bandwidth and
preventing cg_p from being removed? Using a fork_child() helper with
prctl(PR_SET_PDEATHSIG, SIGKILL), like deadline_switch_test.c and
deadline_bw_test.c do, ensures children exit with the test.

[ ... ]

> +static int test_rebuild(enum depart how)
> +{
> + int ret = KSFT_FAIL, fd[2], err;
> + pid_t pid = -1;
> +
> + if (pipe(fd))
> + return KSFT_FAIL;
> + if (make_partition(cg_p, ncpus - 1)) {
> + ksft_print_msg("no partition root on CPU %d\n", ncpus - 1);
> + ret = KSFT_SKIP;
> + goto out;
> + }
> + pid = departing(cg_p, how, fd);
> + err = departed(&pid, how, fd[0]);
> + if (err) {
> + ksft_print_msg("the deadline task failed (%d)\n", err);
> + goto out;
> + }
> + if (make_partition(cg_q, ncpus - 2)) {
> + ksft_print_msg("no partition root on CPU %d\n", ncpus - 2);
> + ret = KSFT_SKIP;
> + goto out;
> + }
> + /*
> + * Wait past the 0-lag time. In the SWITCHED_OUT case the task is still
> + * alive then: it sleeps in P as a SCHED_OTHER task.
> + */
> + sleep_ns(1500 * NSEC_PER_MSEC);
> + ret = check_p();
> +out:
> + reap(pid);
> + remove_partition(cg_q);
> + remove_partition(cg_p);
> + close(fd[0]);
> + if (fd[1] >= 0)
> + close(fd[1]);
> + return ret;
> +}
> +
> +/*
> + * Have a task outside P switch to SCHED_OTHER and sleep. Before its 0-lag
> + * time, move it into P and kill it. Then check P.
> + */
> +static int test_move(void)
> +{
> + int ret = KSFT_FAIL, fd[2], err;
> + pid_t pid = -1;
> +
> + if (pipe(fd))
> + return KSFT_FAIL;
> + if (make_partition(cg_p, ncpus - 1)) {
> + ksft_print_msg("no partition root on CPU %d\n", ncpus - 1);
> + ret = KSFT_SKIP;
> + goto out;
> + }
> + pid = departing(NULL, SWITCHED_OUT, fd);
> + err = departed(&pid, SWITCHED_OUT, fd[0]);
> + if (err) {
> + ksft_print_msg("the deadline task failed (%d)\n", err);
> + goto out;
> + }
> + if (enter(cg_p, pid)) {
> + ksft_print_msg("the task cannot move into P\n");
> + goto out;
> + }

[Severity: Low]
If make_partition(cg_q, ncpus - 2) in test_rebuild() or enter(cg_p, pid)
in test_move() fails after departed() has succeeded, does jumping directly
to out skip waiting for the departed task's 0-lag inactive timer? The
next test case in main() would then start while the 400ms/1000ms bandwidth
is still pending removal from the root domain.

[ ... ]

> +int main(void)
> +{
> + char buf[256], path[PATH_MAX + 32];
> + int added;
> +
> + ksft_print_header();
> + if (geteuid())
> + ksft_exit_skip("needs root\n");
> + ncpus = get_nprocs();
> + if (ncpus < 3)
> + ksft_exit_skip("needs 3 CPUs\n");

[Severity: Medium]
Can picking CPUs ncpus - 1 and ncpus - 2 from get_nprocs() fail when
online CPU numbering has gaps or when isolcpus=domain is configured?

Unlike deadline_bw_test.c, which reads /sys/devices/system/cpu/online and
/sys/devices/system/cpu/isolated, picks online non-isolated CPUs, and
restricts task affinity away from isolated CPUs, this test assumes online
CPUs are contiguously numbered 0..ncpus-1 and none are isolated. When
isolcpus=domain is used (which deadline_bw_test.c requires for many of its
cases), ncpus - 1 or ncpus - 2 can be isolated or offline, and in
test_move() the child spawned by departing(NULL, SWITCHED_OUT, fd)
inherits root-cgroup affinity that includes isolated CPUs, causing
set_deadline() to fail.

Since roughly half of this file duplicates the cgroup v2, partition, and
SCHED_DEADLINE helpers from deadline_bw_test.c in the same directory,
could these helpers be shared (or these three cases folded into
deadline_bw_test.c) so online and isolated CPUs are handled consistently?

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