From nobody Fri Jun 12 17:14:35 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 A11023446AF; Wed, 13 May 2026 13:30:51 +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=1778679053; cv=none; b=ArL66NB0TtEjZgnsa6lbN+Z7EVE7uROzR8dF32gXpYAEQsrZArmrnkV6l9dRO9CFzJDyMXxe9NbvAfOcWWMGTH1UeaVNq0CbUd4q1lEwBlOdaYOMZSIOP+tx5fa/3CZowCn1kmkrM3NvTiuHwU8E9/HBCjQ5CR5vX2E8pWq6kJs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778679053; c=relaxed/simple; bh=1pChfbj8tFToy9AdYZiA72qsSNyQ/k6eQBBa/U5DLbM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZE1vpa/BmBOSCbwlTYNuRPt4oUQT9p86NPF+1q93DkITOeQVplmuhF+HuH1pUFSRu1HvULUGaaKtNSr6IMMBklKNGdlgNpJJ4u8ygg2Xc5y3maQvQYsY2vRDAkXGaozb7vD8Zxv3YN+uLmaoxrRDz/VajAcJaaB/SGY5katsM9E= 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=XfittQgl; 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="XfittQgl" Received: from Gigabyte.tail209581.ts.net (unknown [IPv6:2a02:8428:7df0:ac01:62d2:7d04:a603:94c1]) (Authenticated sender: jnilo@free.fr) by smtp6-g21.free.fr (Postfix) with ESMTPSA id 0F90078034D; Wed, 13 May 2026 15:30:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=free.fr; s=smtp-20201208; t=1778679049; bh=1pChfbj8tFToy9AdYZiA72qsSNyQ/k6eQBBa/U5DLbM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XfittQgl+I8wB5mr1P1x3IMGUdUOoQ16Y8sb3qBh20JB89AkaKRwSSCYriEZUajEF WmlrFgsCQEQEo2xEJ7JR5BmKq4PwKtwFTDfNW2mteFs6NDT1EdwoIn9c5e6n8tvJcy YoH9oCKYCjPvbmjeiCkiu8DOnxoT+Z2f73pbr8GIsjVmPI1t7U135cG3oSZiUhzToa qmzp3ZAXAewsPGOdQkl1mapoeSyNpXLD8O/kImHSnAbtBsBj74zo3+yrZNCGN9REvh hg6OM6y12FlScQK9NSbMeQQqkCOtDX29E/9QWK1iXZl8SEUjGexHmvwQudjpyRIIKV EFvOlEdUVwPDA== From: Jacques Nilo To: Greg Kroah-Hartman , Jiri Slaby Cc: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Andy Shevchenko , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Jacques Nilo Subject: [PATCH v2 1/3] serial: core: introduce guard(uart_port_lock_check_sysrq_irqsave) Date: Wed, 13 May 2026 15:30:23 +0200 Message-ID: <3849af4bc55d5d2a424fa850844e94d641b2f8a6.1778675349.git.jnilo@free.fr> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: 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(uart_port_lock_check_sysrq_irqsave) variant whose destructor is the sysrq-aware unlock helper. The lock side is identical to uart_port_lock_irqsave -- only the unlock-time behaviour differs. Callers that may capture SysRq characters must use guard(uart_port_lock_check_sysrq_irqsave); the existing guard(uart_port_lock_irqsave) keeps its current plain-unlock semantics for the many callers that do not process RX. 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. Cc: stable@vger.kernel.org Signed-off-by: Jacques Nilo Reviewed-by: Andy Shevchenko Reviewed-by: Ilpo J=C3=A4rvinen Tested-by: Maciej W. Rozycki --- include/linux/serial_core.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index 4f7bbdd90..d1404c97d 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -1286,6 +1286,18 @@ 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_check_sysrq_irqsave, struct uart_port, + uart_port_lock_irqsave(_T->lock, &_T->flags), + uart_unlock_and_check_sysrq_irqrestore(_T->lock, _T->f= lags), + unsigned long flags); + /* * We do the SysRQ and SAK checking like this... */ --=20 2.43.0 From nobody Fri Jun 12 17:14:35 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 54A2734677F; Wed, 13 May 2026 13:31:00 +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=1778679061; cv=none; b=EknmkAzbjuq8WdMEz63XSkEO1C3Z8Wa1VKe7rxhIEoy0jGwgMbxz0hQzJl/ugD4RE+D3X0z2HFbUfi5MFrfZKjGo444YZx1YCulFeQ+ZUWUvx3nlz+BgulICLA/V9jEs3csBLgzgmDn6v0se654qFJ2ME2UpWWHKKqK3VUMtf00= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778679061; c=relaxed/simple; bh=rFSZzmaNHh3nnM1+XFRMC3hCaekKxH0gbrQyq/EosdA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=X62mfyc3r2l4B6GKAkqt2ldp/esVyEtoTBVpw9URTnYCxrl+VueQSilOcq8pHnh1t1b0521Y3qRKQ425MMqXAEp5w9hQ38hQaB0kEp1cR4CaX30Qn4O+hdJBxwpRttjAw4muzMElq0wfJIH+OleC/h2peUZlBIFId1o1dN6Q5fc= 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=A8Mjidyb; 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="A8Mjidyb" Received: from Gigabyte.tail209581.ts.net (unknown [IPv6:2a02:8428:7df0:ac01:62d2:7d04:a603:94c1]) (Authenticated sender: jnilo@free.fr) by smtp6-g21.free.fr (Postfix) with ESMTPSA id ED4D1780505; Wed, 13 May 2026 15:30:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=free.fr; s=smtp-20201208; t=1778679058; bh=rFSZzmaNHh3nnM1+XFRMC3hCaekKxH0gbrQyq/EosdA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A8MjidybtcHZEf3dBGt2zBqZ0b48v5NkUqa5lmCfqNToGFRWs4ImA7b2ifTHlGkQt gkEPJvOasUuv12rzozBEXrwK7dW9WwxUTvD/+O+6nHrl9SZT7H5xVmrzvv8sPi49f3 +0MMVJeM3/00C7ZCvkhkjjNDFIabg56wgP3Z2oUWkyHoDoy7J/m8kcrQjbMAXEoYV9 RzuspDm4igOF7tRMQNaEG2ObGM3lp3H3OpSZx3JZs3TKG3RTzwYnW8yiJgujvC5Qvg MGMaw0PhpWj7wqgt62JMt3mBOGWUCoHzw9ZTzlWLs5Q2GcjhT24gwql32NdjY+Brqy 3jKQO0eJsr06w== From: Jacques Nilo To: Greg Kroah-Hartman , Jiri Slaby Cc: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Andy Shevchenko , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Jacques Nilo Subject: [PATCH v2 2/3] serial: 8250: dispatch SysRq character in serial8250_handle_irq() Date: Wed, 13 May 2026 15:30:24 +0200 Message-ID: <52692ae6c3501f7940347cef364ad7fcacaab7e5.1778675349.git.jnilo@free.fr> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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_check_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 Reviewed-by: Ilpo J=C3=A4rvinen Signed-off-by: Jacques Nilo Reviewed-by: Andy Shevchenko Tested-by: Maciej W. Rozycki --- 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..59203bbfb 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_check_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_check_sysrq_irqsave)(port); serial8250_handle_irq_locked(port, iir); =20 return 1; --=20 2.43.0 From nobody Fri Jun 12 17:14:35 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 84466426D33; Wed, 13 May 2026 13:31:09 +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=1778679070; cv=none; b=IyeGFVew/pq3cL/LyMlvZWHjxOXI1Yk7T5laAGJznjhhx+9xau3C+vKonWy+5IUjdrmqWfVLQvSSBqkiRQXEoX+K5nM/rO6K14R95eyzgNpE+1EuMqLwgd+9bUQNyabXaKpk4sdPBkFffloUUD55ItfrJhNxeRVkJ0Zqjtg1sJk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778679070; c=relaxed/simple; bh=MWDkcVOr6KS8kDZhMAwM+aCcisSi6DzrNcUYEZllN14=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qepcLF5xPOkRY3UsfSkckDpNu0xM6r4HD9WJDz2jiNC1DhHkMfnp2R5Hb6LKW3dFQm4T4IH5Rm8EFNb4tCksf/JemfGnYIVDXnklNlYgTWD54zs0IyGfYWJnvPxZ3tEWXUfsDE11D6o6OwbgApukQbo7g8Bl3qMOwupcedfsVmQ= 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=hXUtLtwv; 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="hXUtLtwv" Received: from Gigabyte.tail209581.ts.net (unknown [IPv6:2a02:8428:7df0:ac01:62d2:7d04:a603:94c1]) (Authenticated sender: jnilo@free.fr) by smtp6-g21.free.fr (Postfix) with ESMTPSA id F2760780509; Wed, 13 May 2026 15:30:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=free.fr; s=smtp-20201208; t=1778679068; bh=MWDkcVOr6KS8kDZhMAwM+aCcisSi6DzrNcUYEZllN14=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hXUtLtwvC5L5z814SH67pRKvxZiH0CANuMcq1ZRMCMJvcmrAxm9es/x+PTJFylgq2 CW99/6GNMtNQkUuyuZRxl6hYV8z64rjNWPSHEWf8cx/RIYog9FUq+ZtoQVaBOs8wDv 1UYYwjCGaVcnLOWsWv24I3ZdZZqWJKrMU+Eum5JxK+WgCTzRYfJ08Ops80PT5zSnH5 WgZiQb6GJ9e9YITTH/YQJ3PKejMoAG0QUWNhnm7afUNu8d6apD6MWtRGNdQuPgPkhU /+Rn/6eBYnljGmo2pWZR4IxQW89PJ5LU3dpK06YlEnWwsJJ/rQfYWWqHsVSe8OngDr YqUYGNEp6MnaA== From: Jacques Nilo To: Greg Kroah-Hartman , Jiri Slaby Cc: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Andy Shevchenko , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Jacques Nilo Subject: [PATCH v2 3/3] serial: 8250_dw: dispatch SysRq character in dw8250_handle_irq() Date: Wed, 13 May 2026 15:30:25 +0200 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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_check_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 Reviewed-by: Ilpo J=C3=A4rvinen Signed-off-by: Jacques Nilo Reviewed-by: Andy Shevchenko --- 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..9d552b224 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_check_sysrq_irqsave)(p); =20 switch (FIELD_GET(DW_UART_IIR_IID, iir)) { case UART_IIR_NO_INT: --=20 2.43.0