Skip to content

serial: fix TX kfifo underflow on flush in five drivers

Samarth Narang linux-arm-kernel linux-arm-msm linux-samsung-soc linux-serial linux-tegra lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest5 patches 1 replyIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5tty: serial: samsung: fix TX kfifo underflow on flushdrivers/tty/serial/samsung_tty.c+22 -00 replies
2/5serial: tegra: don't advance the TX kfifo for a flushed transferdrivers/tty/serial/serial-tegra.c+8 -00 replies
3/5serial: sprd: fix TX kfifo underflow on flushdrivers/tty/serial/sprd_serial.c+22 -20 replies
4/5tty: serial: msm: fix TX kfifo underflow on flushdrivers/tty/serial/msm_serial.c+18 -10 replies
5/5serial: pch_uart: fix TX kfifo underflow on flushdrivers/tty/serial/pch_uart.c+25 -20 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/5] serial: fix TX kfifo underflow on flush in five drivers

This series addresses the TX kfifo underflow reported in the parent thread, where uart_flush_buffer() resets the transmit kfifo but a completion callback from an earlier DMA transfer may still call uart_xmit_advance() using the byte count from before the flush.

The fixes take two approaches depending on how each driver manages its TX DMA mappings. In samsung and tegra, which map the TX buffer once, samsung's new flush_buffer() terminates the outstanding transfer, as tegra's already does, following the approach introduced in 8250 by 9e512eaaf8f4. A completion already in progress skips the kfifo update if the transfer has since been retired by flush_buffer() or stop_tx().

In sprd, msm, and pch_uart, which map each transfer separately, terminating DMA there would leave the flush hook to unmap a buffer the controller may still be reading. These drivers therefore leave the transfer running and mark it as flushed, allowing the completion callback to unmap the buffer without advancing the kfifo. This means that the data already queued for DMA before the flush may still be transmitted.

All five patches have only been compile-tested with arm64 defconfig and the relevant drivers enabled, including pch_uart through COMPILE_TEST, using W=1 with no new warnings. I do not have access to the affected hardware, so testing by someone with suitable devices would be appreciated.

One race remains, which is also present in the 8250 fix: a completion may already be running when the flush occurs but acquire the port lock only after a new transfer has started, potentially mistaking the new transfer's state for its own. Preventing this would require tracking individual transfers, for example with a generation counter, which I have left out of this series to keep the changes focused.

Samarth Narang (5):
tty: serial: samsung: fix TX kfifo underflow on flush
serial: tegra: don't advance the TX kfifo for a flushed transfer
serial: sprd: fix TX kfifo underflow on flush
tty: serial: msm: fix TX kfifo underflow on flush
serial: pch_uart: fix TX kfifo underflow on flush

 drivers/tty/serial/msm_serial.c   | 19 ++++++++++++++++++-
 drivers/tty/serial/pch_uart.c     | 27 +++++++++++++++++++++++++--
 drivers/tty/serial/samsung_tty.c  | 22 ++++++++++++++++++++++
 drivers/tty/serial/serial-tegra.c |  8 ++++++++
 drivers/tty/serial/sprd_serial.c  | 24 ++++++++++++++++++++++--
 5 files changed, 95 insertions(+), 5 deletions(-)

base-commit: 36aad21d50d1af3f6954bb0c988257a908202477

Signature · 1 line
2.34.1