Skip to content

Commit 4f55a74

Browse files
osctobegregkh
authored andcommitted
ALSA: pcm: fix snd_pcm_link() lockdep splat
commit e18035c upstream. Add and use snd_pcm_stream_lock_nested() in snd_pcm_link/unlink implementation. The code is fine, but generates a lockdep complaint: ============================================ WARNING: possible recursive locking detected 5.7.1mq+ torvalds#381 Tainted: G O -------------------------------------------- pulseaudio/4180 is trying to acquire lock: ffff888402d6f508 (&group->lock){-...}-{2:2}, at: snd_pcm_common_ioctl+0xda8/0xee0 [snd_pcm] but task is already holding lock: ffff8883f7a8cf18 (&group->lock){-...}-{2:2}, at: snd_pcm_common_ioctl+0xe4e/0xee0 [snd_pcm] other info that might help us debug this: Possible unsafe locking scenario: CPU0 ---- lock(&group->lock); lock(&group->lock); *** DEADLOCK *** May be due to missing lock nesting notation 2 locks held by pulseaudio/4180: #0: ffffffffa1a05190 (snd_pcm_link_rwsem){++++}-{3:3}, at: snd_pcm_common_ioctl+0xca0/0xee0 [snd_pcm] #1: ffff8883f7a8cf18 (&group->lock){-...}-{2:2}, at: snd_pcm_common_ioctl+0xe4e/0xee0 [snd_pcm] [...] Cc: stable@vger.kernel.org Fixes: f57f3df ("ALSA: pcm: More fine-grained PCM link locking") Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl> Link: https://lore.kernel.org/r/37252c65941e58473b1219ca9fab03d48f47e3e3.1591610330.git.mirq-linux@rere.qmqm.pl Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent b75524c commit 4f55a74

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

sound/core/pcm_native.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ void snd_pcm_stream_lock_irq(struct snd_pcm_substream *substream)
138138
}
139139
EXPORT_SYMBOL_GPL(snd_pcm_stream_lock_irq);
140140

141+
static void snd_pcm_stream_lock_nested(struct snd_pcm_substream *substream)
142+
{
143+
struct snd_pcm_group *group = &substream->self_group;
144+
145+
if (substream->pcm->nonatomic)
146+
mutex_lock_nested(&group->mutex, SINGLE_DEPTH_NESTING);
147+
else
148+
spin_lock_nested(&group->lock, SINGLE_DEPTH_NESTING);
149+
}
150+
141151
/**
142152
* snd_pcm_stream_unlock_irq - Unlock the PCM stream
143153
* @substream: PCM substream
@@ -2200,7 +2210,7 @@ static int snd_pcm_link(struct snd_pcm_substream *substream, int fd)
22002210
snd_pcm_stream_unlock_irq(substream);
22012211

22022212
snd_pcm_group_lock_irq(target_group, nonatomic);
2203-
snd_pcm_stream_lock(substream1);
2213+
snd_pcm_stream_lock_nested(substream1);
22042214
snd_pcm_group_assign(substream1, target_group);
22052215
refcount_inc(&target_group->refs);
22062216
snd_pcm_stream_unlock(substream1);
@@ -2216,7 +2226,7 @@ static int snd_pcm_link(struct snd_pcm_substream *substream, int fd)
22162226

22172227
static void relink_to_local(struct snd_pcm_substream *substream)
22182228
{
2219-
snd_pcm_stream_lock(substream);
2229+
snd_pcm_stream_lock_nested(substream);
22202230
snd_pcm_group_assign(substream, &substream->self_group);
22212231
snd_pcm_stream_unlock(substream);
22222232
}

0 commit comments

Comments
 (0)