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=1796319565; b=LZBpOowsA7q6pmuqHuhfVIhknb8gNBovoUOqqzSLtQGFOlYbVWjXRwyeh3JZqlSD/SI3 DlJdTMdXlQcYU/YUX20CrJoW80jwToXS1Abf6xKkN3IczOz9K5rAen7bDSoxNO4/bIJUz cKfSmm1AUR+4b618CdO4fj+EDdbLCAEY9k4tIp5TgYdGKJEXVfghHtoolpW55IpfQy+/j LyDGRovo8OSIy+TgZyS2L1e2a+ZYxdPVHas2UEe67bx9tIblMuyLfsZcy5BotJWDJ3i+X KOxspqfNqc7wtIEd/NpD6OA8BVt9DEp6n1oO0KNPq5m4uxaAJq1Fi0yAUL+UBrNNykw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796319565; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=8DmVDO18Bz+1u6sYNTTXTi5nWbtePqmvGw44gWrEmyo=; b=zJoMCJ3e8LPWB1tjU7HWB0OPkpqlRew6skZ7baTj3Ldw7VJgdMFKWJsIez54CfL00ajH avldPNk5hVRMgFobtjl+a/ueUs5s3ruSQL6AvkyoZbu9NDRCFXy0YiywH3vwLg7RecQqB e5y4h+uO/kxQbaA53D8+jteG+RxO7hkgB1ybMqxGJkaOn2fle0zQ8ZIsfm1inLtUsVPy3 1g5sQm8AEVIZXQOLHyuzSLxJ8teG7hAw76dKR0ReGg4OwZbXZAjGxSnH15B2g+Mg/AXRK kyHUCR7XJEj0oV3No8rS1/zyDEKInujttFavWAh8cl4ARqsaDbEK0dMaiM6A4j7/kCQ== 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=EICCBDeP; 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 54F96606A322; Thu, 3 Dec 2026 17:39: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=EICCBDeP Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01CFC1F000C1; Thu, 3 Dec 2026 17:39:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796319565; bh=8DmVDO18Bz+1u6sYNTTXTi5nWbtePqmvGw44gWrEmyo=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=EICCBDeP2UnbVo++VSSV4vB/eQXvRZ8GPj/yb8tstIsL2gx0lwMQ8qVOgKOyB+UKw LIXyp1PDnROKV7XXPITqBrVxCtaSSjST3/CFMWih+zi0EGGvXMOUiRSEXStd/jZQV6 uQ1Ylxn1Caac1JQ9CUBxLDiiSaXFGKrb3/5STddekFcjxwPyWIQB061iLpFvilV2W4 H17Itly9/FLZqXmut3mLOayu/c5Ptmd+haOkikScgl275Ou2wCpH07F37pae+7cRZM 1S2M3a8v+LqULXp15FOc9RWvAdO8s4U9WXkwi4D+rPtdootuaUSSi/DCEW/N2ngiFq ly6jQJ0CKqayQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v14 28/39] sched/deadline: Cancel the replenishment timer with the parameters 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 17:39: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 4 potential issues to consider: - [Medium] sched/deadline: double dl_release_params() wipes constrained task deadline - [Medium] sched/deadline: switched_from_dl() zeroes preserved constrained deadline - [Medium] sched/deadline: dl_task_timer() leaves phantom deadline on departed task - [Medium] sched/deadline: dl_task_timer() misses stale callback check when boosted -- commit 3ee57a6bbb822d45131cce62988fa9cdd9ab1948 Author: Mathieu Desnoyers sched/deadline: Cancel the replenishment timer with the parameters This commit cancels the replenishment timer alongside parameter release in task_non_contending() and inactive_task_timer() so a task re-entering SCHED_DEADLINE does not inherit a stale timer from its previous reservation. > diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c > index 081c5812a063b..82066b2402a95 100644 > --- a/kernel/sched/deadline.c > +++ b/kernel/sched/deadline.c > @@ -781,6 +781,7 @@ static void task_non_contending(struct sched_dl_entit= y *dl_se, bool dl_task) > if (dl_task && READ_ONCE(p->__state) =3D=3D TASK_DEAD) > sub_rq_bw(dl_se, &rq->dl); > dl_task_release_bw(p); > + cancel_replenish_timer(dl_se); > dl_release_params(dl_se); > } > } [Severity: Medium] Can switched_from_dl() wipe the deadline that dl_release_params() just preserved for a constrained-deadline task? When a queued constrained-deadline task (such as one that called sched_yield()) leaves SCHED_DEADLINE past its 0-lag time, switched_from_dl() calls task_non_contending(&p->dl, false). That cancels the replenishment timer and calls dl_release_params(), which clears p->dl.dl_runtime to 0 while keeping p->dl.deadline. On return, switched_from_dl() then executes the boosted-task cleanup: 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; } } With dl_throttled cleared, the replenishment timer cancelled, and deadline zeroed, re-entering SCHED_DEADLINE before the next period bypasses dl_check_constrained_dl() and grants a fresh period, exceeding the task's admitted bandwidth. Checking !p->dl.dl_runtime before calling task_non_contending() (or using else if) would preserve the deadline. > @@ -2630,6 +2631,7 @@ static enum hrtimer_restart inactive_task_timer(str= uct hrtimer *timer) > } > =20 > dl_task_release_bw(p); > + cancel_replenish_timer(dl_se); > dl_release_params(dl_se); > =20 > goto unlock; [Severity: Medium] Can a racing inactive_task_timer() call dl_release_params() a second time and wipe a constrained task's preserved deadline? dl_release_params() is not idempotent: the first call clears dl_deadline and dl_period to 0 while keeping dl_se->deadline, so a second call sees dl_is_implicit(dl_se) as true (0 =3D=3D 0) and overwrites deadline with 0. This can happen when inactive_task_timer() is waiting on task_rq_lock() as the task wakes and leaves SCHED_DEADLINE: CPU0 CPU1 ---- ---- __run_hrtimer(inactive_timer) inactive_task_timer() task_rq_lock(p) [waits] task_contending() dl_non_contending =3D 0 cancel_inactive_timer() =3D=3D -1 switched_from_dl() task_non_contending(..., false) hrtimer_active() =3D=3D true dl_task_release_bw(p) cancel_replenish_timer(dl_se) dl_release_params(dl_se) dl_deadline =3D dl_period =3D 0 rq_unlock() [acquires rq lock] !dl_task(p) is true dl_release_params(dl_se) deadline =3D 0 <-- wipes deadline Clearing the preserved deadline lets the task bypass dl_check_constrained_dl() if it re-enters SCHED_DEADLINE before its next period, exceeding its admitted bandwidth. In addition, when zerolag_time >=3D 0 while inactive_task_timer() is running, task_non_contending() releases bandwidth and cancels dl_timer before the new 0-lag time. Guarding dl_release_params() with an early return when !dl_se->dl_runtime would prevent the second call from wiping deadline. [Severity: Medium] What happens if dl_task_timer() fires before inactive_task_timer() on a departed constrained-deadline task? Suppose a constrained-deadline task overruns its runtime (runtime < 0) in period [0, P] and leaves SCHED_DEADLINE before P. Its 0-lag time falls after P, so dl_task_timer() fires first at P; seeing !dl_task(p) and dl_throttled, it calls replenish_dl_entity(dl_se) and advances dl_se->deadline to P + dl_deadline. When inactive_task_timer() later runs at the 0-lag time, cancel_replenish_timer() is a no-op and dl_release_params() clears runtime to 0 while keeping that advanced deadline. If the task re-enters SCHED_DEADLINE during (0-lag, 2*P) without ever having run in [P, 2*P], it is given zero runtime and throttled for an extra period until 2*P. [Severity: Medium] Does cancel_replenish_timer() handle a dl_task_timer() callback that is already running on another CPU? cancel_replenish_timer() calls hrtimer_try_to_cancel(), which returns -1 if dl_task_timer() is already executing and waiting on task_rq_lock(p). Because __run_hrtimer() already cleared is_queued, a subsequent start_dl_timer() for a new reservation R2 re-arms dl_timer while the stale callback is still pending: CPU0 CPU1 ---- ---- __run_hrtimer(dl_timer) timer->is_queued =3D false dl_task_timer() task_rq_lock(p) [waits] inactive_task_timer() cancel_replenish_timer() =3D=3D -1 dl_release_params(dl_se) rq_unlock() p re-enters SCHED_DEADLINE (R2) throttles while blocking -> start_dl_timer() [queues for T2] PI-boosted while asleep [acquires rq lock] !task_on_rq_queued(p) is true replenish_dl_entity(dl_se) <-- premature replenish If the PI donor then deboosts the task before T2 and the task wakes up, it runs with unearned runtime while the newer dl_timer remains queued, violating CBS bandwidth guarantees. A later patch in this series, commit "sched/deadline: Keep the debt of a task across a change of parameters", guards the non-boosted case with a dl_next_period(dl_se) check, but skips it when is_dl_boosted(dl_se) is true, leaving this sleeping PI-boosted case exposed. Checking hrtimer_is_queued(timer) under task_rq_lock(p) in dl_task_timer() would reject any stale callback once dl_timer has been re-armed. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1796296313.gi= t.mathieu.desnoyers@efficios.com?part=3D28