From patchwork Thu Oct 9 02:09:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 5056191 Return-Path: X-Original-To: patchwork-dmaengine@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id F3872C11AC for ; Thu, 9 Oct 2014 02:09:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2447520123 for ; Thu, 9 Oct 2014 02:09:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2B7822017D for ; Thu, 9 Oct 2014 02:09:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751223AbaJICJK (ORCPT ); Wed, 8 Oct 2014 22:09:10 -0400 Received: from relmlor3.renesas.com ([210.160.252.173]:50051 "EHLO relmlie2.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750875AbaJICJJ (ORCPT ); Wed, 8 Oct 2014 22:09:09 -0400 Received: from unknown (HELO relmlir1.idc.renesas.com) ([10.200.68.151]) by relmlie2.idc.renesas.com with ESMTP; 09 Oct 2014 11:09:07 +0900 Received: from relmlac3.idc.renesas.com (relmlac3.idc.renesas.com [10.200.69.23]) by relmlir1.idc.renesas.com (Postfix) with ESMTP id 43568469DD; Thu, 9 Oct 2014 11:09:06 +0900 (JST) Received: by relmlac3.idc.renesas.com (Postfix, from userid 0) id 44FE3180A1; Thu, 9 Oct 2014 11:09:06 +0900 (JST) Received: from relmlac3.idc.renesas.com (localhost [127.0.0.1]) by relmlac3.idc.renesas.com (Postfix) with ESMTP id 3D7D1180A0; Thu, 9 Oct 2014 11:09:06 +0900 (JST) Received: from relmlii2.idc.renesas.com [10.200.68.66] by relmlac3.idc.renesas.com with ESMTP id MAE09750; Thu, 9 Oct 2014 11:09:06 +0900 X-IronPort-AV: E=Sophos;i="5.04,681,1406559600"; d="scan'208";a="171989146" Received: from mail-hk1lp0120.outbound.protection.outlook.com (HELO APAC01-HK1-obe.outbound.protection.outlook.com) ([207.46.51.120]) by relmlii2.idc.renesas.com with ESMTP/TLS/AES256-SHA; 09 Oct 2014 11:09:05 +0900 Received: from HKXPR06MB327.apcprd06.prod.outlook.com (10.141.133.17) by HKXPR06MB070.apcprd06.prod.outlook.com (10.242.122.17) with Microsoft SMTP Server (TLS) id 15.0.1044.10; Thu, 9 Oct 2014 02:09:04 +0000 Received: from localhost (211.11.155.132) by HKXPR06MB327.apcprd06.prod.outlook.com (10.141.133.17) with Microsoft SMTP Server (TLS) id 15.0.1044.10; Thu, 9 Oct 2014 02:09:03 +0000 From: Yoshihiro Shimoda To: , , , , , CC: , , Yoshihiro Shimoda Subject: [PATCH] dmaengine: shdma: fix a race condition in __ld_cleanup() Date: Thu, 9 Oct 2014 11:09:00 +0900 Message-ID: <1412820540-4892-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> X-Mailer: git-send-email 1.9.4.msysgit.1 MIME-Version: 1.0 X-Originating-IP: [211.11.155.132] X-ClientProxiedBy: HKXPR02CA0063.apcprd02.prod.outlook.com (25.161.48.48) To HKXPR06MB327.apcprd06.prod.outlook.com (10.141.133.17) X-Microsoft-Antispam: UriScan:;UriScan:; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:HKXPR06MB327; X-Forefront-PRVS: 0359162B6D X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6069001)(6009001)(189002)(199003)(229853001)(50466002)(42186005)(95666004)(105586002)(66066001)(107046002)(64706001)(80022003)(21056001)(122386002)(76482002)(40100002)(120916001)(46102003)(87976001)(99396003)(20776003)(77156001)(78352002)(4396001)(47776003)(33646002)(48376002)(102836001)(89996001)(85852003)(77096002)(19580405001)(85306004)(93916002)(19580395003)(62966002)(31966008)(104166001)(50986999)(50226001)(106356001)(36756003)(88136002)(97736003)(92566001)(92726001)(101416001)(87286001)(2201001)(575784001)(42382002)(76506005)(88662002); DIR:OUT; SFP:1102; SCL:1; SRVR:HKXPR06MB327; H:localhost; FPR:; MLV:sfv; PTR:InfoNoRecords; MX:0; A:0; LANG:en; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:HKXPR06MB070; X-OriginatorOrg: renesas.com Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch fixes a race condition about a list of shdma-base driver. If we don't apply this patch, a dma slave driver (especially a usb peripheral driver) may not be able to start the transfer. If a dma slave driver has a callback, __ld_cleanup() will call the callback before this driver removes the list. After the callback, since the return value of __ld_cleanup() is not zero, shdma_chan_ld_cleanup() calls __ld_cleanup() again. And, __ld_clean() will removes the list. At this time, if a dma slave driver calls dmaengine_submit() before this driver removes the list, this driver will set schan->pm_state to SHDMA_PM_PENDING in shdma_tx_submit(). And then, even if a dma slave driver calls dma_async_issue_pending(), this driver don't start the transfer because the schan->pm_state is SHDMA_PM_PENDING in shdma_issue_pending(). So, this patch adds a new condition in __ld_clean() to check if the schan->pm_state is SHDMA_PM_PENDING or not. Signed-off-by: Yoshihiro Shimoda --- This patch is based on slave-dma.git / next branch. (commit id : ade4a2a8e6e40fe18be1f83e5ea2e915692a0028) drivers/dma/sh/shdma-base.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c index 42d4974..2fd2f0ea 100644 --- a/drivers/dma/sh/shdma-base.c +++ b/drivers/dma/sh/shdma-base.c @@ -391,6 +391,8 @@ static dma_async_tx_callback __ld_cleanup(struct shdma_chan *schan, bool all) dev_dbg(schan->dev, "Bring down channel %d\n", schan->id); pm_runtime_put(schan->dev); schan->pm_state = SHDMA_PM_ESTABLISHED; + } else if (schan->pm_state == SHDMA_PM_PENDING) { + shdma_chan_xfer_ld_queue(schan); } } }