Skip to content

Commit 3c75c0e

Browse files
tiwaibroonie
authored andcommitted
ASoC: soc-pcm: Fix DPCM lockdep warning due to nested stream locks
The recent change for DPCM locking caused spurious lockdep warnings. Actually the warnings are false-positive, as those are triggered due to the nested stream locks for FE and BE. Since both locks belong to the same lock class, lockdep sees it as if a deadlock. For fixing this, we need to take PCM stream locks for BE with the nested lock primitives. Since currently snd_pcm_stream_lock*() helper assumes only the top-level single locking, a new helper function snd_pcm_stream_lock_irqsave_nested() is defined for a single-depth nested lock, which is now used in the BE DAI trigger that is always performed inside a FE stream lock. Fixes: b2ae806 ("ASoC: soc-pcm: serialize BE triggers") Reported-and-tested-by: Hans de Goede <[email protected]> Reported-and-tested-by: Marek Szyprowski <[email protected]> Link: https://lore.kernel.org/r/[email protected] Link: https://lore.kernel.org/alsa-devel/[email protected] Signed-off-by: Takashi Iwai <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent fb25621 commit 3c75c0e

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

include/sound/pcm.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@ void snd_pcm_stream_unlock(struct snd_pcm_substream *substream);
614614
void snd_pcm_stream_lock_irq(struct snd_pcm_substream *substream);
615615
void snd_pcm_stream_unlock_irq(struct snd_pcm_substream *substream);
616616
unsigned long _snd_pcm_stream_lock_irqsave(struct snd_pcm_substream *substream);
617+
unsigned long _snd_pcm_stream_lock_irqsave_nested(struct snd_pcm_substream *substream);
617618

618619
/**
619620
* snd_pcm_stream_lock_irqsave - Lock the PCM stream
@@ -632,6 +633,20 @@ unsigned long _snd_pcm_stream_lock_irqsave(struct snd_pcm_substream *substream);
632633
void snd_pcm_stream_unlock_irqrestore(struct snd_pcm_substream *substream,
633634
unsigned long flags);
634635

636+
/**
637+
* snd_pcm_stream_lock_irqsave_nested - Single-nested PCM stream locking
638+
* @substream: PCM substream
639+
* @flags: irq flags
640+
*
641+
* This locks the PCM stream like snd_pcm_stream_lock_irqsave() but with
642+
* the single-depth lockdep subclass.
643+
*/
644+
#define snd_pcm_stream_lock_irqsave_nested(substream, flags) \
645+
do { \
646+
typecheck(unsigned long, flags); \
647+
flags = _snd_pcm_stream_lock_irqsave_nested(substream); \
648+
} while (0)
649+
635650
/**
636651
* snd_pcm_group_for_each_entry - iterate over the linked substreams
637652
* @s: the iterator

sound/core/pcm_native.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,19 @@ unsigned long _snd_pcm_stream_lock_irqsave(struct snd_pcm_substream *substream)
172172
}
173173
EXPORT_SYMBOL_GPL(_snd_pcm_stream_lock_irqsave);
174174

175+
unsigned long _snd_pcm_stream_lock_irqsave_nested(struct snd_pcm_substream *substream)
176+
{
177+
unsigned long flags = 0;
178+
if (substream->pcm->nonatomic)
179+
mutex_lock_nested(&substream->self_group.mutex,
180+
SINGLE_DEPTH_NESTING);
181+
else
182+
spin_lock_irqsave_nested(&substream->self_group.lock, flags,
183+
SINGLE_DEPTH_NESTING);
184+
return flags;
185+
}
186+
EXPORT_SYMBOL_GPL(_snd_pcm_stream_lock_irqsave_nested);
187+
175188
/**
176189
* snd_pcm_stream_unlock_irqrestore - Unlock the PCM stream
177190
* @substream: PCM substream

sound/soc/soc-pcm.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ static inline void snd_soc_dpcm_stream_lock_irq(struct snd_soc_pcm_runtime *rtd,
4646
snd_pcm_stream_lock_irq(snd_soc_dpcm_get_substream(rtd, stream));
4747
}
4848

49-
#define snd_soc_dpcm_stream_lock_irqsave(rtd, stream, flags) \
50-
snd_pcm_stream_lock_irqsave(snd_soc_dpcm_get_substream(rtd, stream), flags)
49+
#define snd_soc_dpcm_stream_lock_irqsave_nested(rtd, stream, flags) \
50+
snd_pcm_stream_lock_irqsave_nested(snd_soc_dpcm_get_substream(rtd, stream), flags)
5151

5252
static inline void snd_soc_dpcm_stream_unlock_irq(struct snd_soc_pcm_runtime *rtd,
5353
int stream)
@@ -2094,7 +2094,7 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
20942094
be = dpcm->be;
20952095
be_substream = snd_soc_dpcm_get_substream(be, stream);
20962096

2097-
snd_soc_dpcm_stream_lock_irqsave(be, stream, flags);
2097+
snd_soc_dpcm_stream_lock_irqsave_nested(be, stream, flags);
20982098

20992099
/* is this op for this BE ? */
21002100
if (!snd_soc_dpcm_be_can_update(fe, be, stream))

0 commit comments

Comments
 (0)