Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp2273972imc; Tue, 12 Mar 2019 10:21:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqxD/UGLZtRb0VmI+/eZYxEM0t7xjtW0pqZmznOdDhWy0kGcU3bWJCVrp1vPpLu26A5rL7+B X-Received: by 2002:a17:902:900a:: with SMTP id a10mr41491428plp.183.1552411290442; Tue, 12 Mar 2019 10:21:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552411290; cv=none; d=google.com; s=arc-20160816; b=F0LXYR/ZSp+VpdEjjIVsnZhD/XQ5VxDwYsqOdAL9u7IgUCBrbFX4TRbZqjvQOpoZcI 2230ThXhaoh9FELQQw/u1riz9qu+jhaBoJHamhbLYNG5txfsq9eKWN0x1VdK/qufUhrq doFEXGvDn8tJI+x1NdVfsde8kR8hL2XaGbAjq8eAPbbmLcX4i/Rc/xf2FV3cXfUcHK3M RItv+LziK8XJylIa8fOSdWtBMAn7mbAFU70M1Q+JefMNfsJ152a/hVEgO0e9D6/TJ1UJ vse1n5IXZOlrlhyzrU3MLw79XK+vc/oR5Nu8T0rw62dhAAJifR1smUVgh1ux7kek0HKx VSNg== 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=+MzujHbAAZDvlcLdEua0Vv3tyEISPl9gaf16OzP8QR8=; b=SnaS8/iPgtgjoPZ+VKLpC1EuZmgWGM2ydQTC/RQvrwenMiRBLuWB+ynJh2bk5pBhw/ nde00JVjwCWU4Bf7ZtRwzzIxCZefR9xcYt09x4eMUXCqcvSsdO+zhOKwxaS3xbQxz9cK q8RSRVUbs4GD3XKGgaksEvErjgvzax6WbUO9UCngErzmGL3RtvslmYdIT7WWG2zGCOmz eAN5FujdVAdQc+6y1JKsLzuUT8qhiJL458ydvUhbCf4dNlcdvltKZfflPJIW9ePiCE+G +sMEMtWTfcM2lYq0PXmiv6/6MsdJrS6E/o4TE9mmNFpUOG/jtrsSZawpXkeWxwQxnsDE R8KA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bO5uPyoC; 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 f9si7825851pgc.576.2019.03.12.10.21.14; Tue, 12 Mar 2019 10:21:30 -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=bO5uPyoC; 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 S1730114AbfCLRSd (ORCPT + 99 others); Tue, 12 Mar 2019 13:18:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:34764 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728408AbfCLRR6 (ORCPT ); Tue, 12 Mar 2019 13:17:58 -0400 Received: from localhost (unknown [104.133.8.98]) (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 996932087C; Tue, 12 Mar 2019 17:17:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552411077; bh=Z+kfzAbXaPrjW6g/uNYf6JWeA00Ak/0dO3ab+xY2fkk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bO5uPyoCt4H+mvpest/UDfeZmwFhmR8BSkkaQKCw5pE34TZCwQvRr7NK96PzF+Ccn J1gSJg2hDuTnRyIPWISGtwEAwkds0L/UbrRGGdw+qPTaPs+qdRj/Bgv+0ojZl+TQ3v d4RCr8obrUea/zlt/wrjsF8BAbX11FisoKPz+6uw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yan Fu , Stefano Garzarella , Stefan Hajnoczi , "David S. Miller" , Sasha Levin Subject: [PATCH 4.9 72/96] vsock/virtio: fix kernel panic after device hot-unplug Date: Tue, 12 Mar 2019 10:10:30 -0700 Message-Id: <20190312171040.050387931@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190312171034.530434962@linuxfoundation.org> References: <20190312171034.530434962@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 22b5c0b63f32568e130fa2df4ba23efce3eb495b ] virtio_vsock_remove() invokes the vsock_core_exit() also if there are opened sockets for the AF_VSOCK protocol family. In this way the vsock "transport" pointer is set to NULL, triggering the kernel panic at the first socket activity. This patch move the vsock_core_init()/vsock_core_exit() in the virtio_vsock respectively in module_init and module_exit functions, that cannot be invoked until there are open sockets. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1609699 Reported-by: Yan Fu Signed-off-by: Stefano Garzarella Acked-by: Stefan Hajnoczi Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/vmw_vsock/virtio_transport.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c index 936d7eee62d0..6cbc08d82e7f 100644 --- a/net/vmw_vsock/virtio_transport.c +++ b/net/vmw_vsock/virtio_transport.c @@ -71,6 +71,9 @@ static u32 virtio_transport_get_local_cid(void) { struct virtio_vsock *vsock = virtio_vsock_get(); + if (!vsock) + return VMADDR_CID_ANY; + return vsock->guest_cid; } @@ -495,10 +498,6 @@ static int virtio_vsock_probe(struct virtio_device *vdev) virtio_vsock_update_guest_cid(vsock); - ret = vsock_core_init(&virtio_transport.transport); - if (ret < 0) - goto out_vqs; - vsock->rx_buf_nr = 0; vsock->rx_buf_max_nr = 0; atomic_set(&vsock->queued_replies, 0); @@ -526,8 +525,6 @@ static int virtio_vsock_probe(struct virtio_device *vdev) mutex_unlock(&the_virtio_vsock_mutex); return 0; -out_vqs: - vsock->vdev->config->del_vqs(vsock->vdev); out: kfree(vsock); mutex_unlock(&the_virtio_vsock_mutex); @@ -567,7 +564,6 @@ static void virtio_vsock_remove(struct virtio_device *vdev) mutex_lock(&the_virtio_vsock_mutex); the_virtio_vsock = NULL; - vsock_core_exit(); mutex_unlock(&the_virtio_vsock_mutex); vdev->config->del_vqs(vdev); @@ -600,14 +596,28 @@ static int __init virtio_vsock_init(void) virtio_vsock_workqueue = alloc_workqueue("virtio_vsock", 0, 0); if (!virtio_vsock_workqueue) return -ENOMEM; + ret = register_virtio_driver(&virtio_vsock_driver); if (ret) - destroy_workqueue(virtio_vsock_workqueue); + goto out_wq; + + ret = vsock_core_init(&virtio_transport.transport); + if (ret) + goto out_vdr; + + return 0; + +out_vdr: + unregister_virtio_driver(&virtio_vsock_driver); +out_wq: + destroy_workqueue(virtio_vsock_workqueue); return ret; + } static void __exit virtio_vsock_exit(void) { + vsock_core_exit(); unregister_virtio_driver(&virtio_vsock_driver); destroy_workqueue(virtio_vsock_workqueue); } -- 2.19.1