From patchwork Thu Mar 2 12:57:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Romain Perier X-Patchwork-Id: 9600183 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1DB1960414 for ; Thu, 2 Mar 2017 12:58:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 03F9D285B5 for ; Thu, 2 Mar 2017 12:58:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EC160285B7; Thu, 2 Mar 2017 12:58:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 48A76285B5 for ; Thu, 2 Mar 2017 12:58:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=E7Q1dsgq3EF3/17To6EeHdq1ePbzeN+ojG12XGb3QYI=; b=EeN 4YgD8Fv/Zg9ItJmexFOvmNO3eurVyleeh9Q0ms+Ux4M0reI6/hYfFn6jaWx5JAURJSuiataryrEo/ GuEuukN8RLc5xr9PyMLga2i3hhmwsXgOz06+ETdfjMDa9uZDglkYxUL3g/tZWv24CcLvr1m84pM7U mv7qWBe26F6aQVxzD81WmnlSvMC8FOpdE0xQ2V5rWwTo50xvnuUWlCGWDkGK2levpujHzIgTau2CB zDOZI7FwRa8qyM0OieDiOso3TzNal0IvYfcBAYa1zEfCv88fHT7kVuy3YvZbk6S24T2F02Q9qQBzd hvoY5ELsdgu1NsvNly7vH72nbMWWwWg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cjQJF-000185-Pj; Thu, 02 Mar 2017 12:58:17 +0000 Received: from bhuna.collabora.co.uk ([2a00:1098:0:82:1000:25:2eeb:e3e3]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cjQIe-0000np-55; Thu, 02 Mar 2017 12:57:42 +0000 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: rperier) with ESMTPSA id 1750026A8DA From: Romain Perier To: Vinod Koul , Dan Williams Subject: [PATCH RESEND] dmaengine: pl330: Fix data race on TX transferred bytes reporting Date: Thu, 2 Mar 2017 13:57:10 +0100 Message-Id: <20170302125710.14483-1-romain.perier@collabora.com> X-Mailer: git-send-email 2.9.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170302_045740_360835_BE3E6F3B X-CRM114-Status: GOOD ( 13.86 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Heiko Stuebner , Romain Perier , linux-rockchip@lists.infradead.org, Sjoerd Simons , dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 and the corresponding size to be wrongly reported when pl330_tx_status is run in that window. This can be reproduced in different ways, the main we have found is with audio playback when the system load is high. When the residue goes up during a transfer, it makes the audio ringbuffer wrapped around and thus does a sudden jump forward. It can also be detected by sudden sound disruptions. This bug was partially solved by commit a40235a2278a ("dmaengine: pl330: Acquire dmac's spinlock in pl330_tx_status"), as it reduces the window where it can happen, but the issue still exists. This patch is a re-worked version of the one wrote by Sjoerd Simons https://patchwork.kernel.org/patch/7568251. Original-author: Sjoerd Simons Signed-off-by: Romain Perier --- Note: Due to an email configuration issue, some of my patches were not received on infradead.org or vger.kernel.org. It is now fixed, so I resend this patch for this reason. drivers/dma/pl330.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c index 740bbb9..4046737 100644 --- a/drivers/dma/pl330.c +++ b/drivers/dma/pl330.c @@ -1640,6 +1640,7 @@ static int pl330_update(struct pl330_dmac *pl330) /* Detach the req */ descdone = thrd->req[active].desc; + descdone->status = DONE; thrd->req[active].desc = NULL; thrd->req_running = -1; @@ -1654,9 +1655,18 @@ static int pl330_update(struct pl330_dmac *pl330) /* Now that we are in no hurry, do the callbacks */ list_for_each_entry_safe(descdone, tmp, &pl330->req_done, rqd) { + struct dma_pl330_chan *pch; + list_del(&descdone->rqd); + spin_unlock_irqrestore(&pl330->lock, flags); - dma_pl330_rqcb(descdone, PL330_ERR_NONE); + pch = descdone->pchan; + /* If desc aborted */ + if (!pch) { + spin_lock_irqsave(&pl330->lock, flags); + continue; + } + tasklet_schedule(&pch->task); spin_lock_irqsave(&pl330->lock, flags); }