From patchwork Mon Jan 9 16:06:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Bailon X-Patchwork-Id: 90508 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp152002qgi; Mon, 9 Jan 2017 08:08:08 -0800 (PST) X-Received: by 10.84.216.2 with SMTP id m2mr189126220pli.31.1483978088872; Mon, 09 Jan 2017 08:08:08 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l189si89163411pfc.33.2017.01.09.08.08.08; Mon, 09 Jan 2017 08:08:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@baylibre-com.20150623.gappssmtp.com; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1762369AbdAIQIG (ORCPT + 7 others); Mon, 9 Jan 2017 11:08:06 -0500 Received: from mail-wm0-f46.google.com ([74.125.82.46]:38709 "EHLO mail-wm0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S970250AbdAIQH1 (ORCPT ); Mon, 9 Jan 2017 11:07:27 -0500 Received: by mail-wm0-f46.google.com with SMTP id k184so126050336wme.1 for ; Mon, 09 Jan 2017 08:07:26 -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=Or26+1g+kkQnSyMo6IcpF8iFb9m1cyu/bwuHlk5tNKs=; b=xsss+2bo+nlRPUHBVaQsUxgG+PZl5eudc8rl4cdDRnq8VfFWP9HZTABHh6CSx2Afqd t/jPFlZNxTzQZZMnjoZSj1Z3MvivuN//wWZSrd6DMEVO2OIXGBd5QkxQcEBh+nvVdhFO 4mOA3Dwua5xLH2Gz/VCgUlHARhgr39sHJJy5aKEc31cNQIH9NvcKG6KHinX/vJA7rwUz Sf6gaBsJMo8qrPLBAcdXEy0cbCPTqqrGttIHFxU8CReQ72lWA7DO3UoAfHqDZ8nE1yo4 F/OazwpJ9T9cGNsQUndSDBpdsDE71PWjaNNSRZUtSIxzpIubLbtQZQyrBjeiVLBPWN8r t0RA== 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=Or26+1g+kkQnSyMo6IcpF8iFb9m1cyu/bwuHlk5tNKs=; b=IGofqXEv7wJvZ96iSrWc/nfS7Ailr9QG3SMcNRZrJUCyP45e7r4oVInK8G8IkRqtXr 4HxQdxZzYJQsUwuMg1nLCF15J1H/LOq0PtmO139Kc/FhfKcfWjL7Xbuvu8jDLjMJXJ+1 IAKbbZNp8RTSjHlN7nlyOwG6Y8dYW4u0iFBOIQ4EkMkkazeaOr5RR8dJ4X6M6NLrr2h1 2ZiepXU9e0qDXcFt4HJVaffUE2pkbl3Y/0QS7hlsrB6f/lniipiDt91Cvh/KEiLKpuuT OmD06WcW0F3oNGp2t684zcdEUap+6QT2zUt+vgYQ9ssfROr6vQTX6c8pfoSljNjxDKrI x5wg== X-Gm-Message-State: AIkVDXKhnxlxo1IegkZ+RC+EFw43xjxTwvj4gFOEuxse5rNpXhTbr2RwSFEIAUdu6Ul0SCfn X-Received: by 10.28.9.131 with SMTP id 125mr4763098wmj.22.1483978046133; Mon, 09 Jan 2017 08:07:26 -0800 (PST) Received: from localhost.localdomain ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id w18sm19656244wme.9.2017.01.09.08.07.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Jan 2017 08:07:25 -0800 (PST) From: Alexandre Bailon To: vinod.koul@intel.com Cc: dmaengine@vger.kernel.org, linux-usb@vger.kernel.org, nsekhar@ti.com, khilman@baylibre.com, ptitiano@baylibre.com, tony@atomide.com, linux-omap@vger.kernel.org, devicetree@vger.kernel.org, robh+dt@kernel.org, b-liu@ti.com, Alexandre Bailon Subject: [PATCH 09/11] dmaengine: cppi41: Fix a race between PM runtime and channel abort Date: Mon, 9 Jan 2017 17:06:54 +0100 Message-Id: <20170109160656.3470-10-abailon@baylibre.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20170109160656.3470-1-abailon@baylibre.com> References: <20170109160656.3470-1-abailon@baylibre.com> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org cppi41_dma_issue_pending() may be called while the device is runtime suspended. In that case, the descritpor will be push 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 pendding descriptor and if so, remove it. Signed-off-by: Alexandre Bailon --- drivers/dma/cppi41.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) -- 2.10.2 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/dma/cppi41.c b/drivers/dma/cppi41.c index 4318e53..e8470b1 100644 --- a/drivers/dma/cppi41.c +++ b/drivers/dma/cppi41.c @@ -751,10 +751,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]) @@ -812,6 +819,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; @@ -1301,7 +1309,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);