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=1796149076; b=1HjqKm/5kAy88ZaJfwZt17eSxf0ObyCIzV80MChInd/kfRst2RoPa0C+nyL/kPnWTEay 2yQ4Kq8lHBpNLGbbv5fC0f0PtVIarZDI6ScCkjTG37MMjmrb3moVYcTIkI7uizRvbStuP cJQ1am8s6Huf0I/NvYp9v7DQDcTAFo85YhIkVc5M0d7I05woL0Zxk2t0iCOefyGKxQYQ6 FHL/P83quO/6kUUCqRTTPfibVHKYWpNTSeF9bLzaUlJD3lcr1u5AaTXiAslt70g0hsFT+ wKsYgfnQuBAsJ/VzJoHPNqIVLWGDmNhnxTjPmN9QE7lLpt8vrspN338HkcXYLhF+QiQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796149076; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=HeB6P4Xvh72TiohNSXMrvNlAyJpJGw7OF701hz5Pk7s=; b=GVuemA735wcJksdl+vv+ug86cOBFqmyS1JFxv9guevotsfyshnt01ofO63lDgQFS0MXa XI9FmAFkDV+TQYYga0s0OclTuLvg8V/3dSj4Nsw9UXI1TdLJA4NbtGM8Q8SE17Xg+mE/j 5W7q0V1makWq5dX7qwhD73Smh29JhUvTHm9FzqHvYg+D1teS+8VmF6V8Y/k0T5S2D3wud AN/whOAYE0h8CPFYe5nriP5z09hlR5UkMQLPA4hplSoufmWbNdoq0x74btJMheUOvpxhk 3Bn5gYzgO4ki7yZt1MtAE+3AJprjJb8i2xfY/+egoSoxBFSI6ymHfMz8ggKM5f2McEw== 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=mIKN96TF; 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 EB6E7606A31A; Tue, 1 Dec 2026 18:17:55 +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=mIKN96TF Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DCB51F0089A; Tue, 1 Dec 2026 18:17:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796149075; bh=HeB6P4Xvh72TiohNSXMrvNlAyJpJGw7OF701hz5Pk7s=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=mIKN96TFf/APPr9vjF1xMY4fXOaRkyWz9hYOigTr2ZAoGvViWkMhjRWpLzAVZBIvx qZzwH0A5Vs915jaCgRW+YmIMWIGqV1Iv3oz4JLTHfYmWttbEUfqw49tTMwpKqjTSM6 ytuTLmZl7Zv9cvUmNjuISxJ8snSBQ9L5jnD7E60u7ph/QQBMm1BBqgMbN4S1FjyKzF qK/H1dTAAcdoJ7bku8qjAhypRMqMnt4CwsXrvvkR6lLz/JVxA39xLPmZyOFbPHSG9s +1GJa9i7qEzyRDhN6Ddmtuk4GT3WAtb0BuyS6m3mwft24m6xb01VSXNxuG0NFibZ04 QDsL4TQqLr/mw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v13 05/36] sched/deadline: Keep a departing constrained task until its next period 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: <835511935d961be832cbaf24e902762d1926e611.1796146461.git.mathieu.desnoyers@efficios.com> References: <835511935d961be832cbaf24e902762d1926e611.1796146461.git.mathieu.desnoyers@efficios.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 18:17:54 +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 2 potential issues to consider: - [Medium] sched/deadline: premature bw release in inactive_task_timer() on pending race - [Medium] sched/deadline: extra period wait when dl_task_timer() precedes inactive timer -- commit 013654a1a833237d3e6842ffbe9cffc69bd53725 Author: Mathieu Desnoyers sched/deadline: Keep a departing constrained task until its next period This commit retains the bandwidth and deadline of a constrained SCHED_DEADLINE task that leaves the class until the later of its 0-lag time and its next period, and adds dl_inactive_pending to coordinate with an active inactive_task_timer() handler. > diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c > index a02975eb91f63..cd7f2ada8cdf3 100644 > --- a/kernel/sched/deadline.c > +++ b/kernel/sched/deadline.c > @@ -515,6 +515,7 @@ static void task_non_contending(struct sched_dl_entit= y *dl_se, bool dl_task) > struct rq *rq =3D rq_of_dl_se(dl_se); > struct dl_rq *dl_rq =3D &rq->dl; > s64 zerolag_time; > + bool running, pending; > =20 > /* > * If this is a non-deadline task that has been boosted, > @@ -528,13 +529,50 @@ static void task_non_contending(struct sched_dl_ent= ity *dl_se, bool dl_task) > =20 > WARN_ON(dl_se->dl_non_contending); > =20 > + /* > + * inactive_task_timer() restarts itself for a constrained task that > + * has left the class. If the task came back while the handler ran, > + * switched_to_dl() could not cancel the timer, which may be queued > + * again. Cancel it here. A running handler cannot be canceled. > + * dl_inactive_pending then tells whether it will still act on the > + * task, once it gets the rq lock or after its restart. > + */ > + if (dl_server(dl_se)) { > + running =3D hrtimer_active(timer); > + pending =3D running; > + } else { > + int ret =3D hrtimer_try_to_cancel(timer); > + > + if (ret =3D=3D 1) > + put_task_struct(dl_task_of(dl_se)); > + running =3D ret < 0; > + pending =3D running && dl_se->dl_inactive_pending; > + } > + > zerolag_time =3D dl_time_to_zerolag(dl_se, rq); > =20 > + /* > + * A constrained task that leaves the class keeps its bandwidth and its > + * deadline until its next period, if that comes after its 0-lag time. > + * Back in the class before then, it goes on with its current period, > + * as if it had stayed. A new period at once would give it more than > + * its runtime in this period. A dying task does not come back, so it > + * releases its bandwidth at its 0-lag time. > + */ > + if (!dl_task && !dl_server(dl_se) && !dl_is_implicit(dl_se) && > + dl_se->deadline && > + READ_ONCE(dl_task_of(dl_se)->__state) !=3D TASK_DEAD) { > + s64 next =3D dl_next_period(dl_se) - rq_clock(rq); > + > + if (next > zerolag_time) > + zerolag_time =3D next; > + } [Severity: Medium] Can a throttled constrained task that leaves SCHED_DEADLINE end up keeping its bandwidth and deadline for an extra unused period? When a constrained task is throttled, start_dl_timer() arms dl_se->dl_timer for dl_next_period(dl_se). If the task switches out of SCHED_DEADLINE before that period ends, task_non_contending() arms inactive_timer for at least dl_next_period(dl_se), so dl_task_timer() expires at the period boundary before inactive_task_timer() and replenishes the departed task: kernel/sched/deadline.c:dl_task_timer() { ... if (!dl_task(p)) { if (dl_se->dl_throttled && !is_dl_boosted(dl_se)) { sched_clock_tick(); update_rq_clock(rq); replenish_dl_entity(dl_se); } goto unlock; } ... } replenish_dl_entity() adds dl_period to dl_se->deadline and dl_runtime to dl_se->runtime. That leaves dl_time_to_zerolag() unchanged, but shifts dl_next_period(dl_se) forward by a full period. When inactive_task_timer() then runs, it sees dl_next_period(dl_se) - rq_clock(rq) > 0 for the newly replenished period and returns HRTIMER_RESTART. The same happens here in task_non_contending() if a sleeping throttled constrained task is replenished at the period boundary by dl_task_timer() and then leaves SCHED_DEADLINE while still asleep before consuming any runtime in the new period (so zerolag_time < 0, but next > 0). In both cases, the task holds its bandwidth in total_bw for a second period in which it never ran as SCHED_DEADLINE, and if it returns to the class after the replenished dl_se->deadline in that second period, dl_check_constrained_dl() throttles it until the period ends. > /* > * If the "0-lag time" already passed, decrease the active > * utilization now, instead of starting a timer > */ > - if ((zerolag_time < 0) || hrtimer_active(&dl_se->inactive_timer)) { > + if ((zerolag_time < 0) || (running && (dl_task || pending))) { > if (dl_server(dl_se)) { > sub_running_bw(dl_se, dl_rq); > } else { > @@ -543,6 +581,14 @@ static void task_non_contending(struct sched_dl_enti= ty *dl_se, bool dl_task) > if (dl_task) > sub_running_bw(dl_se, dl_rq); > =20 > + /* > + * The pending handler of a task that has left the > + * class releases its bandwidth, or restarts for its > + * next period. > + */ > + if (pending && !dl_task && > + READ_ONCE(p->__state) !=3D TASK_DEAD) > + return; [ ... ] > @@ -2321,6 +2369,40 @@ static enum hrtimer_restart inactive_task_timer(st= ruct hrtimer *timer) > if (dl_server(dl_se)) > goto no_task; > =20 > + /* > + * A constrained task which has left the class keeps its bandwidth > + * and its deadline until its next period, as in > + * task_non_contending(). This timer may have been armed for the > + * 0-lag time while the task was still in the class. > + */ > + if (!dl_task(p) && READ_ONCE(p->__state) !=3D TASK_DEAD && > + !dl_is_implicit(dl_se)) { > + s64 left =3D dl_next_period(dl_se) - rq_clock(rq); > + > + if (left > 0) { > + ktime_t at =3D ktime_add_ns(hrtimer_cb_get_time(timer), left); > + > + /* > + * The timer is not queued: while this handler runs, > + * task_non_contending() finds dl_inactive_pending set > + * and does not arm it. > + */ > + WARN_ON_ONCE(hrtimer_is_queued(timer)); > + hrtimer_set_expires(timer, at); > + task_rq_unlock(rq, p, &rf); > + return HRTIMER_RESTART; > + } > + } [Severity: Medium] Can inactive_task_timer() release a departing task's bandwidth before its 0-lag time when task_non_contending() takes the pending early return? When pending is true for a departing task, task_non_contending() returns early for both implicit and constrained tasks, relying on the running inactive_task_timer() handler to wait until the required retention time. However, inactive_task_timer() only checks dl_next_period(dl_se) - rq_clock(rq) when !dl_is_implicit(dl_se), and never checks dl_time_to_zerolag(dl_se, rq): CPU0 CPU1 T blocks before 0-lag time task_non_contending() arms timer inactive_task_timer() task_rq_lock(T) waits T wakes up at/after 0-lag time replenish_dl_new_period() T runs and consumes runtime sched_setattr(T, SCHED_OTHER) switched_from_dl() task_non_contending() pending is true -> returns acquires task_rq_lock(T) __dl_sub() / __dl_clear_params() <-- releases bandwidth before new 0-lag If T has an implicit deadline, !dl_is_implicit(dl_se) is false, so inactive_task_timer() immediately subtracts T's bandwidth from total_bw and clears its parameters even though its new 0-lag time is in the future. If T has a constrained deadline and overran its runtime (dl_se->runtime < 0), dl_time_to_zerolag(dl_se, rq) is later than dl_next_period(dl_se) - rq_clock(rq), so inactive_task_timer() releases T's bandwidth at dl_next_period(dl_se) before the overrun is paid back. In either case, T can re-enter SCHED_DEADLINE and consume more than its reserved bandwidth. In addition, unlike task_non_contending(), this check does not guard on dl_se->deadline !=3D 0 before calling dl_next_period(dl_se), which can be 0 if a sleeping task enters and leaves SCHED_DEADLINE with constrained parameters while a previously restarted inactive_task_timer() is waiting for task_rq_lock(). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1796146461.gi= t.mathieu.desnoyers@efficios.com?part=3D5