From patchwork Tue Jan 17 13:45:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Bailon X-Patchwork-Id: 9521035 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 44A83601C3 for ; Tue, 17 Jan 2017 13:53:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2453A28564 for ; Tue, 17 Jan 2017 13:53:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 178C428568; Tue, 17 Jan 2017 13:53:53 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC53328564 for ; Tue, 17 Jan 2017 13:53:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751151AbdAQNxw (ORCPT ); Tue, 17 Jan 2017 08:53:52 -0500 Received: from mail-wm0-f43.google.com ([74.125.82.43]:36052 "EHLO mail-wm0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751023AbdAQNxw (ORCPT ); Tue, 17 Jan 2017 08:53:52 -0500 Received: by mail-wm0-f43.google.com with SMTP id c85so200893334wmi.1 for ; Tue, 17 Jan 2017 05:53:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7fpgNcJJF18Kt6HTI8Dobj2zVZWFCpKfcQZW2WXdZ28=; b=NW9R8tqoUZeE0s3BbO79EoPB8CAsjWykxvADOdnBXLaVxafl3Ht/wBmse+njGJLUse RDfW8Bi3HfaLVX9VxNBF3t3TyT6iCp2TANmSFzGoX5gJCTS1ZTZj5lD0dE24y76lMC/d hm81U7Gii0UBuauV020nMBUCGEiAhDPSWrp9jLzMioSR81yKTL13rb6ze+bgl5gTLnsk Crql9eDt57yLoPxYr+5+6hcbpRY3A+vXebVfJR1v+NZzveKJtCC6ZHl7/vsyEpKSauIu m+yqIXrQD7YzFwEKOqMelQVRqJMcffkQkzC2yVaxZJVTAQd2eMcGwxSrgWyzbahlftGm BfLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7fpgNcJJF18Kt6HTI8Dobj2zVZWFCpKfcQZW2WXdZ28=; b=fbDgzJG07xjKyjGSY23pyvMS10igGcknjKgPFx9w9NP7SRwlSUQmf9Mkvbd45s7aTm QJVDV/akJaedMFkbr4TDKaLBb6jCcu4H1+SCfzhYNt5nLZE/I3ZgOFavDmEPLw/hSKUK 1heSPH24niBIMx7VqJckCc8tiRBcIoQRdlFkQDD3Na0J+lrT3CA9Kkzo8eb3hpOLCwDk SKaOfD3Kj5n8R1g2wAyYpnRkQiMcEYU+r3WiHUGoeuidwnXLqhMyDrwex9hSme76LpRs PEX1ESme3C0Q13zxX267DNVLnIrYwzsgymlMtUDMfSYRtpINaiybbuZ5n+WdJ3dmFs/k Wwjg== X-Gm-Message-State: AIkVDXI1fkkwpULhNXsKvYPdwzTmyblVauoGvh+38ypW1HpGRBTxGTWNQ3+ROoGBooxls/Lh X-Received: by 10.28.203.75 with SMTP id b72mr18055115wmg.110.1484660757604; Tue, 17 Jan 2017 05:45:57 -0800 (PST) Received: from localhost.localdomain ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id l187sm37064811wml.6.2017.01.17.05.45.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 17 Jan 2017 05:45:57 -0800 (PST) From: Alexandre Bailon To: vinod.koul@intel.com, b-liu@ti.com, robh+dt@kernel.org Cc: dmaengine@vger.kernel.org, nsekhar@ti.com, khilman@baylibre.com, ptitiano@baylibre.com, tony@atomide.com, linux-omap@vger.kernel.org, sergei.shtylyov@cogentembedded.com, devicetree@vger.kernel.org, Alexandre Bailon Subject: [PATCH v2 7/7] dmaengine: cppi41: Fix a race between PM runtime and channel abort Date: Tue, 17 Jan 2017 14:45:40 +0100 Message-Id: <20170117134540.9988-8-abailon@baylibre.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20170117134540.9988-1-abailon@baylibre.com> References: <20170117134540.9988-1-abailon@baylibre.com> Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP cppi41_dma_issue_pending() may be called while the device is runtime suspended. In that case, the descriptor will be pushed to the pending list and then be queued to hardware queue. But if cppi41_stop_chan() is called before the device got time to resume, then the descriptor will remain in the pending list and be queued to hardware queue after the teardown. During the channel stop, check if there is a pending descriptor and if so, remove it. Signed-off-by: Alexandre Bailon --- drivers/dma/cppi41.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/dma/cppi41.c b/drivers/dma/cppi41.c index 303ccee..0bc4f1a 100644 --- a/drivers/dma/cppi41.c +++ b/drivers/dma/cppi41.c @@ -687,10 +687,17 @@ static int cppi41_stop_chan(struct dma_chan *chan) { struct cppi41_channel *c = to_cpp41_chan(chan); struct cppi41_dd *cdd = c->cdd; + unsigned long flags; u32 desc_num; u32 desc_phys; int ret; + /* Remove pending descriptor that haven't been pushed to queue */ + spin_lock_irqsave(&cdd->lock, flags); + if (!list_empty(&c->node)) + list_del_init(&c->node); + spin_unlock_irqrestore(&cdd->lock, flags); + desc_phys = lower_32_bits(c->desc_phys); desc_num = (desc_phys - cdd->descs_phys) / sizeof(struct cppi41_desc); if (!cdd->chan_busy[desc_num]) @@ -748,6 +755,7 @@ static int cppi41_add_chans(struct device *dev, struct cppi41_dd *cdd) cchan->desc_phys = cdd->descs_phys; cchan->desc_phys += i * sizeof(struct cppi41_desc); cchan->chan.device = &cdd->ddev; + INIT_LIST_HEAD(&cchan->node); list_add_tail(&cchan->chan.device_node, &cdd->ddev.channels); } cdd->first_td_desc = n_chans; @@ -1163,7 +1171,7 @@ static int __maybe_unused cppi41_runtime_resume(struct device *dev) spin_lock_irqsave(&cdd->lock, flags); list_for_each_entry_safe(c, _c, &cdd->pending, node) { push_desc_queue(c); - list_del(&c->node); + list_del_init(&c->node); } spin_unlock_irqrestore(&cdd->lock, flags);