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=1796321678; b=eclKQw3GnmRpb194J3pL0CO0JlEUOLnTN6UCRgdAmVHJLYiFRRA9WjCr+WRBVbcUmCzU i8n0UAhBGdU/TxnYgqtt2m4S6PFToOLmDPh/24KyZCwIJpX3wuCPUvqTqFFqNAhaj6140 SJqN7+KMyP7fZT1VfzL7TT2q7X96EabBpTnsy+xdwK+kwnMYXIJboh0UBZj8G44t/4msf NKfMUE/bseJ9gMPnwq8xuhHkl53PyKm0TQRCZw4W7N+UAnGkz0813wWaTFMewkJgvXtIT O6Me+p7pZHv5W5RTw9KQJ+M7HBOsTRiqIdympvC9xfXJ5LpgQMGrw/feqdXO5Fiz5sQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796321678; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=gd6AjVeUdIJg7puKqlLAl5sdvK8XCYKJEPad/wndS8Q=; b=Y4IVryPig1z3Rk6B42jpYvO5UY9nPjiQTb3La4ZmdqlsTynDlmvbhGmypkbWadnVX5P8 NVdsTEX01XhILKNGrUocY6Tkk+2McNppaaThIaT6aSBJrBrXFEv48CG8AKVp2XOJgVE3J QA6nyAOI8dKQeopp4WLTu9BOrT+BHZuelMQTGFavd1aWYQiTaE0ffxmq+apzRYOosg/6u 0LUbLtmF19ouigZtLM5OkAkd9x82DsSykhNHti/JgW2BBqomO+GLpVpt9BQo5xI8URgMl 9agdqOYB+tfGZ0IxSt9dnc0/NYDyzhU5JUcHgQqwatxZP/+IR/M0MxOCjYC158rnqtQ== 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=W19YZUm0; 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 410DC606A322; Thu, 3 Dec 2026 18:14:37 +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=W19YZUm0 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8181F1F0089A; Thu, 3 Dec 2026 18:14:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796321677; bh=gd6AjVeUdIJg7puKqlLAl5sdvK8XCYKJEPad/wndS8Q=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=W19YZUm0oHQyTEZ2+riU0qrPl2CMP/qsTqqB5tXteMyyEeAhMmItUCD1JNHKBQRHm f8XCDN5027OXaH5WDGDJzSXKK9K5WEQO0RH9EaS8LaUAalbzny33dT1sLNHrUcA+IC qCchK0+RN45Bo4WFjGiTAxnQk/RIo6GEmWA7T6i24mACzz47FAKili/e/O3zCaTwxW JDO6Ww4AuBrkuT1hk/wX2/AWwzoOAIMquIAWBb8iSK/xVmO8TJdleyQDQBJtfduHL3 vDq4V0h3W4ZS4xYwz/6F7O9ElIukjNb2mjiQJFYWxSdIldRY63IhjjyASaLH0/hdgS 9MYB+jWoD10Ag== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v14 36/39] sched/deadline: Keep a reaped deadline task in a rebuild 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: <44135091542c76aa297063a36b531c9371543ff0.1796296313.git.mathieu.desnoyers@efficios.com> References: <44135091542c76aa297063a36b531c9371543ff0.1796296313.git.mathieu.desnoyers@efficios.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 18:14:37 +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: - [High] sched/deadline: unconditional task_rq_lock() in release_task() regresses exit - [Medium] sched/deadline: rebuilds drop live dl_departed_list tasks with older dl_bw_gen - [Medium] sched/deadline: rebuilds drop 0-lag bw on TASK_DEAD/deboost race before depart - [Medium] sched/deadline: dl_clear_root_domains() skips task/CPU checks on active CPU -- commit f94214ebaf6d381e037df3c660707d6ae2d886b2 Author: Mathieu Desnoyers sched/deadline: Keep a reaped deadline task in a rebuild This commit adds dl_task_unhash() to release_task() so a reaped deadline task is placed on dl_departed_list before leaving the task list, keeping its bandwidth accounted across root-domain rebuilds until its last schedule or 0-lag time. It also keeps exited tasks on dl_departed_list when boosted back into SCHED_DEADLINE and updates dl_clear_root_domains() and dl_add_task_root_domain() to account for live tasks on that list. > diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c > index f2429672358c0..1eba22b9010bd 100644 > --- a/kernel/sched/deadline.c > +++ b/kernel/sched/deadline.c [ ... ] > @@ -440,6 +444,30 @@ static void dl_task_depart(struct task_struct *p) > list_add(&dl_se->dl_departed_node, &dl_departed_list); > } > =20 > +/* > + * Put @p on dl_departed_list if it is a deadline task with a bandwidth. > + * release_task() calls this before it takes @p off the task list, so > + * that a rebuild still counts @p until its last schedule. That schedule, > + * or the inactive timer after it, takes @p off the list. The caller hol= ds > + * tasklist_lock for writing: no walk of the task list runs meanwhile. > + */ > +void dl_task_unhash(struct task_struct *p) > +{ > + struct rq_flags rf; > + struct rq *rq; > + > + lockdep_assert_held_write(&tasklist_lock); > + /* > + * Test dl_bw under the rq lock. __sched_setscheduler() admits under > + * that lock, and can still admit @p here: @p sets exit_state without > + * that lock. > + */ > + rq =3D task_rq_lock(p, &rf); > + if (dl_task(p) && dl_task_holds_bw(p)) > + dl_task_depart(p); > + task_rq_unlock(rq, p, &rf); > +} [Severity: High] Does taking task_rq_lock() unconditionally here regress exit scalability when SCHED_DEADLINE is not in use? release_task() calls dl_task_unhash() on every reaped process and thread while holding the global tasklist_lock for writing. When a parent reaps a child that last ran on another CPU, acquiring p->pi_lock and the remote rq->__lock under tasklist_lock bounces the runqueue lock cacheline across CPUs, injects contention onto remote CPUs, and extends tasklist_lock hold time for concurrent fork, exit, wait, and /proc walks. Elsewhere in kernel/sched/deadline.c (such as dl_rebuild_rd_accounting()), work is skipped when dl_nr_bw_tasks is zero. Could dl_task_unhash() avoid task_rq_lock() on the common non-deadline fast path by gating on dl_nr_bw_tasks together with in-flight deadline admissions? [ ... ] > @@ -4576,19 +4617,20 @@ void dl_add_task_root_domain(struct task_struct *= p) > if (p->dl.dl_bw_gen =3D=3D dl_bw_gen) > goto unlock; > if (!list_empty(&p->dl.dl_departed_node)) { > - int recorded =3D p->dl.dl_bw_cpu; > - > /* > * The walk also finds a dead task that departed before an > * earlier rebuild, if it is not reaped yet. If that rebuild > * dropped its bandwidth, dl_clear_root_domains() skipped it, > * and its release removes nothing. Skip it here too. > + * > + * The clear counted the other tasks on the list, or dropped a > + * dead task whose CPU is inactive. It left out a task in the > + * class with no active CPU in its mask, since it cannot ask > + * the cpuset. Count that task here. > */ > - if (p->dl.dl_bw_gen !=3D dl_bw_gen - 1) > + if (p->dl.dl_bw_gen !=3D dl_bw_gen - 1 || cpu >=3D nr_cpu_ids || > + READ_ONCE(p->__state) =3D=3D TASK_DEAD) > goto unlock; [Severity: Medium] Can this generation check drop the bandwidth of a live task on dl_departed_list whose dl_bw_gen is older than dl_bw_gen - 1? Suppose an exited departed task had its bandwidth dropped by rebuild G + 1 (leaving p->dl.dl_bw_gen at G), and a boost brings it back into SCHED_DEADLINE during rebuild G + 2 so dl_task_undepart() keeps it on dl_departed_list and sets dl_bw_skip_gen to G + 2. If no CPU in p->cpus_mask is active, dl_clear_root_domains() leaves it out with dl_bw_gen still G, and when dl_add_task_root_domain() later finds an active CPU via the cpuset, p->dl.dl_bw_gen !=3D dl_bw_gen - 1 skips it and leaves total_bw undercounted. dl_clear_root_domains() has the same problem across consecutive rebuilds: if a live reaped or boosted task on dl_departed_list is left out by rebuild G + 1 for lack of an active CPU in its mask, rebuild G + 2 skips it at dl_bw_gen !=3D dl_bw_gen - 1 && dl_bw_skip_gen !=3D dl_bw_gen. Similarly, if an exited departed task is boosted back outside dl_bw_rebuilding() while dl_task_count_cpu() finds no active CPU, dl_task_undepart() does not set dl_bw_skip_gen for the next rebuild, so the next rebuild also drops it. Checking for live in-class tasks (dl_task(p) && READ_ONCE(p->__state) !=3D TASK_DEAD) before skipping older generations in dl_clear_root_domains() and dl_add_task_root_domain() would cover these cases. [ ... ] > @@ -4778,20 +4821,40 @@ void dl_clear_root_domains(void) > /* > * Skip bandwidth that an earlier rebuild dropped. It is not > * counted now, and its release removes nothing > - * (dl_task_release_bw()). > + * (dl_task_release_bw()). Count it anyway if > + * dl_task_undepart() asked for it through dl_bw_skip_gen: a > + * boost brought an exited task back into the class. > */ > - if (dl_se->dl_bw_gen !=3D dl_bw_gen - 1) > + if (dl_se->dl_bw_gen !=3D dl_bw_gen - 1 && > + dl_se->dl_bw_skip_gen !=3D dl_bw_gen) > + goto left_out; > + if (cpu < 0) > goto left_out; > /* > - * Drop the bandwidth of a task whose CPU is inactive. A CPU > - * that goes offline is in the default root domain by then. > - * The root domain that counted the task cannot be found > - * from the recorded number. The release then removes > - * nothing. A boost of the task back into the class counts > - * it again (dl_task_undepart()). > + * Drop the bandwidth of a departed task whose CPU is inactive. > + * A CPU that goes offline is in the default root domain by > + * then. The root domain that counted the task cannot be found > + * from the recorded number. The release then removes nothing. > + * A boost of the task back into the class counts it again > + * (dl_task_undepart()). > + * > + * A task on the list can also still run in the class. It is a > + * reaped task before its last schedule, or an exited task that > + * a boost brought back. The walk leaves it to the clear. Count > + * it on the CPU the walk would pick. This reads the task > + * without its locks, so the CPU can be wrong. The bandwidth > + * then stays in that root domain until the release, or the > + * next rebuild. > */ > - if (cpu < 0 || !cpu_active(cpu)) > - goto left_out; > + if (!cpu_active(cpu)) { [Severity: Medium] When the recorded dl_bw_cpu is still active, can dl_clear_root_domains() charge a live task on dl_departed_list to the wrong root domain? Because dl_task_count_cpu(p) is only called inside if (!cpu_active(cpu)), a reaped deadline task put on dl_departed_list with dl_bw_cpu =3D 0 that migrates to CPU1 before a cpuset partition splits {0, 1} into two root domains still has cpu_active(0) true. dl_clear_root_domains() then charges its bandwidth to CPU0's root domain instead of CPU1's, over-accounting one root domain and under-accounting the other until inactive_task_timer() fires. The same mismatch happens when an exited departed task with dl_bw_skip_gen =3D=3D dl_bw_gen is boosted on CPU1 while its stale dl_bw_cpu is active in another root domain. If that exited task is also deboosted before dl_clear_root_domains() runs, dl_task_depart() returns early without clearing dl_bw_skip_gen, and skipping the !dl_task(p) / TASK_DEAD check when cpu_active(cpu) is true resurrects its dropped bandwidth for the rest of its 0-lag period. > + struct task_struct *p =3D dl_task_of(dl_se); > + > + if (!dl_task(p) || READ_ONCE(p->__state) =3D=3D TASK_DEAD) > + goto left_out; > + cpu =3D dl_task_count_cpu(p); > + if (cpu >=3D nr_cpu_ids) > + goto left_out; > + } [Severity: Medium] Can this check drop a task's 0-lag bandwidth if a rebuild races between do_task_dead() setting TASK_DEAD and task_non_contending() calling dl_task_depart()? CPU0 (rebuild) CPU2 (task p, dl_bw_cpu =3D 1) release_task() -> dl_task_unhash() /* on dl_departed_list, moves to CPU2 */ do_task_dead() set_special_state(TASK_DEAD) /* CPU1 goes offline */ dl_clear_root_domains() !cpu_active(1) p->__state =3D=3D TASK_DEAD goto left_out <-- bw dropped __schedule() -> dequeue_task_dl() task_non_contending() dl_task_depart(p) !list_empty -> returns early Once dl_clear_root_domains() leaves the task out with a stale dl_bw_gen, dl_task_depart() on active CPU2 sees !list_empty(&dl_se->dl_departed_node) and returns without updating dl_bw_cpu or recounting the bandwidth, leaving CPU2's root domain undercounted for the entire 0-lag interval. A symmetric race happens when rt_mutex_setprio() updates p->prio out of SCHED_DEADLINE before switched_from_dl() calls dl_task_depart(), and dl_add_task_root_domain() has the same TASK_DEAD check for a task on dl_departed_list that has not yet reached its last schedule. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1796296313.gi= t.mathieu.desnoyers@efficios.com?part=3D36