Skip to content

Commit f8d6e9d

Browse files
ij-intelgregkh
authored andcommitted
serial: 8250: Fix __stop_tx() & DMA Tx restart races
Commit e8ffbb7 ("serial: 8250: use THRE & __stop_tx also with DMA") changed __dma_tx_complete() to enable THRI that is cleared in __stop_tx() once THRE is asserted as UART runs out bits to transmit. It is possible, however, that more data arrives in between in which case serial8250_tx_dma() resumes Tx. THRI is not supposed to be on during DMA Tx because DMA is based on completion handler, therefore THRI must be cleared unconditionally in serial8250_tx_dma(). When Tx is about to start, another race window exists with serial8250_handle_irq() leading to a call into __stop_tx() while the Tx has already been resumed: __tx_complete(): -> spin_lock(port->lock) -> dma->tx_running = 0 -> serial8250_set_THRI() -> spin_unlock(port->lock) uart_start(): serial8250_handle_irq(): -> spin_lock(port->lock) -> serial8250_tx_dma(): -> dma->tx_running = 1 -> spin_unlock(port->lock) -> spin_lock(port->lock) -> __stop_tx() Close this race by checking !dma->tx_running before calling into __stop_tx(). Fixes: e8ffbb7 ("serial: 8250: use THRE & __stop_tx also with DMA") Signed-off-by: Ilpo Järvinen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 211565b commit f8d6e9d

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

drivers/tty/serial/8250/8250_dma.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ int serial8250_tx_dma(struct uart_8250_port *p)
106106
UART_XMIT_SIZE, DMA_TO_DEVICE);
107107

108108
dma_async_issue_pending(dma->txchan);
109-
if (dma->tx_err) {
109+
serial8250_clear_THRI(p);
110+
if (dma->tx_err)
110111
dma->tx_err = 0;
111-
serial8250_clear_THRI(p);
112-
}
112+
113113
return 0;
114114
err:
115115
dma->tx_err = 1;

drivers/tty/serial/8250/8250_port.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1949,7 +1949,7 @@ int serial8250_handle_irq(struct uart_port *port, unsigned int iir)
19491949
if ((status & UART_LSR_THRE) && (up->ier & UART_IER_THRI)) {
19501950
if (!up->dma || up->dma->tx_err)
19511951
serial8250_tx_chars(up);
1952-
else
1952+
else if (!up->dma->tx_running)
19531953
__stop_tx(up);
19541954
}
19551955

0 commit comments

Comments
 (0)