Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ALSA: pcm: Disable bottom softirqs as part of spin_lock_irq() on PREEMPT_RT

snd_pcm_group_lock_irq() acquires a spinlock_t and disables interrupts
via spin_lock_irq(). This also implicitly disables the handling of
softirqs such as TIMER_SOFTIRQ.
On PREEMPT_RT softirqs are preemptible and spin_lock_irq() does not
disable them. That means a timer can be invoked during spin_lock_irq()
on the same CPU. Due to synchronisations reasons local_bh_disable() has
a per-CPU lock named softirq_ctrl.lock which synchronizes individual
softirq against each other.
syz-bot managed to trigger a lockdep report where softirq_ctrl.lock is
acquired in hrtimer_cancel() in addition to hrtimer_run_softirq(). This
is a possible deadlock.

The softirq_ctrl.lock can not be made part of spin_lock_irq() as this
would lead to too much synchronisation against individual threads on the
system. To avoid the possible deadlock, softirqs must be manually
disabled before the lock is acquired.

Disable softirqs before the lock is acquired on PREEMPT_RT.

Reported-by: syzbot+10b4363fb0f46527f3f3@syzkaller.appspotmail.com
Fixes: d2d6422f8bd1 ("x86: Allow to enable PREEMPT_RT.")
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>

authored by

Sebastian Andrzej Siewior and committed by
Takashi Iwai
9fc4a3da 84973249

+13 -8
+13 -8
sound/core/pcm_native.c
··· 84 84 } 85 85 86 86 /* define group lock helpers */ 87 - #define DEFINE_PCM_GROUP_LOCK(action, mutex_action) \ 87 + #define DEFINE_PCM_GROUP_LOCK(action, bh_lock, bh_unlock, mutex_action) \ 88 88 static void snd_pcm_group_ ## action(struct snd_pcm_group *group, bool nonatomic) \ 89 89 { \ 90 - if (nonatomic) \ 90 + if (nonatomic) { \ 91 91 mutex_ ## mutex_action(&group->mutex); \ 92 - else \ 93 - spin_ ## action(&group->lock); \ 92 + } else { \ 93 + if (IS_ENABLED(CONFIG_PREEMPT_RT) && bh_lock) \ 94 + local_bh_disable(); \ 95 + spin_ ## action(&group->lock); \ 96 + if (IS_ENABLED(CONFIG_PREEMPT_RT) && bh_unlock) \ 97 + local_bh_enable(); \ 98 + } \ 94 99 } 95 100 96 - DEFINE_PCM_GROUP_LOCK(lock, lock); 97 - DEFINE_PCM_GROUP_LOCK(unlock, unlock); 98 - DEFINE_PCM_GROUP_LOCK(lock_irq, lock); 99 - DEFINE_PCM_GROUP_LOCK(unlock_irq, unlock); 101 + DEFINE_PCM_GROUP_LOCK(lock, false, false, lock); 102 + DEFINE_PCM_GROUP_LOCK(unlock, false, false, unlock); 103 + DEFINE_PCM_GROUP_LOCK(lock_irq, true, false, lock); 104 + DEFINE_PCM_GROUP_LOCK(unlock_irq, false, true, unlock); 100 105 101 106 /** 102 107 * snd_pcm_stream_lock - Lock the PCM stream