Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1033905pxa; Thu, 20 Aug 2020 00:11:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwUdt0EtwOppBHkAXNKOI3bDr22mPm8a6J9kocHDFI0v+ILpSF1X4Xb1l/rA8wVDCGywMey X-Received: by 2002:a17:906:1392:: with SMTP id f18mr1856201ejc.521.1597907508333; Thu, 20 Aug 2020 00:11:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597907508; cv=none; d=google.com; s=arc-20160816; b=sh0Ts057G30gvSzjSVnC1qb160E37lQrs454O6abM6lz9HOb5YVVNB5aIVIOIlUMEe J5tw9hZKmj9tcNcELz9SJOuKet/u0CxTfyEUVcXJYYbTwrWDAepC2+BsoPcy2Js3B6mh 1lkGlKtiJTr96FtBi+QS1enaZkJBUCF27QPq2sqooBiws6qEVzskoifnm0KF0CpIuS+Q lfEeBDfk5768knmTatLBcAG+KNkr/a+Gmpz6eVvypaz4kLIFUJmuo49f5+2pomZ814bT Hi18EpP01VytFf/SHlzgFm28tmLiYzbW3ibLcddU7/f6M0sSA4IWJ9uRD8LKKdrnLtje hHgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=cL62l6BXxSmcauO2EgRRUA54g8vOOyiNUdW5coltsR0=; b=z1EGG9Qb87nw4oVTyNeFHWi9BY89VRwIX9ryjTpyf2PD5GWbz16dNOPjzq8kvpHNFK vjB9JUEwvDc5qn8rQI2g45hBhgSMsrlcKaGmpEBZfjQaVyKfJeKf5bHF3eX/3QMB0eHi /GAX933/JoMcy3DoM0PygeTthuAHvhcA1xY4fmM+VVhIk7C13YUsD2Dodhc1yAkHy1Ek b2XWTQLV+ren2mmBPg3qLnAFnWpRoTGBPshQvVjm9boLWKjo/Q5eVrtOKvilQzsOY0Nd zqkcBpb8/CcuuoLzgJFX6SLD+SrlKaALzHli9JHVVIuqyLxRczOA7HM3QyunXBFNiq+6 lFrA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w25si746309ejy.124.2020.08.20.00.11.24; Thu, 20 Aug 2020 00:11:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725925AbgHTHK2 (ORCPT + 99 others); Thu, 20 Aug 2020 03:10:28 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:52821 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725820AbgHTHK0 (ORCPT ); Thu, 20 Aug 2020 03:10:26 -0400 X-Greylist: delayed 1068 seconds by postgrey-1.27 at vger.kernel.org; Thu, 20 Aug 2020 03:10:26 EDT 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 Cc: Benjamin Bara - SKIDATA , Robin Gong , "alsa-devel@alsa-project.org" , "timur@kernel.org" , "linux-kernel@vger.kernel.org" , "nicoleotsuka@gmail.com" , "vkoul@kernel.org" , dl-linux-imx , "kernel@pengutronix.de" , "dmaengine@vger.kernel.org" , "dan.j.williams@intel.com" , "shawnguo@kernel.org" , "linux-arm-kernel@lists.infradead.org" , Richard Leitner - SKIDATA 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: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 |