ALSA: pcm: Apply sync-stop at SNDRV_PCM_IOCTL_DROP ioctl
PATCH 1/1 ALSA: pcm: Apply sync-stop at SNDRV_PCM_IOCTL_DROP ioctl
When a PCM stream is stopped via SNDRV_PCM_IOCTL_DROP ioctl, it calls snd_pcm_stop() but sync-stop operation is missing. Although this is usually no big issue, let's add snd_pcm_sync_stop() call, just to be sure.
--- sound/core/pcm_native.c | 2 ++ 1 file changed, 2 insertions(+)
sound/core/pcm_native.c +2 -0
@@ -2332,6 +2332,8 @@ static int snd_pcm_drop(struct snd_pcm_substream *substream) result =snd_pcm_stop (substream,SNDRV_PCM_STATE_SETUP );/* runtime->control->appl_ptr = runtime->status->hw_ptr; */ +snd_pcm_sync_stop (substream, true); +return result; }
Signature · 1 line
2.55.0
Quoted 15 lines · Takashi Iwai
When a PCM stream is stopped via
SNDRV_PCM_IOCTL_DROPioctl, it callssnd_pcm_stop()but sync-stop operation is missing. Although this is usually no big issue, let's addsnd_pcm_sync_stop()call, just to be sure.Signed-off-by Takashi Iwai <[email protected]>--- sound/core/pcm_native.c | 2 ++ 1 file changed, 2 insertions(+)sound/core/pcm_native.c +0
-0
sound/core/pcm_native.c static int snd_pcm_drop(struct snd_pcm_substream *substream) · line 2338
Quoted 7 lines
sound/core/pcm_native.c +2
-0@@ -2332,6 +2332,8 @@ static int snd_pcm_drop(struct snd_pcm_substream *substream) result =snd_pcm_stop (substream,SNDRV_PCM_STATE_SETUP );/* runtime->control->appl_ptr = runtime->status->hw_ptr; */ +snd_pcm_sync_stop (substream, true); +return result; }
This patch landed in today's linux-next as commit fdf9a21cda78 ("ALSA: pcm: Apply sync-stop at SNDRV_PCM_IOCTL_DROP ioctl"). In my tests I found that it triggers the kernel bug about invalid context for sleeping.
It looks that thissnd_pcm_sync_stop() should be called outside the scope of the guard(pcm_stream_lock_irq)(substream).
Here is log from one of my test boards:
--->8----
root@target:~# speaker-test -l1
speaker-test 1.1.3
Playback device is default
Stream parameters are 48000Hz, S16_LE, 1 channels
Using 16 octaves of pink noise
Rate set to 48000Hz (requested 48000Hz)
Buffer size range from 128 to 131072
Period size range from 64 to 65536
Using max buffer size 131072
Periods = 4
was set period_size = 32768
was set buffer_size = 131072
0 - Front Left
Time per period = 0.030588
BUG: sleeping function called from invalid context at ./include/linux/dmaengine.h:1326
in_atomic(): 1, irqs_disabled(): 128, non_block: 0, pid: 1691, name: speaker-testpreempt_count: 1, expected: 0
RCU nest depth: 0, expected: 0
locks held by speaker-test/1691: 1, last CPU#3:
#0: c22ad2a4 (&group->lock#2){..-.}-{3:3}, at: snd_pcm_drop+0x30/0xd0
irq event stamp: 10920 hardirqs last enabled at (10919): [<c0dcda30>] _raw_spin_unlock_irqrestore+0x5c/0x60 hardirqs last disabled at (10920): [<c0dcd5e0>] _raw_spin_lock_irq+0x60/0x64 softirqs last enabled at (10832): [<c0113ab4>] vfp_support_entry+0x98/0x400 softirqs last disabled at (10830): [<c0113a44>] vfp_support_entry+0x28/0x400 CPU: 3 UID: 0 PID: 1691 Comm: speaker-test Not tainted 7.3.0-rc6-00238-gfdf9a21cda78 #13903 PREEMPT Hardware name: Samsung Exynos (Flattened Device Tree) Call trace: unwind_backtrace from show_stack+0x10/0x14 show_stack from dump_stack_lvl+0x6c/0x8c dump_stack_lvl from __might_resched+0x198/0x264 __might_resched from snd_dmaengine_pcm_sync_stop+0x8c/0xac snd_dmaengine_pcm_sync_stop from snd_soc_pcm_component_sync_stop+0x3c/0x98 snd_soc_pcm_component_sync_stop from snd_pcm_drop+0x68/0xd0 snd_pcm_drop from sys_ioctl+0x508/0xc2c sys_ioctl from ret_fast_syscall+0x0/0x1c Exception stack(0xf1da1fa8 to 0xf1da1ff0)
...
root@target:~#
--->8----
Best regards
Signature · 2 lines
Marek Szyprowski, PhD Samsung R&D Institute Poland
Quoted 29 lines · Marek Szyprowski
Quoted 15 lines · Takashi Iwai
When a PCM stream is stopped via
SNDRV_PCM_IOCTL_DROPioctl, it callssnd_pcm_stop()but sync-stop operation is missing. Although this is usually no big issue, let's addsnd_pcm_sync_stop()call, just to be sure.Signed-off-by Takashi Iwai <[email protected]>--- sound/core/pcm_native.c | 2 ++ 1 file changed, 2 insertions(+)sound/core/pcm_native.c +0
-0sound/core/pcm_native.c static int snd_pcm_drop(struct snd_pcm_substream *substream) · line 2338
Quoted 7 lines
sound/core/pcm_native.c +2
-0@@ -2332,6 +2332,8 @@ static int snd_pcm_drop(struct snd_pcm_substream *substream) result =snd_pcm_stop (substream,SNDRV_PCM_STATE_SETUP );/* runtime->control->appl_ptr = runtime->status->hw_ptr; */ +snd_pcm_sync_stop (substream, true); +return result; }This patch landed in today's linux-next as commit
fdf9a21cda78("ALSA: pcm: Apply sync-stop atSNDRV_PCM_IOCTL_DROPioctl"). In my tests I found that it triggers the kernel bug about invalid context for sleeping.
Quoted 2 lines
It looks that
thissnd_pcm_sync_stop()should be called outside the scope of the guard(pcm_stream_lock_irq)(substream).
Gah, obviously it's calling in a wrong context, and I overlooked guard() line.
I'm going to submit the trivial fix.
thanks,
Takashi