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 5/8] serial: core: allow drivers to reserve flushed transmit storage
Date: Fri, 04 Dec 2026 10:37:27 +0000 [thread overview]
Message-ID: <sashiko-outbox-249612@kernel.org> (raw)
In-Reply-To: <20261204-submit-serial-8250-dma-cancel-v1-v14-5-b691fec8097d@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] serial: core: uart_handle_cts_change() bypasses xmit_ready
and xmit_blocked
- [Medium] serial: core: uart_write_room() accesses TX state unlocked
when port is NULL
--
commit b6fc200be09d3f4b5211694994aadb7eb87b39ed
Author: James Hilliard <james.hilliard1@gmail.com>
serial: core: allow drivers to reserve flushed transmit storage
This commit adds uart_xmit_block() and uart_xmit_unblock() so drivers can
prevent reuse of flushed transmit FIFO storage until asynchronous DMA
transfers retire. It also tracks transmit readiness separately from DMA
storage ownership and gates writes, write wakeups, and TX starts on both.
> diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
> index b06d2649be343..937ce2df39409 100644
> --- a/drivers/tty/serial/serial_core.c
> +++ b/drivers/tty/serial/serial_core.c
[ ... ]
> @@ -162,7 +229,10 @@ static void __uart_start(struct uart_state *state)
> {
> struct uart_port *port = state->uart_port;
>
> - if (!port || port->flags & UPF_DEAD || uart_tx_stopped(port))
> + if (!port || port->flags & UPF_DEAD || uart_tx_stopped(port) || !state->xmit_ready)
> + return;
> + /* High-priority flow-control characters have their own storage. */
> + if (state->xmit_blocked && !port->x_char)
> return;
>
> uart_port_start_tx(port);
[Severity: Medium]
Does uart_handle_cts_change() bypass the xmit_ready and xmit_blocked checks
added here?
drivers/tty/serial/serial_core.c:uart_handle_cts_change() {
...
if (uport->hw_stopped) {
if (active) {
uport->hw_stopped = false;
uport->ops->start_tx(uport);
uart_write_wakeup(uport);
}
}
...
}
On a port using software-assisted CTS flow control, a CTS rising edge calls
uport->ops->start_tx(uport) directly without checking state->xmit_ready or
state->xmit_blocked. During uart_suspend_port(), state->xmit_ready is cleared
and ops->stop_tx() is called, but CTS interrupts stay enabled across the
msleep(10) drain loop before ops->shutdown(), so a CTS assertion can restart
TX/DMA on retained xmit_fifo data.
Similarly, while state->xmit_blocked is true and uport->x_char is zero, a CTS
rising edge still invokes ops->start_tx(), which re-enables TX interrupts or
transmitter/DMA hardware in drivers that do not return early on an empty FIFO
(such as pl011_start_tx() and atmel_start_tx()).
Should uart_handle_cts_change() route the TX restart through
__uart_start(uport->state) or check state->xmit_ready and
(!state->xmit_blocked || uport->x_char) before calling ops->start_tx()?
[ ... ]
> @@ -644,7 +722,7 @@ static unsigned int uart_write_room(struct tty_struct *tty)
> unsigned int ret;
>
> port = uart_port_ref_lock(state, &flags);
> - if (!state->port.xmit_buf)
> + if (!state->port.xmit_buf || !uart_xmit_writable(state))
> ret = 0;
> else
> ret = kfifo_avail(&state->port.xmit_fifo);
[Severity: Medium]
Can uart_write_room() read state->xmit_ready, state->xmit_blocked, and
state->port.xmit_fifo without port->lock when uart_port_ref_lock() returns
NULL?
Unlike uart_put_char() and uart_write(), uart_write_room() does not check
!port. When a serial console is detached in serial_core_remove_one_port(),
__tty_hangup() leaves console_fops and a live line discipline on /dev/console
after state->refcount drops to zero, so poll() or write() can still reach
uart_write_room() with port == NULL:
CPU0 CPU1
tty_poll() -> uart_write_room()
port = uart_port_ref_lock(...)
/* refcount == 0 -> NULL,
no lock held */
serial_core_add_one_port()
uart_open() -> uart_startup()
/* updates xmit_buf, xmit_fifo,
xmit_ready under port->lock */
uart_xmit_writable(state) <-- data race
kfifo_avail(&state->port.xmit_fifo)
This races with concurrent updates under the new port->lock and can return
stale write room or a torn kfifo_avail() result. Checking !port alongside
!state->port.xmit_buf avoids the unlocked access.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-submit-serial-8250-dma-cancel-v1-v14-0-b691fec8097d@gmail.com?part=5
next prev parent reply other threads:[~2026-12-04 10:37 UTC|newest]
Thread overview: 15+ 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
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 [this message]
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:44 ` sashiko-bot
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-249612@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