Re: [PATCH] ALSA: sb: fix potential deadlock on &chip->mixer_lock

From: 叶澄锋
Date: Tue Jun 27 2023 - 06:55:48 EST


Oh yes, sorry for not considering that one.

Best regards
Chengfeng

Takashi Iwai <tiwai@xxxxxxx> 于2023年6月27日周二 18:01写道:
>
> On Tue, 27 Jun 2023 11:56:16 +0200,
> Chengfeng Ye wrote:
> >
> > As &chip->mixer_lock is also acquired by the irq snd_sb8dsp_interrupt()
> > which executes under hard-irq context, code executing under process
> > context should disable irq before acquiring the lock, otherwise
> > deadlock could happen if the process context hold the lock then
> > preempt by the interruption.
> >
> > As the ALSA Driver document described, PCM prepare callbacks are not
> > executed with irq disabled by default, thus the acquiring of
> > &chip->mixer_lock should be irq disabled.
> >
> > Possible deadlock scenario:
> > snd_sb8_playback_prepare
> > -> spin_lock(&chip->mixer_lock);
> > <irq interrupt>
> > -> snd_sb8dsp_interrupt()
> > -> snd_sb8_capture_trigger()
> > -> spin_lock(&chip->mixer_lock); (deadlock here)
> >
> > This flaw was found using an experimental static analysis tool we are
> > developing for irq-related deadlock.
> >
> > The tentative patch fix the potential deadlock by spin_lock_irqsave().
> >
> > Signed-off-by: Chengfeng Ye <dg573847474@xxxxxxxxx>
>
> I believe it's a false-positive. There is already a call
> spin_lock_irqsave(&chip->reg_lock, flags);
> beforehand.
>
>
> thanks,
>
> Takashi