]> git.baikalelectronics.ru Git - kernel.git/commit
dm bufio: avoid a possible ABBA deadlock
authorMikulas Patocka <mpatocka@redhat.com>
Sun, 30 Apr 2017 21:33:26 +0000 (17:33 -0400)
committerMike Snitzer <snitzer@redhat.com>
Mon, 1 May 2017 19:18:13 +0000 (15:18 -0400)
commit751869fc16a19b521db7767efae95344ca0a0cc4
tree7db34655122c059ee824083e4a682e229be2adc7
parenta83956dbcf8f44364293465220409b5ed8e4567b
dm bufio: avoid a possible ABBA deadlock

__get_memory_limit() tests if dm_bufio_cache_size changed and calls
__cache_size_refresh() if it did.  It takes dm_bufio_clients_lock while
it already holds the client lock.  However, lock ordering is violated
because in cleanup_old_buffers() dm_bufio_clients_lock is taken before
the client lock.

This results in a possible deadlock and lockdep engine warning.

Fix this deadlock by changing mutex_lock() to mutex_trylock().  If the
lock can't be taken, it will be re-checked next time when a new buffer
is allocated.

Also add "unlikely" to the if condition, so that the optimizer assumes
that the condition is false.

Cc: stable@vger.kernel.org
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
drivers/md/dm-bufio.c