public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [BUG] ALSA: core: possible deadlock involving waiting and locking operations
@ 2022-01-29  3:33 Jia-Ju Bai
  2022-01-29  4:27 ` Takashi Sakamoto
  0 siblings, 1 reply; 5+ messages in thread
From: Jia-Ju Bai @ 2022-01-29  3:33 UTC (permalink / raw)
  To: perex, tiwai, broonie, o-takashi; +Cc: alsa-devel, linux-kernel

Hello,

My static analysis tool reports a possible deadlock in the sound driver 
in Linux 5.10:

snd_card_disconnect_sync()
   spin_lock_irq(&card->files_lock); --> Line 461 (Lock A)
   wait_event_lock_irq(card->remove_sleep, ...); --> Line 462 (Wait X)
   spin_unlock_irq(&card->files_lock); --> Line 465 (Unlock A)

snd_hwdep_release()
   mutex_lock(&hw->open_mutex); --> Line 152 (Lock B)
   mutex_unlock(&hw->open_mutex); --> Line 157 (Unlock B)
   snd_card_file_remove()
     wake_up_all(&card->remove_sleep); --> Line 976 (Wake X)

snd_hwdep_open()
   mutex_lock(&hw->open_mutex); --> Line 95 (Lock B)
   snd_card_file_add()
     spin_lock(&card->files_lock); --> Line 932 (Lock A)
     spin_unlock(&card->files_lock); --> Line 940 (Unlock A)
   mutex_unlock(&hw->open_mutex); --> Line 139 (Unlock B)

When snd_card_disconnect_sync() is executed, "Wait X" is performed by 
holding "Lock A". If snd_hwdep_open() is executed at this time, it holds 
"Lock B" and then waits for acquiring "Lock A". If snd_hwdep_release() 
is executed at this time, it waits for acquiring "Lock B", and thus 
"Wake X" cannot be performed to wake up "Wait X" in 
snd_card_disconnect_sync(), causing a possible deadlock.

I am not quite sure whether this possible problem is real and how to fix 
it if it is real.
Any feedback would be appreciated, thanks :)


Best wishes,
Jia-Ju Bai

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

end of thread, other threads:[~2022-01-29  8:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-29  3:33 [BUG] ALSA: core: possible deadlock involving waiting and locking operations Jia-Ju Bai
2022-01-29  4:27 ` Takashi Sakamoto
2022-01-29  8:07   ` Jia-Ju Bai
2022-01-29  8:20     ` Takashi Iwai
2022-01-29  8:28       ` Jia-Ju Bai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox