• Mikulas Patocka's avatar
    dm bufio: avoid a possible ABBA deadlock · bbe86592
    Mikulas Patocka authored
    [ Upstream commit 1b0fb5a5 ]
    
    __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: default avatarMikulas Patocka <mpatocka@redhat.com>
    Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
    Signed-off-by: default avatarSasha Levin <alexander.levin@verizon.com>
    bbe86592
dm-bufio.c 46.1 KB