Skip to content
  • Dexuan Cui's avatar
    vsock: Fix a lockdep warning in __vsock_release() · 0d9138ff
    Dexuan Cui authored
    
    
    Lockdep is unhappy if two locks from the same class are held.
    
    Fix the below warning for hyperv and virtio sockets (vmci socket code
    doesn't have the issue) by using lock_sock_nested() when __vsock_release()
    is called recursively:
    
    ============================================
    WARNING: possible recursive locking detected
    5.3.0+ #1 Not tainted
    --------------------------------------------
    server/1795 is trying to acquire lock:
    ffff8880c5158990 (sk_lock-AF_VSOCK){+.+.}, at: hvs_release+0x10/0x120 [hv_sock]
    
    but task is already holding lock:
    ffff8880c5158150 (sk_lock-AF_VSOCK){+.+.}, at: __vsock_release+0x2e/0xf0 [vsock]
    
    other info that might help us debug this:
     Possible unsafe locking scenario:
    
           CPU0
           ----
      lock(sk_lock-AF_VSOCK);
      lock(sk_lock-AF_VSOCK);
    
     *** DEADLOCK ***
    
     May be due to missing lock nesting notation
    
    2 locks held by server/1795:
     #0: ffff8880c5d05ff8 (&sb->s_type->i_mutex_key#10){+.+.}, at: __sock_release+0x2d/0xa0
     #1: ffff8880c5158150 (sk_lock-AF_VSOCK){+.+.}, at: __vsock_release+0x2e/0xf0 [vsock]
    
    stack backtrace:
    CPU: 5 PID: 1795 Comm: server Not tainted 5.3.0+ #1
    Call Trace:
     dump_stack+0x67/0x90
     __lock_acquire.cold.67+0xd2/0x20b
     lock_acquire+0xb5/0x1c0
     lock_sock_nested+0x6d/0x90
     hvs_release+0x10/0x120 [hv_sock]
     __vsock_release+0x24/0xf0 [vsock]
     __vsock_release+0xa0/0xf0 [vsock]
     vsock_release+0x12/0x30 [vsock]
     __sock_release+0x37/0xa0
     sock_close+0x14/0x20
     __fput+0xc1/0x250
     task_work_run+0x98/0xc0
     do_exit+0x344/0xc60
     do_group_exit+0x47/0xb0
     get_signal+0x15c/0xc50
     do_signal+0x30/0x720
     exit_to_usermode_loop+0x50/0xa0
     do_syscall_64+0x24e/0x270
     entry_SYSCALL_64_after_hwframe+0x49/0xbe
    RIP: 0033:0x7f4184e85f31
    
    Tested-by: default avatarStefano Garzarella <sgarzare@redhat.com>
    Signed-off-by: default avatarDexuan Cui <decui@microsoft.com>
    Reviewed-by: default avatarStefano Garzarella <sgarzare@redhat.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    0d9138ff