Skip to content

Commit f6a1964

Browse files
vwaxgregkh
authored andcommitted
serial: pl011: Fix DMA ->flush_buffer()
PL011's ->flush_buffer() implementation releases and reacquires the port lock. Due to a race condition here, data can end up being added to the circular buffer but neither being discarded nor being sent out. This leads to, for example, tcdrain(2) waiting indefinitely. Process A Process B uart_flush_buffer() - acquire lock - circ_clear - pl011_flush_buffer() -- release lock -- dmaengine_terminate_all() uart_write() - acquire lock - add chars to circ buffer - start_tx() -- start DMA - release lock -- acquire lock -- turn off DMA -- release lock // Data in circ buffer but DMA is off According to the comment in the code, the releasing of the lock around dmaengine_terminate_all() is to avoid a deadlock with the DMA engine callback. However, since the time this code was written, the DMA engine API documentation seems to have been clarified to say that dmaengine_terminate_all() (in the identically implemented but differently named dmaengine_terminate_async() variant) does not wait for any running complete callback to be completed and can even be called from a complete callback. So there is no possibility of deadlock if the DMA engine driver implements this API correctly. So we should be able to just remove this release and reacquire of the lock to prevent the aforementioned race condition. Signed-off-by: Vincent Whitchurch <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent f4c4754 commit f6a1964

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

drivers/tty/serial/amba-pl011.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -813,10 +813,8 @@ __acquires(&uap->port.lock)
813813
if (!uap->using_tx_dma)
814814
return;
815815

816-
/* Avoid deadlock with the DMA engine callback */
817-
spin_unlock(&uap->port.lock);
818-
dmaengine_terminate_all(uap->dmatx.chan);
819-
spin_lock(&uap->port.lock);
816+
dmaengine_terminate_async(uap->dmatx.chan);
817+
820818
if (uap->dmatx.queued) {
821819
dma_unmap_sg(uap->dmatx.chan->device->dev, &uap->dmatx.sg, 1,
822820
DMA_TO_DEVICE);

0 commit comments

Comments
 (0)