Linux Serial subsystem development
 help / color / mirror / Atom feed
* [PATCH v3] serial: 8250_of: clear stuck empty-FIFO RX-timeout on LPC32xx
@ 2026-07-22 14:03 Ryan Wilbur
  2026-07-30 14:41 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Ryan Wilbur @ 2026-07-22 14:03 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby
  Cc: Ilpo Järvinen, Andy Shevchenko, John Ogness, Manuel Lauss,
	Hugo Villeneuve, linux-serial, linux-kernel, Ryan Wilbur, stable

The NXP LPC32xx UART (PORT_LPC3220) can latch an RX character-timeout
interrupt while the RX FIFO is empty: IIR reports UART_IIR_RX_TIMEOUT
(0x0c) but LSR.DR is clear. A character timeout is only cleared by
reading RHR, but serial8250_rx_chars() reads RHR only when LSR.DR is
set, so nothing ever clears the condition. The interrupt is
level-triggered and re-fires immediately, so on a single-core ARM926
the resulting interrupt storm livelocks the CPU.

It is reproducible when userspace repeatedly opens the front-panel port
(ttyS1): serial8250_do_set_termios() re-enables interrupts on unlock and
the handler then spins forever with iir=0xcc lsr=0x60 ier=0x05, tripping
the soft-lockup detector in serial8250_handle_irq_locked().

LPC32xx has no dedicated 8250 glue driver, it's driven by the generic
8250_of. Add a hardware specific handle_irq for PORT_LPC3220, wired up
in of_platform_serial_setup() the same way fsl8250_handle_irq is
installed. The handler follows dw8250_handle_irq(): on an RX timeout
with an empty FIFO (LSR.DR and LSR.BI clear) it does one throwaway RHR
read to clear the condition, then calls serial8250_handle_irq_locked().
No real received data is ever discarded, and it is a no-op on healthy
UARTs which never report a timeout with DR clear.

This is the same class of bug already worked around in other 8250 drivers;
see commit 424d79183af0 ("serial: 8250_dw: Avoid "too much work" from bogus rx timeout interrupt")
which reports the identical iir=0xcc/lsr=0x60. See also
UART_RX_TIMEOUT_QUIRK in 8250_omap, and the note in 8250_bcm7271.

Cc: stable@vger.kernel.org
Assisted-by: Claude:Opus4.8
Signed-off-by: Ryan Wilbur <rwilbur633@gmail.com>
---
Changes in v3:
- Move the workaround out of the generic serial8250_handle_irq_locked()
  into an LPC32xx-specific ->handle_irq in 8250_of.c
- Skip the dummy read when LSR.BI is set, matching dw8250_handle_irq

Changes in v2:
- Drop the PORT_LPC3220 gate and handle the spurious RX timeout generically

v2: https://lore.kernel.org/linux-serial/20260720131123.29840-1-rwilbur633@gmail.com/
v1: https://lore.kernel.org/linux-serial/20260717123530.481021-1-rwilbur633@gmail.com/

 drivers/tty/serial/8250/8250_of.c | 37 +++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/drivers/tty/serial/8250/8250_of.c b/drivers/tty/serial/8250/8250_of.c
index f0537fb6ef4f..93db28a48dea 100644
--- a/drivers/tty/serial/8250/8250_of.c
+++ b/drivers/tty/serial/8250/8250_of.c
@@ -82,6 +82,40 @@ static int of_platform_serial_clk_notifier_cb(struct notifier_block *nb, unsigne
 	return NOTIFY_DONE;
 }
 
+static int lpc32xx_handle_irq(struct uart_port *port)
+{
+	struct uart_8250_port *up = up_to_u8250p(port);
+	unsigned int iir;
+	u16 status;
+
+	guard(serial8250_rpm)(up);
+
+	iir = serial_port_in(port, UART_IIR);
+	if (iir & UART_IIR_NO_INT)
+		return 0;
+
+	guard(uart_port_lock_check_sysrq_irqsave)(port);
+
+	/*
+	 * The LPC32xx UART can assert an RX character-timeout interrupt while
+	 * the RX FIFO is empty: IIR reports UART_IIR_RX_TIMEOUT but LSR.DR is
+	 * clear. The timeout is only cleared by reading RHR, but the core RX
+	 * path skips that read when the FIFO is empty, so the level-triggered
+	 * IRQ re-fires forever and livelocks this single-core SoC. Do one
+	 * throwaway RHR read to clear it; a healthy UART never reports a
+	 * timeout with DR/BI clear, so no received data is ever discarded.
+	 */
+	if ((iir & 0x3f) == UART_IIR_RX_TIMEOUT) {
+		status = serial_lsr_in(up);
+		if (!(status & (UART_LSR_DR | UART_LSR_BI)))
+			serial_port_in(port, UART_RX);
+	}
+
+	serial8250_handle_irq_locked(port, iir);
+
+	return 1;
+}
+
 /*
  * Fill a struct uart_port for a given device node
  */
