Linux Serial subsystem development
 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 11:34 ` sashiko-bot
  2026-12-02 16:34 ` [PATCH v2] serial: imx: disable TX interrupts when already stopped Michael Glembotzki
  0 siblings, 2 replies; 4+ 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] 4+ messages in thread

* Re: [PATCH] serial: imx: stop TX-ready interrupt storm on idle port
  2026-12-02 11:15 [PATCH] serial: imx: stop TX-ready interrupt storm on idle port Michael Glembotzki
@ 2026-12-02 11:34 ` sashiko-bot
  2026-12-02 16:34 ` [PATCH v2] serial: imx: disable TX interrupts when already stopped Michael Glembotzki
  1 sibling, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-12-02 11:34 UTC (permalink / raw)
  To: Michael Glembotzki, linux-serial

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] serial: imx: incomplete TX interrupt storm fix in
  imx_uart_int()
- [Low] serial: imx: missing Fixes trailer for commit cb1a60923609
--

commit 11d7b6ef67792384c5672f5466f0d1655bebf34b
Author: Michael Glembotzki <m.glembo@gmail.com>

> serial: imx: stop TX-ready interrupt storm on idle port
>
> 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>

[Severity: Low]
Since this fixes the early return before clearing UCR1_TRDYEN in
imx_uart_stop_tx() and is tagged for stable, should it include:

  Fixes: cb1a60923609 ("serial: imx: implement rts delaying for rs485")

> diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
> index 0831bd5ee3dc2..258e03b744c06 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;
>  	}

[Severity: Medium]
Can this still leave UCR1_TRDYEN enabled in an interrupt storm when
uart_tx_stopped(&sport->port) is true and xmit_fifo is non-empty?

When flow control stops transmission while unsent bytes remain in
xmit_fifo, kfifo_is_empty() is false, so this new check is skipped.
imx_uart_transmit_buffer() then sees uart_tx_stopped() and calls
imx_uart_stop_tx() without draining xmit_fifo:

drivers/tty/serial/imx.c:imx_uart_transmit_buffer() {
	...
	if (kfifo_is_empty(&tport->xmit_fifo) ||
			uart_tx_stopped(&sport->port)) {
		imx_uart_stop_tx(&sport->port);
		return;
	}
	...
}

Because sport->tx_state is OFF, imx_uart_stop_tx() returns early without
clearing UCR1_TRDYEN, repeating the interrupt loop and starving the CPU.

Handling this in imx_uart_int() also misses a few other paths where
imx_uart_stop_tx() returns early while sport->tx_state == OFF: draining
pending characters in imx_uart_transmit_buffer() fails to clear
UCR1_TRDYEN at the end of the transfer, USR2_TXDC with UCR4_TCEN set is
not cleared, and platforms with a separate TX IRQ use imx_uart_txint()
instead of imx_uart_int().

Would clearing UCR1_TRDYEN (and UCR4_TCEN) in imx_uart_stop_tx() before
the sport->tx_state == OFF early return cover all of these paths in one
place?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202111526.664966-2-Michael.Glembotzki@iris-sensing.com?part=1

^ permalink raw reply	[flat|nested] 4+ 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 11:34 ` sashiko-bot
@ 2026-12-02 16:34 ` Michael Glembotzki
  2026-12-02 16:44   ` sashiko-bot
  1 sibling, 1 reply; 4+ 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] 4+ messages in thread

* Re: [PATCH v2] serial: imx: disable TX interrupts when already stopped
  2026-12-02 16:34 ` [PATCH v2] serial: imx: disable TX interrupts when already stopped Michael Glembotzki
@ 2026-12-02 16:44   ` sashiko-bot
  0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-12-02 16:44 UTC (permalink / raw)
  To: Michael Glembotzki, linux-serial

> 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>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202163424.698658-2-Michael.Glembotzki@iris-sensing.com?part=1

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

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

Thread overview: 4+ 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 11:34 ` sashiko-bot
2026-12-02 16:34 ` [PATCH v2] serial: imx: disable TX interrupts when already stopped Michael Glembotzki
2026-12-02 16:44   ` sashiko-bot

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