From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69874C433DF for ; Tue, 25 Aug 2020 06:14:42 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3503120706 for ; Tue, 25 Aug 2020 06:14:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="j+qQr3mQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3503120706 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=eABuc/YwqR78gLELZGdKBc79O3tP0ql66JQ8WPkRIM8=; b=j+qQr3mQuBg/KUbTrLvf/6P2U l7j5aOUbrOfUaD4eiAFX5vlJkIiRHmEktMxt5MoJGR1GRKTG3SKy+2RUgJtK1RLkR8ealVInLf7xX G7nxHi7IntNsk3sEkKWMdPNw7pgY/dLAAgkJi11RzfbGxZ2Gsr3vo367CQNkASLlwqIQUykfFoa9F xCPjGK0CbSTPETw+uFu7ozXd0xatL+EOwtsSw+FAv6xa4vbHugVrimWZmVCTPAtQlQn/YhmJDsXps OGlIHngD6u5C48U669MrhsPiWY0f20gYUJL9N7zLW8t5wIZyDbHVi63usJ5d6GF23UKwZ26QOTh69 k7fU6pSsA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kASCq-0001rB-PT; Tue, 25 Aug 2020 06:13:16 +0000 Received: from metis.ext.pengutronix.de ([85.220.165.71]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kASCo-0001qZ-6l for linux-arm-kernel@lists.infradead.org; Tue, 25 Aug 2020 06:13:15 +0000 Received: from [2001:67c:670:100:1d::c0] (helo=ptx.hi.pengutronix.de) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kASCS-0004AV-Lp; Tue, 25 Aug 2020 08:12:52 +0200 Received: from sha by ptx.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1kASCO-0001dd-22; Tue, 25 Aug 2020 08:12:48 +0200 Date: Tue, 25 Aug 2020 08:12:48 +0200 From: Sascha Hauer To: Robin Gong Subject: Re: pcm|dmaengine|imx-sdma race condition on i.MX6 Message-ID: <20200825061247.GL13023@pengutronix.de> References: <20200813112258.GA327172@pcleri> <61498763c60e488a825e8dd270732b62@skidata.com> <16942794-1e03-6da0-b8e5-c82332a217a5@metafoo.de> <20200820065221.GF19745@pengutronix.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Sent-From: Pengutronix Hildesheim X-URL: http://www.pengutronix.de/ X-IRC: #ptxdist @freenode X-Accept-Language: de,en X-Accept-Content-Type: text/plain X-Uptime: 07:55:28 up 187 days, 13:25, 139 users, load average: 0.40, 0.16, 0.11 User-Agent: Mutt/1.10.1 (2018-07-13) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c0 X-SA-Exim-Mail-From: sha@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200825_021314_293553_B1E9BA49 X-CRM114-Status: GOOD ( 28.86 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "alsa-devel@alsa-project.org" , Lars-Peter Clausen , "timur@kernel.org" , "linux-kernel@vger.kernel.org" , "nicoleotsuka@gmail.com" , "vkoul@kernel.org" , Benjamin Bara - SKIDATA , "kernel@pengutronix.de" , "dmaengine@vger.kernel.org" , "dan.j.williams@intel.com" , Richard Leitner - SKIDATA , "shawnguo@kernel.org" , "linux-arm-kernel@lists.infradead.org" , dl-linux-imx Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Aug 21, 2020 at 09:52:00AM +0000, Robin Gong wrote: > On 2020/08/20 14:52 Sascha Hauer wrote: > > On Wed, Aug 19, 2020 at 01:08:29PM +0200, Lars-Peter Clausen wrote: > > > > For the first option, which is potentially more performant, we have > > > > to leave the atomic PCM context and we are not sure if we are allowed to. > > > > For the second option, we would have to divide the dma_device > > > > terminate_all into an atomic sync and an async one, which would > > > > align with the dmaengine API, giving it the option to ensure termination in > > an atomic context. > > > > Based on my understanding, most of them are synchronous anyways, for > > > > the currently async ones we would have to implement busy waits. > > > > However, with this approach, we reach the WARN_ON [6] inside of an > > > > atomic context, indicating we might not do the right thing. > > > > > > I don't know how feasible this is to implement in the SDMA dmaengine > > driver. > > > But I think what is should do is to have some flag to indicate if a > > > terminate is in progress. If a new transfer is issued while terminate > > > is in progress the transfer should go on a list. Once terminate > > > finishes it should check the list and start the transfer if there are any on the > > list. > > > > The list is already there in form of the vchan helpers the driver uses. > Seems Lars major concern is on the race condition between next descriptor > and sdma_channel_terminate_work which free the last terminated descriptor, > not the ability of vchan to support multi descriptors. But anyway, I think we > should take care vchan_get_all_descriptors to free descriptors during terminate > phase in case it's done in worker like sdma_channel_terminate_work, since that > may free the next descriptor wrongly. That's what my patch attached in > 0001-dmaengine-imx-sdma-add-terminated-list-for-freed-des.patch > https://www.spinics.net/lists/arm-kernel/msg829972.html Indeed this should solve the problem of freeing descriptors allocated between terminate_all and a following prep_slave*. > > > > > I think the big mistake the driver makes is to configure fields in struct > > sdma_channel and also the hardware directly in sdma_prep_memcpy(), > > sdma_prep_slave_sg() and sdma_prep_dma_cyclic(). All information should be > > stored in the struct sdma_desc allocated in the prep functions and only be used > > when it's time to fire that specific descriptor. > Sorry Sascha, seems that's another topic and your intention is to make sure only > software involved in sdma_prep_* and all HW moved into one function inside > sdma_start_desc. I agree that will make code more clean but my concern is > sdma_start_desc is protect by spin_lock which should be short as possible while > some HW touch as context_load may cost some time. Anyway, that's another topic, > maybe we can refine it in the future. Yes, you are right. This is another topic. Sascha -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel