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>
This commit is contained in:
parent
86331f39a5
commit
1b0fb5a5b2
@ -940,11 +940,12 @@ static void __get_memory_limit(struct dm_bufio_client *c,
|
|||||||
{
|
{
|
||||||
unsigned long buffers;
|
unsigned long buffers;
|
||||||
|
|
||||||
if (ACCESS_ONCE(dm_bufio_cache_size) != dm_bufio_cache_size_latch) {
|
if (unlikely(ACCESS_ONCE(dm_bufio_cache_size) != dm_bufio_cache_size_latch)) {
|
||||||
mutex_lock(&dm_bufio_clients_lock);
|
if (mutex_trylock(&dm_bufio_clients_lock)) {
|
||||||
__cache_size_refresh();
|
__cache_size_refresh();
|
||||||
mutex_unlock(&dm_bufio_clients_lock);
|
mutex_unlock(&dm_bufio_clients_lock);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
buffers = dm_bufio_cache_size_per_client >>
|
buffers = dm_bufio_cache_size_per_client >>
|
||||||
(c->sectors_per_block_bits + SECTOR_SHIFT);
|
(c->sectors_per_block_bits + SECTOR_SHIFT);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user