* [PATCHv2] serial: 8250: Fix thread unsafe __dma_tx_complete function
@ 2014-04-24 9:34 Loic Poulain
2014-04-24 10:23 ` Heikki Krogerus
0 siblings, 1 reply; 2+ messages in thread
From: Loic Poulain @ 2014-04-24 9:34 UTC (permalink / raw)
To: gregkh, heikki.krogerus; +Cc: linux-serial, Loic Poulain
__dma_tx_complete is not protected against concurrent
call of serial8250_tx_dma. it can lead to circular tail
index corruption or parallel call of serial_tx_dma on the
same data portion.
This patch fixes this issue by holding the port lock.
Signed-off-by: Loic Poulain <loic.poulain@intel.com>
---
v2: extend lock to protect xmit tail (cf doc)
and tx_running. tx_running and tail have to
be updated atomically.
update commit message.
drivers/tty/serial/8250/8250_dma.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/tty/serial/8250/8250_dma.c b/drivers/tty/serial/8250/8250_dma.c
index 7046769..ab9096d 100644
--- a/drivers/tty/serial/8250/8250_dma.c
+++ b/drivers/tty/serial/8250/8250_dma.c
@@ -20,12 +20,15 @@ static void __dma_tx_complete(void *param)
struct uart_8250_port *p = param;
struct uart_8250_dma *dma = p->dma;
struct circ_buf *xmit = &p->port.state->xmit;
-
- dma->tx_running = 0;
+ unsigned long flags;
dma_sync_single_for_cpu(dma->txchan->device->dev, dma->tx_addr,
UART_XMIT_SIZE, DMA_TO_DEVICE);
+ spin_lock_irqsave(&p->port.lock, flags);
+
+ dma->tx_running = 0;
+
xmit->tail += dma->tx_size;
xmit->tail &= UART_XMIT_SIZE - 1;
p->port.icount.tx += dma->tx_size;
@@ -35,6 +38,8 @@ static void __dma_tx_complete(void *param)
if (!uart_circ_empty(xmit) && !uart_tx_stopped(&p->port))
serial8250_tx_dma(p);
+
+ spin_unlock_irqrestore(&p->port.lock, flags);
}
static void __dma_rx_complete(void *param)
--
1.8.3.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCHv2] serial: 8250: Fix thread unsafe __dma_tx_complete function
2014-04-24 9:34 [PATCHv2] serial: 8250: Fix thread unsafe __dma_tx_complete function Loic Poulain
@ 2014-04-24 10:23 ` Heikki Krogerus
0 siblings, 0 replies; 2+ messages in thread
From: Heikki Krogerus @ 2014-04-24 10:23 UTC (permalink / raw)
To: Loic Poulain; +Cc: gregkh, linux-serial
On Thu, Apr 24, 2014 at 11:34:48AM +0200, Loic Poulain wrote:
> __dma_tx_complete is not protected against concurrent
> call of serial8250_tx_dma. it can lead to circular tail
> index corruption or parallel call of serial_tx_dma on the
> same data portion.
>
> This patch fixes this issue by holding the port lock.
>
> Signed-off-by: Loic Poulain <loic.poulain@intel.com>
I think this should also go to stable tree. It applies on top of >=v3.9.
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Thanks!
--
heikki
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-04-24 10:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-24 9:34 [PATCHv2] serial: 8250: Fix thread unsafe __dma_tx_complete function Loic Poulain
2014-04-24 10:23 ` Heikki Krogerus
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.