OpenCloudOS-Kernel/drivers/tty
John Keeping 5e00346deb serial: 8250: Fix fifo underflow on flush
commit 9e512eaaf8f4008c44ede3dfc0fbc9d9c5118583 upstream.

When flushing the serial port's buffer, uart_flush_buffer() calls
kfifo_reset() but if there is an outstanding DMA transfer then the
completion function will consume data from the kfifo via
uart_xmit_advance(), underflowing and leading to ongoing DMA as the
driver tries to transmit another 2^32 bytes.

This is readily reproduced with serial-generic and amidi sending even
short messages as closing the device on exit will wait for the fifo to
drain and in the underflow case amidi hangs for 30 seconds on exit in
tty_wait_until_sent().  A trace of that gives:

     kworker/1:1-84    [001]    51.769423: bprint:               serial8250_tx_dma: tx_size=3 fifo_len=3
           amidi-763   [001]    51.769460: bprint:               uart_flush_buffer: resetting fifo
 irq/21-fe530000-76    [000]    51.769474: bprint:               __dma_tx_complete: tx_size=3
 irq/21-fe530000-76    [000]    51.769479: bprint:               serial8250_tx_dma: tx_size=4096 fifo_len=4294967293
 irq/21-fe530000-76    [000]    51.781295: bprint:               __dma_tx_complete: tx_size=4096
 irq/21-fe530000-76    [000]    51.781301: bprint:               serial8250_tx_dma: tx_size=4096 fifo_len=4294963197
 irq/21-fe530000-76    [000]    51.793131: bprint:               __dma_tx_complete: tx_size=4096
 irq/21-fe530000-76    [000]    51.793135: bprint:               serial8250_tx_dma: tx_size=4096 fifo_len=4294959101
 irq/21-fe530000-76    [000]    51.804949: bprint:               __dma_tx_complete: tx_size=4096

Since the port lock is held in when the kfifo is reset in
uart_flush_buffer() and in __dma_tx_complete(), adding a flush_buffer
hook to adjust the outstanding DMA byte count is sufficient to avoid the
kfifo underflow.

Fixes: 9ee4b83e51 ("serial: 8250: Add support for dmaengine")
Cc: stable <stable@kernel.org>
Signed-off-by: John Keeping <jkeeping@inmusicbrands.com>
Link: https://lore.kernel.org/r/20250208124148.1189191-1-jkeeping@inmusicbrands.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-02-21 13:57:18 +01:00
..
hvc
ipwireless
serdev
serial serial: 8250: Fix fifo underflow on flush 2025-02-21 13:57:18 +01:00
vt vt: prevent kernel-infoleak in con_font_get() 2024-10-22 15:46:31 +02:00
Kconfig
Makefile
amiserial.c
ehv_bytechan.c
goldfish.c
mips_ejtag_fdc.c
moxa.c
mxser.c
n_gsm.c tty: n_gsm: Fix use-after-free in gsm_cleanup_mux 2024-10-22 15:46:34 +02:00
n_hdlc.c
n_null.c
n_tty.c tty: n_tty: Fix buffer offsets when lookahead is used 2024-06-21 14:38:24 +02:00
nozomi.c
pty.c
rpmsg_tty.c
synclink_gt.c
sysrq.c of: remove internal arguments from of_property_for_each_u32() 2025-02-08 09:51:51 +01:00
tty.h
tty_audit.c
tty_baudrate.c
tty_buffer.c
tty_io.c tty: ldsic: fix tty_ldisc_autoload sysctl's proc_handler 2024-12-09 10:32:45 +01:00
tty_ioctl.c tty: allow TIOCSLCKTRMIOS with CAP_CHECKPOINT_RESTORE 2024-02-05 20:14:32 +00:00
tty_jobctrl.c
tty_ldisc.c tty: add the option to have a tty reject a new ldisc 2024-06-27 13:49:05 +02:00
tty_ldsem.c
tty_mutex.c
tty_port.c
ttynull.c
vcc.c