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=1796381096; b=gz+FQmzfoHIqMeoGPeDruEnzqoRouWz7b3MrJI2rVKtG7OzNQ1wf9+EG8zuJVQPBmyEm W9yQSJtpChzZdns8N7u9au1K1CJVTLpoI7vcshTyGsJRkAMjK4QoQ1O3eDwjwSZba6l28 d7U+Tb/2Gwpz2QTptuuO+Jg1kL666A5LnAH3TrMU4QMhmbYZtn7ydUtNhV3rVZECOMW9H JfiGQjQVvL+AybkaveZ+T1mR2D+2FQwR+EPeVwId4asGe3ZHsOadjaJ3ZmtoNaT3vppj3 vDF7qlws1HWtuwumuuOgeFjHaRwD1LBGMpyNAC3egwCpSf3Y2sGeywHykW/EN6cewsw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381096; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=Icx0O+e82HNZliMiX4FiHibJ5CTeRGCRZBrDI3/w5oQ=; b=Q+yWQMarOmB3JXF4gJTM4RVhXU3VwYnDLmY3fHLLKLBEBDHeA6s95Esb+doXgJs8hO6D PUoQ5WzDGMNUrbY92+8UlzE6X+o3itpRYkPLPt7NqksWA8rbfQqq3rMcaRJ1ABQTxgDyr zhYNWzLVs2rw+H49bmYXNQm9dPrqZmlzjbZwJf6MJKbcYjQS9V88J/AC3XwaI4Ku/2ym8 AoNVXs/yJgo7BnxbJeljm64wmDOP5JewSj+RjNqQlM1sgPrhLyGAv+H8O32GFs53jQIKa 0M7pBYTnjiqCkDt2YsOlEusUqqy4hu10cRQaf/0acAaykECSifDeccYvBcsQ38qAyRw== 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=C739dlnF; 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 A5507606A322; Fri, 4 Dec 2026 10:44:56 +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=C739dlnF Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3AC171F000CE; Fri, 4 Dec 2026 10:44:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796381096; bh=Icx0O+e82HNZliMiX4FiHibJ5CTeRGCRZBrDI3/w5oQ=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=C739dlnFY4c/wVzD0Ga8nf8GFNLzdzJyqSkgpZ5DUV5Q+yrp2bNgy622rCGiEFsGO CzEqY1d1NL/SeDix2yqGRAl2DsvhxMVkYpbIVJxZaRBsl8/fIA5ow2qE4kswWfQ5G8 RQkYqs7AT15A4KmJ2NBDr/wj+SIf7nrl8dzl6XJUwHI0JOBFwNWsAJma695bfUKzHe jOzdBNwymjyNLtYAG2ej6+OWaxz61FH/7ANwFVvRvevpHmtdM+5ZYZanI7GHhTkDpd CQ9MCBOhv/6gFkWRsTCGH31SV9uCSc5KGvJaiIPkID0wdx4GKo35PeCPUsFb0teT8N jKERT798sMLkw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v14 7/8] serial: 8250: retire canceled RX DMA before reusing the receive buffer 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-7-b691fec8097d@gmail.com> References: <20261204-submit-serial-8250-dma-cancel-v1-v14-0-b691fec8097d@gmail.com> <20261204-submit-serial-8250-dma-cancel-v1-v14-7-b691fec8097d@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 10:44:55 +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: 8250: rx_flush_work() demotes bursty RX DMA to PIO on every timeout - [Medium] serial: 8250: unsynchronized up->dma read in serial8250_em485_stop_tx() -- commit ec92d45cfc9de1099bca1fc304582975c431c023 Author: James Hilliard serial: 8250: retire canceled RX DMA before reusing the receive buffer This commit defers reuse of the 8250 RX DMA buffer after an RX flush until a worker retires canceled callbacks with dmaengine_synchronize(), adding pause retry and synchronous termination recovery paths along with IER masking during recovery. Link: https://lore.kernel.org/r/20261109162135.906262-1-rrangel@chromium.or= g/ [ ... ] > diff --git a/drivers/tty/serial/8250/8250_dma.c b/drivers/tty/serial/8250= /8250_dma.c > index 739a8238e4dec..1d7c3c5b75643 100644 > --- a/drivers/tty/serial/8250/8250_dma.c > +++ b/drivers/tty/serial/8250/8250_dma.c [ ... ] > @@ -240,6 +414,9 @@ int serial8250_rx_dma(struct uart_8250_port *p) > =20 > if (dma->shutting_down || dma->rx_running) > return 0; > + /* A retiring transfer has released the FIFO, but not its buffer. */ > + if (dma->rx_err || dma->rx_terminating) > + return -EIO; > =20 > serial8250_do_prepare_rx_dma(p); > =20 > @@ -260,16 +437,26 @@ int serial8250_rx_dma_flush(struct uart_8250_port *= p) > { > struct uart_8250_dma *dma =3D p->dma; > + int ret; > =20 > - if (!dma || !dma->rxchan || !dma->rx_running) > - return; > + lockdep_assert_held_once(&p->port.lock); > =20 > - dmaengine_pause(dma->rxchan); > - __dma_rx_complete(p); > - dmaengine_terminate_async(dma->rxchan); > + if (!serial8250_rx_dma_running(p)) > + return 0; > + /* A late interrupt must not hand a still-active receiver to PIO. */ > + if (dma->shutting_down) > + return -ESHUTDOWN; > + if (dma->rx_terminating) > + return -EIO; > + if (dma->rx_pause_pending) > + return -EAGAIN; > + > + ret =3D serial8250_rx_dma_try_flush(p); > + schedule_work(&dma->rx_flush_work); > + return ret; > } [Severity: Medium] Does scheduling rx_flush_work on every RX timeout demote subsequent incoming bursts from DMA to byte-by-byte PIO? Because dma->rx_size defaults to PAGE_SIZE, every burst shorter than 4 KB ends in UART_IIR_RX_TIMEOUT -> serial8250_rx_dma_flush(). Until rx_flush_work finishes dmaengine_synchronize() on system_percpu_wq, serial8250_rx_dma() returns -EIO and the ISR uses serial8250_rx_chars(). At high baudrates (1 to 4 Mbps), normal-priority workqueue latency and provider device_synchronize waits (such as vchan_synchronize() or synchronize_irq()) can exceed the FIFO fill time, raising IRQ overhead and risking RX FIFO overruns; providers with NULL device_synchronize also wait. Double-buffering the RX buffer would avoid blocking new DMA submissions while the previous transfer retires. [ ... ] > diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/825= 0/8250_port.c > index cfbd154bf5f92..49d6a0b19fb40 100644 > --- a/drivers/tty/serial/8250/8250_port.c > +++ b/drivers/tty/serial/8250/8250_port.c [ ... ] > @@ -1332,7 +1332,8 @@ void serial8250_em485_stop_tx(struct uart_8250_port= *p, bool toggle_ier) > * Enable previously disabled RX interrupts. > */ > if (!(p->port.rs485.flags & SER_RS485_RX_DURING_TX)) { > - serial8250_clear_and_reinit_fifos(p); > + if (!serial8250_rx_dma_recovering(p)) > + serial8250_clear_and_reinit_fifos(p); > =20 > if (toggle_ier) { > /* [Severity: Medium] Can serial8250_rx_dma_recovering() race with serial8250_do_startup() cleari= ng up->dma to NULL on a console port with boot-time half-duplex RS485 emulatio= n? On drivers like 8250_dw, probe sets up->dma non-NULL even on a kernel console, and uart_configure_port() initializes em485 before first open. Wh= en the console TTY is first opened, serial8250_do_startup() logs "forbid DMA f= or kernel console" and clears up->dma unlocked while console writes run: CPU0 CPU1 serial8250_do_startup() serial8250_console_write() if (up->dma && uart_console(port)) up->rs485_stop_tx(up, false) dev_warn_ratelimited(...) serial8250_em485_stop_tx(up, fals= e) serial8250_rx_dma_recovering(up) if (up->dma) /* non-NULL */ up->dma =3D NULL; up->dma->rx_pause_pending <-- NULL pointer dereference Because serial8250_rx_dma_recovering() reads up->dma repeatedly without READ_ONCE() or a local copy, a reload after the NULL check causes a NULL pointer dereference in the console write path. Clearing up->dma under uart_port_lock_irqsave in serial8250_do_startup() would close this race. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204-submit-ser= ial-8250-dma-cancel-v1-v14-0-b691fec8097d@gmail.com?part=3D7