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: 9505363 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 E59D7606E1 for ; Mon, 9 Jan 2017 16:08:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D79DA28474 for ; Mon, 9 Jan 2017 16:08:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CC1E228497; Mon, 9 Jan 2017 16:08:46 +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=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 6EF7428474 for ; Mon, 9 Jan 2017 16:08:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1762370AbdAIQIH (ORCPT ); Mon, 9 Jan 2017 11:08:07 -0500 Received: from mail-wm0-f46.google.com ([74.125.82.46]:37272 "EHLO mail-wm0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S970252AbdAIQH1 (ORCPT ); Mon, 9 Jan 2017 11:07:27 -0500 Received: by mail-wm0-f46.google.com with SMTP id c206so37931023wme.0 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=IEpzYLE6+2okA7Uay7AFTZ66kMOEYg/RdPUfLwEezi0spflxnfDL3r4lC6uc+Euoom hFbNKzJVJl41rQRsqibYQNVhnxugL3+RhLeWORiCPyDB2/WF9FOJ5RWiSStU22NceeT2 aIBRYWYW1hq9HAg5xm2e3pAt2bnsktyR96vClxwInyFakgYh9EPRZxrYSZqBuZ+GidZc H1+8wJoaLaBjPm1rHfwMaA+fS+/GBl0MOZE18KeVi8fC4ujYjwWw/0+MQ/+/OG0qlRF0 Rq0k3mEneYtR67+3zhrqXfArdENvTKD8zoiPmEaa5d/dV9s3JKlHtKSRnfN7laeCahjz jZRA== X-Gm-Message-State: AIkVDXKmiDAddV46knR+FwjhxXMyqOcmWCta8HA6vuhkZ40ixyAEx2VRNUStBDG/OJr4gtXK 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: 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 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(-) 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);