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: 9505367 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 B7CA8606E1 for ; Mon, 9 Jan 2017 16:08:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA74228474 for ; Mon, 9 Jan 2017 16:08:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F0CE28497; Mon, 9 Jan 2017 16:08:51 +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=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 31B4028474 for ; Mon, 9 Jan 2017 16:08:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757564AbdAIQIG (ORCPT ); Mon, 9 Jan 2017 11:08:06 -0500 Received: from mail-wm0-f44.google.com ([74.125.82.44]:33039 "EHLO mail-wm0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S970253AbdAIQH1 (ORCPT ); Mon, 9 Jan 2017 11:07:27 -0500 Received: by mail-wm0-f44.google.com with SMTP id n129so24655309wmn.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=VEB4m7fw+z5x8fgru+dJF/yxW0xL0AG9eQg/loxdsU4BSOD7kp0eucbSmzAPMwc8dW rIigePHUYN2W9iDuGm4gg6dL7HzbbYJm9kJqmYCn4rVDPwpShWiBqFdntNh+BLsHFgS+ /p+XxUNbdTspoH7HJARAi69LdNTfEkeKbNJ3cdS25YoYKWfiYl8s6Gh4MBjnUrdVV2h9 noXWS4LZBxBNATu5eWkLDltOXisL+YqFPviB+VPxxzZOh5/5XSr0FD4XZmDIioSt172o QrmxhJ1NcZaY7mURoP8m/OHGwHaGXMxsigyoULzpsF56kDRiJeQOndEmwMPbJaOXdH3d 5Q+g== X-Gm-Message-State: AIkVDXJPn1ZCoxH++LVgG5vzuThbnSwhjOMmkBqgsAq5a4nd2bJlRZ9t/FtRNeUZ6WF0kZps 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: 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 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);