Skip to contentSkip to conversation

Added few improvement and fixes.

PATCH Applied Sanjay R Mehta 2 participants 4 messages Feb 2, 2022 – Feb 15, 2022 dmaengine

lore
Share & tools
lore
#0 lore raw

v2 cover Added few improvement and fixes.

From: Sanjay R Mehta <[email protected]>

This patch series fixes a concurrency issue with DMA transfer and descriptor handling with a graceful exit.

Sanjay R Mehta (2):
dmaengine: ptdma: fix concurrency issue with multiple dma transfer
dmaengine: ptdma: handle the cases based on DMA is complete

 drivers/dma/ptdma/ptdma-dmaengine.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH v2 1/2 dmaengine: ptdma: fix concurrency issue with multiple dma transfer

From: Sanjay R Mehta <[email protected]>

The command should be submitted only if the engine is idle, for this, the next available descriptor is checked and set the flag to false in case the descriptor is non-empty.

---
 drivers/dma/ptdma/ptdma-dmaengine.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/dma/ptdma/ptdma-dmaengine.c +6 -1
index c9e52f6..e38dca4 100644
@@ -233,9 +233,14 @@ static void pt_issue_pending(struct dma_chan *dma_chan)
 	struct pt_dma_chan *chan = to_pt_chan(dma_chan);
 	struct pt_dma_desc *desc;
 	unsigned long flags;
+	bool engine_is_idle = true;
 
 	spin_lock_irqsave(&chan->vc.lock, flags);
 
+	desc = pt_next_dma_desc(chan);
+	if (desc)
+		engine_is_idle = false;
+
 	vchan_issue_pending(&chan->vc);
 
 	desc = pt_next_dma_desc(chan);
@@ -243,7 +248,7 @@ static void pt_issue_pending(struct dma_chan *dma_chan)
 	spin_unlock_irqrestore(&chan->vc.lock, flags);
 
 	/* If there was nothing active, start processing */
-	if (desc)
+	if (engine_is_idle)
 		pt_cmd_callback(desc, 0);
 }
 
Signature · 1 line
2.7.4
#2 lore raw

PATCH v2 2/2 dmaengine: ptdma: handle the cases based on DMA is complete

In reply to Sanjay R Mehta

From: Sanjay R Mehta <[email protected]>

There is a need to segregate the cases when DMA is complete or not. In case if DMA is already complete there is no need to handle it again and gracefully exit from the function.

---
 drivers/dma/ptdma/ptdma-dmaengine.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
drivers/dma/ptdma/ptdma-dmaengine.c +11 -6
index e38dca4..91b93e8 100644
@@ -100,12 +100,17 @@ static struct pt_dma_desc *pt_handle_active_desc(struct pt_dma_chan *chan,
 		spin_lock_irqsave(&chan->vc.lock, flags);
 
 		if (desc) {
-			if (desc->status != DMA_ERROR)
-				desc->status = DMA_COMPLETE;
-
-			dma_cookie_complete(tx_desc);
-			dma_descriptor_unmap(tx_desc);
-			list_del(&desc->vd.node);
+			if (desc->status != DMA_COMPLETE) {
+				if (desc->status != DMA_ERROR)
+					desc->status = DMA_COMPLETE;
+
+				dma_cookie_complete(tx_desc);
+				dma_descriptor_unmap(tx_desc);
+				list_del(&desc->vd.node);
+			} else {
+				/* Don't handle it twice */
+				tx_desc = NULL;
+			}
 		}
 
 		desc = pt_next_dma_desc(chan);
Signature · 1 line
2.7.4