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=-5.2 required=3.0 tests=BAYES_00,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 B98ADC433E1 for ; Thu, 20 Aug 2020 06:53:37 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (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 3DF1720738 for ; Thu, 20 Aug 2020 06:53:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="a7wknNuu" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3DF1720738 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 9F6D61673; Thu, 20 Aug 2020 08:52:45 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 9F6D61673 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1597906415; bh=Wts9YUneOFOepJtboJgVvggU/nJoptY4HHCaKffVgeI=; h=Date:From:To:Subject:References:In-Reply-To:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=a7wknNuuBdYNS5ylUEsP0TU5/0SY4VVFmjnERVhYL0+w+hr73L1kaGN/Z4lFoN56O 4RwamPGR9RCfyOlDZjGyzFKVNB8jf9rXZxjz/eEcuO+ge+Aot2D3eqzyn2cdXvQvVS qkkTBdEcZllvW/M6uO0mwL7THdN04JufeNhcMXqM= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 3D97DF800D3; Thu, 20 Aug 2020 08:52:45 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 61AC1F80228; Thu, 20 Aug 2020 08:52:43 +0200 (CEST) Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [85.220.165.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 4BA02F800D3 for ; Thu, 20 Aug 2020 08:52:33 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 4BA02F800D3 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 1k8eQz-0000f8-L0; Thu, 20 Aug 2020 08:52:25 +0200 Received: from sha by ptx.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1k8eQv-0003ht-Hg; Thu, 20 Aug 2020 08:52:21 +0200 Date: Thu, 20 Aug 2020 08:52:21 +0200 From: Sascha Hauer To: Lars-Peter Clausen Subject: Re: pcm|dmaengine|imx-sdma race condition on i.MX6 Message-ID: <20200820065221.GF19745@pengutronix.de> References: <20200813112258.GA327172@pcleri> <61498763c60e488a825e8dd270732b62@skidata.com> <16942794-1e03-6da0-b8e5-c82332a217a5@metafoo.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <16942794-1e03-6da0-b8e5-c82332a217a5@metafoo.de> 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: 08:19:09 up 182 days, 13:49, 135 users, load average: 0.10, 0.14, 0.14 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: alsa-devel@alsa-project.org Cc: "alsa-devel@alsa-project.org" , "timur@kernel.org" , "linux-kernel@vger.kernel.org" , Richard Leitner - SKIDATA , "nicoleotsuka@gmail.com" , "vkoul@kernel.org" , Benjamin Bara - SKIDATA , "kernel@pengutronix.de" , "dmaengine@vger.kernel.org" , "dan.j.williams@intel.com" , Robin Gong , "shawnguo@kernel.org" , "linux-arm-kernel@lists.infradead.org" , dl-linux-imx X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" 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. 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. More specifically sdma_config_write() may not be called from sdma_prep_slave_sg() or sdma_prep_dma_cyclic(), but instead must be called from sdma_start_desc(). sdma_config_ownership() also must be called later in sdma_start_desc(). 'direction' must be a member of struct sdma_desc, not of struct sdma_channel. Overall this sounds like a fair amount of work to do, but should be feasible and IMO is a step in the right direction. 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 |