Skip to content

Commit 9fc4a3d

Browse files
Sebastian Andrzej Siewiortiwai
authored andcommitted
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: d2d6422 ("x86: Allow to enable PREEMPT_RT.") Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 8497324 commit 9fc4a3d

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

sound/core/pcm_native.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,24 @@ void snd_pcm_group_init(struct snd_pcm_group *group)
8484
}
8585

8686
/* 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) \
8888
static void snd_pcm_group_ ## action(struct snd_pcm_group *group, bool nonatomic) \
8989
{ \
90-
if (nonatomic) \
90+
if (nonatomic) { \
9191
mutex_ ## mutex_action(&group->mutex); \
92-
else \
93-
spin_ ## action(&group->lock); \
94-
}
95-
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);
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+
} \
99+
}
100+
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);
100105

101106
/**
102107
* snd_pcm_stream_lock - Lock the PCM stream

0 commit comments

Comments
 (0)