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=1796312725; b=e6HlEGkvFw6i9m80a9X+pTT5litOhg3VoIEsfGR3WeWQDJLgah9hweY63f6cH1dm4SxD Kx/cu0zhNtr/G3RW17j/o0aU5cjtZ5bGKnNcJf6stD5sziHzKXF4J2N/lb/+pP+Oa4h2l 9uY508AXxOYtyP80imtjc5v7zFjTCD9K6ORVFi1N9ZWtGbqxSsihkPpKa7RItnXH4056l bWohC1cm1ThCkdes/YQyplRZrZuwnxQLuQe9vgoNxDvrOpyOjSc7w1Qe8evMJvVzDhJKP 8gPQfCXZ/xzELangrBRuXUronfoRD98FTGvwNjwALPOIyAgJ1f1caT8FJn1Vw7TuC7g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796312725; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=xoMRWDOrq9stUnnG35a8LDdEbVOQ7yu5+y0Q7Cbk7AE=; b=MzDbcPLYWaiO4d6fwwO6ZhTHmWU47o5Fy8qmlIGBYwEBm914ioLXmTZqw/zJGB4p2dEu LCyhY8yiPf7kNl5WQl6CAmnG3o1QPl/FXSN9fwq2JkH0Hg4/2mtRq8RhB8C3ET448FCT+ +b6PBWi+siGSSPvsZn+pyVHnvW3hGG3k3pXAaKQO0lFV1BI4uHxSmlqHQyT0dQP5ZkhQl K3JTWZjO9ib8+7YLPLkSGtr83VOmoRrKqapy8exmFS8DZKeHQTQpF0RBBakzHEvClKipf aQX4oWdfTgeo4djEYpKYrrtbADxrvHi4pjLIDYLVwmaKN6IifeYq0DbTgYQr4rUWUnw== 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=XJbAmrHu; 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 7578D606A322; Thu, 3 Dec 2026 15:45:25 +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=XJbAmrHu Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC0A81F0089B; Thu, 3 Dec 2026 15:45:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796312725; bh=xoMRWDOrq9stUnnG35a8LDdEbVOQ7yu5+y0Q7Cbk7AE=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=XJbAmrHuGkRAHzW+tox0k1cM1Khk/rPzkfWnGOcLgPKQO5kMljRBs05j4bx8RhFrE 7SJdV+oCbwIvaz38+nT6tZ4icP2SkK2reYpg1YljKomqvHkQl5qThMHPIbzEj11wY2 VMLS3tlQX2RLRNw/uCGe6ocrLhIPKNIqu3w5TVOAolipYUk1Wekz37Z4Oe5/LajXzC Q0wFCiRsHkfFThTnuTxuRPGeEHWLrBfhnMyjyLIuOZakvitc7z1ABb/2KWOP+k/FcQ J0JxrAG56XhWkBfz6IVRLDVv7ETIP24d9i8YYhQusaV34X+4Z/4qJnUGfaA7C/ouaH pPgXHDPP88Ovg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v14 08/39] sched/deadline: Keep the deadline of a departed constrained task 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: <65864008a1fdbd111bd0612860a4ccad3f4c7a75.1796296313.git.mathieu.desnoyers@efficios.com> References: <65864008a1fdbd111bd0612860a4ccad3f4c7a75.1796296313.git.mathieu.desnoyers@efficios.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 15:45:24 +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 6 potential issues to consider: - [High] sched/deadline: switched_from_dl() wipes preserved deadline of queued task - [Medium] sched/deadline: non-idempotent dl_release_params() wipes preserved deadline - [Medium] sched/deadline: preserved deadline breaks PI boost in update_dl_entity() - [Medium] sched/deadline: dl_release_params() retains stale deadline across reentry - [Medium] sched/deadline: dl_release_params() leaves future deadline with zero runtime - [Medium] sched/deadline: dl_release_params() keeps replenished next-period deadline -- commit 6e0cda7a366c85d079b40022ecc95931ec1d4f8d Author: Mathieu Desnoyers sched/deadline: Keep the deadline of a departed constrained task This patch introduces dl_release_params() and calls it from task_non_contending() and inactive_task_timer() in place of __dl_clear_params() so that a departed constrained SCHED_DEADLINE task keeps its deadline after its bandwidth is released. Link: https://lore.kernel.org/all/axAxdNEE1Q2OuxNQ@jlelli-thinkpadt14gen4.r= emote.csb/ > diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c > index c88cac6bc5fe7..422a8120454a3 100644 > --- a/kernel/sched/deadline.c > +++ b/kernel/sched/deadline.c [ ... ] > @@ -2341,7 +2342,7 @@ static enum hrtimer_restart inactive_task_timer(str= uct hrtimer *timer) > raw_spin_lock(&dl_b->lock); > __dl_sub(dl_b, p->dl.dl_bw, dl_bw_cpus(task_cpu(p))); > raw_spin_unlock(&dl_b->lock); > - __dl_clear_params(dl_se); > + dl_release_params(dl_se); > =20 > goto unlock; > } [Severity: Medium] Can a race between inactive_task_timer() and task_non_contending() call dl_release_params() twice and wipe the preserved deadline? CPU0 CPU1 inactive_task_timer() (waits on task_rq_lock) switched_to_dl() cancel_inactive_timer() -> -1 switched_from_dl() task_non_contending(&p->dl, false) hrtimer_active() is true dl_release_params(dl_se) (zeroes dl_deadline/dl_period, keeps deadline) task_rq_unlock() task_rq_lock() !dl_task(p) is true dl_release_params(dl_se) <-- wipes deadline to 0 On the second call, dl_deadline and dl_period are both 0, so dl_is_implicit(dl_se) evaluates to true and __dl_clear_params() overwrites the preserved deadline with 0. If the task re-enters SCHED_DEADLINE before its next period, it bypasses dl_check_constrained_dl() throttling and can exceed its reserved bandwidth. Returning early when !dl_se->dl_runtime in dl_release_params() or inactive_task_timer() would keep parameter release idempotent. [Severity: Medium] When a throttled constrained task leaves SCHED_DEADLINE with an overrun, does inactive_task_timer() preserve the replenished next-period deadline with zero runtime? When dl_se->runtime < 0, dl_time_to_zerolag() places the 0-lag time strictly after dl_next_period(dl_se). At dl_next_period(dl_se), dl_task_timer() fires first and calls replenish_dl_entity(), advancing dl_se->deadline into the next period. When inactive_task_timer() then runs at the 0-lag time, dl_release_params() clears dl_se->runtime to 0 while keeping that next-period deadline. If the task re-enters SCHED_DEADLINE during that next period after already waiting out its previous period and overrun, it has zero runtime and is throttled for an entire extra period. [ ... ] > @@ -3682,7 +3683,8 @@ static void switched_from_dl(struct rq *rq, struct = task_struct *p) > * the "inactive timer" fires, it can continue to consume its current > * runtime using its current deadline. If it stays outside of > * SCHED_DEADLINE until the 0-lag time passes, inactive_task_timer() > - * will reset the task parameters. > + * will reset the task parameters. A constrained task keeps its > + * deadline: see dl_release_params(). > */ > if (task_on_rq_queued(p) && p->dl.dl_runtime) > task_non_contending(&p->dl, false); [Severity: High] Does switched_from_dl() immediately wipe the deadline that dl_release_params() just preserved for a queued constrained task? When a queued constrained task leaves SCHED_DEADLINE after its 0-lag time has passed, task_non_contending(&p->dl, false) calls dl_release_params(), which zeroes p->dl.dl_runtime while keeping p->dl.deadline. The block right below then sees !p->dl.dl_runtime and clears p->dl.deadline back to 0: kernel/sched/deadline.c:switched_from_dl() { ... if (task_on_rq_queued(p) && p->dl.dl_runtime) task_non_contending(&p->dl, false); ... if (!p->dl.dl_runtime) { p->dl.deadline =3D 0; p->dl.runtime =3D 0; } } Without its deadline, re-entering SCHED_DEADLINE before the next period immediately starts a new period with full runtime, allowing the task to exceed its reserved bandwidth. Moving the !p->dl.dl_runtime reset for PI-boosted tasks above task_non_contending() would avoid wiping it. [ ... ] > @@ -4155,6 +4157,29 @@ static void __dl_clear_params(struct sched_dl_enti= ty *dl_se) > dl_se->dl_bw_oncpu =3D 0; > } > =20 > +/* > + * Clear the parameters of a task which left the class, once its > + * bandwidth is released. A task with a constrained deadline keeps its > + * deadline. Leaving the class and coming back before its next period > + * then gives it no new runtime. Back in the class, it waits for that > + * period, as a task asleep in the class does: > + * - between its deadline and its next period, dl_check_constrained_dl() > + * throttles it; > + * - before its deadline, it has no runtime left. > + * > + * An implicit deadline task keeps nothing. In the class too, a wakeup > + * after its 0-lag time starts a new period. > + */ > +static void dl_release_params(struct sched_dl_entity *dl_se) > +{ > + u64 deadline =3D dl_se->deadline; > + bool constrained =3D !dl_is_implicit(dl_se); > + > + __dl_clear_params(dl_se); > + if (constrained) > + dl_se->deadline =3D deadline; > +} [Severity: Medium] Can keeping a future dl_se->deadline with runtime =3D=3D 0 break priority inheritance when the departed task is later boosted while asleep? For a constrained task whose 0-lag time precedes its absolute deadline, dl_release_params() leaves a non-DL task with dl_runtime =3D=3D 0, runtime = =3D=3D 0, and a future dl_se->deadline. If a short-deadline waiter boosts the task while it is asleep, rt_mutex_setprio() sets pi_se and ENQUEUE_REPLENISH, but sched_change_end() skips the enqueue because the task is not queued. When the task wakes up before its preserved deadline, update_dl_entity() sees dl_time_before(dl_se->deadline, rq_clock(rq)) is false and dl_entity_overflow() is false (because runtime =3D=3D 0 makes left =3D=3D 0= ). It skips replenish_dl_new_period() and enqueues the boosted task onto dl_rq with its stale future deadline and zero runtime instead of the donor's earlier deadline, causing priority inversion and deadline misses for the donor. [Severity: Medium] Does retaining dl_se->deadline indefinitely without clearing it on re-entry corrupt period calculations when the task returns with a longer dl_period? Nothing clears the preserved deadline after the old period expires, and __setparam_dl() installs new dl_deadline and dl_period values without resetting it. If a task that ran a short constrained period (such as 10ms) re-enters seconds later with a longer dl_period (such as 4000ms), dl_next_period() combines the stale deadline with the new dl_period and produces a timestamp still in the future. On wakeup, dl_check_constrained_dl() then spuriously throttles the task for up to the new dl_period even though its old period ended seconds earlier. If the task instead re-enters asleep and switches back to SCHED_OTHER without running, dl_time_to_zerolag() sees the future dl_next_period(), arms inactive_timer, and pins the newly admitted bandwidth in total_bw. [Severity: Medium] When a departed constrained task re-enters SCHED_DEADLINE before its preserved future deadline, does runtime =3D=3D 0 let it run unbudgeted and trigger spurious overruns? If the task's 0-lag time passed before dl_se->deadline (for example, 10ms runtime, 50ms deadline, 100ms period after running 1ms gives a 0-lag time of 10ms), dl_release_params() leaves a future deadline with runtime =3D=3D 0 and dl_throttled =3D=3D 0. Re-entering SCHED_DEADLINE before that deadline skips both dl_check_constrained_dl() and update_dl_entity(), so enqueue_dl_entity() queues the task unthrottled with zero runtime. When scheduled, the task executes unbudgeted until the next tick or hrtick, accumulates negative runtime debt in update_curr_dl_se(), and spuriously sets dl_overrun (delivering SIGXCPU under SCHED_FLAG_DL_OVERRUN). Even with the zero-runtime throttling added later in commit "sched/deadline: Keep the debt of a task across a change of parameters", re-entering with a shorter period where dl_next_period(dl_se) <=3D rq_clock < dl_se->deadline still clears dl_throttled without replenishing when start_dl_timer() returns 0 and enqueues the task with zero runtime. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1796296313.gi= t.mathieu.desnoyers@efficios.com?part=3D8