@@ -185,6 +219,9 @@ static int of_platform_serial_setup(struct platform_device *ofdev,
 	case PORT_NPCM:
 		ret = npcm_setup(port);
 		break;
+	case PORT_LPC3220:
+		port->handle_irq = lpc32xx_handle_irq;
+		break;
 	default:
 		/* Nothing to do */
 		ret = 0;

base-commit: da7b5fd4e17f8e44c5590f2d603c01d499f056e6
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] serial: 8250_of: clear stuck empty-FIFO RX-timeout on LPC32xx
  2026-07-22 14:03 [PATCH v3] serial: 8250_of: clear stuck empty-FIFO RX-timeout on LPC32xx Ryan Wilbur
@ 2026-07-30 14:41 ` Greg Kroah-Hartman
  2026-07-30 18:50   ` Ryan Wilbur
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2026-07-30 14:41 UTC (permalink / raw)
  To: Ryan Wilbur
  Cc: Jiri Slaby, Ilpo Järvinen, Andy Shevchenko, John Ogness,
	Manuel Lauss, Hugo Villeneuve, linux-serial, linux-kernel, stable

On Wed, Jul 22, 2026 at 11:03:53AM -0300, Ryan Wilbur wrote:
> The NXP LPC32xx UART (PORT_LPC3220) can latch an RX character-timeout
> interrupt while the RX FIFO is empty: IIR reports UART_IIR_RX_TIMEOUT
> (0x0c) but LSR.DR is clear. A character timeout is only cleared by
> reading RHR, but serial8250_rx_chars() reads RHR only when LSR.DR is
> set, so nothing ever clears the condition. The interrupt is
> level-triggered and re-fires immediately, so on a single-core ARM926
> the resulting interrupt storm livelocks the CPU.
> 
> It is reproducible when userspace repeatedly opens the front-panel port
> (ttyS1): serial8250_do_set_termios() re-enables interrupts on unlock and
> the handler then spins forever with iir=0xcc lsr=0x60 ier=0x05, tripping
> the soft-lockup detector in serial8250_handle_irq_locked().
> 
> LPC32xx has no dedicated 8250 glue driver, it's driven by the generic
> 8250_of. Add a hardware specific handle_irq for PORT_LPC3220, wired up
> in of_platform_serial_setup() the same way fsl8250_handle_irq is
> installed. The handler follows dw8250_handle_irq(): on an RX timeout
> with an empty FIFO (LSR.DR and LSR.BI clear) it does one throwaway RHR
> read to clear the condition, then calls serial8250_handle_irq_locked().
> No real received data is ever discarded, and it is a no-op on healthy
> UARTs which never report a timeout with DR clear.
> 
> This is the same class of bug already worked around in other 8250 drivers;
> see commit 424d79183af0 ("serial: 8250_dw: Avoid "too much work" from bogus rx timeout interrupt")
> which reports the identical iir=0xcc/lsr=0x60. See also
> UART_RX_TIMEOUT_QUIRK in 8250_omap, and the note in 8250_bcm7271.
> 
> Cc: stable@vger.kernel.org
> Assisted-by: Claude:Opus4.8
> Signed-off-by: Ryan Wilbur <rwilbur633@gmail.com>
> ---
> Changes in v3:
> - Move the workaround out of the generic serial8250_handle_irq_locked()
>   into an LPC32xx-specific ->handle_irq in 8250_of.c
> - Skip the dummy read when LSR.BI is set, matching dw8250_handle_irq
> 
> Changes in v2:
> - Drop the PORT_LPC3220 gate and handle the spurious RX timeout generically

This breaks the build :(

Even sashiko noticed this:
	https://sashiko.dev/#/patchset/20260722140353.115899-1-rwilbur633@gmail.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] serial: 8250_of: clear stuck empty-FIFO RX-timeout on LPC32xx
  2026-07-30 14:41 ` Greg Kroah-Hartman
@ 2026-07-30 18:50   ` Ryan Wilbur
  0 siblings, 0 replies; 3+ messages in thread
From: Ryan Wilbur @ 2026-07-30 18:50 UTC (permalink / raw)
  To: gregkh
  Cc: andriy.shevchenko, hvilleneuve, ilpo.jarvinen, jirislaby,
	john.ogness, linux-kernel, linux-serial, manuel.lauss, rwilbur633,
	stable

> This breaks the build :(

Thanks, and sorry. It slipped by because my build had
CONFIG_SERIAL_OF_PLATFORM=y, so modpost never flagged the missing
namespace import. v4 will add MODULE_IMPORT_NS("SERIAL_8250") (as 8250_dw.c
does), I'll send it once I've confirmed the modular build.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-07-30 18:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-22 14:03 [PATCH v3] serial: 8250_of: clear stuck empty-FIFO RX-timeout on LPC32xx Ryan Wilbur
2026-07-30 14:41 ` Greg Kroah-Hartman
2026-07-30 18:50   ` Ryan Wilbur

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox