diff options
author | Mikulas Patocka <mpatocka@redhat.com> | 2017-04-30 17:33:26 -0400 |
---|---|---|
committer | Sasha Levin <alexander.levin@verizon.com> | 2017-05-17 15:08:24 -0400 |
commit | bbe86592f9c33a5a34bed9b02d7ec1a6e5a287ec (patch) | |
tree | 103f6a6a74c23bdaeb8bcaf0257bcc39c23f412a /drivers/md | |
parent | 9575253a91e6fb3cb88ba95e7802c6b0aa215c7e (diff) |
dm bufio: avoid a possible ABBA deadlock
[ Upstream commit 1b0fb5a5b2dc0dddcfa575060441a7176ba7ac37 ]
__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>
Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
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 86dbbc737402..d86ded2a7949 100644 --- a/drivers/md/dm-bufio.c +++ b/drivers/md/dm-bufio.c @@ -908,10 +908,11 @@ static void __get_memory_limit(struct dm_bufio_client *c, { unsigned long buffers; - if (ACCESS_ONCE(dm_bufio_cache_size) != dm_bufio_cache_size_latch) { - mutex_lock(&dm_bufio_clients_lock); - __cache_size_refresh(); - mutex_unlock(&dm_bufio_clients_lock); + if (unlikely(ACCESS_ONCE(dm_bufio_cache_size) != dm_bufio_cache_size_latch)) { + if (mutex_trylock(&dm_bufio_clients_lock)) { + __cache_size_refresh(); + mutex_unlock(&dm_bufio_clients_lock); + } } buffers = dm_bufio_cache_size_per_client >> |