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=1796309951; b=LXQAcKJy3g+hiB8fpnrCzlDwft78pEX2Y0wkvUjOAwugR4sUokjKuCg35CKW07GXOMS8 yM7xQ0zzsc5M7V/GfWPBCT2Y6xK+Lj4xxK/TtpUDt5PqNF3m08OInHTyZxL2dr8TsLrI4 x1ilNyTunNUtvjjQPjn8NaDxF1Bc5mIdcNmYawW7dYbgj7WW/PM6nWQ9mZ0BOBOmmSRbr ImdLbA9vk9qdYsdSY9j2uhjLNr7grPwgSDJuVdBIjDxxrW3JgoKucfVX3kPAaHB0Vpyyj TnY/xidEnd0Umy0/m8ftCx5+fFKZ74ee1BpykuzoQvEjaV1cLdSe3s69M/AYNSrtRFA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796309951; 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=9PYR6T2187uwpdXMMI2xpW6rgj3SOWzWndWcmQvvjPs=; b=gNdzDParlzrQQCg6TAjkwfCWPyP8QAJWDt8Xo3JpYAbuot9Vq7yNt+B+NGrPivvt4k8w fdBJMkB+jKKek0b3JAKO+2atF2SHQOk1krmJEBimROvLzKV/F0XT/1kf56jDhl9utI4zs jJYhmEyWm7lUAjFFQunddp+DfXQLIb3eSgTQ3ayShSJf6xirFS2r8JG+FUc1bQQLxa+cG uKZ0I7LApjke2I6Q/W4U8b7OJ776ZOQozV4RCW7IMZBKemoJH6/OJdV+Gu3KrpTdAiRmL Hzzi96TI9wLynho8UXcauU62v48tXMPdXzRt63sO+fFjQngrD7KbHCSNW2W4G5WvLDg== 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=SBvxMmGl; 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 6DDAD606A69E; Thu, 3 Dec 2026 14:59:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6DDAD606A69E 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=SBvxMmGl DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=smtpout1; t=1796309949; bh=9PYR6T2187uwpdXMMI2xpW6rgj3SOWzWndWcmQvvjPs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SBvxMmGlUChLzk8o76wlV2GRAZVCymRvCXOtKpr1PS4UwBlKK1pxiheobux3iwb4p ZQ+mT69tmAJmdYJlgQAw0TbPMMB/dpSvU0YBqvISW93sIJjhtF4qlzGjCXa6d6kNJ1 4jUgjvtoAeLY5L8KBuqtYwfjFwN4pOG/rsV4mSJbPKg3W2fLgOEUgGpplCtjq1CyV2 9yyuIk1MLt/b2wLBIdVSAuQkUUIQUh5Yq3ixK8qEjxVPenjmVINoEiOZ0ljCfCbTA9 OKHbfw63iJC8JKK7f0PESkHJA3URerlmh6pQTBdOOF4RrCUhgQmZTivusAFgIEx/u4 PiMflnmNoVtBA== Received: from thinkos.internal.efficios.com (unknown [IPv6:2605:8d80:7180:6739:ac39:5d4:4093:61c6]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4jgHp35NFDzZBP; Thu, 03 Dec 2026 09:59:07 -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, anna-maria@linutronix.de, frederic@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, oleg@redhat.com, brauner@kernel.org, stable@vger.kernel.org Subject: [PATCH v14 05/39] sched/deadline: Clear dl_overrun under the rq lock Date: Thu, 3 Dec 2026 09:58:19 -0500 Message-ID: <75d9b1000ae69e7bc18ef464fc3ce813f33ec90c.1796296313.git.mathieu.desnoyers@efficios.com> 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 check_dl_overrun() clears dl_overrun without the rq lock. dl_overrun is a bit field. It shares a word with other flags of the deadline entity, such as dl_throttled, dl_non_contending and dl_bw_oncpu. These change under the rq lock. The clear loads the whole word and stores it back. If another CPU changes one of these flags in between, the store undoes that change, and leaves the state of the task wrong. check_dl_overrun() runs under the siglock. Without PREEMPT_RT, the siglock disables interrupts, so the window is a few instructions. With PREEMPT_RT, the siglock is a sleeping lock and interrupts stay on. The task can be preempted between the load and the store, so the window can be long. This was found by reading. Fix this by clearing dl_overrun under task_rq_lock(), in a new helper, dl_task_clear_overrun(). The caller holds the siglock. signal_wake_up_state() takes the same lock order: the siglock, then pi_lock and the rq lock. Fixes: 34be39305a77 ("sched/deadline: Implement "runtime overrun signal" support") Reported-by: Juri Lelli Closes: https://lore.kernel.org/all/axAxdNEE1Q2OuxNQ@jlelli-thinkpadt14gen4.remote.csb/ Signed-off-by: Mathieu Desnoyers Cc: stable@vger.kernel.org --- include/linux/sched/deadline.h | 2 ++ kernel/sched/deadline.c | 20 ++++++++++++++++++++ kernel/time/posix-cpu-timers.c | 4 +--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/include/linux/sched/deadline.h b/include/linux/sched/deadline.h index 273538200a44..47c8be0ca14a 100644 --- a/include/linux/sched/deadline.h +++ b/include/linux/sched/deadline.h @@ -43,6 +43,8 @@ extern void dl_clear_root_domain_cpu(int cpu); extern bool dl_task_needs_bw_move(struct task_struct *p, const struct cpumask *new_mask); +extern bool dl_task_clear_overrun(struct task_struct *p); + extern u64 dl_cookie; extern bool dl_bw_visited(int cpu, u64 cookie); diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c index a02975eb91f6..0afcb7b53bc4 100644 --- a/kernel/sched/deadline.c +++ b/kernel/sched/deadline.c @@ -4154,6 +4154,26 @@ void init_dl_entity(struct sched_dl_entity *dl_se) #endif } +/* + * Clear the runtime overrun flag of @p. Return true if it was set. + * + * dl_overrun shares a word with other flags, such as dl_throttled, + * which change under the rq lock. Clear it under that lock too, or the + * store could undo a change to another flag. + * + * The caller holds the siglock of @p. signal_wake_up_state() takes the + * same lock order: siglock, then pi_lock and the rq lock. + */ +bool dl_task_clear_overrun(struct task_struct *p) +{ + guard(task_rq_lock)(p); + + if (!p->dl.dl_overrun) + return false; + p->dl.dl_overrun = 0; + return true; +} + bool dl_param_changed(struct task_struct *p, const struct sched_attr *attr) { struct sched_dl_entity *dl_se = &p->dl; diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c index 2f23d62ad446..b37a38041170 100644 --- a/kernel/time/posix-cpu-timers.c +++ b/kernel/time/posix-cpu-timers.c @@ -976,10 +976,8 @@ static void collect_posix_cputimers(struct posix_cputimers *pct, u64 *samples, static inline void check_dl_overrun(struct task_struct *tsk) { - if (tsk->dl.dl_overrun) { - tsk->dl.dl_overrun = 0; + if (tsk->dl.dl_overrun && dl_task_clear_overrun(tsk)) send_signal_locked(SIGXCPU, SEND_SIG_PRIV, tsk, PIDTYPE_TGID); - } } static bool check_rlimit(u64 time, u64 limit, int signo, bool rt, bool hard) -- 2.47.3