From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: James Hilliard <james.hilliard1@gmail.com>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Jiri Slaby" <jirislaby@kernel.org>,
"Raul E Rangel" <rrangel@chromium.org>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Heikki Krogerus" <heikki.krogerus@linux.intel.com>,
"Tony Lindgren" <tony@atomide.com>,
"Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org
Subject: Re: [PATCH v2 4/4] serial: 8250: retire canceled RX DMA before reusing the receive buffer
Date: Fri, 23 Oct 2026 11:30:18 +0300 [thread overview]
Message-ID: <atsbGvUUeDYHT_md@ashevche-desk.local> (raw)
In-Reply-To: <20261022-submit-serial-8250-dma-cancel-v1-v2-4-088ea51e3891@gmail.com>
On Thu, Oct 22, 2026 at 06:34:05PM -0600, James Hilliard wrote:
> The RX timeout path pauses a transfer, copies its data and terminates it
> asynchronously. Clearing rx_running at that point lets another receive
> reuse the buffer and cookie while the old callback is still waiting for
> the port lock. Inspecting the new cookie cannot distinguish that callback
> from the completion of a new transfer.
>
> Reserve the receive buffer until a worker has drained the canceled
> callbacks. Deliver the paused data before allowing the interrupt handler
> to drain the FIFO through PIO. Normal retirement only releases ownership;
> leave subsequent receive handling to the UART interrupt instead of reading
> LSR and restarting DMA from the worker.
>
> Reject new flush work during shutdown, including late Intel MID DMA
> timeouts. Serialize those timeout callers with the port lock. Stop and
> drain retirement work before freeing the channels and buffer.
>
> Check pause failures before accessing the buffer. A successful pause is
> the quiescence guarantee, even when a provider still reports IN_PROGRESS.
> On pause, status or termination failure, mask receive interrupts and let
> the worker stop DMA before handing the FIFO to PIO. Preserve stop_rx() and
> shutdown while restoring deferred interrupts, and hold a runtime PM
> reference around worker register accesses. Keep RX on PIO until reopen.
>
> Abort the DesignWare idle sequence when RX cannot be stopped. Preserve its
> empty-FIFO timeout workaround during PIO recovery. If the provider still
> cannot terminate the channel in process context, retain its buffer and
> leave receive interrupts masked.
...
> struct uart_8250_dma {
> bool shutting_down;
> bool tx_terminating;
> bool tx_flushed;
> + bool rx_terminating;
> + bool rx_err;
If they are protected by the same lock, we may actually move to bitfields.
Example:
unsigned int rx_err:1;
> + /* Receive interrupt enables deferred during RX DMA recovery. */
> + u8 rx_ier;
> };
...
> static void dma_rx_complete(void *param)
> {
> struct uart_8250_port *p = param;
> struct uart_8250_dma *dma = p->dma;
> + struct dma_tx_state state;
> + enum dma_status status;
> unsigned long flags;
>
> uart_port_lock_irqsave(&p->port, &flags);
> - if (dma->shutting_down)
> + if (dma->shutting_down || dma->rx_terminating)
> goto out;
Again repeating the same idiom you have in previous patch.
> - if (dma->rx_running)
> - __dma_rx_complete(p);
> + if (dma->rx_running) {
> + status = dmaengine_tx_status(dma->rxchan, dma->rx_cookie, &state);
> + if (status == DMA_ERROR) {
> + serial8250_rx_dma_recover(p);
> + goto out;
> + }
> + if (status != DMA_COMPLETE)
> + goto out;
> + serial8250_rx_dma_copy(p, &state);
> + dma->rx_running = 0;
> + }
>
> /*
> - * Cannot be combined with the previous check because __dma_rx_complete()
> - * changes dma->rx_running.
> + * The completed transfer no longer owns the receive buffer.
> */
> - if (!dma->rx_running && (serial_lsr_in(p) & UART_LSR_DR))
> + if (!dma->rx_running && (p->ier & UART_IER_RDI) &&
> + (serial_lsr_in(p) & UART_LSR_DR))
This has a side-effect. Earlier we do read LSR_DR, but now only if _RDI is set.
Would it be problematic?
> p->dma->rx_dma(p);
> out:
> uart_port_unlock_irqrestore(&p->port, flags);
> }
...
> + dma->rx_terminating = false;
> + dma->rx_running = 0;
> + if (dma->shutting_down)
> + return;
> + if (dma->rx_err) {
Perhaps
if (!dma->rx_err)
return;
?
> + /* PIO may now drain the FIFO; stop_rx() can cancel these enables. */
> + p->ier |= dma->rx_ier;
> + dma->rx_ier = 0;
> + serial_port_out(&p->port, UART_IER, p->ier);
> + dev_warn(p->port.dev, "RX DMA failed, using PIO\n");
> + }
> +}
...
> + /* Some providers still report IN_PROGRESS after a successful pause. */
Yeah, we need to address that. (I used to have some patches locally,
but they were rebased uncountable number of times without looking at
the result of those rebases, so it's probably rotten enough and may
not be used anymore.)
...
> - * This problem has only been observed so far when not in DMA mode
> - * so we limit the workaround only to non-DMA mode.
> + * Only read the FIFO when DMA no longer owns it, including PIO fallback
> + * after a DMA error.
> - if (!(quirks & DW_UART_QUIRK_SKIP_EMPTY_FIFO_READ) && !up->dma && rx_timeout) {
> + if (!(quirks & DW_UART_QUIRK_SKIP_EMPTY_FIFO_READ) &&
> + (!up->dma || !up->dma->rx_running) && rx_timeout) {
> status = serial_lsr_in(up);
This is a good question. We need to have this be tested on the affected
platforms.
...
> guard(serial8250_rpm)(up);
>
> + if (up->dma)
> + up->dma->rx_ier = 0;
Now we have a copy of IER in UART port and in DMA structure. Why do we need
both?
> up->ier &= ~(UART_IER_RLSI | UART_IER_RDI);
> serial_port_out(port, UART_IER, up->ier);
--
With Best Regards,
Andy Shevchenko
prev parent reply other threads:[~2026-10-23 8:30 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-23 0:34 [PATCH v2 0/4] serial: 8250: serialize DMA cancellation with buffer reuse James Hilliard
2026-10-23 0:34 ` [PATCH v2 1/4] serial: 8250_omap: separate locked TX DMA completion processing James Hilliard
2026-10-23 7:36 ` Andy Shevchenko
2026-10-23 0:34 ` [PATCH v2 2/4] serial: core: allow drivers to reserve flushed transmit storage James Hilliard
2026-10-23 0:34 ` [PATCH v2 3/4] serial: 8250: drain canceled TX DMA before reusing its buffer James Hilliard
2026-10-23 7:51 ` Andy Shevchenko
2026-10-23 0:34 ` [PATCH v2 4/4] serial: 8250: retire canceled RX DMA before reusing the receive buffer James Hilliard
2026-10-23 8:30 ` Andy Shevchenko [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=atsbGvUUeDYHT_md@ashevche-desk.local \
--to=andriy.shevchenko@linux.intel.com \
--cc=bigeasy@linutronix.de \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=james.hilliard1@gmail.com \
--cc=jirislaby@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=rrangel@chromium.org \
--cc=tony@atomide.com \
/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
all inboxes | Powered by JetHome®