From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796380648; b=AAdY4MeySqTCPSh7qcOPzifR2pVX/mypFxBrjrQkIwL02jkJeq5f9fcCGNwGAFJ8am0I wcypOdUGkgxQe99KBS0WQrcpt+gtl3JrDK6z9S+XLmC0+ifiEqIULC2W8Jybd7SBjahIh Pw905vfmUs7KGoImsHdaDoHkITLAT+qvZxNSZkEoeq1dFzKETkbxj/jbfh8xb8q/5Z66E DzHNSHg0izX6Voa3P4hKfQQMNZ9ow/2WBID4vIKhZNZCbyx+zh4RX7FBjlknfWhiBzntv lqK4rUuT5+SJ9RSEJAD2E2EU3ILq0tskYDmqnSKX560qTnwdqoE+MKMkfI1Gdt7xi1w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380648; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=l5/gZ9bqBSteu8xWcKxtOMNKigXfdgXfh7PML82m8SM=; b=IKTlDFu4pGq9BHHIYWj8ZJeBG0CargQSF2CJ4rtc1cZfVG1eR/o5g1cGd0kEaDvt4YeW Zrru+MomIcFo4Zv0YS/pKueoDE98m5Pt4jULX+/oOqbGwanApsEg2nBTMKDhW1J7lYIh9 zS1zzC88uCIUQnz55piWLNyZdpWmj9C/EdOA8fD4LN8I73Cr97e2STRhlzn2lgTB/87Yc lk6Hqt3+na6Z1kZaoGtI4dOkR2NXuMzyDINblh6g8aqULrPddZJBq5X2LpugrtSZ8t95U 1D6KQ1+A8bbHzo7JVz0zaddrpTMApTi3AZldUz8K2KjNUYtgVxf8eUcNCw2wm1+3KKA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=L8IHQrj9; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 56E0F606A33D; Fri, 4 Dec 2026 10:37:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=L8IHQrj9 Received: by smtp.kernel.org (Postfix) with ESMTPSA id F08571F000C2; Fri, 4 Dec 2026 10:37:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796380648; bh=l5/gZ9bqBSteu8xWcKxtOMNKigXfdgXfh7PML82m8SM=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=L8IHQrj9GWMTJz8ZN0xLSGw6mxruS7hK19NHxbhj3F/DfIOp6gQZVkWN6kAn5Secx zyVfZGc4hnkKpu1KzJgEQRu/ZvWsf6fZLptho2nkH0jpQK2jOSiL7PU4+WSezMOKva nIYlso+V9F+6PVnNzzeeBLRqW3G7y0lkYd4l2XgJw3Xk/3Xmn5KiLX1QWD+3yHBayA 4zfp0KlgcBQMvh7gWAFfNdieduxAN10Dypq0jrfNj1whC0SCWxZ1Ts2kyYPdbBcryN jNWFaa7nTwCOauDT2ueI7RZrSFSO7sxj4TaFkguQ1QDkVFqaN6Bw26ZmR7ZnAYlQ+b CB8o6jt/bvl6w== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v14 5/8] serial: core: allow drivers to reserve flushed transmit storage Reply-To: sashiko-reviews@lists.linux.dev To: "James Hilliard" Cc: linux-serial@vger.kernel.org, imx@lists.linux.dev, Frank.Li@kernel.org In-Reply-To: <20261204-submit-serial-8250-dma-cancel-v1-v14-5-b691fec8097d@gmail.com> References: <20261204-submit-serial-8250-dma-cancel-v1-v14-0-b691fec8097d@gmail.com> <20261204-submit-serial-8250-dma-cancel-v1-v14-5-b691fec8097d@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 10:37:27 +0000 X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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 =3D state->uart_port; > =20 > - 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; > =20 > 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 =3D 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 clear= ed 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 C= TS 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 FI= FO (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; > =20 > port =3D uart_port_ref_lock(state, &flags); > - if (!state->port.xmit_buf) > + if (!state->port.xmit_buf || !uart_xmit_writable(state)) > ret =3D 0; > else > ret =3D 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/conso= le after state->refcount drops to zero, so poll() or write() can still reach uart_write_room() with port =3D=3D NULL: CPU0 CPU1 tty_poll() -> uart_write_room() port =3D uart_port_ref_lock(...) /* refcount =3D=3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204-submit-ser= ial-8250-dma-cancel-v1-v14-0-b691fec8097d@gmail.com?part=3D5