All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ASoC: pcm: Sync delayed work before releasing resources
@ 2017-08-25 10:04 Takashi Iwai
  2017-09-26  0:39 ` Kuninori Morimoto
  2017-09-27 17:10 ` Applied "ASoC: pcm: Sync delayed work before releasing resources" to the asoc tree Mark Brown
  0 siblings, 2 replies; 5+ messages in thread
From: Takashi Iwai @ 2017-08-25 10:04 UTC (permalink / raw)
  To: Mark Brown; +Cc: alsa-devel, Kuninori Morimoto

When ASoC driver is unbound dynamically during its operation (i.e. a
kind of hot-unplug), we may hit Oops due to the resource access after
the release by a delayed work, something like:

  Unable to handle kernel paging request at virtual address dead000000000220
  ....
  PC is at soc_dapm_dai_stream_event.isra.14+0x20/0xd0
  LR is at snd_soc_dapm_stream_event+0x74/0xa8
  ....
  [<ffff000008715610>] soc_dapm_dai_stream_event.isra.14+0x20/0xd0
  [<ffff00000871989c>] snd_soc_dapm_stream_event+0x74/0xa8
  [<ffff00000871b23c>] close_delayed_work+0x3c/0x50
  [<ffff0000080bbd6c>] process_one_work+0x1ac/0x318
  [<ffff0000080bbf20>] worker_thread+0x48/0x420
  [<ffff0000080c201c>] kthread+0xfc/0x128
  [<ffff0000080842f0>] ret_from_fork+0x10/0x18

For fixing the race, this patch adds a sync-point in pcm private_free
callback to finish the delayed work before actually releasing the
resources.

Reported-by: Hiep Cao Minh <cm-hiep@jinso.co.jp>
Reported-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Tested-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/soc/soc-pcm.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index 94b88b897c3b..c0f0b09cb433 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -2632,6 +2632,17 @@ static int dpcm_fe_dai_close(struct snd_pcm_substream *fe_substream)
 	return ret;
 }
 
+static void soc_pcm_private_free(struct snd_pcm *pcm)
+{
+	struct snd_soc_pcm_runtime *rtd = pcm->private_data;
+	struct snd_soc_platform *platform = rtd->platform;
+
+	/* need to sync the delayed work before releasing resources */
+	flush_delayed_work(&rtd->delayed_work);
+	if (platform->driver->pcm_free)
+		platform->driver->pcm_free(pcm);
+}
+
 /* create a new pcm */
 int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
 {
@@ -2757,7 +2768,7 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
 		}
 	}
 
-	pcm->private_free = platform->driver->pcm_free;
+	pcm->private_free = soc_pcm_private_free;
 out:
 	dev_info(rtd->card->dev, "%s <-> %s mapping ok\n",
 		 (rtd->num_codecs > 1) ? "multicodec" : rtd->codec_dai->name,
-- 
2.14.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] ASoC: pcm: Sync delayed work before releasing resources
  2017-08-25 10:04 [PATCH] ASoC: pcm: Sync delayed work before releasing resources Takashi Iwai
@ 2017-09-26  0:39 ` Kuninori Morimoto
  2017-09-26 16:13   ` Mark Brown
  2017-09-27 17:10 ` Applied "ASoC: pcm: Sync delayed work before releasing resources" to the asoc tree Mark Brown
  1 sibling, 1 reply; 5+ messages in thread
From: Kuninori Morimoto @ 2017-09-26  0:39 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel, Mark Brown


Hi Mark

> When ASoC driver is unbound dynamically during its operation (i.e. a
> kind of hot-unplug), we may hit Oops due to the resource access after
> the release by a delayed work, something like:
> 
>   Unable to handle kernel paging request at virtual address dead000000000220
>   ....
>   PC is at soc_dapm_dai_stream_event.isra.14+0x20/0xd0
>   LR is at snd_soc_dapm_stream_event+0x74/0xa8
>   ....
>   [<ffff000008715610>] soc_dapm_dai_stream_event.isra.14+0x20/0xd0
>   [<ffff00000871989c>] snd_soc_dapm_stream_event+0x74/0xa8
>   [<ffff00000871b23c>] close_delayed_work+0x3c/0x50
>   [<ffff0000080bbd6c>] process_one_work+0x1ac/0x318
>   [<ffff0000080bbf20>] worker_thread+0x48/0x420
>   [<ffff0000080c201c>] kthread+0xfc/0x128
>   [<ffff0000080842f0>] ret_from_fork+0x10/0x18
> 
> For fixing the race, this patch adds a sync-point in pcm private_free
> callback to finish the delayed work before actually releasing the
> resources.
> 
> Reported-by: Hiep Cao Minh <cm-hiep@jinso.co.jp>
> Reported-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> Tested-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> Signed-off-by: Takashi Iwai <tiwai@suse.de>
> ---

This patch solved my issue, can you consider this ?

Best regards
---
Kuninori Morimoto

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ASoC: pcm: Sync delayed work before releasing resources
  2017-09-26  0:39 ` Kuninori Morimoto
@ 2017-09-26 16:13   ` Mark Brown
  2017-09-27  0:46     ` Kuninori Morimoto
  0 siblings, 1 reply; 5+ messages in thread
From: Mark Brown @ 2017-09-26 16:13 UTC (permalink / raw)
  To: Kuninori Morimoto; +Cc: Takashi Iwai, alsa-devel


