Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2677463pxa; Mon, 24 Aug 2020 23:21:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfa3VBaRfHXRK8/1LDwD2VlGvfXjNQOPxWCN73rX/jUIBzi2s5f38pjtWey5/aPbxDr2Ku X-Received: by 2002:a17:906:f28b:: with SMTP id gu11mr8697566ejb.407.1598336512425; Mon, 24 Aug 2020 23:21:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598336512; cv=none; d=google.com; s=arc-20160816; b=ZAIwtrkCxvf4Sppp93e7RUQSTBWUvyRcXusVM+UdtXElGyuDSlQ6+4FjriE5YwKLbI A+WRo516aFjI4oENI3vanNRZQTx4l4zIuHjL2yuzN3sagEjJQJGLMEQSZK7NiNyg2dpV Zh05ZfW8mTLSGbysDr5kbHSG3jDd6W577y44XXm3VXvhZPDXFFKbBCZBquNsyqN4fKTT +IQ1NiPQCa6PNUhR7vc8Xz4Z6kWz3rXOSSYuaPHn2Jn8rrulwOmSHNRPgUeLgoUEDacW 7cbi5V0d46I9Ug++ehrWTQPbN4kKGFWPSJhj0NTuERfczVoE5fvcsJesvEpfax+CtR7V C78w== 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=MNnPxzj60sDmJ0IxS6U1REf4zt3I/5FIld8bcVSCbzc=; b=RdWOrgBExCv03wjM/ROIMiZ6YxLVi/AKzV2HstOB5JqmWsFdXqDRakImcGmYESRBR3 dpWag8zgsaO3vzcmuXcalVcs6wEUiIdPONC3afFk9DD360YzuQEysdqpvyndrDq1qRpl LzEnXClBJWrAslBjgQKjyMlV/7hB1UfKWHWCC7OqkXb7kM4laiBs6R9aoUtRPqBLM+Mn YoMnj2LdP5ynPWaYfIKiQTAAx1QtUelKt0v55AjMmkNgmhwOegaa1SOO2+pauJSeMK2k /q9iihEfJcfUrhLWURlBWp2uvew/thz7XLGq0nHg3vyHG0bCUa4I1GG1Y8Cx4g6vqwMV dECQ== 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 h12si8151936eje.650.2020.08.24.23.21.29; Mon, 24 Aug 2020 23:21:52 -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 S1728899AbgHYGNF (ORCPT + 99 others); Tue, 25 Aug 2020 02:13:05 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:51859 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726189AbgHYGNE (ORCPT ); Tue, 25 Aug 2020 02:13:04 -0400 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 Cc: Lars-Peter Clausen , Benjamin Bara - SKIDATA , "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: <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-Type: text/plain; charset=us-ascii 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-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 |