mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: "Lars-Peter Clausen" <lars@metafoo.de>
Cc: "Vinod Koul" <vinod.koul@intel.com>,
	<alsa-devel@alsa-project.org>,
	"Russell King" <rmk+kernel@arm.linux.org.uk>,
	"Shengjiu Wang" <shengjiu.wang@freescale.com>,
	"Laurent Pinchart" <renesas@ideasonboard.com>,
	"Dan Williams" <dan.j.williams@intel.com>,
	"Jonah Petri" <jpetri@izotope.com>,
	"Matt Campbell" <mcampbell@izotope.com>,
	"Qiao Zhou" <zhouqiao@marvell.com>,
	"Kuninori Morimoto" <kuninori.morimoto.gx@renesas.com>,
	<dmaengine@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 4/4] ALSA: pcm_dmaengine: Properly synchronize DMA on shutdown
Date: Tue, 20 Oct 2015 13:17:11 +0200	[thread overview]
Message-ID: <s5h37x5g56w.wl-tiwai@suse.de> (raw)
In-Reply-To: <1445334391-12272-5-git-send-email-lars@metafoo.de>

On Tue, 20 Oct 2015 11:46:31 +0200,
Lars-Peter Clausen wrote:
> 
> Use the new dmaengine_synchronize() function to make sure that all complete
> callbacks have finished running before the runtime data, which is accessed
> in the completed callback, is freed.
> 
> This fixes a long standing use-after-free race condition that has been
> observed on some systems.

What if a substream is restarted immediately after the stop?


Takashi

> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> ---
>  sound/core/pcm_dmaengine.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/sound/core/pcm_dmaengine.c b/sound/core/pcm_dmaengine.c
> index fba365a..697c166 100644
> --- a/sound/core/pcm_dmaengine.c
> +++ b/sound/core/pcm_dmaengine.c
> @@ -202,13 +202,13 @@ int snd_dmaengine_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
>  		if (runtime->info & SNDRV_PCM_INFO_PAUSE)
>  			dmaengine_pause(prtd->dma_chan);
>  		else
> -			dmaengine_terminate_all(prtd->dma_chan);
> +			dmaengine_terminate_async(prtd->dma_chan);
>  		break;
>  	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
>  		dmaengine_pause(prtd->dma_chan);
>  		break;
>  	case SNDRV_PCM_TRIGGER_STOP:
> -		dmaengine_terminate_all(prtd->dma_chan);
> +		dmaengine_terminate_async(prtd->dma_chan);
>  		break;
>  	default:
>  		return -EINVAL;
> @@ -346,6 +346,7 @@ int snd_dmaengine_pcm_close(struct snd_pcm_substream *substream)
>  {
>  	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
>  
> +	dmaengine_synchronize(prtd->dma_chan);
>  	kfree(prtd);
>  
>  	return 0;
> @@ -362,9 +363,11 @@ int snd_dmaengine_pcm_close_release_chan(struct snd_pcm_substream *substream)
>  {
>  	struct dmaengine_pcm_runtime_data *prtd = substream_to_prtd(substream);
>  
> +	dmaengine_synchronize(prtd->dma_chan);
>  	dma_release_channel(prtd->dma_chan);
> +	kfree(prtd);
>  
> -	return snd_dmaengine_pcm_close(substream);
> +	return 0;
>  }
>  EXPORT_SYMBOL_GPL(snd_dmaengine_pcm_close_release_chan);
>  
> -- 
> 2.1.4
> 
> 

  reply	other threads:[~2015-10-20 11:17 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-20  9:46 [PATCH 0/4] dmaengine: Add transfer termination synchronization support Lars-Peter Clausen
2015-10-20  9:46 ` [PATCH 1/4] " Lars-Peter Clausen
2015-10-29 21:59   ` Andy Shevchenko
2015-10-30 14:16     ` Lars-Peter Clausen
2015-10-20  9:46 ` [PATCH 2/4] dmaengine: virt-dma: Add synchronization helper function Lars-Peter Clausen
2015-10-20  9:46 ` [PATCH 3/4] dmaengine: axi_dmac: Add synchronization support Lars-Peter Clausen
2015-10-20  9:46 ` [PATCH 4/4] ALSA: pcm_dmaengine: Properly synchronize DMA on shutdown Lars-Peter Clausen
2015-10-20 11:17   ` Takashi Iwai [this message]
2015-10-20 11:40     ` Lars-Peter Clausen
2015-10-20 12:36       ` Takashi Iwai
2015-10-20 13:01       ` Lars-Peter Clausen
2015-10-29  1:26 ` [PATCH 0/4] dmaengine: Add transfer termination synchronization support Vinod Koul

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=s5h37x5g56w.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=dan.j.williams@intel.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=jpetri@izotope.com \
    --cc=kuninori.morimoto.gx@renesas.com \
    --cc=lars@metafoo.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcampbell@izotope.com \
    --cc=renesas@ideasonboard.com \
    --cc=rmk+kernel@arm.linux.org.uk \
    --cc=shengjiu.wang@freescale.com \
    --cc=vinod.koul@intel.com \
    --cc=zhouqiao@marvell.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®