From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=158.69.130.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795655353; b=vWBrSYfwbPiBsTIgomDKJ93zZXKD6OcYLRL9ho6ujR/3T09zNNU1lO3/Xuy3KW2Q3ZXS 6chEVzSSjMaybtK0ZN4rONjETmY3TA1LPD82ndQFinpBmmxWUHfaWd410/k8790pDTLbF LQLlpS59gcSrLCnlYO6Pjx5i2tkdj6MtAcf+h6ajWBu594MKDc3nWxIBaw806RgI2+Wxq ayv5wXPfUYYFn7+DM1Yl/UtQpl4lnW6B5O1exTTkUQGrR+uo4+0h+w24cYIO3+Dbb7sQU UZ1po8KNDl6+BAOhUz3F1oV3EXkpJbmvbROyHfCGMFgqH8B+B8ETEYLUnDses3c0r/g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795655353; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=+w/6dNkUojgm+/pCcYC0tQkbARFv9Xb7tCfV/+CABMU=; b=CdPV9PtExEhY5D19QC6xdcSqTlFR9Iv+qTf4foz+VvwnarmLd4bkeVS40HdOj2c+GAmM 7BbyRt1bw4vOw4jraGYBhY+Fe8Cd6O8lMTXR2GJN4ypAJkTyqbDw9tcjC6/1GwInzXafE B/k7LcCZqd5r4/ddASvG6trtFesdF76gZGYyxCUDGl9XF4YXSPdK/K0phV0D5MkOWZrnL dquWPE18MSHMPXEpHpUDi+nHkY/WgmS52HQtwMI22fM6v0e1EBxGOKmTtX9uuh/Ljt0J2 k95FoA8jaqKf21znH6C5PcNISex+QLd/TYn2PHkXWsVllXl0nMVSutv6s1+w86NPGDQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=efficios.com; spf=pass smtp.mailfrom=efficios.com; dkim=pass header.d=efficios.com header.i=@efficios.com header.a=rsa-sha256 header.s=smtpout1 header.b=xcDKWHtC; arc=none smtp.remote-ip=158.69.130.18 Received: from smtpout.efficios.com (smtpout.efficios.com [158.69.130.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 7A061606B777; Thu, 26 Nov 2026 01:09:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7A061606B777 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=efficios.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.a=rsa-sha256 header.s=smtpout1 header.b=xcDKWHtC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=smtpout1; t=1795655351; bh=+w/6dNkUojgm+/pCcYC0tQkbARFv9Xb7tCfV/+CABMU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xcDKWHtCEoKYeVlcDDbgQTfRFzDTuzG/OQAWiYMQtxYPHwbRkLmcAyivO0FbK8dXa mbK+SGn1DFMekcuRTqfjQAit2vhvF2stCkFSMTWSXZLi+ZQRUYZMozD+kcRfqQicm2 VfNFXmT4BIy4mTbURcwH8LVOd3wCGwozKh/A7HgwXZwP22G1wEo7AWlAE2eiRLwSLP xE7rCBHI2UB/+kfiB1d036R4NJ1jv+BpRueiscA+agmE9/sn6oyBSuuFNElnZky/jV Ut0Wb6PMPXVBnXcjXZWWl4afKWRGoRTM15ALedog6FzmTiLrmvFuTofajKzzPbCsNi Ki0hxu5xq+DGQ== Received: from thinkos.internal.efficios.com (unknown [IPv6:2606:6d00:100:4000:cacb:9855:de1f:ded2]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4jZdjg1PplzWg4; Wed, 25 Nov 2026 20:09:11 -0500 (EST) From: Mathieu Desnoyers To: juri.lelli@redhat.com, peterz@infradead.org, mingo@redhat.com, vincent.guittot@linaro.org Cc: Mathieu Desnoyers , tglx@kernel.org, will@kernel.org, boqun@kernel.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, kprateek.nayak@amd.com, luca.abeni@santannapisa.it, tommaso.cucinotta@gmail.com, mathieu.poirier@linaro.org, longman@redhat.com, ridong.chen@linux.dev, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com, shuah@kernel.org, bigeasy@linutronix.de, clrkwllms@kernel.org, parri.andrea@gmail.com, m.szyprowski@samsung.com, kayracizmeci@gmail.com, weihengqiuu@gmail.com, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-rt-devel@lists.linux.dev, stable@vger.kernel.org Subject: [PATCH v11 32/43] sched/deadline: Start a period for a task requeued onto an rt_mutex Date: Wed, 25 Nov 2026 20:08:31 -0500 Message-ID: X-Mailer: git-send-email 2.47.3 In-Reply-To: References: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The waiter node of an rt_mutex holds the deadline of its task, as a sort key. task_blocks_on_rt_mutex() copies it when the task blocks. A task that blocks by itself is running, so its deadline is a current one. FUTEX_CMP_REQUEUE_PI is different. It makes a task that sleeps in FUTEX_WAIT_REQUEUE_PI wait on the rt_mutex of a PI futex, with rt_mutex_start_proxy_lock(). That task is not running. Its deadline can be one that it would never run with: - 0, if sched_setattr() made it SCHED_DEADLINE while it slept. switched_to_dl() leaves its deadline to its next wakeup. - one that has passed, if it slept past it. The waiter then sorts before the waiters with a real deadline. At the unlock, it gets the lock before waiters with earlier deadlines. Its deadline also decides the boost of the owner. Fix this in __rt_mutex_start_proxy_lock(), before its trylock: the trylock reads the deadline too. Add dl_proxy_block(), which applies the wakeup rule of update_dl_entity() to the requeued task: - A deadline of 0, or one that has passed, gets a new period. For a boosted task, it is a period of its donor. - A task past its deadline and before its next period keeps its deadline: its wakeup throttles it until that period. A new period would start before its next period, which the constrained gap forbids. So its waiter still sorts first. - futex_lock_pi() also calls __rt_mutex_start_proxy_lock(), with the current task. That task is running, so its deadline is up to date. dl_proxy_block() is not called for it. The Sashiko AI review of this series found this. The case requeue_pi_new_period of deadline_bw_test, added later in this series, tests the deadline of 0. It fails without this patch. Fixes: 2d3d891d3344 ("sched/deadline: Add SCHED_DEADLINE inheritance logic") Signed-off-by: Mathieu Desnoyers Cc: stable@vger.kernel.org --- include/linux/sched/deadline.h | 1 + kernel/locking/rtmutex_api.c | 12 +++++++ kernel/sched/deadline.c | 59 ++++++++++++++++++++++++++++++++-- 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/include/linux/sched/deadline.h b/include/linux/sched/deadline.h index fa66e75cbdd8..5c53b12948a7 100644 --- a/include/linux/sched/deadline.h +++ b/include/linux/sched/deadline.h @@ -63,6 +63,7 @@ extern int dl_task_bw_reserve_cpu(struct task_struct *p, const struct cpumask *new_mask); extern int dl_task_bw_reserved_cpu(struct task_struct *p); extern void dl_task_bw_unreserve(struct task_struct *p); +extern void dl_proxy_block(struct task_struct *p); extern bool dl_task_keeps_root_domain(struct task_struct *p, const struct cpumask *new_mask, const struct cpumask *pending); diff --git a/kernel/locking/rtmutex_api.c b/kernel/locking/rtmutex_api.c index 6bdbd36bac94..f1246efc62d3 100644 --- a/kernel/locking/rtmutex_api.c +++ b/kernel/locking/rtmutex_api.c @@ -342,6 +342,18 @@ int __sched __rt_mutex_start_proxy_lock(struct rt_mutex_base *lock, lockdep_assert_held(&lock->wait_lock); + /* + * A requeued @task sleeps, so its deadline can be stale. The trylock + * below and the waiter node both read it: update it first. + * futex_lock_pi() passes current, which is running. Its deadline is + * up to date. + */ + if (task != current) { + raw_spin_lock(&task->pi_lock); + dl_proxy_block(task); + raw_spin_unlock(&task->pi_lock); + } + if (try_to_take_rt_mutex(lock, task, NULL)) return 1; diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index 5d1d4ea28878..c59953e80b1a 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -1682,6 +1682,59 @@ static inline u64 dl_next_period(struct sched_dl_entity *dl_se) return dl_se->deadline - dl_se->dl_deadline + dl_se->dl_period; } +#ifdef CONFIG_RT_MUTEXES +/* + * FUTEX_CMP_REQUEUE_PI makes @p wait on an rt_mutex while @p sleeps. + * The waiter node of @p takes its deadline before any wakeup. So apply + * the wakeup rule of update_dl_entity() to @p now: + * - A deadline of 0, which a task that entered the class asleep has, + * gets a new period. + * - A constrained task past its deadline and before its next period + * keeps its deadline. Its wakeup throttles it until that period. Its + * waiter node keeps that passed deadline, and sorts first. + * - Any other task gets the check of update_dl_entity(). A deadline + * that has passed gets a new period. + * + * The caller holds the pi_lock of @p. + */ +void dl_proxy_block(struct task_struct *p) +{ + struct sched_dl_entity *dl_se = &p->dl; + struct rq_flags rf; + struct rq *rq; + + if (!dl_task(p)) + return; + rq = __task_rq_lock(p, &rf); + update_rq_clock(rq); + if (task_on_rq_queued(p) || dl_se->dl_throttled) + goto unlock; + /* + * A boosted task runs on the parameters of its donor. Start a period + * from them if its deadline is 0 or has passed. A task in the class + * with no runtime of its own is always boosted: the test of + * dl_runtime is only a guard. + */ + if (is_dl_boosted(dl_se) || !dl_se->dl_runtime) { + if (!dl_se->deadline || + dl_time_before(dl_se->deadline, rq_clock(rq))) + replenish_dl_new_period(dl_se, rq); + goto unlock; + } + if (!dl_se->deadline) { + replenish_dl_new_period(dl_se, rq); + goto unlock; + } + if (!dl_is_implicit(dl_se) && + dl_time_before(dl_se->deadline, rq_clock(rq)) && + dl_time_before(rq_clock(rq), dl_next_period(dl_se))) + goto unlock; + update_dl_entity(dl_se); +unlock: + __task_rq_unlock(rq, p, &rf); +} +#endif + /* * If the entity depleted all its runtime, and if we want it to sleep * while waiting for some new execution time to become available, we @@ -4939,9 +4992,9 @@ static void switched_to_dl(struct rq *rq, struct task_struct *p) * A task that comes back to the class before its 0-lag time * keeps its deadline. For a constrained task, that deadline * can have passed before its next period. As - * dl_check_constrained_dl() does, leave such a task alone - * unless it is boosted. Its wakeup throttles it until its - * next period. + * dl_check_constrained_dl() and dl_proxy_block() do, leave + * such a task alone unless it is boosted. Its wakeup + * throttles it until its next period. */ if (dl_task_pi_blocked(p) && !p->dl.dl_throttled && dl_time_before(p->dl.deadline, rq_clock(rq)) && -- 2.47.3