linux-stable/drivers/tty/serial
Ilpo Järvinen 57e9af7831 serial: 8250_dma: Fix DMA Rx rearm race
As DMA Rx can be completed from two places, it is possible that DMA Rx
completes before DMA completion callback had a chance to complete it.
Once the previous DMA Rx has been completed, a new one can be started
on the next UART interrupt. The following race is possible
(uart_unlock_and_check_sysrq_irqrestore() replaced with
spin_unlock_irqrestore() for simplicity/clarity):

CPU0					CPU1
					dma_rx_complete()
serial8250_handle_irq()
  spin_lock_irqsave(&port->lock)
  handle_rx_dma()
    serial8250_rx_dma_flush()
      __dma_rx_complete()
        dma->rx_running = 0
        // Complete DMA Rx
  spin_unlock_irqrestore(&port->lock)

serial8250_handle_irq()
  spin_lock_irqsave(&port->lock)
  handle_rx_dma()
    serial8250_rx_dma()
      dma->rx_running = 1
      // Setup a new DMA Rx
  spin_unlock_irqrestore(&port->lock)

					  spin_lock_irqsave(&port->lock)
					  // sees dma->rx_running = 1
					  __dma_rx_complete()
					    dma->rx_running = 0
					    // Incorrectly complete
					    // running DMA Rx

This race seems somewhat theoretical to occur for real but handle it
correctly regardless. Check what is the DMA status before complething
anything in __dma_rx_complete().

