diff options
author | Mikulas Patocka <mpatocka@redhat.com> | 2017-04-30 17:33:26 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-05-25 09:44:33 -0400 |
commit | 98e7b9d45bf443b02a7b8aacb2e502042ea88441 (patch) | |
tree | cab44445554457d80a7639034012ae5b4c297e3d /drivers/md | |
parent | c5066c4c1b7ee20538eebd48e79a93cd4963b72c (diff) |
dm bufio: avoid a possible ABBA deadlock
commit 1b0fb5a5b2dc0dddcfa575060441a7176ba7ac37 upstream.
__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.
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/md')
-rw-r--r-- | drivers/md/dm-bufio.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c index 125aedc3875f..d0745965f8ec 100644 --- a/drivers/md/dm-bufio.c +++ b/drivers/md/dm-bufio.c | |||
@@ -923,10 +923,11 @@ static void __get_memory_limit(struct dm_bufio_client *c, | |||
923 | { | 923 | { |
924 | unsigned long buffers; | 924 | unsigned long buffers; |
925 | 925 | ||
926 | if (ACCESS_ONCE(dm_bufio_cache_size) != dm_bufio_cache_size_latch) { | 926 | if (unlikely(ACCESS_ONCE(dm_bufio_cache_size) != dm_bufio_cache_size_latch)) { |
927 | mutex_lock(&dm_bufio_clients_lock); | 927 | if (mutex_trylock(&dm_bufio_clients_lock)) { |
928 | __cache_size_refresh(); | 928 | __cache_size_refresh(); |
929 | mutex_unlock(&dm_bufio_clients_lock); | 929 | mutex_unlock(&dm_bufio_clients_lock); |
930 | } | ||
930 | } | 931 | } |
931 | 932 | ||
932 | buffers = dm_bufio_cache_size_per_client >> | 933 | buffers = dm_bufio_cache_size_per_client >> |