Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH] serial: imx: stop TX-ready interrupt storm on idle port
@ 2026-12-02 11:15 Michael Glembotzki
  2026-12-02 16:34 ` [PATCH v2] serial: imx: disable TX interrupts when already stopped Michael Glembotzki
  0 siblings, 1 reply; 2+ messages in thread
From: Michael Glembotzki @ 2026-12-02 11:15 UTC (permalink / raw)
  To: linux-serial; +Cc: gregkh, jirislaby, s.hauer, Michael Glembotzki, stable

On i.MX8MP, watchdog diagnostics captured repeated UART TX-ready
interrupts with tx_state OFF, an empty transmit buffer and no pending
x_char. The normal transmit handler calls imx_uart_stop_tx(), but that
function returns early when the state is OFF without clearing
UCR1_TRDYEN. The still-asserted interrupt can starve the CPU and prevent
the watchdog from being serviced.

When this precise idle condition is observed in the interrupt handler,
clear TRDYEN and continue the normal handler. Keep UART and RX enabled;
subsequent transmission can enable TX-ready interrupts through the
regular TX path. Do not change behavior when characters are pending.

The origin of the inconsistent state is not yet known. This change
addresses the observed interrupt loop, not the initial state mismatch.

Cc: stable@vger.kernel.org
Signed-off-by: Michael Glembotzki <Michael.Glembotzki@iris-sensing.com>
---

Tested on i.MX8MP hardware with an NXP-based Linux 6.6.161 kernel.
The mainline adaptation was compile-tested for ARM64, including
console support, but has not been runtime-tested.
 
For a 6.6 backport, the transmit-buffer check needs to use
uart_circ_empty(&sport->port.state->xmit) instead of
kfifo_is_empty(&sport->port.state->port.xmit_fifo).

 drivers/tty/serial/imx.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index 0831bd5..258e03b 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -1038,6 +1038,14 @@ static irqreturn_t imx_uart_int(int irq, void *dev_id)
 	}
 
 	if ((usr1 & USR1_TRDY) || (usr2 & USR2_TXDC)) {
+		/* An idle transmitter must not keep firing a ready interrupt. */
+		if ((usr1 & USR1_TRDY) && sport->tx_state == OFF &&
+		    !sport->port.x_char &&
+		    kfifo_is_empty(&sport->port.state->port.xmit_fifo)) {
+			u32 current_ucr1 = imx_uart_readl(sport, UCR1);
+
+			imx_uart_writel(sport, current_ucr1 & ~UCR1_TRDYEN, UCR1);
+		}
 		imx_uart_transmit_buffer(sport);
 		ret = IRQ_HANDLED;
 	}
-- 
2.56.1

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

* [PATCH v2] serial: imx: disable TX interrupts when already stopped
  2026-12-02 11:15 [PATCH] serial: imx: stop TX-ready interrupt storm on idle port Michael Glembotzki
@ 2026-12-02 16:34 ` Michael Glembotzki
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Glembotzki @ 2026-12-02 16:34 UTC (permalink / raw)
  To: linux-serial; +Cc: gregkh, jirislaby, s.hauer, stable, Michael Glembotzki

On i.MX8MP, watchdog diagnostics captured repeated UART TX-ready
interrupts with tx_state OFF, an empty transmit buffer and no pending
x_char. The normal transmit handler calls imx_uart_stop_tx(), but that
function returns early when the state is OFF without clearing
UCR1_TRDYEN or UCR4_TCEN. A still-enabled TX interrupt can starve the CPU
and prevent the watchdog from being serviced.

Clear both TX interrupt enable bits before returning from the OFF branch
of imx_uart_stop_tx(). This also handles stopped transmission with data
still queued, a buffer drained by the transmit handler, and platforms
using a separate TX interrupt handler. Keep the existing DMA and RS485
handling for other TX states unchanged.

UART and RX remain enabled. Subsequent transmission can enable TX
interrupts again through the normal start path.

The origin of the inconsistent state is not yet known. This change
addresses the observed interrupt loop, not the initial state mismatch.

Fixes: cb1a60923609 ("serial: imx: implement rts delaying for rs485")
Cc: stable@vger.kernel.org
Signed-off-by: Michael Glembotzki <Michael.Glembotzki@iris-sensing.com>
---

Runtime-tested on i.MX8MP hardware with an NXP-based Linux 6.6.161
kernel. Mainline has not been runtime-tested.

Changes in v2:
- Disable TRDYEN and TCEN in the OFF branch of imx_uart_stop_tx()
  instead of handling only an empty buffer in the combined IRQ handler.
- Add the Fixes tag for the commit introducing the early return.

v1: https://lore.kernel.org/linux-serial/20261202111526.664966-2-Michael.Glembotzki@iris-sensing.com/

 drivers/tty/serial/imx.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -415,8 +415,15 @@ static void imx_uart_stop_tx(struct uart_port *port)
 	struct imx_port *sport = to_imx_port(port);
 	u32 ucr1, ucr4, usr2;
 
-	if (sport->tx_state == OFF)
+	if (sport->tx_state == OFF) {
+		/* Disable stale TX interrupts even when already stopped. */
+		ucr1 = imx_uart_readl(sport, UCR1);
+		imx_uart_writel(sport, ucr1 & ~UCR1_TRDYEN, UCR1);
+
+		ucr4 = imx_uart_readl(sport, UCR4);
+		imx_uart_writel(sport, ucr4 & ~UCR4_TCEN, UCR4);
 		return;
+	}
 
 	/*
 	 * We are maybe in the SMP context, so if the DMA TX thread is running
-- 
2.56.1

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

end of thread, other threads:[~2026-12-02 16:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 11:15 [PATCH] serial: imx: stop TX-ready interrupt storm on idle port Michael Glembotzki
2026-12-02 16:34 ` [PATCH v2] serial: imx: disable TX interrupts when already stopped Michael Glembotzki

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