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=1796313438; b=eqMSLTN+R+3zl7BWvsYQTy/Kn/z6Aa2xD27LXWEd1+WuCUIGIwcx4ovyoVON2oZM6E+f LS6sgVkWsdXLvlHnN26gGCB5J35m33nqISv46sz711h4widQInE5DXBEMcSqU33yH2AYx Q73IbaLOvcsS0oEo2D/16799J1UzK0+Lsu8I+DNoDkohDmU0C+WUQvmepP4wdfYwaD8qY De+kvybvsz4nCm4/2UQ7tBuze7FZ+DQt8PjDk4sk7yfPyUe9nSlGL0/fAc91aUdoCVVVp 81SvrpBBkg9B9K3WiSAwyALo6qAbM+hZtgy5F6/bW8a3xQOu6pBnNp9cq7kX/n5SQVw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796313438; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=RHDH7RpgugrMX2SoMeiSbILAu7oLWhBHO20Z0xVukLQ=; b=uceg1I1RFSU06JZyoWhCgmddwpajGpel7gm6GTYC8BCPPFWMRnLfp/Tm5jZQ0AQMyAhh R/4jt/KLAU9lpHB8B0tmajlT+hPLCkI+f6Y7whTz7j1EZon8XKfuD9XnsMLAi9lPFyge4 CZX/3+uJ6huCBCwa/A7hxiLNxsAetDjI6V2C+beq2DxM0sM7vCNIBEg1t8nkv5EkEU0MQ OZhpBIbzbHmvhB/q1wDhUf9XEsAnz17AGEOAPYnZnjUTzN6gIADQuinrlroThJmqCT4EW +G500OnuQHa359XpOLb4Cz8L/yy6dh3TE5M1Np5XhO4ES89L7DPnqSm7Hxk3VsbdQ0Q== 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=XQcKDnuq; 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 3176B606A322; Thu, 3 Dec 2026 15:57:17 +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=XQcKDnuq Received: by smtp.kernel.org (Postfix) with ESMTPSA id 79FFF1F000C1; Thu, 3 Dec 2026 15:57:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796313437; bh=RHDH7RpgugrMX2SoMeiSbILAu7oLWhBHO20Z0xVukLQ=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=XQcKDnuqTGuNZJqRkgYXZ+F81M7jOgHEGer69YziSN+ghy6vcH4xWag+amVpI4Ruv QY8eY70J4t3mPWaQeRdtjrVsctlTt2zsjtybakvoWjM+EWkHgoivPqrGg6uv0assSV 96IKVStoltswpdpPQnq33iUsGpDD3LItujSJ7dojG0ufKEV5efHkDOtm3B6D1QNE6I 4z+Hp993o0T7SvIquczOypBIvUg1TsrQNVtcDpzpU2yGs5h7axMpG/gB/Q1ixera9Z AFg2TNDFztm5OD0XbxAjciVewtpiSCZxJrPVp5x2VlTUnQHCmwpdV8SMXvNVmihQBD Xop3PJoJsbZOQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v14 10/39] sched/deadline: Rebuild the root domains' accounting from the task list Reply-To: sashiko-reviews@lists.linux.dev To: "Mathieu Desnoyers" Cc: linux-rt-devel@lists.linux.dev, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com, linux-kernel@vger.kernel.org In-Reply-To: References: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 15:57:17 +0000 X-Mailing-List: linux-kernel@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 4 potential issues to consider: - [Medium] sched/deadline: O(all threads) walk under tasklist_lock in dl_rebuild_rd_accounting() - [Low] sched/deadline: dead src_cs_head, stale cpuset_locked name, leftover externs - [Low] sched: stale cpuset_locked name and lock comments in __sched_setscheduler() - [Low] sched/deadline: data race on p->dl.dl_bw in dl_add_task_root_domain() -- commit c4ca672f54bfcb613c3239a48123aa44bc43b690 Author: Mathieu Desnoyers sched/deadline: Rebuild the root domains' accounting from the task list This commit replaces the cpuset-based walk in dl_rebuild_rd_accounting() with a tasklist walk gated by a global count of bandwidth-holding deadline tasks (dl_nr_bw_tasks), and adds dl_accounting_mutex to serialize admissions against rebuilds when CONFIG_CPUSETS is disabled. > diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c > index 4159abfbbbb53..7628cf77bdfd2 100644 > --- a/kernel/cgroup/cpuset.c > +++ b/kernel/cgroup/cpuset.c [ ... ] > @@ -3181,9 +3119,7 @@ static void clear_attach_data(struct llist_head *he= ad, bool cancel) > llist_for_each_entry_safe(cs, next, lnode, attach_node) { > init_llist_node(&cs->attach_node); > if (cs->nr_migrate_dl_tasks) { > - if (!cancel) > - atomic_add(cs->nr_migrate_dl_tasks, &cs->nr_deadline_tasks); > - else if (cs->dl_bw_cpu >=3D 0) /* && cancel */ > + if (cancel && cs->dl_bw_cpu >=3D 0) > dl_bw_free(cs->dl_bw_cpu, cs->sum_migrate_dl_bw); > cs->nr_migrate_dl_tasks =3D 0; > cs->sum_migrate_dl_bw =3D 0; > @@ -3272,7 +3208,6 @@ static int cpuset_can_attach(struct cgroup_taskset = *tset) > * contribute to sum_migrate_dl_bw. > */ > cs->nr_migrate_dl_tasks++; > - oldcs->nr_migrate_dl_tasks--; > if (dl_task_needs_bw_move(task, cs->effective_cpus)) > cs->sum_migrate_dl_bw +=3D task->dl.dl_bw; > } [Severity: Low] Can src_cs_head be removed now that nr_deadline_tasks and oldcs->nr_migrate_dl_tasks-- are gone? cpuset_can_attach_check() still adds oldcs to src_cs_head, and clear_attach_data() only unlinks it without reading or updating any source-cpuset state. Separately, dl_add_task_root_domain(), dl_clear_root_domain(), and dl_clear_root_domains() in include/linux/sched/deadline.h no longer have callers outside kernel/sched/deadline.c and can be made static. > diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c > index 7d1e305049c25..889a70314918c 100644 > --- a/kernel/sched/deadline.c > +++ b/kernel/sched/deadline.c [ ... ] > @@ -3712,7 +3728,13 @@ void dl_add_task_root_domain(struct task_struct *p) > struct cpumask *msk; > =20 > raw_spin_lock_irqsave(&p->pi_lock, rf.flags); > - if (!dl_task(p) || dl_entity_is_special(&p->dl)) { > + /* > + * Count nothing for a special entity, or for a task with no > + * bandwidth. The walk of the task list also finds exited tasks. An > + * exited task whose bandwidth went with its parameters has a dl_bw > + * of 0. > + */ > + if (!dl_task(p) || dl_entity_is_special(&p->dl) || !p->dl.dl_bw) { > raw_spin_unlock_irqrestore(&p->pi_lock, rf.flags); > return; > } [Severity: Low] Can the unmarked reads of p->dl.flags and p->dl.dl_bw here race with __dl_clear_params()? CPU0 CPU1 __schedule() dl_rebuild_rd_accounting() dequeue_task_dl() dl_add_task_root_domain(p) dequeue_dl_entity() raw_spin_lock_irqsave(&p->pi_lock) task_non_contending() dl_task_release_bw() dl_release_params() __dl_clear_params() dl_se->flags =3D 0; if (... || dl_entity_is_special(&p-= >dl) dl_se->dl_bw =3D 0; || !p->dl.dl_bw) <-- data race When a dying deadline task past its 0-lag time runs task_non_contending(), __dl_clear_params() writes dl_se->flags and 64-bit dl_se->dl_bw under only rq->__lock after dl_task_release_bw() has dropped dl_departed_lock. Meanwhile dl_add_task_root_domain() holds only p->pi_lock, so KCSAN can flag a data race and 32-bit architectures can observe torn 64-bit reads. Later patches in this series (commit "sched/deadline: Record the root domain holding a task's bandwidth" and commit "sched/deadline: Leave a dying task out of a rebuild of the accounting") prevent bandwidth corruption here, though the unmarked accesses remain. Using READ_ONCE()/WRITE_ONCE() on dl_bw and flags, or moving the !p->dl.dl_bw check under dl_departed_lock, would avoid the race. [ ... ] > +void dl_rebuild_rd_accounting(void) > +{ > + struct task_struct *g, *p; > + > + lockdep_assert_cpus_held(); > + lockdep_assert_held(&sched_domains_mutex); > + lockdep_assert_cpuset_lock_held(); > + lockdep_assert_dl_accounting_held(); > + > + dl_clear_root_domains(); > + > + /* > + * Without a task that holds a bandwidth, there is nothing to count. > + * The walk would still visit every thread of the system. A CPU > + * that goes offline or comes back runs a rebuild, so a suspend and > + * a resume run one for each CPU. A task gets a bandwidth under the > + * locks this rebuild holds, so the count cannot leave 0 meanwhile. > + */ > + if (!atomic_read(&dl_nr_bw_tasks)) > + return; > + > + read_lock(&tasklist_lock); > + for_each_process_thread(g, p) { > + /* > + * Test the class without the task's locks, and take them only > + * for a deadline task. A task enters the class under the locks > + * this rebuild holds, or by a boost. A boost brings no > + * bandwidth of its own to count. > + */ > + if (dl_task(p)) > + dl_add_task_root_domain(p); > + } > + read_unlock(&tasklist_lock); > +} [Severity: Medium] Does holding read_lock(&tasklist_lock) across for_each_process_thread() here introduce a latency and lock-contention regression when a deadline task is active? With CONFIG_CPUSETS, rebuilds previously skipped cpusets with no deadline tasks and never took tasklist_lock. Now, as long as even one task holds deadline bandwidth (including a departed task waiting on its 0-lag timer), every CPU hotplug or suspend/resume rebuild walks every thread in the system with read_lock(&tasklist_lock) held. On non-PREEMPT_RT kernels that disables preemption for milliseconds (0.7 to 1.2 ms per rebuild on 10,000 threads) and stalls write_lock_irq(&tasklist_lock) callers such as copy_process() and exit paths, multiplied across every CPU on suspend and resume. Tracking bandwidth-holding sched_dl_entity objects on a dedicated list updated in __setparam_dl() and __dl_clear_params() would keep rebuilds O(deadline tasks) without taking tasklist_lock. > diff --git a/kernel/sched/syscalls.c b/kernel/sched/syscalls.c > index 595bdb9bd04f3..145940d0ce4de 100644 > --- a/kernel/sched/syscalls.c > +++ b/kernel/sched/syscalls.c > @@ -568,6 +568,7 @@ int __sched_setscheduler(struct task_struct *p, > if (pi && (dl_policy(policy) || dl_policy(p->policy))) { > cpuset_locked =3D true; > cpuset_lock(); > + dl_accounting_lock(); > } [Severity: Low] This isn't a bug, but cpuset_locked now tracks dl_accounting_lock() as well (and only dl_accounting_mutex without CONFIG_CPUSETS). Renaming it to dl_accounting_locked and updating the cpuset_mutex-only comments in __sched_setscheduler() would keep the locking documentation accurate. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1796296313.gi= t.mathieu.desnoyers@efficios.com?part=3D10