[PATCH 4/4] dmaengine: xilinx_dma: Add device synchronisation callback

Adrian Larumbe adrian.martinezlarumbe at imgtec.com
Fri Apr 23 02:19:13 BST 2021


This was required as an answer to a very unusual race condition, whereby a
thread waiting on a completion signaled in a callback triggered by
dmaengine_desc_callback_invoke might immediately attempt to release the
DMA channel whilst the channel lock was still free. This would cause the
remaining descriptors to be deallocated, and xilinx_dma_chan_desc_cleanup
to perform an invalid memory access when attempting to traverse the rest
of the channel's done_list.

Now, when releasing a DMA channel, it will wait until the tasklet has
finished.

Signed-off-by: Adrian Larumbe <adrian.martinezlarumbe at imgtec.com>
---
 drivers/dma/xilinx/xilinx_dma.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/dma/xilinx/xilinx_dma.c b/drivers/dma/xilinx/xilinx_dma.c
index 40c6cf8bf0e6..d4bad999e7f9 100644
--- a/drivers/dma/xilinx/xilinx_dma.c
+++ b/drivers/dma/xilinx/xilinx_dma.c
@@ -942,6 +942,13 @@ static void xilinx_dma_free_chan_resources(struct dma_chan *dchan)
 
 }
 
+static void xilinx_dma_synchronize(struct dma_chan *dchan)
+{
+	struct xilinx_dma_chan *chan = to_xilinx_chan(dchan);
+
+	tasklet_kill(&chan->tasklet);
+}
+
 /**
  * xilinx_dma_get_residue - Compute residue for a given descriptor
  * @chan: Driver specific dma channel
@@ -3235,6 +3242,7 @@ static int xilinx_dma_probe(struct platform_device *pdev)
 	xdev->common.device_tx_status = xilinx_dma_tx_status;
 	xdev->common.device_issue_pending = xilinx_dma_issue_pending;
 	xdev->common.device_config = xilinx_dma_slave_config;
+	xdev->common.device_synchronize = xilinx_dma_synchronize;
 	if (xdev->dma_config->dmatype == XDMA_TYPE_AXIDMA) {
 		dma_cap_set(DMA_CYCLIC, xdev->common.cap_mask);
 		xdev->common.device_prep_slave_sg = xilinx_dma_prep_slave_sg;
-- 
2.17.1




More information about the linux-arm-kernel mailing list