linux-stable/sound/core
Takashi Iwai 2f103287ef ALSA: Fix deadlocks with kctl removals at disconnection
commit 87988a534d upstream.

In snd_card_disconnect(), we set card->shutdown flag at the beginning,
call callbacks and do sync for card->power_ref_sleep waiters at the
end.  The callback may delete a kctl element, and this can lead to a
deadlock when the device was in the suspended state.  Namely:

* A process waits for the power up at snd_power_ref_and_wait() in
  snd_ctl_info() or read/write() inside card->controls_rwsem.

* The system gets disconnected meanwhile, and the driver tries to
  delete a kctl via snd_ctl_remove*(); it tries to take
  card->controls_rwsem again, but this is already locked by the
  above.  Since the sleeper isn't woken up, this deadlocks.

An easy fix is to wake up sleepers before processing the driver
disconnect callbacks but right after setting the card->shutdown flag.
Then all sleepers will abort immediately, and the code flows again.

So, basically this patch moves the wait_event() call at the right
timing.  While we're at it, just to be sure, call wait_event_all()
instead of wait_event(), although we don't use exclusive events on
this queue for now.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=218816
Cc: <stable@vger.kernel.org>
Reviewed-by: Jaroslav Kysela <perex@perex.cz>
Link: https://lore.kernel.org/r/20240510101424.6279-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-06-12 11:11:21 +02:00
..
oss ALSA: control: Introduce unlocked version for snd_ctl_find_*() helpers 2023-07-20 10:03:00 +02:00
seq ALSA: seq: ump: Fix conversion from MIDI2 to MIDI1 UMP messages 2024-04-27 17:11:38 +02:00
compress_offload.c ALSA: compress: Don't embed device 2023-08-17 09:24:15 +02:00
control.c ALSA: control: Don't embed ctl_dev 2023-08-17 09:23:30 +02:00
control_compat.c ALSA: control: Introduce unlocked version for snd_ctl_find_*() helpers 2023-07-20 10:03:00 +02:00
control_led.c ALSA: control: Don't embed ctl_dev 2023-08-17 09:23:30 +02:00
ctljack.c
device.c
hrtimer.c
hwdep.c ALSA: hwdep: Don't embed device 2023-08-17 09:24:01 +02:00
hwdep_compat.c
info.c ALSA: info: Fix potential deadlock at disconnection 2023-11-28 17:20:10 +00:00
info_oss.c
init.c ALSA: Fix deadlocks with kctl removals at disconnection 2024-06-12 11:11:21 +02:00
isadma.c
jack.c ALSA: control: Take controls_rwsem lock in snd_ctl_remove() 2023-07-20 10:01:27 +02:00
Kconfig
Makefile ALSA: Drop leftover snd-rtctimer stuff from Makefile 2024-03-06 14:48:37 +00:00
memalloc.c
memalloc_local.h
memory.c ALSA: core: Add memory copy helpers between iov_iter and iomem 2023-08-18 12:18:16 +02:00
misc.c
pcm.c ALSA: pcm: fix out-of-bounds in snd_pcm_state_names 2023-12-13 18:45:20 +01:00
pcm_compat.c ALSA: pcm: Fix missing fixup call in compat hw_refine ioctl 2023-08-29 16:03:11 +02:00
pcm_dmaengine.c
pcm_drm_eld.c
pcm_iec958.c
pcm_lib.c ALSA: pcm: Fix error checks of default read/write copy ops 2023-09-02 08:11:48 +02:00
pcm_local.h
pcm_memory.c
pcm_misc.c
pcm_native.c ALSA: pcm: Drop obsoleted PCM copy_user and copy_kernel ops 2023-08-18 12:19:19 +02:00
pcm_param_trace.h
pcm_timer.c
pcm_trace.h
rawmidi.c ALSA: rawmidi: Fix NULL dereference at proc read 2023-09-16 08:08:05 +02:00
rawmidi_compat.c
seq_device.c
sound.c
sound_oss.c
timer.c ALSA: timer: Create device with snd_device_alloc() 2023-08-17 09:24:21 +02:00
timer_compat.c
ump.c ALSA: ump: Fix the discard error code from snd_ump_legacy_open() 2024-03-06 14:48:39 +00:00
ump_convert.c
vmaster.c ALSA: vmaster: Add snd_ctl_add_followers() helper 2023-07-21 09:37:47 +02:00