Linux Serial subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "James Hilliard" <james.hilliard1@gmail.com>
Cc: linux-serial@vger.kernel.org, imx@lists.linux.dev, Frank.Li@kernel.org
Subject: Re: [PATCH v14 2/8] serial: serialize asynchronous write wakeups with the port lock
Date: Fri, 04 Dec 2026 10:30:23 +0000	[thread overview]
Message-ID: <sashiko-outbox-249600@kernel.org> (raw)
In-Reply-To: <20261204-submit-serial-8250-dma-cancel-v1-v14-2-b691fec8097d@gmail.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] serial: zs: deadlock from calling schedule_work() in
  zs_console_write()
- [Medium] serial: sb1250-duart: 20ms IRQ-off spin in sbd_set_termios()
- [Medium] serial: atmel: IRQ-disabling lock held across full RX/TX
  tasklet execution
--

commit 99c0892280c906bd3d8025ef585adcd610824380
Author: James Hilliard <james.hilliard1@gmail.com>

serial: serialize asynchronous write wakeups with the port lock

This commit adds UART port locking around asynchronous write wakeups,
modem-status handling, and transmit paths across 20 serial drivers, and
defers DECstation ZS transmit restarts after console output to a workqueue.

> diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
> index c3880259e3bce..4c3a6e10d92f2 100644
> --- a/drivers/tty/serial/atmel_serial.c
> +++ b/drivers/tty/serial/atmel_serial.c

[ ... ]

> @@ -1702,10 +1704,9 @@ static void atmel_tasklet_rx_func(struct tasklet_struct *t)
>  							  tasklet_rx);
>  	struct uart_port *port = &atmel_port->uart;
>  
> -	/* The interrupt handler does not take the lock */
> -	uart_port_lock(port);
> +	guard(uart_port_lock_irqsave)(port);
> +
>  	atmel_port->schedule_rx(port);
> -	uart_port_unlock(port);
>  }
>  
>  static void atmel_tasklet_tx_func(struct tasklet_struct *t)
> @@ -1714,10 +1715,9 @@ static void atmel_tasklet_tx_func(struct tasklet_struct *t)
>  							  tasklet_tx);
>  	struct uart_port *port = &atmel_port->uart;
>  
> -	/* The interrupt handler does not take the lock */
> -	uart_port_lock(port);
> +	guard(uart_port_lock_irqsave)(port);
> +
>  	atmel_port->schedule_tx(port);
> -	uart_port_unlock(port);
>  }

[Severity: Medium]
Does holding uart_port_lock_irqsave() across the full schedule_rx() and
schedule_tx() callbacks regress hardirq latency and risk RX overruns?

Every RX and TX tasklet run now keeps local hardware interrupts disabled
across expensive hot-path work.  In atmel_rx_from_dma(), dmaengine_tx_status()
busy-waits for the hardware FIFO flush in at_xdmac_tx_status(), followed by
two 4KB non-coherent DMA cache syncs and tty_insert_flip_string().

In PIO mode, atmel_rx_from_ring() drains up to 1024 buffered characters with
local interrupts masked.  On single-core AT91/SAMA5 SoCs, that prevents
hardirq atmel_rx_chars() from emptying the 1-byte RHR and risks hardware RX
overruns.

Narrowing the port lock inside the schedule_rx() and schedule_tx() paths so
DMA status polling, cache syncs, and flip-buffer work run with interrupts
enabled would avoid this regression.

[ ... ]

> diff --git a/drivers/tty/serial/sb1250-duart.c b/drivers/tty/serial/sb1250-duart.c
> index b4e1b90e59608..55179e5dcb51c 100644
> --- a/drivers/tty/serial/sb1250-duart.c
> +++ b/drivers/tty/serial/sb1250-duart.c

[ ... ]

