zfsonlinux/spl — pull request #421 by tuxoko (2014-12-18 12:55:32+00:00)
Title: mutex: force serialization on mutex_exit() to fix races

It is known that mutex in Linux is not safe when using it to synchronize
the freeing of object in which the mutex is embedded:
http://lwn.net/Articles/575477/

The known places in ZFS which are suspected to suffer from the race condition
are zio->io_lock and dbuf->db_mtx:
zio uses zio->io_lock and zio->io_cv to synchronize freeing between zio_wait()
and zio_done().
dbuf uses dbuf->db_mtx to protect reference counting.

Add it's been reported multiple time that zio->io_lock and dbuf->db_mtx suffer
from corruption, which is exactly the symptom of the race.
https://github.com/zfsonlinux/zfs/issues/2523
https://github.com/zfsonlinux/zfs/issues/2897

This patch fix this kind of race by forcing serializaion on mutex_exit() with
a spinlock, making the mutex safer by sacrificing a bit of performance and
memory overhead.

Signed-off-by: Chunwei Chen