From: Raul E Rangel <rrangel@chromium.org>
To: James Hilliard <james.hilliard1@gmail.com>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Jiri Slaby" <jirislaby@kernel.org>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
"Heikki Krogerus" <heikki.krogerus@linux.intel.com>,
"Tony Lindgren" <tony@atomide.com>,
"Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
"Richard Genoud" <richard.genoud@bootlin.com>,
"Nicolas Ferre" <nicolas.ferre@microchip.com>,
"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
"Claudiu Beznea" <claudiu.beznea@tuxon.dev>,
"Jacky Huang" <ychuang3@nuvoton.com>,
"Shan-Chun Hung" <schung@nuvoton.com>,
"Pali Rohár" <pali@kernel.org>, "Frank Li" <Frank.Li@nxp.com>,
"Sascha Hauer" <s.hauer@pengutronix.de>,
"Pengutronix Kernel Team" <kernel@pengutronix.de>,
"Fabio Estevam" <festevam@gmail.com>,
"Maciej W. Rozycki" <macro@orcam.me.uk>,
"Timur Tabi" <timur@kernel.org>,
linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, imx@lists.linux.dev,
linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH v8 5/6] serial: 8250: retire canceled RX DMA before reusing the receive buffer
Date: Fri, 30 Oct 2026 11:36:34 -0600 [thread overview]
Message-ID: <20261030173635.2186490-1-rrangel@chromium.org> (raw)
In-Reply-To: <CADvTj4qK-1SX_+YZW1jdW-e5JOZ2iz3vAK_8UvkyZWb0rAeyiQ@mail.gmail.com>
On Thu, Oct 29, 2026 at 6:32 PM James Hilliard <james.hilliard1@gmail.com> wrote:
> With a persistent pause failure and an incomplete transfer, the
> worker keeps retrying. RX remains masked and the runtime PM reference
> is held until the condition resolves or shutdown takes over. There
> is no receive-progress guarantee if the peer remains idle and pause
> continues to fail.
...
> A failed pause with an incomplete cookie does not distinguish a
> persistent hardware fault from completion that has not yet been
> published. A fixed retry limit does not resolve that ambiguity.
>
> Terminating after the limit may discard received data, including a
> completed buffer whose completion is still unpublished. Successful
> termination would make subsequent buffer reuse safe, but would not
> recover those bytes. This would therefore be a potentially lossy
> error-recovery policy rather than a lossless timeout flush.
Checking the in-tree dmaengine providers shows why bounding the retry loop
and escalating to recovery is necessary in practice:
1. `serial8250_request_dma()` (`8250_dma.c:428`) checks `caps.cmd_pause`,
which `dma_get_slave_caps()` (`drivers/dma/dmaengine.c:614`) sets purely
from `!!device->device_pause`. However, `drivers/dma/tegra186-gpc-dma.c`
(lines 422-423, 1351, 1521) unconditionally assigns
`tdma->dma_dev.device_pause = tegra_dma_device_pause` (so
`caps.cmd_pause == true`), and then returns `-ENOSYS` at runtime on
Tegra186 where `tdc->tdma->chip_data->hw_support_pause` is false. And on
Tegra194/234/264 (`tegra186-gpc-dma.c:399-413`) and Tegra210
(`tegra210-adma.c:574-579`), `.device_pause()` polls a hardware busy bit
with an atomic timeout and returns `-ETIMEDOUT` or `-EBUSY` if an active
burst does not pause in time.
2. In the in-tree providers where `.device_pause()` returns an error because
a transfer already completed—such as `drivers/dma/ti/edma.c:870, 1468-1469`
(returning `-EINVAL` when `!echan->edesc`) and
`drivers/dma/stm32/stm32-dma.c:751-753, 836, 1432` (returning `-EPERM`
when `chan->status != DMA_IN_PROGRESS`)—the DMA hardirq handler calls
`vchan_cookie_complete()` *before* clearing the active descriptor, so
`dmaengine_tx_status()` already reports `DMA_COMPLETE` on the very first
check in `serial8250_rx_dma_try_flush()`.
Even on a controller where hardware rejects `pause` the instant the 4096th
byte finishes while its completion hardirq is still masked by `port->lock`,
the only thing delaying `completed_cookie` publication is local IRQ masking
under `port->lock`. Once `serial8250_rx_dma_flush_work()` drops `port->lock`
(enabling local IRQs) and sleeps `usleep_range(1000, 2000)` in process
context, any pending DMA completion hardirq runs in microseconds. Across
5 retries (5-10 ms with `port->lock` released on each sleep), a completed
4 KB transfer will have published `DMA_COMPLETE`.
By contrast, leaving the `for (;;)` loop unbounded turns any persistent
`dmaengine_pause()` error (`-ENOSYS`, `-EINVAL`, `-EBUSY`, `-ETIMEDOUT`) on
a partial transfer into a guaranteed 100% loss of all current and future RX
data until `close()`, a 500-1000 Hz `system_percpu_wq` spin, a permanent
runtime-PM leak, and silently aborted `dw8250_set_divisor()` /
`dw8250_check_lcr()` calls (`-EAGAIN`). Escalating to recovery after a
bounded retry budget is strictly better than wedging the receiver forever.
> That requires termination to succeed and callbacks to be drained.
> If termination fails, the channel may still access the FIFO, so PIO
> must remain excluded.
>
> The recovery requirements depend on why the provider cannot pause.
Agreed—and `serial8250_rx_dma_flush_work()` in Patch 5/6 already enforces
that when `serial8250_rx_dma_recover(p)` is called (`8250_dma.c:210-216`):
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;
}
}
When `serial8250_rx_dma_recover(p)` sets `dma->rx_err = true` and
`dma->rx_terminating = true`, the worker exits the retry loop and calls
`dmaengine_terminate_sync(dma->rxchan)`. If `dmaengine_terminate_sync()`
returns non-zero, the worker returns early at line 215 with
`dma->rx_terminating == true` and `dma->rx_running == 1`, keeping RX
interrupts masked in `IER` and keeping PIO excluded (`serial8250_rx_dma_flush()`
continues returning `-EIO`). It only clears `dma->rx_running = 0` and unmasks
`IER` for PIO fallback after `dmaengine_terminate_sync(dma->rxchan)` succeeds
(`ret == 0`).
Thanks,
Raul
next prev parent reply other threads:[~2026-10-30 17:36 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-29 7:36 [PATCH v8 0/6] serial: 8250: serialize DMA cancellation with buffer reuse James Hilliard
2026-10-29 7:36 ` [PATCH v8 1/6] serial: 8250_omap: separate locked TX DMA completion processing James Hilliard
2026-10-29 7:36 ` [PATCH v8 2/6] serial: serialize asynchronous write wakeups with the port lock James Hilliard
2026-10-29 14:17 ` Andy Shevchenko
2026-10-29 17:13 ` James Hilliard
2026-10-29 7:36 ` [PATCH v8 3/6] serial: core: allow drivers to reserve flushed transmit storage James Hilliard
2026-10-29 7:37 ` [PATCH v8 4/6] serial: 8250: drain canceled TX DMA before reusing its buffer James Hilliard
2026-10-29 14:19 ` Andy Shevchenko
2026-10-29 17:15 ` James Hilliard
2026-10-30 9:33 ` Andy Shevchenko
2026-10-29 7:37 ` [PATCH v8 5/6] serial: 8250: retire canceled RX DMA before reusing the receive buffer James Hilliard
2026-10-29 14:22 ` Andy Shevchenko
2026-10-29 17:17 ` James Hilliard
2026-10-29 22:27 ` Raul E Rangel
2026-10-30 0:32 ` James Hilliard
2026-10-30 17:36 ` Raul E Rangel [this message]
2026-10-29 7:37 ` [PATCH v8 6/6] serial: 8250: retain DMA resources when termination fails James Hilliard
2026-10-29 14:23 ` Andy Shevchenko
2026-10-29 17:19 ` James Hilliard
2026-10-29 22:27 ` Raul E Rangel
2026-10-30 0:35 ` James Hilliard
2026-10-30 17:36 ` Raul E Rangel
2026-10-30 9:40 ` Andy Shevchenko
2026-10-30 17:09 ` James Hilliard
2026-10-30 17:53 ` Andy Shevchenko
2026-10-30 18:08 ` 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=20261030173635.2186490-1-rrangel@chromium.org \
--to=rrangel@chromium.org \
--cc=Frank.Li@nxp.com \
--cc=alexandre.belloni@bootlin.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=bigeasy@linutronix.de \
--cc=claudiu.beznea@tuxon.dev \
--cc=festevam@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=imx@lists.linux.dev \
--cc=james.hilliard1@gmail.com \
--cc=jirislaby@kernel.org \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=macro@orcam.me.uk \
--cc=nicolas.ferre@microchip.com \
--cc=pali@kernel.org \
--cc=richard.genoud@bootlin.com \
--cc=s.hauer@pengutronix.de \
--cc=schung@nuvoton.com \
--cc=timur@kernel.org \
--cc=tony@atomide.com \
--cc=ychuang3@nuvoton.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