Skip to contentSkip to conversation

dmaengine: pl330: Fix race in residue reporting

PATCH New Sjoerd Simons 1 participant 1 message Feb 1, 2017 1 message not in the archive Arm Rockchip

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 dmaengine: pl330: Fix race in residue reporting

Hey Romain,

I submitted this ages ago, but got distracted. Thanks for reviving. Note that i remember Krzysztof had some review remarks, it's probably worth digging up the old thread and making sure you address those.

Quoted 20 lines · Romain Perier

From: Sjoerd Simons <[email protected]>

When a transfer completes there is a small window between the descriptor
being unset as the current active one in the thread and it being marked
as done. This causes the residue to be incorrectly set when pl330_tx_status is run in that window. Practically this caused issue for me with audio playback as the residue goes up during a transfer (as the in-progress transfer is no longer accounted for), which makes the higher levels think the audio ringbuffer wrapped around
and thus did a sudden big jump forward.

To resolve this, add a field protected by the dma engine lock to indicate the transfer is done but the status hasn't been updated yet.

Quoted 7 lines

Series-to: Vinod Koul <[email protected]>
Series-cc: dmaengine at vger.kernel.org
Series-cc: linux-kernel at vger.kernel.org
Series-cc: Krzysztof Kozlowski <[email protected]>
Series-cc: linux-rockchip at lists.infradead.org
Series-cc: linux-samsung-soc at vger.kernel.org Series-cc:??linux-arm-kernel at vger.kernel.org

These are patman metadata, you probably want to drop these from the commit message ;)

Quoted 47 lines

?drivers/dma/pl330.c | 9 ++++++++-
?1 file changed, 8 insertions(+), 1 deletion(-)

drivers/dma/pl330.c +0 -0
index 740bbb9..d942fac 100644
@@ -521,6 +521,9 @@ struct dma_pl330_desc {

?
? enum desc_status status;
?

drivers/dma/pl330.c +3 -0
+	/* Transfer completed, but not yet moved to DONE state */
+	bool xferred;
+

? int bytes_requested;
? bool last;
?

drivers/dma/pl330.c +0 -0
@@ -1508,6 +1511,9 @@ static void dma_pl330_rqcb(struct
 dma_pl330_desc *desc, enum pl330_op_err err)
 ?	spin_lock_irqsave(&pch->lock, flags);

?
? desc->status = DONE;

drivers/dma/pl330.c +3 -0
+	spin_lock(&pch->thread->dmac->lock);
+	desc->xferred = false;
+	spin_unlock(&pch->thread->dmac->lock);

?
? spin_unlock_irqrestore(&pch->lock, flags);
?

drivers/dma/pl330.c +0 -0
@@ -1640,6 +1646,7 @@ static int pl330_update(struct pl330_dmac
 *pl330)

?
? /* Detach the req */
? descdone = thrd->req[active].desc;

drivers/dma/pl330.c +1 -0
+			descdone->xferred = true;

? thrd->req[active].desc = NULL;
?
? thrd->req_running = -1;

drivers/dma/pl330.c +0 -0
@@ -2311,7 +2318,7 @@ pl330_tx_status(struct dma_chan *chan,
 dma_cookie_t cookie,

?
? /* Check in pending list */
? list_for_each_entry(desc, &pch->work_list, node) {

drivers/dma/pl330.c +1 -1
-		if (desc->status == DONE)
+		if (desc->xferred || desc->status == DONE)

? transferred = desc->bytes_requested;
? else if (running && desc == running)
? transferred =

Signature · 2 lines
Sjoerd Simons
Collabora Ltd.