All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Vítor Hugo Silva" <vitorhg20080@gmail.com>
To: sashiko-reviews@lists.linux.dev
Cc: devicetree@vger.kernel.org, linux-serial@vger.kernel.org,
	 robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH RFC 12/19] serial: esp32: Rearm TX interrupts when the FIFO is full
Date: Fri, 27 Nov 2026 15:40:22 +0000	[thread overview]
Message-ID: <awmieG6bM5iKWYzv@dom0> (raw)
In-Reply-To: <sashiko-outbox-236334@kernel.org>

On Thu, Nov 26, 2026 at 11:32:18PM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Medium] serial: esp32: TX IRQ storm in esp32_uart_transmit_buffer()
>   after x_char
> --
> 
> commit dad4b1d831af0fbc408461f76bacc91b367f0e67
> Author: Vítor Hugo Silva <vitorhg20080@gmail.com>
> 
> serial: esp32: Rearm TX interrupts when the FIFO is full
> 
> This commit rearms the TX FIFO empty interrupt in
> esp32_uart_transmit_buffer() whenever data or x_char is waiting to be sent
> even if the TX FIFO is full, and acquires the port lock in
> esp32_uart_txint().
> 
> > diff --git a/drivers/tty/serial/esp32_uart.c b/drivers/tty/serial/esp32_uart.c
> > index 304e1345518bd..002d6fdbd875f 100644
> > --- a/drivers/tty/serial/esp32_uart.c
> > +++ b/drivers/tty/serial/esp32_uart.c
> > @@ -354,14 +354,14 @@ static void esp32_uart_transmit_buffer(struct uart_port *port)
> >  	unsigned int pending;
> >  	u8 ch;
> >  
> > -	if (tx_fifo_used >= ESP32_UART_TX_FIFO_SIZE)
> > -		return;
> > -
> > +	tx_fifo_used = min_t(u32, tx_fifo_used, ESP32_UART_TX_FIFO_SIZE);
> >  	pending = uart_port_tx_limited(port, ch,
> >  				       ESP32_UART_TX_FIFO_SIZE - tx_fifo_used,
> >  				       true, esp32_uart_put_char(port, ch),
> >  				       ({}));
> > -	if (pending) {
> > +
> > +	/* Rearm TX even if the FIFO had no room for queued data. */
> > +	if (port->x_char || (pending && !uart_tx_stopped(port))) {
> >  		u32 int_ena;
> >  
> >  		int_ena = esp32_uart_read(port, UART_INT_ENA_REG);
> 
> [Severity: Medium]
> Can this cause a UART_TXFIFO_EMPTY_INT interrupt storm after a deferred
> port->x_char is sent while TX flow is stopped?

Yes. For v2, I'll use UART_TX_NOSTOP and let
esp32_uart_transmit_buffer() control when the TX IRQ is masked.
After sending x_char while TX is stoppped, driver masks the TX IRQ and
leaves the queued data in place until the TX resumes.

I've tested this and it works with a mocked FIFO and in the hardware
itself, where the serial console stayed normal and responsive during
normal use.

> 
> If uart_send_xchar() runs when the hardware TX FIFO is full,
> uart_tx_stopped(port) is true, and xmit_fifo is non-empty (pending > 0),
> uart_port_tx_limited() runs with count == 0 and leaves port->x_char set, so
> this check enables UART_TXFIFO_EMPTY_INT.
> 
> When the FIFO drains below the empty threshold, esp32_uart_txint() calls
> uart_port_tx_limited(), which transmits port->x_char, clears port->x_char
> to 0, and breaks out of its loop because uart_tx_stopped(port) is true.
> Because pending > 0, __uart_port_tx() does not call port->ops->stop_tx():
> 
> include/linux/serial_core.h:__uart_port_tx() {
>     ...
> 	pending = kfifo_len(&__tport->xmit_fifo);
> 	if (pending < WAKEUP_CHARS) {
> 		uart_write_wakeup(__port);
> 
> 		if (!((flags) & UART_TX_NOSTOP) && pending == 0)
> 			__port->ops->stop_tx(__port);
> 	}
>     ...
> }
> 
> Back in esp32_uart_transmit_buffer(), port->x_char is now 0 and
> uart_tx_stopped(port) is true, so nothing disables UART_TXFIFO_EMPTY_INT.
> Once that x_char shifts out, UART_TXFIFO_EMPTY_INT fires continuously in a
> hardirq storm until TX flow resumes or the port is shut down.  Adding an
> else branch that calls esp32_uart_stop_tx(port) would ensure the interrupt
> is disabled.
> 
> -- 
> Sashiko AI review · https://sashiko.dev/#/patchset/20261125233020.1380594-1-vitorhg20080@gmail.com?part=12

Thanks,
Vítor

  reply	other threads:[~2026-11-27 15:40 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 23:30 [PATCH RFC 00/19] riscv: Add initial support for Espressif ESP32-P4 Vítor Hugo Silva
2026-11-25 23:30 ` Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 01/19] riscv: Prepare ESP32-P4 early CLIC trap vectors Vítor Hugo Silva
2026-11-25 23:30   ` Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 02/19] riscv: Handle ESP32-P4 CLIC trap context Vítor Hugo Silva
2026-11-25 23:30   ` Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 03/19] dt-bindings: interrupt-controller: Add Espressif ESP32-P4 CLIC Vítor Hugo Silva
2026-11-25 23:30   ` Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 04/19] irqchip: Add Espressif ESP32-P4 CLIC support Vítor Hugo Silva
2026-11-25 23:30   ` Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 05/19] dt-bindings: interrupt-controller: Add Espressif ESP32-P4 interrupt matrix Vítor Hugo Silva
2026-11-25 23:30   ` Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 06/19] irqchip: Add Espressif ESP32-P4 interrupt matrix support Vítor Hugo Silva
2026-11-25 23:30   ` Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 07/19] dt-bindings: timer: Add Espressif ESP32-P4 CLINT Vítor Hugo Silva
2026-11-25 23:30   ` Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 08/19] clocksource/drivers/timer-clint: Add Espressif ESP32-P4 support Vítor Hugo Silva
2026-11-25 23:30   ` Vítor Hugo Silva
2026-11-26 23:32   ` sashiko-bot
2026-11-27 16:18   ` [PATCH RFC v2] " Vítor Hugo Silva
2026-11-27 16:18     ` Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 09/19] dt-bindings: serial: Add Espressif ESP32-P4 UART Vítor Hugo Silva
2026-11-25 23:30   ` Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 10/19] serial: esp32: Restore the ESP32 UART driver Vítor Hugo Silva
2026-11-25 23:30   ` Vítor Hugo Silva
2026-11-26 23:32   ` sashiko-bot
2026-11-27 16:55   ` [PATCH RFC 1/4] serial: esp32: Validate the baud rate before programming the UART Vítor Hugo Silva
2026-11-27 16:55     ` Vítor Hugo Silva
2026-11-27 16:55     ` [PATCH RFC 2/4] serial: esp32: Fix ESP32-S3 baud rate prescaler calculation Vítor Hugo Silva
2026-11-27 16:55       ` Vítor Hugo Silva
2026-11-27 16:55     ` [PATCH RFC 3/4] serial: esp32: Deliver and mask receive break interrupts Vítor Hugo Silva
2026-11-27 16:55       ` Vítor Hugo Silva
2026-11-27 16:55     ` [PATCH RFC 4/4] serial: esp32: Enable the UART clock during port registration Vítor Hugo Silva
2026-11-27 16:55       ` Vítor Hugo Silva
2026-11-27 19:25   ` [PATCH RFC 1/2] serial: esp32: Enable hardware RTS/CTS flow control Vítor Hugo Silva
2026-11-27 19:25     ` Vítor Hugo Silva
2026-11-27 19:25     ` [PATCH RFC 2/2] serial: esp32: Report active-low CTS correctly on ESP32-S3 and ESP32-P4 Vítor Hugo Silva
2026-11-27 19:25       ` Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 11/19] serial: esp32: Add support for the ESP32-P4 UART Vítor Hugo Silva
2026-11-25 23:30   ` Vítor Hugo Silva
2026-11-26 23:32   ` sashiko-bot
2026-11-27 19:39   ` [PATCH RFC v2] " Vítor Hugo Silva
2026-11-27 19:39     ` Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 12/19] serial: esp32: Rearm TX interrupts when the FIFO is full Vítor Hugo Silva
2026-11-25 23:30   ` Vítor Hugo Silva
2026-11-26 23:32   ` sashiko-bot
2026-11-27 15:40     ` Vítor Hugo Silva [this message]
2026-11-27 15:56   ` [PATCH RFC v2] " Vítor Hugo Silva
2026-11-27 15:56     ` Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 13/19] serial: esp32: Add early console support for ESP32-P4 Vítor Hugo Silva
2026-11-25 23:30   ` Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 14/19] riscv: Synchronize instructions written to ESP32-P4 PSRAM Vítor Hugo Silva
2026-11-25 23:30   ` Vítor Hugo Silva
2026-11-26 23:32   ` sashiko-bot
2026-11-27 22:13   ` [PATCH RFC v2] " Vítor Hugo Silva
2026-11-27 22:13     ` Vítor Hugo Silva
2026-11-28 22:16     ` sashiko-bot
2026-11-30 10:31       ` Vítor Hugo Silva
2026-11-30 12:23     ` [PATCH RFC v3] " Vítor Hugo Silva
2026-11-30 12:23       ` Vítor Hugo Silva
2026-12-01 12:24       ` sashiko-bot
2026-11-25 23:30 ` [PATCH RFC 15/19] riscv: Align init data to the ESP32-P4 PMP granularity Vítor Hugo Silva
2026-11-25 23:30   ` Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 16/19] dt-bindings: riscv: Add Waveshare ESP32-P4-Module-DEV-KIT Vítor Hugo Silva
2026-11-25 23:30   ` Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 17/19] dt-bindings: riscv: cpus: Document Espressif ESP32-P4 HP harts Vítor Hugo Silva
2026-11-25 23:30   ` Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 18/19] riscv: dts: Add Waveshare ESP32-P4-Module-DEV-KIT Vítor Hugo Silva
2026-11-25 23:30   ` Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 19/19] MAINTAINERS: Add the Espressif ESP32-P4 platform Vítor Hugo Silva
2026-11-25 23:30   ` Vítor Hugo Silva
2026-11-26 23:32 ` [PATCH RFC 00/19] riscv: Add initial support for Espressif ESP32-P4 sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=awmieG6bM5iKWYzv@dom0 \
    --to=vitorhg20080@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.