[-- Attachment #1.1: Type: text/plain, Size: 649 bytes --]

On Tue, Sep 26, 2017 at 12:39:14AM +0000, Kuninori Morimoto wrote:

> This patch solved my issue, can you consider this ?

Please don't send content free pings and please allow a reasonable time
for review.  People get busy, go on holiday, attend conferences and so 
on so unless there is some reason for urgency (like critical bug fixes)
please allow at least a couple of weeks for review.  If there have been
review comments then people may be waiting for those to be addressed.
Sending content free pings just adds to the mail volume (if they are
seen at all) and if something has gone wrong you'll have to resend the
patches anyway.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ASoC: pcm: Sync delayed work before releasing resources
  2017-09-26 16:13   ` Mark Brown
@ 2017-09-27  0:46     ` Kuninori Morimoto
  0 siblings, 0 replies; 5+ messages in thread
From: Kuninori Morimoto @ 2017-09-27  0:46 UTC (permalink / raw)
  To: Mark Brown; +Cc: Takashi Iwai, alsa-devel


Hi Mark

> > This patch solved my issue, can you consider this ?
> 
> Please don't send content free pings and please allow a reasonable time
> for review.  People get busy, go on holiday, attend conferences and so 
> on so unless there is some reason for urgency (like critical bug fixes)
> please allow at least a couple of weeks for review.  If there have been
> review comments then people may be waiting for those to be addressed.
> Sending content free pings just adds to the mail volume (if they are
> seen at all) and if something has gone wrong you'll have to resend the
> patches anyway.

Sorry for my noise.
I will wait more

Best regards
---
Kuninori Morimoto

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Applied "ASoC: pcm: Sync delayed work before releasing resources" to the asoc tree
  2017-08-25 10:04 [PATCH] ASoC: pcm: Sync delayed work before releasing resources Takashi Iwai
  2017-09-26  0:39 ` Kuninori Morimoto
@ 2017-09-27 17:10 ` Mark Brown
  1 sibling, 0 replies; 5+ messages in thread
From: Mark Brown @ 2017-09-27 17:10 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: Hiep Cao Minh, alsa-devel, Mark Brown, Kuninori Morimoto

The patch

   ASoC: pcm: Sync delayed work before releasing resources

has been applied to the asoc tree at

   git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git 

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

>From 5d61f0ba6524dcbad198126e5793157c8afdea91 Mon Sep 17 00:00:00 2001
From: Takashi Iwai <tiwai@suse.de>
Date: Fri, 25 Aug 2017 12:04:07 +0200
Subject: [PATCH] ASoC: pcm: Sync delayed work before releasing resources

When ASoC driver is unbound dynamically during its operation (i.e. a
kind of hot-unplug), we may hit Oops due to the resource access after
the release by a delayed work, something like:

  Unable to handle kernel paging request at virtual address dead000000000220
  ....
  PC is at soc_dapm_dai_stream_event.isra.14+0x20/0xd0
  LR is at snd_soc_dapm_stream_event+0x74/0xa8
  ....
  [<ffff000008715610>] soc_dapm_dai_stream_event.isra.14+0x20/0xd0
  [<ffff00000871989c>] snd_soc_dapm_stream_event+0x74/0xa8
  [<ffff00000871b23c>] close_delayed_work+0x3c/0x50
  [<ffff0000080bbd6c>] process_one_work+0x1ac/0x318
  [<ffff0000080bbf20>] worker_thread+0x48/0x420
  [<ffff0000080c201c>] kthread+0xfc/0x128
  [<ffff0000080842f0>] ret_from_fork+0x10/0x18

For fixing the race, this patch adds a sync-point in pcm private_free
callback to finish the delayed work before actually releasing the
resources.

Reported-by: Hiep Cao Minh <cm-hiep@jinso.co.jp>
Reported-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Tested-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 sound/soc/soc-pcm.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index 94b88b897c3b..c0f0b09cb433 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -2632,6 +2632,17 @@ static int dpcm_fe_dai_close(struct snd_pcm_substream *fe_substream)
 	return ret;
 }
 
+static void soc_pcm_private_free(struct snd_pcm *pcm)
+{
+	struct snd_soc_pcm_runtime *rtd = pcm->private_data;
+	struct snd_soc_platform *platform = rtd->platform;
+
+	/* need to sync the delayed work before releasing resources */
+	flush_delayed_work(&rtd->delayed_work);
+	if (platform->driver->pcm_free)
+		platform->driver->pcm_free(pcm);
+}
+
 /* create a new pcm */
 int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
 {
@@ -2757,7 +2768,7 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
 		}
 	}
 
-	pcm->private_free = platform->driver->pcm_free;
+	pcm->private_free = soc_pcm_private_free;
 out:
 	dev_info(rtd->card->dev, "%s <-> %s mapping ok\n",
 		 (rtd->num_codecs > 1) ? "multicodec" : rtd->codec_dai->name,
-- 
2.14.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-09-27 17:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-25 10:04 [PATCH] ASoC: pcm: Sync delayed work before releasing resources Takashi Iwai
2017-09-26  0:39 ` Kuninori Morimoto
2017-09-26 16:13   ` Mark Brown
2017-09-27  0:46     ` Kuninori Morimoto
2017-09-27 17:10 ` Applied "ASoC: pcm: Sync delayed work before releasing resources" to the asoc tree Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.