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: 9600181 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 656E960414 for ; Thu, 2 Mar 2017 12:58:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 50648285B5 for ; Thu, 2 Mar 2017 12:58:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 453E0285B7; Thu, 2 Mar 2017 12:58:03 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=no 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 A33BF285B6 for ; Thu, 2 Mar 2017 12:57:46 +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=wXrOxugBriz4ePvja3mjI9nxConF3nstkdUU3lM2obo=; b=r/H ZxjAsr7J2E9fVgIUdCGB0Z9xKRoHQiVDrta6cR/gsNbsPtOipXTyE5hs9HgxbSBN9IxRAWfsb6s0m j3VouWsbYYZDCjutzM9aF2r4ZCeItrCVXGTSy6jDRemx0+9qlcY4e+eYhEIpbDoocKxRwBsPv93tw eaZdxfs7zqiF3m2Ugj2e3FHLORqbzTYWgX6x4Vpo1zCOOvxoeFwsqaMyrTzt67N5OCwz/4E4C4mes K+UYhKJNDg0FFFOgCByVvY6EQWARfrdidp14mWtfov5Io06jdByyu8NfhA1zIdGel6H79x7eNDfwC BC669XcvuhwKEtc4wCRZneZ/T0OtnBA==; 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 1cjQIi-0000uF-Gm; Thu, 02 Mar 2017 12:57:44 +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-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: 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-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=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); }