Linux Serial subsystem development
 help / color / mirror / Atom feed
* [PATCH v3] serial: 8250: calculate TX length before preparing DMA flow control
@ 2026-12-04  9:56 James Hilliard
  2026-12-04 10:17 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: James Hilliard @ 2026-12-04  9:56 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby, Raul E Rangel, Ilpo Järvinen,
	Andy Shevchenko, Heikki Krogerus, Miquel Raynal
  Cc: linux-kernel, linux-serial, stable, James Hilliard

The Renesas RZ/N1 preparation hook programs the UART DMA block size from
dma->tx_size. The generic TX path calls that hook before calculating the
length of the new transfer, so it programs zero on the first transfer and
the previous length on subsequent transfers.

Calculate the scatterlist length before calling the preparation hook so
the UART flow controller and DMA descriptor use the same transfer size.

Fixes: 1788cf6a91d9 ("tty: serial: switch from circ_buf to kfifo")
Cc: stable@vger.kernel.org
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
Changes in v3:
- Rebase on current tty-next for resubmission.
- Add Miquel's Reviewed-by.
- Link to v2: https://patch.msgid.link/20261023-submit-serial-8250-dma-tx-length-v1-v2-1-c3106ef4d2df@gmail.com

Changes in v2:
- Correct the Fixes tag to the kfifo conversion, as pointed out by
  Miquel Raynal.
- Add Cc: stable@vger.kernel.org.
- Link to v1: https://patch.msgid.link/20261022-submit-serial-8250-dma-tx-length-v1-v1-1-18cecc89a099@gmail.com
---
 drivers/tty/serial/8250/8250_dma.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_dma.c b/drivers/tty/serial/8250/8250_dma.c
index 1da605cc8601..2dc47adafec0 100644
--- a/drivers/tty/serial/8250/8250_dma.c
+++ b/drivers/tty/serial/8250/8250_dma.c
@@ -110,8 +110,6 @@ int serial8250_tx_dma(struct uart_8250_port *p)
 		return 0;
 	}
 
-	serial8250_do_prepare_tx_dma(p);
-
 	sg_init_table(sgl, ARRAY_SIZE(sgl));
 
 	ret = kfifo_dma_out_prepare_mapped(&tport->xmit_fifo, sgl, ARRAY_SIZE(sgl),
@@ -122,6 +120,8 @@ int serial8250_tx_dma(struct uart_8250_port *p)
 	for_each_sg(sgl, sg, ret, i)
 		dma->tx_size += sg_dma_len(sg);
 
+	serial8250_do_prepare_tx_dma(p);
+
 	desc = dmaengine_prep_slave_sg(dma->txchan, sgl, ret,
 				       DMA_MEM_TO_DEV,
 				       DMA_PREP_INTERRUPT | DMA_CTRL_ACK);

---
base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
base-tree: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git tty-next
change-id: 20261022-submit-serial-8250-dma-tx-length-v1-bf627278129a

Best regards,
--  
James Hilliard <james.hilliard1@gmail.com>


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v3] serial: 8250: calculate TX length before preparing DMA flow control
  2026-12-04  9:56 [PATCH v3] serial: 8250: calculate TX length before preparing DMA flow control James Hilliard
@ 2026-12-04 10:17 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-04 10:17 UTC (permalink / raw)
  To: James Hilliard; +Cc: linux-serial

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] serial: 8250: multi-SG TX wrap breaks RZ/N1 peripheral DMA flow
  control
--

commit 657ef7e8d98bc808e1f5202a741d3828179f07d3
Author: James Hilliard <james.hilliard1@gmail.com>

serial: 8250: calculate TX length before preparing DMA flow control

This commit moves serial8250_do_prepare_tx_dma() after the scatterlist
length summation in serial8250_tx_dma() so dma->tx_size reflects the
current transfer.

> diff --git a/drivers/tty/serial/8250/8250_dma.c b/drivers/tty/serial/8250/8250_dma.c
> index 1da605cc86011..2dc47adafec05 100644
> --- a/drivers/tty/serial/8250/8250_dma.c
> +++ b/drivers/tty/serial/8250/8250_dma.c
> @@ -110,8 +110,6 @@ int serial8250_tx_dma(struct uart_8250_port *p)
>  		return 0;
>  	}
>  
> -	serial8250_do_prepare_tx_dma(p);
> -
>  	sg_init_table(sgl, ARRAY_SIZE(sgl));
>  
>  	ret = kfifo_dma_out_prepare_mapped(&tport->xmit_fifo, sgl, ARRAY_SIZE(sgl),
> @@ -122,6 +120,8 @@ int serial8250_tx_dma(struct uart_8250_port *p)
>  	for_each_sg(sgl, sg, ret, i)
>  		dma->tx_size += sg_dma_len(sg);
>  
> +	serial8250_do_prepare_tx_dma(p);
> +
>  	desc = dmaengine_prep_slave_sg(dma->txchan, sgl, ret,
>  				       DMA_MEM_TO_DEV,
>  				       DMA_PREP_INTERRUPT | DMA_CTRL_ACK);

[Severity: High]
Can this read past the end of the TX kfifo buffer and stall TX DMA when
pending data wraps around UART_XMIT_SIZE?

When tport->xmit_fifo wraps, kfifo_dma_out_prepare_mapped() populates
both entries of sgl with two non-contiguous segments and returns 2.
Summing both into dma->tx_size makes dw8250_prepare_tx_dma() program
RZN1_UART_TDMACR for a single UART block covering both segments.

Meanwhile, dwc_prep_slave_sg() in drivers/dma/dw/core.c configures
DW_DMA_FC_P_M2P because dma->txconf.device_fc is set, and chains two
LLI descriptors with DWC_CTLL_INT_EN only on the second one.

In peripheral-flow-controller mode, the DW-AHB-DMAC ends an LLI on the
peripheral's dma_last handshake rather than the segment length.  During
the first LLI, it reads past dma->tx_addr + UART_XMIT_SIZE into adjacent
kernel memory and transmits those bytes over the UART.

Once the UART asserts dma_last after the combined length, the DMAC moves
to the second LLI and stalls waiting for requests from the completed
UART block, so __dma_tx_complete() never runs and dma->tx_running stays
set.

Limiting kfifo_dma_out_prepare_mapped() to 1 entry when
dma->txconf.device_fc is set would keep each flow-controlled block
contiguous and let __dma_tx_complete() submit the wrapped remainder next.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-submit-serial-8250-dma-tx-length-v1-v3-1-7a6250992bd6@gmail.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-04 10:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04  9:56 [PATCH v3] serial: 8250: calculate TX length before preparing DMA flow control James Hilliard
2026-12-04 10:17 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox