Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp2292866imc; Tue, 12 Mar 2019 10:44:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqwiXOcNnCSiKVYkgs0+ZL6nmXzvAfdkZaTfy2h5k6KO+dlRaKkxHKBqeUcCwS+1B3hAsn1y X-Received: by 2002:a63:c64c:: with SMTP id x12mr36304166pgg.285.1552412686098; Tue, 12 Mar 2019 10:44:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552412686; cv=none; d=google.com; s=arc-20160816; b=Jpg+ZS/IzwjRYZ7pm/wJncTKkWL0SgCGwh4ItxI13b+w6RHxsA/avnZtulqoNb+z+9 yyDW59pjtTELZkS7R+o0zlwlVzWpgInJTDXjW83rayp+LYdGIpahfDReqk0As2dCtGv8 1hi8HfJx4ToqiWaVIxmMDIp/iqmt4z0QEDi3JBtDuzz4hlCtKzzsSKeSozrZVs+jQvpr hJy0lKbmp4K+x4uNVdyl7K8uIDzY9llF1NBTPuwpKvZoFJNByjU67Mq95cha+yATgQ0X kMN3ZLwopZMAEOZ8lF8l/WNc88ApnBL9lTeDEMfjSOaozHN7BzSeNZogPpAWk2+PtpqP Q8mA== 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=udzRlshzk5KkOL/TZdAY39B8CH0NbtoLo5eHo3wqjus=; b=L+HUVFMWOYsStVidWS7y/O0PH00BmWC2WFIlH0kOl8DukOuaYCFDFFHvQLZBxYyGxj X9pxdHLPGKeAKK+ttp0x1npmbmQTnsaffyB1LbnZPj6pi2+3cVuzKhP9OtFkBIE6kNcy TflCJsZE231F59JaYMhCLjLDUmbJb9I5+EmSsMn/P1iU4S+hDYg2h/a1f1HLHk2wcaMV GImaarjknHr0tiBxpqziuR5nRJCakKx4Wkxc85YoK1MUa1xgm8wEwsDmslIxUq77nT3D WsvrJS/YNjkM/Tg6UsL/DMUqD/5MOpF2A73DRQlorhcsTh5wFv4J3IbWyCDwLaEnckFL OKzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=weYU8HsR; 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 u5si7994280pgh.221.2019.03.12.10.44.30; Tue, 12 Mar 2019 10:44:46 -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=weYU8HsR; 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 S1728037AbfCLRPr (ORCPT + 99 others); Tue, 12 Mar 2019 13:15:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:54554 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728554AbfCLRO5 (ORCPT ); Tue, 12 Mar 2019 13:14:57 -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 15C1C2186A; Tue, 12 Mar 2019 17:14:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552410896; bh=zgNnVPvwqkx/ITkfh61/fzm906rvwanjUcgg2+8EjF8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=weYU8HsR2j4oTjgONbgP5FyOlfz4Y+jD9a5EATdQ0/GibyGjhN3PxhGEuy7rHrLpS O/9W/1qPvEjhyk9FK/CeTcdt+0bquCh6UMh+6WTLliSgtBAFzrunLQhYRDNEOPK0Zj RWGtrhxitNWWCfySu0PgGpldZnr9WpRzH92n8too= 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.19 099/149] vsock/virtio: fix kernel panic after device hot-unplug Date: Tue, 12 Mar 2019 10:08:37 -0700 Message-Id: <20190312170357.877342574@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190312170349.421581206@linuxfoundation.org> References: <20190312170349.421581206@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.19-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 5d3cce9e8744..9dae54698737 100644 --- a/net/vmw_vsock/virtio_transport.c +++ b/net/vmw_vsock/virtio_transport.c @@ -75,6 +75,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; } @@ -584,10 +587,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); @@ -618,8 +617,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); @@ -669,7 +666,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); @@ -702,14 +698,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