From nobody Fri Jun 12 21:29:36 2026 Received: from smtp6-g21.free.fr (smtp6-g21.free.fr [212.27.42.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63D3B3E1736; Tue, 12 May 2026 13:46:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.27.42.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778593597; cv=none; b=o8lr+u4z7aJIfxDFFyXEqDppbncr3SWwnBZ/8hOOXnzMRHiDFc7rwFBMHjgl7DYdtAWJLCeVfVTaYVQ7k83AFo3OYKHEFoQ7OSSAUnVR4BMtNmGvgO0kgXfokFshPAl2CW0S20U+MogLWeowFw7O6sUMIByCtZa/g0UTnRAFSUo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778593597; c=relaxed/simple; bh=cuWMSsUlc2lCcUTutxW89kagkofY7NkL4XjmQE+73Uo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sEDI0HkzOh3TAY/HbUqbqovb4LhWO9WSaU2LJqsNVJz34U2oa7S0Ld/4QUiq+5wCeACz3Ecdxm9hW4/EcB7u+/msQ1qQle6XWp6xEyqwZHN10E9XVTrW9vrBQR5TDb0O00XZNe0Rm5SzXf6q8SqEVKX0irjgC9BR/CNyYyoTZ34= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=free.fr; spf=pass smtp.mailfrom=free.fr; dkim=pass (2048-bit key) header.d=free.fr header.i=@free.fr header.b=Rwc24TgV; arc=none smtp.client-ip=212.27.42.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=free.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=free.fr Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=free.fr header.i=@free.fr header.b="Rwc24TgV" Received: from Gigabyte.tail209581.ts.net (unknown [IPv6:2a02:8428:7df0:ac01:fbfd:168d:553c:3eec]) (Authenticated sender: jnilo@free.fr) by smtp6-g21.free.fr (Postfix) with ESMTPSA id DD96C780513; Tue, 12 May 2026 15:46:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=free.fr; s=smtp-20201208; t=1778593593; bh=cuWMSsUlc2lCcUTutxW89kagkofY7NkL4XjmQE+73Uo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rwc24TgVdSF/BtT+qR8X8lc/YgmhpP/mRClmF0Jxz4T3JHK1KGjqComY3CAj6fsfb wONhcxGC2589UxRaALXL8H0j87asEhjmfdzrGWm6mgRnYLm7f9aOgcBrAbi7D89Qeq l5gVHkYgPDX+ZNsE2kpgC9Ot93tlkiW3yFlrNp3uUsR5vSZ3hQa5TUp3PucQJaGQ/2 A7nxxMIYpFzorXja2o4dS2kPpyWnXvX+JfY7d0DKLVPzCM2qA019kilb+Kr9FOjRfa iN/FjjrJ61Ua7RLHGLzt5LXYgzdoQNNW9YWlspoqZxoXW6bS01qbs+T8tkj8tDISiR 3wyfvgjYK4vjQ== From: Jacques Nilo To: Greg Kroah-Hartman , Jiri Slaby Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Johan Hovold , Jacques Nilo Subject: [PATCH 1/3] serial: core: introduce guard(uart_port_lock_sysrq_irqsave) Date: Tue, 12 May 2026 15:46:12 +0200 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: <5efe9e03-4d86-43a0-9ec2-e610ff31095d@free.fr> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" uart_handle_break() and uart_prepare_sysrq_char() (in include/linux/serial_core.h) capture a SysRq character into port->sysrq_ch while the port lock is held and rely on the unlock helper -- uart_unlock_and_check_sysrq_irqrestore() -- to dispatch the captured character to handle_sysrq() on scope exit. The existing guard(uart_port_lock_irqsave) cannot be used by IRQ handlers that process RX, because its destructor calls plain uart_port_unlock_irqrestore() and silently drops port->sysrq_ch. Add a dedicated guard variant whose destructor is the sysrq-aware unlock helper. Callers that may capture SysRq characters opt in by using guard(uart_port_lock_sysrq_irqsave); the existing uart_port_lock_irqsave guard keeps its current plain-unlock semantics for the many callers that do not process RX. The lock side is identical to uart_port_lock_irqsave -- only the unlock-time behaviour differs. Naming mirrors uart_unlock_and_check_sysrq_irqrestore() (sysrq before irqsave/irqrestore). The new macro is placed after the CONFIG_MAGIC_SYSRQ_SERIAL block so both definitions of uart_unlock_and_check_sysrq_irqrestore() (sysrq enabled and disabled) are visible at expansion time. When CONFIG_MAGIC_SYSRQ_SERIAL=3Dn the destructor degenerates to plain uart_port_unlock_irqrestore(), so there is no overhead. No functional change on its own; users are converted in the following patches. Signed-off-by: Jacques Nilo --- include/linux/serial_core.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index 4f7bbdd90..4fa079dc9 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -1286,6 +1286,19 @@ static inline void uart_unlock_and_check_sysrq_irqre= store(struct uart_port *port } #endif /* CONFIG_MAGIC_SYSRQ_SERIAL */ =20 +/* + * Variant of guard(uart_port_lock_irqsave) for IRQ handlers that may capt= ure + * a SysRq character via uart_prepare_sysrq_char(). The destructor uses the + * sysrq-aware unlock helper so that a captured port->sysrq_ch is dispatch= ed + * to handle_sysrq() on scope exit. The plain guard variant silently drops + * sysrq_ch and must not be used by callers that process RX. + */ +DEFINE_LOCK_GUARD_1(uart_port_lock_sysrq_irqsave, struct uart_port, + uart_port_lock_irqsave(_T->lock, &_T->flags), + uart_unlock_and_check_sysrq_irqrestore(_T->lock, + _T->flags), + unsigned long flags); + /* * We do the SysRQ and SAK checking like this... */ --=20 2.43.0 From nobody Fri Jun 12 21:29:36 2026 Received: from smtp6-g21.free.fr (smtp6-g21.free.fr [212.27.42.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1718239061D; Tue, 12 May 2026 13:46:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.27.42.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778593605; cv=none; b=s0nhIqrKnv15CiYW9Y90p0nlycgChfUrEGW2tHTvsV8ghVFnNPYEBceg0jT6VP0XrFmT+CB+RQWv82CiOZhwYKgtYTBvn7nJswz9lpm2YeJugG/gdnaFjYxU7PvM2jq23GT8xdooov07BiE0R6ih+jrMciV4ndkWfC3wBV0Bors= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778593605; c=relaxed/simple; bh=m437a1eC5erEltzYgDEjAvmQ4AYcGoZ1JiHBWjIqBso=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IWLS2rmAwVXE9egO1u63AYPBDgl907HVgu1mrcpubLAW/b6f5pyIH6FiyXEwscMcvEeC6VzsqtVU8O33+9e2L6VxRVdWuqYqp+mq1WQqQ8O0iF4IKnatf30fkQJVbNBEFYXM+yoCRSCyPlFw79hgM2TaeWzEKBpgSFUHQE4Pbjw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=free.fr; spf=pass smtp.mailfrom=free.fr; dkim=pass (2048-bit key) header.d=free.fr header.i=@free.fr header.b=kY5x5MdD; arc=none smtp.client-ip=212.27.42.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=free.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=free.fr Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=free.fr header.i=@free.fr header.b="kY5x5MdD" Received: from Gigabyte.tail209581.ts.net (unknown [IPv6:2a02:8428:7df0:ac01:fbfd:168d:553c:3eec]) (Authenticated sender: jnilo@free.fr) by smtp6-g21.free.fr (Postfix) with ESMTPSA id B2E6F780375; Tue, 12 May 2026 15:46:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=free.fr; s=smtp-20201208; t=1778593602; bh=m437a1eC5erEltzYgDEjAvmQ4AYcGoZ1JiHBWjIqBso=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kY5x5MdDeaqvpAEbPzcHe7ZuTdd2WNanEinBt3W3CJYWuhoplqFcQ8sP7X0Lo8WtC X0OJ+9/o0QqxcoViwbQIUiQCiTF2Dp8Kz9xl3OQhGfR9Fa7knWWFmw0XHFHTx3w+LK tsiOp1G+ihVNcnJNr3OtY7BYuIE5kgiI+7UcBka+/nbLi5aVG8SsZs2k1J15n8MPmr CjA2KxUZZvqPUoqXlVCVw2vRO/rcHeb0/2Iejtg+IQCBjDesSUGUVr0ZqsYRmnie/n 3jDjNDeMFNPkAqSy3RC7KdN9fi+OM+4WwfbjNP//dFMIo0ATIMK9yG4aK1YQbCxWMb 6QgIqRce1E9dw== From: Jacques Nilo To: Greg Kroah-Hartman , Jiri Slaby Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Johan Hovold , Jacques Nilo , stable@vger.kernel.org Subject: [PATCH 2/3] serial: 8250: dispatch SysRq character in serial8250_handle_irq() Date: Tue, 12 May 2026 15:46:13 +0200 Message-ID: <5d6d693aa9e92f05412d0f9395872d41e1b8e444.1778592805.git.jnilo@free.fr> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: <5efe9e03-4d86-43a0-9ec2-e610ff31095d@free.fr> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" serial8250_handle_irq() captures a SysRq character into port->sysrq_ch inside serial8250_handle_irq_locked() via uart_prepare_sysrq_char() (reached from serial8250_read_char()). Dispatch of that captured character to handle_sysrq() is expected to happen at port-unlock time, through uart_unlock_and_check_sysrq[_irqrestore](). After commit 8324a54f604d ("serial: 8250: Add serial8250_handle_irq_locked()") the function was reduced to a wrapper that takes the port lock via guard(uart_port_lock_irqsave) whose destructor is plain uart_port_unlock_irqrestore(). The sysrq-aware unlock helper is no longer called, so port->sysrq_ch is captured but never dispatched: BREAK + SysRq key is consumed silently. This was the very condition Johan Hovold's 853a9ae29e978 ("serial: 8250: fix handle_irq locking", 2021) introduced uart_unlock_and_check_sysrq_irqrestore() to address. Switch to the new guard(uart_port_lock_sysrq_irqsave), whose destructor is the sysrq-aware unlock helper, restoring the pre-split behaviour. Update the Context: comment on serial8250_handle_irq_locked() so future HW-specific 8250 wrappers know to use the same guard or the explicit sysrq-aware unlock. Verified on RTL8196E with CONFIG_MAGIC_SYSRQ_SERIAL=3Dy: BREAK + 'h' on the console UART produces the SysRq help dump in dmesg and the brk counter in /proc/tty/driver/serial increments correctly. Fixes: 8324a54f604d ("serial: 8250: Add serial8250_handle_irq_locked()") Cc: stable@vger.kernel.org Signed-off-by: Jacques Nilo Reviewed-by: Ilpo J=C3=A4rvinen --- drivers/tty/serial/8250/8250_port.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/= 8250_port.c index e4e6a53eb..64f3487e8 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -1786,7 +1786,10 @@ static bool handle_rx_dma(struct uart_8250_port *up,= unsigned int iir) } =20 /* - * Context: port's lock must be held by the caller. + * Context: port's lock must be held by the caller. The caller must + * release it via guard(uart_port_lock_sysrq_irqsave) or + * uart_unlock_and_check_sysrq_irqrestore(), which captures SysRq + * character on unlock. */ void serial8250_handle_irq_locked(struct uart_port *port, unsigned int iir) { @@ -1839,7 +1842,7 @@ int serial8250_handle_irq(struct uart_port *port, uns= igned int iir) if (iir & UART_IIR_NO_INT) return 0; =20 - guard(uart_port_lock_irqsave)(port); + guard(uart_port_lock_sysrq_irqsave)(port); serial8250_handle_irq_locked(port, iir); =20 return 1; --=20 2.43.0 From nobody Fri Jun 12 21:29:36 2026 Received: from smtp6-g21.free.fr (smtp6-g21.free.fr [212.27.42.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 319643905E6; Tue, 12 May 2026 13:46:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.27.42.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778593616; cv=none; b=OqEY6t2nmMINdrDgWyKBvrwrEqJzNaCEcLR+yvUfmSdnl0boO/qOWrfg5Uvg7MScOloeevgNKlbIk2G/hsdGMxgYtKSpK3K5adMe8ZaMMRd8ChX0HIzKcVRmSP+wo6aDhlecE+MThMZIuVptjhMFkD0RF5qrnNVdC1uLbegCZ44= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778593616; c=relaxed/simple; bh=pD/TIRqDBL2gNCarLAfMgoSHPi48/blEreoh5bgIh4A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UxHk53uwYyemCMv5/bGmPCPSmpVf2EzHfFeh860YjfWGuRWLznLaGErdoi7OBijkLlMmoSiarQsFUXqXIbEiA+rlNbPXo4AakVT7RDgfVVpSYlNypY8wKcPlczt8IpIMRafW7cklFS9m1VvL1EfYQLpntL1YebzgUIvJfdhO3cw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=free.fr; spf=pass smtp.mailfrom=free.fr; dkim=pass (2048-bit key) header.d=free.fr header.i=@free.fr header.b=EIi8lVHL; arc=none smtp.client-ip=212.27.42.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=free.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=free.fr Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=free.fr header.i=@free.fr header.b="EIi8lVHL" Received: from Gigabyte.tail209581.ts.net (unknown [IPv6:2a02:8428:7df0:ac01:fbfd:168d:553c:3eec]) (Authenticated sender: jnilo@free.fr) by smtp6-g21.free.fr (Postfix) with ESMTPSA id B8F96780371; Tue, 12 May 2026 15:46:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=free.fr; s=smtp-20201208; t=1778593611; bh=pD/TIRqDBL2gNCarLAfMgoSHPi48/blEreoh5bgIh4A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EIi8lVHL4tB2DyOnrijHsxieXXdI74ApcqFhFRkGrsCuycGgeNnFni2qNizxht9uF ZJTN9r35hihLAKdhWVI1n1Ph9cqsd1qQ9NjTySIJBAm7q/2rzEePiqdVX2F+JsVwEx G3uVFqsCBL2HQ/fdMAiqqZr26I6q9LJmq5Fn9sCrdMehVHkIZ6+2oZhCYhRcR5RZHl YUIXkygLbqFtZuxBQh6blT0sIhvBPBegfAii0VWTushYwLCtyR3KepmAOC1k+JVCWj TxAZ5ucewjcblQ3O1fpuitXibZYbKh59+EyD4ArS6tNgldO5WMn/HVJZ4Wcfu8SXMV GTYQU0LfTA6fQ== From: Jacques Nilo To: Greg Kroah-Hartman , Jiri Slaby Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Johan Hovold , Jacques Nilo , stable@vger.kernel.org Subject: [PATCH 3/3] serial: 8250_dw: dispatch SysRq character in dw8250_handle_irq() Date: Tue, 12 May 2026 15:46:14 +0200 Message-ID: <340a4a76e5dbeb2e49ad4b8d41b9631e09e94bec.1778592805.git.jnilo@free.fr> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: <5efe9e03-4d86-43a0-9ec2-e610ff31095d@free.fr> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" dw8250_handle_irq() calls serial8250_handle_irq_locked() with the port lock held via guard(uart_port_lock_irqsave). The guard destructor is plain uart_port_unlock_irqrestore(), so a SysRq character captured into port->sysrq_ch by uart_prepare_sysrq_char() is dropped without ever being dispatched to handle_sysrq(). This is the same regression pattern as in serial8250_handle_irq(), introduced when 883c5a2bc934 ("serial: 8250_dw: Rework dw8250_handle_irq() locking and IIR handling") moved the function to the guard()-based locking scheme without using the sysrq-aware unlock helper. Switch to guard(uart_port_lock_sysrq_irqsave) so that captured sysrq_ch is dispatched on scope exit, matching the fix in serial8250_handle_irq(). Fixes: 883c5a2bc934 ("serial: 8250_dw: Rework dw8250_handle_irq() locking a= nd IIR handling") Cc: stable@vger.kernel.org Signed-off-by: Jacques Nilo Reviewed-by: Ilpo J=C3=A4rvinen --- drivers/tty/serial/8250/8250_dw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/82= 50_dw.c index 55e40c10f..237543fa7 100644 --- a/drivers/tty/serial/8250/8250_dw.c +++ b/drivers/tty/serial/8250/8250_dw.c @@ -416,7 +416,7 @@ static int dw8250_handle_irq(struct uart_port *p) unsigned int quirks =3D d->pdata->quirks; unsigned int status; =20 - guard(uart_port_lock_irqsave)(p); + guard(uart_port_lock_sysrq_irqsave)(p); =20 switch (FIELD_GET(DW_UART_IIR_IID, iir)) { case UART_IIR_NO_INT: --=20 2.43.0