]> git.baikalelectronics.ru Git - kernel.git/commit
ALSA: pcm: Fix rwsem deadlock for non-atomic PCM stream
authorTakashi Iwai <tiwai@suse.de>
Wed, 17 Feb 2016 13:30:26 +0000 (14:30 +0100)
committerTakashi Iwai <tiwai@suse.de>
Thu, 18 Feb 2016 10:27:52 +0000 (11:27 +0100)
commitbc9b0b11a498b57dadafcbc83943f6a48394d282
treec5595e0762602ea68bd0761c0055f555f0c4f275
parentb983138276014bec9b0060fbea03f5f66a0aebe4
ALSA: pcm: Fix rwsem deadlock for non-atomic PCM stream

A non-atomic PCM stream may take snd_pcm_link_rwsem rw semaphore twice
in the same code path, e.g. one in snd_pcm_action_nonatomic() and
another in snd_pcm_stream_lock().  Usually this is OK, but when a
write lock is issued between these two read locks, the problem
happens: the write lock is blocked due to the first reade lock, and
the second read lock is also blocked by the write lock.  This
eventually deadlocks.

The reason is the way rwsem manages waiters; it's queued like FIFO, so
even if the writer itself doesn't take the lock yet, it blocks all the
waiters (including reads) queued after it.

As a workaround, in this patch, we replace the standard down_write()
with an spinning loop.  This is far from optimal, but it's good
enough, as the spinning time is supposed to be relatively short for
normal PCM operations, and the code paths requiring the write lock
aren't called so often.

Reported-by: Vinod Koul <vinod.koul@intel.com>
Tested-by: Ramesh Babu <ramesh.babu@intel.com>
Cc: <stable@vger.kernel.org> # v3.18+
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/core/pcm_native.c