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>,
"Peter Ujfalusi" <peter.ujfalusi@ti.com>,
"Vignesh Raghavendra" <vigneshr@ti.com>,
"Patrice Chotard" <patrice.chotard@foss.st.com>,
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 v9 7/8] serial: 8250: retire canceled RX DMA before reusing the receive buffer
Date: Tue, 3 Nov 2026 09:11:03 -0700 [thread overview]
Message-ID: <20261103161104.2449407-7-rrangel@chromium.org> (raw)
In-Reply-To: <20261102-submit-serial-8250-dma-cancel-v1-v9-7-9159caade148@gmail.com>
Hi James,
Thanks for v9 — fixing asc_startup() locking in Patch 2/8, waking
tty->write_wait for drain waiters in Patch 5/8, splitting OMAP RX locking
and IRQ quiescing into Patches 3/8 and 4/8, and adding rx_pause_wait with
immediate wakeups from dma_rx_complete() and serial8250_do_shutdown() all
look good. Waking rx_pause_wait under port->lock cleanly avoids delaying
normal completion or cancel_work_sync(&dma->rx_flush_work) during shutdown.
Two remaining comments on Patch 7/8:
1. Escalating to serial8250_rx_dma_recover() after a bounded pause-stall
window on partial RX transfers:
The commit message notes:
> A provider which never pauses or completes retains RX ownership until
> an error or shutdown; a timeout alone cannot establish that discarding
> the buffer is safe.
I completely agree that a timeout alone cannot establish that *reusing*
or *freeing* dma->rx_buf is safe while the channel is still running.
However, calling serial8250_rx_dma_recover(p) under p->port.lock once
the retry budget expires does *not* reuse or free dma->rx_buf without
stopping the channel:
- Calling serial8250_rx_dma_recover(p) under p->port.lock inside the
worker's retry block sets dma->rx_err = true and
dma->rx_terminating = true (and keeps RX masked in UART_IER), which
causes serial8250_rx_dma_flush_work() to exit the for (;;) loop
(retry = false, recover = true) and call
dmaengine_terminate_sync(dma->rxchan) outside p->port.lock in process
context (8250_dma.c:233-239).
- If dmaengine_terminate_sync(dma->rxchan) succeeds (ret == 0), the
channel is stopped and its callbacks are drained, so clearing
rx_pause_pending/rx_terminating and restoring p->ier safely falls back
to PIO ("RX DMA failed, using PIO\n").
- If dmaengine_terminate_sync(dma->rxchan) also fails (ret != 0),
lines 235-239 already retain dma->rx_buf and return early with RX
interrupts masked.
Why does this matter in practice?
Look at drivers/dma/tegra186-gpc-dma.c:
- Line 1521 unconditionally assigns .device_pause = tegra_dma_device_pause,
so dma_get_slave_caps() (drivers/dma/dmaengine.c:614) sets
caps.cmd_pause = true and serial8250_request_dma() enables RX DMA.
- On Tegra186, tegra186_dma_chip_data sets .hw_support_pause = false
(line 1351), so tegra_dma_device_pause() (lines 420-423) unconditionally
returns -ENOSYS. (On Tegra194/234/264, tegra_dma_pause() at lines
389-414 polls TEGRA_GPCDMA_STATUS_BUSY after setting
TEGRA_GPCDMA_CHAN_CSRE_PAUSE for 20 us and returns -ETIMEDOUT if the
channel does not pause.)
When an RX timeout interrupt (UART_IIR_RX_TIMEOUT) fires on a partial
transfer (e.g. a few bytes typed at an interactive console or a short
command waiting for a reply, count < 4096), hardware transfer completion
will never occur while the remote peer is waiting for our response. With
an unbounded for (;;) loop:
- Those partial bytes in dma->rx_buf are never delivered anyway (even if
we wait forever until the user closes the port, serial8250_release_dma()
terminates the channel without copying dma->rx_buf).
- UART RX remains permanently dead with RLSI/RDI masked and never falls
back to PIO.
- serial8250_rx_dma_flush_work() holds a runtime PM reference
(guard(serial8250_rpm)(p)) for the lifetime of the open port.
- On 8250_dw, dw8250_idle_enter() (8250_dw.c:151) sees
serial8250_rx_dma_flush(up) == -EAGAIN and silently aborts
dw8250_set_divisor() and dw8250_check_lcr(), breaking baud-rate and
LCR updates while rx_pause_pending is stuck.
If serial8250_rx_dma_flush_work() escalates to serial8250_rx_dma_recover(p)
under p->port.lock once the stall threshold is reached (or immediately when
dmaengine_pause() returns -ENOSYS / -EOPNOTSUPP), dmaengine_terminate_sync()
safely stops the channel before any buffer state is released and the UART
recovers on PIO instead of wedging until close().
2. Minor nit in drivers/tty/serial/8250/8250_omap.c:783-784:
In omap_8250_shutdown():
WRITE_ONCE(up->dma->rx_pause_wakeup, true);
wake_up(&up->dma->rx_pause_wait);
8250_omap uses its own synchronous omap_8250_rx_dma_flush() and never
schedules rx_flush_work or sleeps on rx_pause_wait, so those two lines
in omap_8250_shutdown() can be dropped.
Thanks,
Raul
next prev parent reply other threads:[~2026-11-03 16:11 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 23:14 [PATCH v9 0/8] serial: 8250: serialize DMA cancellation with buffer reuse James Hilliard
2026-11-02 23:14 ` [PATCH v9 1/8] serial: 8250_omap: separate locked TX DMA completion processing James Hilliard
2026-11-03 16:10 ` Raul E Rangel
2026-11-02 23:14 ` [PATCH v9 2/8] serial: serialize asynchronous write wakeups with the port lock James Hilliard
2026-11-03 16:10 ` Raul E Rangel
2026-11-03 17:06 ` Andy Shevchenko
2026-11-03 20:25 ` Maciej W. Rozycki
2026-11-02 23:14 ` [PATCH v9 3/8] serial: 8250_omap: serialize RX DMA completion and flushing James Hilliard
2026-11-03 11:55 ` Ilpo Järvinen
2026-11-03 16:10 ` Raul E Rangel
2026-11-02 23:14 ` [PATCH v9 4/8] serial: 8250_omap: quiesce DMA IRQ handling before shutdown James Hilliard
2026-11-03 16:11 ` Raul E Rangel
2026-11-02 23:14 ` [PATCH v9 5/8] serial: core: allow drivers to reserve flushed transmit storage James Hilliard
2026-11-03 16:11 ` Raul E Rangel
2026-11-03 17:08 ` Andy Shevchenko
2026-11-02 23:14 ` [PATCH v9 6/8] serial: 8250: drain canceled TX DMA before reusing its buffer James Hilliard
2026-11-03 16:11 ` Raul E Rangel
2026-11-03 17:21 ` Andy Shevchenko
2026-11-02 23:14 ` [PATCH v9 7/8] serial: 8250: retire canceled RX DMA before reusing the receive buffer James Hilliard
2026-11-03 16:11 ` Raul E Rangel [this message]
2026-11-03 18:05 ` James Hilliard
2026-11-03 17:33 ` Andy Shevchenko
2026-11-03 17:54 ` James Hilliard
2026-11-03 18:06 ` Andy Shevchenko
2026-11-03 18:16 ` James Hilliard
2026-11-03 20:59 ` Andy Shevchenko
2026-11-02 23:14 ` [PATCH v9 8/8] serial: 8250: retain DMA resources when termination fails James Hilliard
2026-11-03 16:11 ` Raul E Rangel
2026-11-03 17:35 ` Andy Shevchenko
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=20261103161104.2449407-7-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=patrice.chotard@foss.st.com \
--cc=peter.ujfalusi@ti.com \
--cc=richard.genoud@bootlin.com \
--cc=s.hauer@pengutronix.de \
--cc=schung@nuvoton.com \
--cc=timur@kernel.org \
--cc=tony@atomide.com \
--cc=vigneshr@ti.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
all inboxes | Powered by JetHome®