Reported-by: Gilles BULOZ <gilles.buloz@kontron.com>
Tested-by: Gilles BULOZ <gilles.buloz@kontron.com>
Fixes: 9ee4b83e51 ("serial: 8250: Add support for dmaengine")
Cc: stable@vger.kernel.org
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Link: https://lore.kernel.org/r/20230130114841.25749-3-ilpo.jarvinen@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-01-31 11:15:16 +01:00
..
8250 serial: 8250_dma: Fix DMA Rx rearm race 2023-01-31 11:15:16 +01:00
cpm_uart serial: cpm_uart: Use uart_xmit_advance() 2022-11-03 03:35:41 +01:00
jsm drivers: serial: jsm: fix some leaks in probe 2022-09-22 16:11:43 +02:00
21285.c tty: serial: use uart_port_tx_limited() 2022-11-03 03:32:40 +01:00
altera_jtaguart.c tty: serial: altera_jtaguart: remove struct altera_jtaguart 2022-11-22 17:51:42 +01:00
altera_uart.c serial: altera_uart: fix locking in polling mode 2022-11-23 09:38:42 +01:00
amba-pl010.c tty: serial: use uart_port_tx_limited() 2022-11-03 03:32:40 +01:00
amba-pl011.c serial: amba-pl011: fix high priority character transmission in rs486 mode 2023-01-19 14:54:58 +01:00
apbuart.c tty: serial: use uart_port_tx_limited() 2022-11-03 03:32:40 +01:00
apbuart.h
ar933x_uart.c serial: ar933x: Use uart_xmit_advance() 2022-11-03 03:35:41 +01:00
arc_uart.c serial: arc: Use uart_xmit_advance() 2022-11-03 03:35:41 +01:00
atmel_serial.c serial: atmel: fix incorrect baudrate setup 2023-01-19 16:24:39 +01:00
atmel_serial.h tty: serial: atmel: Use FIELD_PREP/FIELD_GET 2022-09-22 16:32:25 +02:00
bcm63xx_uart.c tty: serial: use uart_port_tx_limited() 2022-11-03 03:32:40 +01:00
clps711x.c serial: clps711x: Use uart_xmit_advance() 2022-11-03 03:35:41 +01:00
digicolor-usart.c serial: digicolor: Use uart_xmit_advance() 2022-11-03 03:35:41 +01:00
dz.c serial: dz: Use uart_xmit_advance() 2022-11-03 03:35:40 +01:00
dz.h
earlycon-arm-semihost.c serial: make uart_console_write->putchar()'s character an unsigned char 2022-03-03 15:06:31 +01:00
earlycon-riscv-sbi.c serial: make uart_console_write->putchar()'s character an unsigned char 2022-03-03 15:06:31 +01:00
earlycon.c tty: serial: earlycon: use console_is_registered() 2022-12-02 11:25:01 +01:00
fsl_linflexuart.c serial: linflexuart: Use uart_xmit_advance() 2022-11-03 03:35:41 +01:00
fsl_lpuart.c tty: serial: fsl_lpuart: switch to new dmaengine_terminate_* API 2022-11-23 09:39:20 +01:00
icom.c serial: Make ->set_termios() old ktermios const 2022-08-30 14:22:35 +02:00
imx.c Merge 6.1-rc6 into tty-next 2022-11-22 17:38:38 +01:00
imx_earlycon.c serial: make uart_console_write->putchar()'s character an unsigned char 2022-03-03 15:06:31 +01:00
ip22zilog.c serial: ip22zilog: Use uart_xmit_advance() 2022-11-03 03:35:41 +01:00
ip22zilog.h
Kconfig serial: sifive: select by default if SOC_CANAAN 2022-11-02 08:10:11 +01:00
kgdb_nmi.c
kgdboc.c tty: serial: kgdboc: fix mutex locking order for configure_kgdboc() 2023-01-16 16:44:53 +01:00
lantiq.c tty: serial: use uart_port_tx() helper 2022-11-03 03:32:40 +01:00
liteuart.c serial: liteuart: Use uart_xmit_advance() 2022-11-03 03:35:42 +01:00
lpc32xx_hs.c tty: serial: use uart_port_tx() helper 2022-11-03 03:32:40 +01:00
Makefile serial: remove VR41XX serial driver 2022-07-16 08:16:01 +02:00
max310x.c serial: max310x: Use uart_xmit_advance() 2022-11-03 03:35:42 +01:00
max3100.c serial: max3100: Use uart_xmit_advance() 2022-11-03 03:35:42 +01:00
mcf.c tty: serial: use uart_port_tx() helper 2022-11-03 03:32:40 +01:00
men_z135_uart.c serial: men_z135_uart: Use uart_xmit_advance() 2022-11-03 03:35:41 +01:00
meson_uart.c serial: meson: Use uart_xmit_advance() 2022-11-03 03:35:42 +01:00
milbeaut_usio.c serial: milbeaut_usio: Use uart_xmit_advance() 2022-11-03 03:35:42 +01:00
mpc52xx_uart.c tty: serial: use uart_port_tx() helper 2022-11-03 03:32:40 +01:00
mps2-uart.c tty: serial: use uart_port_tx() helper 2022-11-03 03:32:40 +01:00
msm_serial.c serial: Fix a typo ("ignorning") 2022-11-09 13:03:12 +01:00
mux.c tty: serial: use uart_port_tx_limited() 2022-11-03 03:32:40 +01:00
mvebu-uart.c serial: mvebu-uart: Use uart_xmit_advance() 2022-11-03 03:35:42 +01:00
mxs-auart.c tty: serial: use uart_port_tx() helper 2022-11-03 03:32:40 +01:00
omap-serial.c tty: serial: use uart_port_tx_limited() 2022-11-03 03:32:40 +01:00
owl-uart.c tty: serial: use uart_port_tx() helper 2022-11-03 03:32:40 +01:00
pch_uart.c serial: pch_uart: Pass correct sg to dma_unmap_sg() 2023-01-19 14:54:56 +01:00
pic32_uart.c TTY/Serial driver changes for 6.2-rc1 2022-12-16 03:31:56 -08:00
pmac_zilog.c serial: pmac_zilog: Use uart_xmit_advance() 2022-11-03 03:35:42 +01:00
pmac_zilog.h serial: pmac_zilog: remove unused uart_pmac_port::termios_cache 2022-05-19 18:23:19 +02:00
pxa.c tty: serial: use uart_port_tx_limited() 2022-11-03 03:32:40 +01:00
qcom_geni_serial.c tty: serial: qcom_geni: avoid duplicate struct member init 2023-01-19 16:24:59 +01:00
rda-uart.c serial: rda: Use uart_xmit_advance() 2022-11-03 03:35:42 +01:00
rp2.c tty: serial: use uart_port_tx_limited() 2022-11-03 03:32:40 +01:00
sa1100.c tty: serial: use uart_port_tx() helper 2022-11-03 03:32:40 +01:00
samsung_tty.c TTY/Serial driver changes for 6.2-rc1 2022-12-16 03:31:56 -08:00
sb1250-duart.c serial: sb1250-duart: Use uart_xmit_advance() 2022-11-03 03:35:42 +01:00
sc16is7xx.c serial: sc16is7xx: Use uart_xmit_advance() 2022-11-03 03:35:41 +01:00
sccnxp.c serial: sccnxp: Use uart_xmit_advance() 2022-11-03 03:35:42 +01:00
serial-tegra.c serial: tegra: Read DMA status before terminating 2022-11-03 03:43:03 +01:00
serial_core.c tty: serial: kgdboc: fix mutex locking order for configure_kgdboc() 2023-01-16 16:44:53 +01:00
serial_mctrl_gpio.c Documentation: serial: move GPIO kernel-doc to the functions 2022-07-28 10:37:42 +02:00
serial_mctrl_gpio.h serial: mctrl_gpio: add a new API to enable / disable wake_irq 2022-02-08 11:07:16 +01:00
serial_txx9.c tty: serial: use uart_port_tx_limited() 2022-11-03 03:32:40 +01:00
sh-sci.c TTY/Serial driver changes for 6.2-rc1 2022-12-16 03:31:56 -08:00
sh-sci.h
sifive.c tty: serial: use uart_port_tx_limited() 2022-11-03 03:32:40 +01:00
sprd_serial.c serial: sprd: Use uart_xmit_advance() 2022-11-03 03:35:42 +01:00
st-asc.c tty: serial: use uart_port_tx_limited() 2022-11-03 03:32:40 +01:00
stm32-usart.c serial: stm32: Merge hard IRQ and threaded IRQ handling into single IRQ handler 2023-01-31 11:15:01 +01:00
stm32-usart.h serial: stm32: make info structs static to avoid sparse warnings 2022-07-28 10:35:23 +02:00
suncore.c
sunhv.c serial: sunhv: Use uart_xmit_advance() 2022-11-03 03:35:42 +01:00
sunplus-uart.c serial: sunplus-uart: Use uart_xmit_advance() 2022-11-03 03:35:43 +01:00
sunsab.c serial: sunsab: Fix error handling in sunsab_init() 2022-11-23 09:38:50 +01:00
sunsab.h
sunsu.c serial: sunsu: Use uart_xmit_advance() 2022-11-03 03:35:43 +01:00
sunzilog.c serial: sunzilog: Use uart_xmit_advance() 2022-11-03 03:35:43 +01:00
sunzilog.h
tegra-tcu.c Merge 7e2cd21e02 ("Merge tag 'tty-6.0-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty") into tty-next 2022-09-25 09:22:13 +02:00
timbuart.c serial: timbuart: Use uart_xmit_advance() 2022-11-03 03:35:43 +01:00
timbuart.h
uartlite.c serial: uartlite: Use uart_xmit_advance() 2022-11-03 03:35:43 +01:00
ucc_uart.c serial: ucc_uart: Use uart_xmit_advance() 2022-11-03 03:35:43 +01:00
vt8500_serial.c serial: Fix a typo ("ignorning") 2022-11-09 13:03:12 +01:00
xilinx_uartps.c TTY/Serial driver changes for 6.2-rc1 2022-12-16 03:31:56 -08:00
zs.c serial: zs: Use uart_xmit_advance() 2022-11-03 03:35:43 +01:00
zs.h