All of lore.kernel.org
 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 v5 5/5] serial: 8250: retire canceled RX DMA before reusing the receive buffer
Date: Sat, 24 Oct 2026 07:24:56 +0000	[thread overview]
Message-ID: <sashiko-outbox-183582@kernel.org> (raw)
In-Reply-To: <20261024-submit-serial-8250-dma-cancel-v1-v5-5-9e52968928d2@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] serial: 8250_dma: dev_warn() called under port lock in serial8250_rx_dma_flush_work()
--

commit 0ccef758673ba1627cbc368a7ea2a4a045241f8f
Author: James Hilliard <james.hilliard1@gmail.com>

serial: 8250: retire canceled RX DMA before reusing the receive buffer

This commit reserves the RX DMA buffer until a worker has drained canceled
callbacks and falls back to PIO via a recovery worker if pausing, querying
status, or terminating the RX DMA channel fails.

> diff --git a/drivers/tty/serial/8250/8250_dma.c b/drivers/tty/serial/8250/8250_dma.c
> index 1a070967bf571..801221baded0a 100644
> --- a/drivers/tty/serial/8250/8250_dma.c
> +++ b/drivers/tty/serial/8250/8250_dma.c
> @@ -86,53 +86,96 @@ void serial8250_tx_dma_sync_buffer(struct uart_8250_port *p,
[ ... ]
> +static void serial8250_rx_dma_flush_work(struct work_struct *work)
> +{
> +	struct uart_8250_dma *dma = container_of(work, struct uart_8250_dma, rx_flush_work);
> +	struct uart_8250_port *p = dma->port;
> +	bool recover;
> +	int ret;
> +
> +	/* All packed flags share the port lock, including this worker snapshot. */
> +	scoped_guard(uart_port_lock_irqsave, &p->port)
> +		recover = dma->rx_err;
> +
> +	if (recover) {
> +		ret = dmaengine_terminate_sync(dma->rxchan);
> +		if (ret) {
> +			/* Retain ownership and keep RX masked if DMA cannot be stopped. */
> +			dev_err(p->port.dev, "failed to stop RX DMA: %d\n", ret);
> +			return;
> +		}
> +	} else {
> +		dmaengine_synchronize(dma->rxchan);
> +	}
> +
> +	guard(serial8250_rpm)(p);
>  
> -	uart_port_lock_irqsave(&p->port, &flags);
> +	guard(uart_port_lock_irqsave)(&p->port);
> +
> +	dma->rx_terminating = false;
> +	dma->rx_running = 0;
>  	if (dma->shutting_down)
> -		goto out;
> -	if (dma->rx_running)
> -		__dma_rx_complete(p);
> +		return;
>  
> -	/*
> -	 * Cannot be combined with the previous check because __dma_rx_complete()
> -	 * changes dma->rx_running.
> -	 */
> -	if (!dma->rx_running && (serial_lsr_in(p) & UART_LSR_DR))
> -		p->dma->rx_dma(p);
> -out:
> -	uart_port_unlock_irqrestore(&p->port, flags);
> +	if (!recover)
> +		return;
> +
> +	/* Apply the current enables, including any intervening stop_rx(). */
> +	serial8250_out_IER(p, p->ier);
> +	dev_warn(p->port.dev, "RX DMA failed, using PIO\n");

[Severity: High]
Does calling dev_warn() while holding p->port.lock with interrupts disabled in
serial8250_rx_dma_flush_work() violate the printk and serial console locking
hierarchy?

When RX DMA recovery is triggered via dma_rx_complete() or
serial8250_rx_dma_flush() -> serial8250_rx_dma_recover(),
serial8250_rx_dma_flush_work() takes guard(uart_port_lock_irqsave)(&p->port)
for the remainder of the function and calls dev_warn() under p->port.lock.

In drivers/tty/serial/serial_core.c, uart_port_spin_lock_init() assigns every
uart_port->lock the shared lockdep class port_lock_key:

  static void uart_port_spin_lock_init(struct uart_port *port)
  {
          spin_lock_init(&port->lock);
          lockdep_set_class(&port->lock, &port_lock_key);
  }

Normal console paths acquire console_lock_dep_map and console_owner_dep_map
outside port_lock_key. Calling dev_warn() while holding p->port.lock enters:

  vprintk_emit()
    -> console_trylock_spinning()
       -> console_flush_all()
          -> console_emit_next_record()
             -> console_lock_spinning_enable()

which acquires console_owner_dep_map inside port_lock_key and invokes legacy
serial console write callbacks that also acquire port_lock_key, risking lockdep
splats or a console-owner spin deadlock.

Should the port lock use scoped_guard(uart_port_lock_irqsave, &p->port) so
that p->port.lock is released after serial8250_out_IER(p, p->ier) and before
dev_warn() is called?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261024-submit-serial-8250-dma-cancel-v1-v5-0-9e52968928d2@gmail.com?part=5

      reply	other threads:[~2026-10-24  7:24 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-24  6:40 [PATCH v5 0/5] serial: 8250: serialize DMA cancellation with buffer reuse James Hilliard
2026-10-24  6:40 ` [PATCH v5 1/5] serial: 8250_omap: separate locked TX DMA completion processing James Hilliard
2026-10-24  6:45   ` sashiko-bot
2026-10-24  6:40 ` [PATCH v5 2/5] serial: serialize asynchronous write wakeups with the port lock James Hilliard
2026-10-24  6:50   ` sashiko-bot
2026-10-25  5:10   ` Maciej W. Rozycki
2026-10-25 15:09     ` Andy Shevchenko
2026-10-25 20:25       ` James Hilliard
2026-10-25 20:44         ` Andy Shevchenko
2026-10-25 22:11           ` James Hilliard
2026-10-26  9:31             ` Andy Shevchenko
2026-10-26 16:45               ` James Hilliard
2026-10-26 19:53                 ` Andy Shevchenko
2026-10-26 19:59                   ` James Hilliard
2026-10-26 20:17                     ` Greg Kroah-Hartman
2026-10-26 20:24                       ` James Hilliard
2026-10-26 20:40                         ` Greg Kroah-Hartman
2026-10-26 20:49                           ` James Hilliard
2026-10-26 21:23                             ` Andy Shevchenko
2026-10-26 21:36                             ` Maciej W. Rozycki
2026-10-26 20:18                     ` Andy Shevchenko
2026-10-25 18:47     ` James Hilliard
2026-10-24  6:40 ` [PATCH v5 3/5] serial: core: allow drivers to reserve flushed transmit storage James Hilliard
2026-10-24  7:26   ` sashiko-bot
2026-10-24  6:40 ` [PATCH v5 4/5] serial: 8250: drain canceled TX DMA before reusing its buffer James Hilliard
2026-10-24  6:55   ` sashiko-bot
2026-10-24  6:40 ` [PATCH v5 5/5] serial: 8250: retire canceled RX DMA before reusing the receive buffer James Hilliard
2026-10-24  7:24   ` sashiko-bot [this message]

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-183582@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 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.