From patchwork Fri Feb 2 10:05:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 10196441 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 7923060388 for ; Fri, 2 Feb 2018 10:10:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 60D2728E21 for ; Fri, 2 Feb 2018 10:10:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5144528E26; Fri, 2 Feb 2018 10:10:04 +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 97D1328E22 for ; Fri, 2 Feb 2018 10:10:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751468AbeBBKKD (ORCPT ); Fri, 2 Feb 2018 05:10:03 -0500 Received: from relmlor3.renesas.com ([210.160.252.173]:64603 "EHLO relmlie2.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750799AbeBBKKB (ORCPT ); Fri, 2 Feb 2018 05:10:01 -0500 Received: from unknown (HELO relmlir4.idc.renesas.com) ([10.200.68.154]) by relmlie2.idc.renesas.com with ESMTP; 02 Feb 2018 19:09:59 +0900 Received: from relmlii1.idc.renesas.com (relmlii1.idc.renesas.com [10.200.68.65]) by relmlir4.idc.renesas.com (Postfix) with ESMTP id 7FD93832F2; Fri, 2 Feb 2018 19:09:58 +0900 (JST) X-IronPort-AV: E=Sophos;i="5.46,448,1511794800"; d="scan'208";a="270103939" Received: from mail-pu1apc01lp0024.outbound.protection.outlook.com (HELO APC01-PU1-obe.outbound.protection.outlook.com) ([65.55.88.24]) by relmlii1.idc.renesas.com with ESMTP/TLS/AES256-SHA256; 02 Feb 2018 19:09:57 +0900 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=renesasgroup.onmicrosoft.com; s=selector1-renesas-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=oPN7Hq3b76snumhm4dObg1Ky6Nh8pmAE/SiIW94fIfM=; b=nPphOcOOxvYcww/fraxUp4lM9h/fMAXMXTwO9hlV4BzTM/NKiW2RRaDDxAKkStmZiyoF1cbln3/iXF54VSxkk2JMjiZUrTs+zpvea83g+fuqGuj9J1NI3yIWVmvQDc3fW7yWq/J41Izyj2CmX2R22qnBJh+Oy4rgCLa0gtyWlq4= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=<>; Received: from localhost.localdomain (211.11.155.138) by SG2PR06MB0981.apcprd06.prod.outlook.com (2a01:111:e400:5213::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.444.14; Fri, 2 Feb 2018 10:09:55 +0000 From: Yoshihiro Shimoda To: vinod.koul@intel.com Cc: dmaengine@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Yoshihiro Shimoda Subject: [PATCH] dmaengine: rcar-dmac: Check the done lists in rcar_dmac_chan_get_residue() Date: Fri, 2 Feb 2018 19:05:15 +0900 Message-Id: <1517565915-14234-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [211.11.155.138] X-ClientProxiedBy: OSXPR01CA0082.jpnprd01.prod.outlook.com (2603:1096:600:f::21) To SG2PR06MB0981.apcprd06.prod.outlook.com (2a01:111:e400:5213::23) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: ecf4097c-7e1f-4e12-e05b-08d56a251bcf X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(8559017)(48565401081)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:SG2PR06MB0981; X-Microsoft-Exchange-Diagnostics: 1; SG2PR06MB0981; 3:wudWf6RoMla2PA8/8ggBAGcJEYFOBB8BlPOsM5814pwBEzuI4sFb8VYd7YJO0wJDVQfHcnX44Qng/HiIpaL8SWm2nGzMFi6Ftsj0U8ROqZkzzbGN5W26mrX3A1yexI79MshFYy79b5mjsZtnJCdKxBPyhn0GKpFxKsi9IfkOucosaO3P6Bv3DnSHf2Crh57VfpNAtGlDi9You5q5KeAAY6IaGRyzLSiYzRjYMZb6TrGY/I9a9D1Bx5K/JRuL6821; 25:yelqs0UFwBXonmrtaKvC099FZ45scDraDxRB05vE/nTqFWiVRd6kk/qqM/OUScH/6oNMSOHOhfdL8Sc3YSmxvu6txQbTHt/mqHQa/eOhkt/1AG3IXU+scukZ0z6jnTqdi4jMM1NeUK0yliM9567adscNiFf1MlnCZv4xTCmqmk3eZWBdnAPY8U3ibKCF4tXyyxhLJuCyButhZXjrxt7OOptwYd4yLCzb/+k+4rwJgHzaa9YjIRbtO4ftIyQSLBagk1nGbRYf3Xo/5QyfjN5MZMtJogcDahIAuFLLJVa25dgUniiWCW4MIe2g0G4nfJJ7J+6UhL7jGMqEtIHC8bFYEg==; 31:AKMh4g24ErbySEU5DTTl1GN9Vl5AZw5mnff8COI+mMz+5JAUBnMC0Hr7GdR5jDp3L52oaQcIW5kAY3GDj6gAc01bpL6/6NiVP0qoS2z4R2m2HH0h4DVHKW7EXzKZlAgIK/5j2OvJ5VgGdQv/cVaiphKcI20wYJO1PV7I+UkTMZc+OB3Y/gi8j6cd/W0wvppwEtaZ6vUr2OyqP791AEjmDzdae3fmSj7SyCGz0MVL2XY= X-MS-TrafficTypeDiagnostic: SG2PR06MB0981: X-Microsoft-Exchange-Diagnostics: 1; SG2PR06MB0981; 20:bjlOGrHfcXrt1eoU1ij0nFcQgKBWHmjpfwVHCSSM6Ml3hWI5qFyeWzVIBc3f7Buff3KaMuEkuLsewbi4HNksd/eELKB+ztsgtWcefX7Fz+W0SZPrwOceIptf5IzOyLASwLcNX9JupCyRluXwgbNwbrE4pQv6aNjZntgqgXrnn75ONGdNtS9P9sswNB8QepMpqIrE1FmZZ0e9HCMJMvhHScOL96OSSI5JcFCbJYn8RhVLwXGHbMkyUcKGuSpljfOJpIZETRBLPIY/mt8inMqpDMP3C6y7ff+aY12cJwu+612C0T/g32hilsD2nFAA7qtNnoMPf+GDMYsAolvhKagyQjZvQC2nbOQQstxVDiHBpHM2IVdSEM6qVqgg1gntSw8rlw6xorvJftwNsPyE/qKR1/5p2l9/dQdI7JdkkfOVBMF4LdbYbh3BOeydm5+H10EQBHpJJK+vmp7G9hLj4XlAcQEUXudVUtW5sQUFz80eFBqk5DuxV4OTDgm2Sf1JhAOa; 4:OeUdMxpViTMgV0GTSQQExqgv/mFxJNkGfOopZzrVgC18fJxOP9QKDF2hHoHsx84xNrERyMw7FV9DVHGSYQ2djIN/zwQ93q+8JlKa3PmmHcX/Hhwz1xtxlqInPGeL4YTGofJHh+EHA7kfK/fGi8UZYnUWDOHtkBg+1morc1hYPOy739w4y6n2k2Y1YZUViEE6Ec2mhhlScPh/Pb485G7eBTw+rxHhUVcAQ1IrsWJmhfWgkweJKaLF4nzI7xlW/Q/0b6VEEkDCSofNX9Clq7ipXQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(8121501046)(5005006)(3231101)(2400082)(944501161)(3002001)(93006095)(10201501046)(6055026)(6041288)(20161123562045)(20161123558120)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061750153)(20161123564045)(6072148)(201708071742011); SRVR:SG2PR06MB0981; BCL:0; PCL:0; RULEID:; SRVR:SG2PR06MB0981; X-Forefront-PRVS: 05715BE7FD X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6069001)(396003)(376002)(366004)(346002)(39860400002)(39380400002)(199004)(189003)(4326008)(386003)(6506007)(36756003)(53936002)(305945005)(47776003)(51416003)(5660300001)(66066001)(81166006)(81156014)(498600001)(2351001)(2906002)(16586007)(6116002)(6916009)(3846002)(42882006)(78352004)(26005)(8936002)(316002)(6666003)(50226002)(25786009)(16526019)(6486002)(68736007)(7736002)(50466002)(6512007)(8676002)(59450400001)(48376002)(52116002)(106356001)(105586002)(107886003)(2361001)(97736004)(3720700003); DIR:OUT; SFP:1102; SCL:1; SRVR:SG2PR06MB0981; H:localhost.localdomain; FPR:; SPF:None; PTR:InfoNoRecords; A:0; MX:0; LANG:en; Received-SPF: None (protection.outlook.com: localhost.localdomain does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SG2PR06MB0981; 23:gIfk89y/KxNcY43uusnRdwW2klXI25juLGG9uwH2q?= =?us-ascii?Q?PmS0HRBHkxa9QI+31eVe3Ft0SmmzqbZeS90BuIDPSxYjHE1NAfmlcxRU6RnX?= =?us-ascii?Q?Lt0rUNnHORCY5p3HfRgHWm+yY5CzuYy/LT2TtlOF7ctRS5ZJzYdURFHAMBnq?= =?us-ascii?Q?0oDaCF5+2oPiBxSIiplZ/6oM85q/kauPyyu/CC01wo2f/qS9hMy8eAK+duFb?= =?us-ascii?Q?79XZZlbx2Y/62n5Gwo5qWN4yQfkqESYuTf3fwEb0bdDriIjmVv1lry+F7xQ+?= =?us-ascii?Q?twr2FkBmXGhMlW1SEEdAWmipFVxxt+3c/a8fa+YzPZ6ztFisqmxzZf+TypAD?= =?us-ascii?Q?Ly8rPlgwJfMh4XpByuLT3x1/HnKFWm6HXefW+pLP6P0I9Hf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Y6OyEsmmzGWIKfO/CZQ3C4D1ZJCYdaSw3n41TFP2rs/oX2QzwT5e6bOPd68Ng= X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Feb 2018 10:09:55.0422 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ecf4097c-7e1f-4e12-e05b-08d56a251bcf X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-Transport-CrossTenantHeadersStamped: SG2PR06MB0981 Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch fixes an issue that a race condition happens between a client driver and the rcar-dmac driver: - The rcar_dmac_isr_transfer_end() is called. - The done list appears, and desc.running is the next active list. - rcar_dmac_chan_get_residue() is called by a client driver before rcar_dmac_isr_channel_thread() is called. - The rcar_dmac_chan_get_residue() will not find any descriptors. - And, the following WARNING happens: WARN(1, "No descriptor for cookie!"); The sh-sci driver with HSCIF (921,600bps) on R-Car H3 can cause this situation. So, this patch checks the done lists in rcar_dmac_chan_get_residue() and returns zero if the done lists has the argument cookie. Tested-by: Nguyen Viet Dung Signed-off-by: Yoshihiro Shimoda --- drivers/dma/sh/rcar-dmac.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/dma/sh/rcar-dmac.c b/drivers/dma/sh/rcar-dmac.c index 2b2c7db..f748be6 100644 --- a/drivers/dma/sh/rcar-dmac.c +++ b/drivers/dma/sh/rcar-dmac.c @@ -1264,8 +1264,17 @@ static unsigned int rcar_dmac_chan_get_residue(struct rcar_dmac_chan *chan, * If the cookie doesn't correspond to the currently running transfer * then the descriptor hasn't been processed yet, and the residue is * equal to the full descriptor size. + * Also, a client driver is possible to call this function before + * rcar_dmac_isr_channel_thread() runs. In this case, the "desc.running" + * will be the next descriptor, and the done list will appear. So, if + * the argument cookie matches the done list's cookie, we can assume + * the residue is zero. */ if (cookie != desc->async_tx.cookie) { + list_for_each_entry(desc, &chan->desc.done, node) { + if (cookie == desc->async_tx.cookie) + return 0; + } list_for_each_entry(desc, &chan->desc.pending, node) { if (cookie == desc->async_tx.cookie) return desc->size;