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=1796275976; b=LqnXMNhvX2ACcX572nVQXMteTckG2mZnzMt/d5F+rMq20E/Ma2djk5w6h/bbsZgNCOtc boAhvoKPQhVAv1Sy/U7CGdDc/Gf759z0uFA4bCBSq+9btg42vhIkoQuSktfbhZlyBVU4D kRqmIyXPr4Q3BDZqk5MQjDzOVkSBsgKvSqQfNFk+bJfl+kGqqbfPAPQxu1am/cCIBwyLl JZCVXapay5iXkdLs1fc7tvpt13Wqz0s9jEjwkKriRbPJQhGBV8+7CrksQXX7PZHzS2zFU iX8Ck9W0vLp4mTE+LP0YejColjutKAaCz6pWn/L/8s8sYMa1b4MlxWNHZcyUdCCEnQw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796275976; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=7Ft814iGR3RKihzGwKdmnfV1OTcwbpSVoMA5DihVwcU=; b=5QgXqldokFH65i8RS+J/RIBmaW50DPYlIopLtb3U2MPAsQNJ95HAXH+l+ByfY8d6ahao wuWI0/1kSXK+9ibuIFFjXXpliDXXtqRtngz7ReMrCr7AvCAyInfqU/YqqHsn1fUG8ZliC LDquU/yhvbAXtoOJrmZ8LDboufnLVKQ6x7wgSTjaM3BH+YaFv56U40Br4F6T/Sqx64zgL I7LroMoyG7aqhT9dG3NRpk9Y04NCbMzGypu4X9iTZQB2JFGRmQnZZtLVxZXL00zbLEwUF GPjQo9eZADUevgRPedIfRrPRNufPbsvcA64D7HgfRd9REW+zJ7gRfQh3cA/PDtQDNeA== 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=QRuwxn59; 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 50647606A322 for ; Thu, 3 Dec 2026 05:32:56 +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=QRuwxn59 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E1D71F00896; Thu, 3 Dec 2026 05:32:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796275976; bh=7Ft814iGR3RKihzGwKdmnfV1OTcwbpSVoMA5DihVwcU=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=QRuwxn59H9ZiodJlPWcp9kObDRQSCBUVY94WBTLGeB4CwlmAcvyv9xjADY4EB1/pE xo2yaYpTZTCEo3J5Go4LUO/ln0j4ueI7xODqGX6L/taVorU/Rj5FGk0UNR6QQjWmiy smrB4JLndeXplh9qasD5dgDPsh8ixJpNeEJ7gZX6IstxU5tBLxIftF+AmS6BALisHQ gzvd70LAsSHVi1zIKc7scbLz72OQcEXRyLWgDyw+Cpj/wbEOowbKm3vfhdwNHsOYJS ce6NN1a1+XRf2L9vg9PVjesEqQr6y2nCmWRVKAa4hYoLSDBx1Jdf8da2UE40Wf7YMz 1Ef58hiK75y5Q== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 8/8] selftests/sched_ext: Test task field reset across sub-scheduler handoffs Reply-To: sashiko-reviews@lists.linux.dev To: "Changwoo Min" Cc: sched-ext@lists.linux.dev In-Reply-To: <20261203045618.982539-9-changwoo@igalia.com> References: <20261203045618.982539-1-changwoo@igalia.com> <20261203045618.982539-9-changwoo@igalia.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 05:32:55 +0000 X-Mailing-List: sched-ext@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 5 potential issues to consider: - [Medium] selftests/sched_ext: unsynchronized child sleep triggers SCX_EXIT_ERROR_REENQ - [Medium] selftests/sched_ext: unchecked kfunc returns allow vacuous sub_handoff passes - [Medium] selftests/sched_ext: handoffs() never checks sub_skel UEI liveness or exit - [Low] selftests/sched_ext: sub_handoff.c duplicates get_cgroup_id() and now_ns() - [Low] selftests/sched_ext: sub_handoff_enable() increments nr_enable too early -- commit 606e70f4ac2fdd8ea9df9beb5122bf3ee7426a80 Author: Changwoo Min selftests/sched_ext: Test task field reset across sub-scheduler handoffs This commit adds the sub_handoff sched_ext selftest to verify that p->scx.bpf_priv and p->scx.dsq_vtime are cleared when a task moves between a root scheduler and a sub-scheduler, and that ops.exit_task() cannot set bpf_priv. > diff --git a/tools/testing/selftests/sched_ext/sub_handoff.bpf.c b/tools/= testing/selftests/sched_ext/sub_handoff.bpf.c > new file mode 100644 > index 0000000000000..d7ce3f4e150c6 > --- /dev/null > +++ b/tools/testing/selftests/sched_ext/sub_handoff.bpf.c [ ... ] > +void BPF_STRUCT_OPS(sub_handoff_enable, struct task_struct *p, > + struct scx_enable_args *args) > +{ > + if (p->pid !=3D target_pid) > + return; > + > + __sync_fetch_and_add(&nr_enable, 1); > + if (p->scx.bpf_priv) > + __sync_fetch_and_add(&nr_stale_priv, 1); > + if (p->scx.dsq_vtime) > + __sync_fetch_and_add(&nr_stale_vtime, 1); > + > + scx_bpf_task_set_priv(p, PRIV_MAGIC | (u32)p->pid); > +} [Severity: Low] Should nr_enable be incremented at the end of sub_handoff_enable() instead of before the stale-field checks? wait_u64() polls nr_enable with __ATOMIC_ACQUIRE as the completion gate before handoffs() asserts on nr_stale_priv and nr_stale_vtime. If a concurrent observer such as a BPF link iterator holds a transient reference to sub_link during bpf_link__destroy(), bpf_scx_unreg() runs asynchronously when that reference is dropped: CPU0 CPU1 handoffs() bpf_link__destroy(*sub_link) (deferred by extra link ref) wait_u64(&root->nr_enable, 2) bpf_link_put_deferred() ... sub_handoff_enable() nr_enable++ (now 2) reads nr_stale_priv =3D=3D 0 <-- stale check has not run yet reads nr_stale_vtime =3D=3D 0 if (p->scx.bpf_priv) nr_stale_priv++ Userspace can then observe zero stale counts even when a regression leaves bpf_priv or dsq_vtime uncleared. Moving the nr_enable increment to the end of sub_handoff_enable() fixes the release-acquire ordering. > + > +/* > + * @p is still on this scheduler but no longer enabled. Neither write ma= y reach > + * the scheduler @p moves to. > + */ > +void BPF_STRUCT_OPS(sub_handoff_exit_task, struct task_struct *p, > + struct scx_exit_task_args *args) > +{ > + if (p->pid !=3D target_pid) > + return; > + > + if (scx_bpf_task_set_priv(p, PRIV_MAGIC | (u32)p->pid)) > + __sync_fetch_and_add(&nr_exit_set, 1); > + scx_bpf_task_set_dsq_vtime(p, VTIME_MAGIC); > +} [Severity: Medium] Can the assertions in handoffs() pass vacuously if the setup writes fail or ops.exit_task() never runs? Both scx_bpf_task_set_priv() and scx_bpf_task_set_dsq_vtime() return a bool, yet sub_handoff_enable() ignores the return of scx_bpf_task_set_priv() and sub_handoff_exit_task() ignores the return of scx_bpf_task_set_dsq_vtime(). sub_handoff_exit_task() also does not count invocations on target_pid. If a regression causes either write to fail or skips ops.exit_task() on handoff, the fields remain 0 and the zero-count assertions in handoffs() still pass. Tracking write failures and ops.exit_task() counts and asserting them in handoffs() would ensure non-zero values were written before verifying they were cleared. > diff --git a/tools/testing/selftests/sched_ext/sub_handoff.c b/tools/test= ing/selftests/sched_ext/sub_handoff.c > new file mode 100644 > index 0000000000000..18e20416c9110 > --- /dev/null > +++ b/tools/testing/selftests/sched_ext/sub_handoff.c [ ... ] > +static u64 get_cgroup_id(const char *path) > +{ > + union { > + u64 id; > + unsigned char bytes[8]; > + } id =3D {}; > + struct file_handle *handle; > + int mount_id, ret; > + > + handle =3D calloc(1, sizeof(*handle) + sizeof(id)); > + if (!handle) > + return 0; > + handle->handle_bytes =3D sizeof(id); > + ret =3D name_to_handle_at(AT_FDCWD, path, handle, &mount_id, 0); > + if (!ret && handle->handle_bytes =3D=3D sizeof(id)) > + memcpy(id.bytes, handle->f_handle, sizeof(id)); > + free(handle); > + > + return ret ? 0 : id.id; > +} > + > +static u64 now_ns(void) > +{ > + struct timespec ts; > + > + clock_gettime(CLOCK_MONOTONIC, &ts); > + return (u64)ts.tv_sec * 1000000000ULL + ts.tv_nsec; > +} [Severity: Low] This isn't a bug, but get_cgroup_id() duplicates get_cgroup_id() in sub_core_caps.c and cgroup_id() in cgroup_nr_cpus.c, and now_ns() duplicates now_ns() in sub_core_caps.c. Could these helpers be moved to the shared util.c and util.h instead? [ ... ] > + /* Step 3: Detaching the sub-scheduler hands the target back */ > + bpf_link__destroy(*sub_link); > + *sub_link =3D NULL; > + > + /* > + * The same checks in the other direction, from the sub-scheduler's > + * ops.exit_task() to the root's second ops.enable(). The root's stale > + * counters also cover its first ops.enable() in step 1. > + */ > + SCX_EQ(wait_u64(&root->nr_enable, 2), 2); > + SCX_EQ(sub->nr_exit_set, 0); > + SCX_EQ(root->nr_stale_priv, 0); > + SCX_EQ(root->nr_stale_vtime, 0); > + > + /* Neither handoff may have made the root exit with an error */ > + SCX_ASSERT_ALIVE(ctx->root_skel, uei); > + return SCX_TEST_PASS; > +} [Severity: Medium] Should handoffs() also verify that sub_skel stayed alive until step 3 and exited cleanly with SCX_EXIT_UNREG? If sub_skel aborts with a runtime error during step 2, the kernel disables it and moves target_pid back to root_skel. root->nr_enable still reaches 2 and all current assertions pass despite the error exit. Checking SCX_ASSERT_ALIVE(ctx->sub_skel, uei) before bpf_link__destroy(*sub_link) and EXIT_KIND(SCX_EXIT_UNREG) afterward would catch unexpected sub_skel exits. [ ... ] > + /* The target sleeps through the handoffs and exits when the pipe close= s */ > + pid =3D fork(); > + if (pid < 0) { > + close(pfd[0]); > + close(pfd[1]); > + SCX_FAIL("Failed to fork target (%d)", errno); > + } > + if (pid =3D=3D 0) { > + close(pfd[1]); > + _exit(read(pfd[0], &c, 1) =3D=3D 0 ? 0 : 1); > + } > + close(pfd[0]); > + > + status =3D handoffs(ctx, pid, &root_link, &sub_link); [Severity: Medium] Can the child still be runnable when step 2 attaches sub_link and trigger SCX_EXIT_ERROR_REENQ on sub_skel? run() enters handoffs() immediately after fork() without waiting for the child to block in read(). Because sub_handoff_sub_attach() grants no CPU capabilities to sub_skel and sub_handoff_enqueue() unconditionally inserts into SCX_DSQ_LOCAL without SCX_ENQ_RESCUE, a runnable child on sub_skel cannot be placed on a local DSQ: CPU0 CPU1 run() fork() handoffs() attach sub_link (child still runnable, not in read()) scx_sub_enable_workfn() scx_bypass(sch, false) sub_handoff_enqueue() scx_bpf_dsq_insert(..., SCX_DSQ_LOCAL, ...) __scx_resolve_local_dsq() -> reject_dsq scx_reenq_reject() (repeats 256x) <-- SCX_EXIT_ERROR_REENQ After SCX_REENQ_MAX_REPEAT rejections, scx_do_enqueue_task() aborts sub_skel with SCX_EXIT_ERROR_REENQ and moves the target back to root_skel before step 3 detaches it. Waiting for the child to sleep before calling handoffs() (as in sub_core_caps.c) avoids this race. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203045618.9825= 39-1-changwoo@igalia.com?part=3D8