From mboxrd@z Thu Jan 1 00:00:00 1970 From: Lars-Peter Clausen Subject: Re: [PATCH 1/4] dmaengine: Add transfer termination synchronization support Date: Fri, 30 Oct 2015 15:16:13 +0100 Message-ID: <56337BAD.2060506@metafoo.de> References: <1445334391-12272-1-git-send-email-lars@metafoo.de> <1445334391-12272-2-git-send-email-lars@metafoo.de> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from smtp-out-188.synserver.de (smtp-out-218.synserver.de [212.40.185.218]) by alsa0.perex.cz (Postfix) with ESMTP id 17BB62604BE for ; Fri, 30 Oct 2015 15:16:17 +0100 (CET) In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org To: Andy Shevchenko Cc: alsa-devel@alsa-project.org, Shengjiu Wang , Kuninori Morimoto , Vinod Koul , Takashi Iwai , "linux-kernel@vger.kernel.org" , Qiao Zhou , Laurent Pinchart , Matt Campbell , dmaengine , Russell King , Dan Williams , Jonah Petri List-Id: alsa-devel@alsa-project.org On 10/29/2015 10:59 PM, Andy Shevchenko wrote: > On Tue, Oct 20, 2015 at 12:46 PM, Lars-Peter Clausen wrote: >> The DMAengine API has a long standing race condition that is inherent to >> the API itself. Calling dmaengine_terminate_all() is supposed to stop and >> abort any pending or active transfers that have previously been submitted. >> Unfortunately it is possible that this operation races against a currently >> running (or with some drivers also scheduled) completion callback. > > [] > >> +/** >> + * dmaengine_terminate_sync() - Terminate all active DMA transfers >> + * @chan: The channel for which to terminate the transfers >> + * >> + * Calling this function will terminate all active and pending transfers >> + * that have previously been submitted to the channel. It is similar to >> + * dmaengine_terminate_async() but guarantees that the DMA transfer has actually >> + * stopped and that all complete callbacks have finished running when the >> + * function returns. >> + * >> + * This function must only be called from non-atomic context and must not be >> + * called from within a complete callback of a descriptor submitted on the same >> + * channel. >> + */ >> +static inline int dmaengine_terminate_sync(struct dma_chan *chan) >> +{ >> + int ret; > > Might be a good idea to add might_sleep(); here. Sound like a good idea, thanks, I'll add it (in dmaengine_synchronize() though). > >> + >> + ret = dmaengine_terminate_async(chan); >> + if (ret) >> + return ret; >> + >> + dmaengine_synchronize(chan); >> + >> + return 0; >> +} > >