Skip to content

Commit

Permalink
ALSA: pcm: fix snd_pcm_link() lockdep splat
Browse files Browse the repository at this point in the history
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]
 jwrdegoede#1: ffff8883f7a8cf18 (&group->lock){-...}-{2:2}, at: snd_pcm_common_ioctl+0xe4e/0xee0 [snd_pcm]
[...]

Cc: [email protected]
Fixes: f57f3df ("ALSA: pcm: More fine-grained PCM link locking")
Signed-off-by: Michał Mirosław <[email protected]>
Link: https://lore.kernel.org/r/37252c65941e58473b1219ca9fab03d48f47e3e3.1591610330.git.mirq-linux@rere.qmqm.pl
Signed-off-by: Greg Kroah-Hartman <[email protected]>

Signed-off-by: Takashi Iwai <[email protected]>
  • Loading branch information
osctobe authored and gregkh committed Jun 17, 2020
1 parent c8b0322 commit 10c3d28
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions sound/core/pcm_native.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ void snd_pcm_stream_lock_irq(struct snd_pcm_substream *substream)
}
EXPORT_SYMBOL_GPL(snd_pcm_stream_lock_irq);

static void snd_pcm_stream_lock_nested(struct snd_pcm_substream *substream)
{
struct snd_pcm_group *group = &substream->self_group;

if (substream->pcm->nonatomic)
mutex_lock_nested(&group->mutex, SINGLE_DEPTH_NESTING);
else
spin_lock_nested(&group->lock, SINGLE_DEPTH_NESTING);
}

/**
* snd_pcm_stream_unlock_irq - Unlock the PCM stream
* @substream: PCM substream
Expand Down Expand Up @@ -2197,7 +2207,7 @@ static int snd_pcm_link(struct snd_pcm_substream *substream, int fd)
snd_pcm_stream_unlock_irq(substream);

snd_pcm_group_lock_irq(target_group, nonatomic);
snd_pcm_stream_lock(substream1);
snd_pcm_stream_lock_nested(substream1);
snd_pcm_group_assign(substream1, target_group);
refcount_inc(&target_group->refs);
snd_pcm_stream_unlock(substream1);
Expand All @@ -2213,7 +2223,7 @@ static int snd_pcm_link(struct snd_pcm_substream *substream, int fd)

static void relink_to_local(struct snd_pcm_substream *substream)
{
snd_pcm_stream_lock(substream);
snd_pcm_stream_lock_nested(substream);
snd_pcm_group_assign(substream, &substream->self_group);
snd_pcm_stream_unlock(substream);
}
Expand Down

0 comments on commit 10c3d28

Please sign in to comment.