> @@ -611,7 +617,7 @@ static void sbd_set_termios(struct uart_port *uport, struct ktermios *termios,
>  	else
>  		aux &= ~M_DUART_CTS_CHNG_ENA;
>  
> -	uart_port_lock(uport);
> +	guard(uart_port_lock_irqsave)(uport);
>  
>  	if (sport->tx_stopped)
>  		command |= M_DUART_TX_DIS;
> @@ -632,8 +638,6 @@ static void sbd_set_termios(struct uart_port *uport, struct ktermios *termios,
>  	write_sbdchn(sport, R_DUART_AUXCTL_X, aux | oldaux);
>  
>  	write_sbdchn(sport, R_DUART_CMD, command);
> -
> -	uart_port_unlock(uport);
>  }

[Severity: Medium]
Can switching sbd_set_termios() to uart_port_lock_irqsave() disable local
hardware interrupts for over 20 ms?

Inside this critical section, sbd_set_termios() calls sbd_line_drain() when
!sport->tx_stopped.  sbd_line_drain() busy-waits with udelay(2) for up to
10,000 iterations waiting for M_DUART_TX_EMT without dropping the lock or
re-enabling interrupts.

At low baud rates while the TX FIFO is draining, this stalls all local
interrupts on the CPU, causing timer latency spikes and RX overruns on other
ports.  Dropping and reacquiring the lock around udelay(2) in
sbd_line_drain(), as zs_line_drain() does, would avoid the long IRQ-off spin.

[ ... ]

> diff --git a/drivers/tty/serial/zs.c b/drivers/tty/serial/zs.c
> index 8f92b4129a385..6126dee0301d9 100644
> --- a/drivers/tty/serial/zs.c
> +++ b/drivers/tty/serial/zs.c

[ ... ]

> @@ -1161,9 +1204,12 @@ static void zs_console_write(struct console *co, const char *s,
>  		zport->regs[1] |= TxINT_ENAB;
>  		write_zsreg(zport, R1, zport->regs[1]);
>  
> -		/* Resume any transmission as the TxIP bit won't be set.  */
> +		/*
> +		 * TxIP won't be set. Defer the restart: console output may be
> +		 * called with the port lock held, and TX must acquire it first.
> +		 */
>  		if (!zport->tx_stopped)
> -			zs_raw_transmit_chars(zport);
> +			schedule_work(&zport->tx_work);
>  	}
>  	spin_unlock_irqrestore(&scc->zlock, flags);
>  }

[Severity: High]
Could calling schedule_work() from zs_console_write() deadlock the kernel?

zs_console_write() is a legacy console->write callback invoked synchronously
from printk(), WARN_ON(), and panic paths with interrupts disabled.  Calling
schedule_work() acquires workqueue pool->lock and scheduler locks (p->pi_lock
and rq->__lock) while holding scc->zlock.

If any warning, oops, or panic prints while pool->lock or a scheduler lock is
held, it recurses into zs_console_write() and deadlocks:

destroy_workqueue()
  raw_spin_lock_irq(&pwq->pool->lock)
  WARN_ON(pwq_busy(pwq))
    printk() -> console_emit_next_record() -> zs_console_write()
      spin_lock_irqsave(&scc->zlock, flags)
      schedule_work(&zport->tx_work)
        __queue_work()
          raw_spin_lock(&pool->lock)  <-- spins forever

Since zs_tx_work() does not sleep, deferring the TX restart with lockless
irq_work_queue() and synchronizing with irq_work_sync() (as in
qcom_geni_serial.c) would avoid taking workqueue or scheduler locks from
console output.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-submit-serial-8250-dma-cancel-v1-v14-0-b691fec8097d@gmail.com?part=2

  reply	other threads:[~2026-12-04 10:30 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 10:03 [PATCH v14 0/8] serial: 8250: serialize DMA cancellation with buffer reuse James Hilliard
2026-12-04 10:03 ` [PATCH v14 1/8] serial: 8250_omap: separate locked TX DMA completion processing James Hilliard
2026-12-04 10:18   ` sashiko-bot
2026-12-04 10:03 ` [PATCH v14 2/8] serial: serialize asynchronous write wakeups with the port lock James Hilliard
2026-12-04 10:30   ` sashiko-bot [this message]
2026-12-04 10:03 ` [PATCH v14 3/8] serial: 8250_omap: serialize RX DMA completion and flushing James Hilliard
2026-12-04 10:20   ` sashiko-bot
2026-12-04 10:03 ` [PATCH v14 4/8] serial: 8250_omap: quiesce DMA IRQ handling before shutdown James Hilliard
2026-12-04 10:03 ` [PATCH v14 5/8] serial: core: allow drivers to reserve flushed transmit storage James Hilliard
2026-12-04 10:37   ` sashiko-bot
2026-12-04 10:03 ` [PATCH v14 6/8] serial: 8250: drain canceled TX DMA before reusing its buffer James Hilliard
2026-12-04 10:31   ` sashiko-bot
2026-12-04 10:03 ` [PATCH v14 7/8] serial: 8250: retire canceled RX DMA before reusing the receive buffer James Hilliard
2026-12-04 10:03 ` [PATCH v14 8/8] serial: 8250: retain DMA resources when termination fails James Hilliard

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=sashiko-outbox-249600@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=imx@lists.linux.dev \
    --cc=james.hilliard1@gmail.com \
    --cc=linux-serial@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox