Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp3376044ybp; Sun, 6 Oct 2019 10:34:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqzTYLjUuG4prBTnR5fsEpYjveOTIFd/Wgw+Q7oCa1EoKdo5SMu9v2HniGFj0WsobD/yHC8s X-Received: by 2002:a50:be87:: with SMTP id b7mr25807459edk.37.1570383242319; Sun, 06 Oct 2019 10:34:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570383242; cv=none; d=google.com; s=arc-20160816; b=LSldtWJwFmFBu4M7BBc/Jh2+Mo4xSIxdfL7VmSSUd7QCI2N9c29beGCqBn9feO9Mhl VPwIHOikUvjyQXON2gCnDGqpX+StZw2AG5woIisXG9yeGobrn+SYHh9avFb2mU9eq8sC CkbP9g/nV5fu7AIqs12olpmW05BYxNYXIuW6n08Ktb/sYWzj15PSsxXTa0dSREqPUJKq 4fqyXJhpRLVkjQZrlAMySH9SFYo8TfXnKxcPImYNfBAvOhYypg/QBihIV1i4hVwjqSdT FO2jfCU6DMBaIwrmSxo+TiL9h+BIXF7TQCpznCRgrty9crhBurS9CrH2gGNGFNEdYV5I zioA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=d1aYR4MP4axnBs2vWLGsK0w/udUgIMwSoFfwNHPDoeg=; b=nFDUUQM4/0WU9izdD+STf7osH/7M8qaT13jY+cZOM4pO6jHBLcBmMUjVifo9tI4Ai2 PH5A8GIiQn20eLBt9dUGMcY5RVWFXD+5wWqGLmZa+y3MreScO/Ag7+4wxXL7YNmIzOmh YdMlDC/06TK+k11ybwC45fh8Abo4/eZ9iAnr3NgTNt0lcYUstzF12qP24+H3A1J6obbp CnRbQ5GN50VxlTb+bRuDErt0nNVOV3mOj5rbpwnuOcuFL+JVHV10DiS0jkr38iKeYaV9 bLS/9TlaaZk1jLrGgze/qavCAw9Z3I7XhHVbdXe50FiRw6yCYB8eagwN2mXYNomyi77W QamA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dY3Qr927; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y27si7704304edd.249.2019.10.06.10.33.38; Sun, 06 Oct 2019 10:34:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dY3Qr927; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729077AbfJFRb6 (ORCPT + 99 others); Sun, 6 Oct 2019 13:31:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:58326 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729527AbfJFRb5 (ORCPT ); Sun, 6 Oct 2019 13:31:57 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 07F122133F; Sun, 6 Oct 2019 17:31:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570383116; bh=ocmlQhmbrOJ5xSoPlVt/zwsFqdeOGrlzZtRTlLOjigU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dY3Qr927GKSrgdCbYTgvU/PWLMmmGny26UIrJURZNA7x6JRxmQb2iQbhsQJCBDvz/ 3cNDShRb5mUGlR5ZLscORuBJ2lQm/eE+D0BegJgAmkmypGMYd/faZ8iypcqHJaFmkM ik4pS/kZrHVq21gRLiCwIkJD1Mly7r7rKQm08ltQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stefano Garzarella , Dexuan Cui , "David S. Miller" Subject: [PATCH 4.19 093/106] vsock: Fix a lockdep warning in __vsock_release() Date: Sun, 6 Oct 2019 19:21:39 +0200 Message-Id: <20191006171201.105134142@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191006171124.641144086@linuxfoundation.org> References: <20191006171124.641144086@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dexuan Cui [ Upstream commit 0d9138ffac24cf8b75366ede3a68c951e6dcc575 ] 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: Stefano Garzarella Signed-off-by: Dexuan Cui Reviewed-by: Stefano Garzarella Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/vmw_vsock/af_vsock.c | 16 ++++++++++++---- net/vmw_vsock/hyperv_transport.c | 2 +- net/vmw_vsock/virtio_transport_common.c | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -641,7 +641,7 @@ struct sock *__vsock_create(struct net * } EXPORT_SYMBOL_GPL(__vsock_create); -static void __vsock_release(struct sock *sk) +static void __vsock_release(struct sock *sk, int level) { if (sk) { struct sk_buff *skb; @@ -651,9 +651,17 @@ static void __vsock_release(struct sock vsk = vsock_sk(sk); pending = NULL; /* Compiler warning. */ + /* The release call is supposed to use lock_sock_nested() + * rather than lock_sock(), if a sock lock should be acquired. + */ transport->release(vsk); - lock_sock(sk); + /* When "level" is SINGLE_DEPTH_NESTING, use the nested + * version to avoid the warning "possible recursive locking + * detected". When "level" is 0, lock_sock_nested(sk, level) + * is the same as lock_sock(sk). + */ + lock_sock_nested(sk, level); sock_orphan(sk); sk->sk_shutdown = SHUTDOWN_MASK; @@ -662,7 +670,7 @@ static void __vsock_release(struct sock /* Clean up any sockets that never were accepted. */ while ((pending = vsock_dequeue_accept(sk)) != NULL) { - __vsock_release(pending); + __vsock_release(pending, SINGLE_DEPTH_NESTING); sock_put(pending); } @@ -711,7 +719,7 @@ EXPORT_SYMBOL_GPL(vsock_stream_has_space static int vsock_release(struct socket *sock) { - __vsock_release(sock->sk); + __vsock_release(sock->sk, 0); sock->sk = NULL; sock->state = SS_FREE; --- a/net/vmw_vsock/hyperv_transport.c +++ b/net/vmw_vsock/hyperv_transport.c @@ -538,7 +538,7 @@ static void hvs_release(struct vsock_soc struct sock *sk = sk_vsock(vsk); bool remove_sock; - lock_sock(sk); + lock_sock_nested(sk, SINGLE_DEPTH_NESTING); remove_sock = hvs_close_lock_held(vsk); release_sock(sk); if (remove_sock) --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -791,7 +791,7 @@ void virtio_transport_release(struct vso struct sock *sk = &vsk->sk; bool remove_sock = true; - lock_sock(sk); + lock_sock_nested(sk, SINGLE_DEPTH_NESTING); if (sk->sk_type == SOCK_STREAM) remove_sock = virtio_transport_close(vsk);