mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jia-Ju Bai <baijiaju1990@gmail.com>
To: perex@perex.cz, tiwai@suse.com, broonie@kernel.org,
	o-takashi@sakamocchi.jp
Cc: alsa-devel@alsa-project.org, linux-kernel <linux-kernel@vger.kernel.org>
Subject: [BUG] ALSA: core: possible deadlock involving waiting and locking operations
Date: Sat, 29 Jan 2022 11:33:26 +0800	[thread overview]
Message-ID: <56766037-972e-9e5b-74c1-88633a72a77f@gmail.com> (raw)

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

             reply	other threads:[~2022-01-29  3:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-29  3:33 Jia-Ju Bai [this message]
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

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=56766037-972e-9e5b-74c1-88633a72a77f@gmail.com \
    --to=baijiaju1990@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=o-takashi@sakamocchi.jp \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.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®