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: 9521027 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 E473B6043D for ; Tue, 17 Jan 2017 13:53:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C633F28568 for ; Tue, 17 Jan 2017 13:53:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BB44628565; Tue, 17 Jan 2017 13:53:02 +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.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham 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 6039628568 for ; Tue, 17 Jan 2017 13:53:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751140AbdAQNxA (ORCPT ); Tue, 17 Jan 2017 08:53:00 -0500 Received: from mail-wm0-f53.google.com ([74.125.82.53]:38328 "EHLO mail-wm0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751158AbdAQNwy (ORCPT ); Tue, 17 Jan 2017 08:52:54 -0500 Received: by mail-wm0-f53.google.com with SMTP id r144so223375769wme.1 for ; Tue, 17 Jan 2017 05:52:40 -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=hxfjljqJ+dO60ezdUv2KwNB49jM8oPWbpceBHLg9KEf47n/Fj4Ti1NDxeeuJnPbjEv qdhMKD5HJnBzUktuKAiAl9kZo0bVRlaBSzeQns+/Z2oAdhLWp+2vcw/8F0chYT8X1wRt UZ9Q3QqalgjXvuP5Oo+62BTDFr8heWFn6jT+30bJroFQx5eizJe5KyCyjq68HQVeg0z1 LV3sK8LqW1fY551OOWeeV1rM07K5i5sLzSZerJXFE17eEGGT2ErE/7ZYVjBJ6MGFuV9/ B8UVdMqf7D5KYTlua1L4avmiMz5DICadSGTqaQXSVtm+M5eFkqJkTtqPmLT2UrEPg3ct GWTA== X-Gm-Message-State: AIkVDXLyu71cW5a+2elcoJQAx++BUZ+VZdstrsRKikLQHRs/5gRPyJoGcmZV38RBU/ZwZ6I/ 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: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@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);