Skip to content

Commit 22b5c0b

Browse files
stefano-garzarelladavem330
authored andcommitted
vsock/virtio: fix kernel panic after device hot-unplug
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 <yafu@redhat.com> Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> Acked-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c14f07c commit 22b5c0b

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

net/vmw_vsock/virtio_transport.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ static u32 virtio_transport_get_local_cid(void)
7575
{
7676
struct virtio_vsock *vsock = virtio_vsock_get();
7777

78+
if (!vsock)
79+
return VMADDR_CID_ANY;
80+
7881
return vsock->guest_cid;
7982
}
8083

@@ -584,10 +587,6 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
584587

585588
virtio_vsock_update_guest_cid(vsock);
586589

587-
ret = vsock_core_init(&virtio_transport.transport);
588-
if (ret < 0)
589-
goto out_vqs;
590-
591590
vsock->rx_buf_nr = 0;
592591
vsock->rx_buf_max_nr = 0;
593592
atomic_set(&vsock->queued_replies, 0);
@@ -618,8 +617,6 @@ static int virtio_vsock_probe(struct virtio_device *vdev)
618617
mutex_unlock(&the_virtio_vsock_mutex);
619618
return 0;
620619

621-
out_vqs:
622-
vsock->vdev->config->del_vqs(vsock->vdev);
623620
out:
624621
kfree(vsock);
625622
mutex_unlock(&the_virtio_vsock_mutex);
@@ -669,7 +666,6 @@ static void virtio_vsock_remove(struct virtio_device *vdev)
669666

670667
mutex_lock(&the_virtio_vsock_mutex);
671668
the_virtio_vsock = NULL;
672-
vsock_core_exit();
673669
mutex_unlock(&the_virtio_vsock_mutex);
674670

675671
vdev->config->del_vqs(vdev);
@@ -702,14 +698,28 @@ static int __init virtio_vsock_init(void)
702698
virtio_vsock_workqueue = alloc_workqueue("virtio_vsock", 0, 0);
703699
if (!virtio_vsock_workqueue)
704700
return -ENOMEM;
701+
705702
ret = register_virtio_driver(&virtio_vsock_driver);
706703
if (ret)
707-
destroy_workqueue(virtio_vsock_workqueue);
704+
goto out_wq;
705+
706+
ret = vsock_core_init(&virtio_transport.transport);
707+
if (ret)
708+
goto out_vdr;
709+
710+
return 0;
711+
712+
out_vdr:
713+
unregister_virtio_driver(&virtio_vsock_driver);
714+
out_wq:
715+
destroy_workqueue(virtio_vsock_workqueue);
708716
return ret;
717+
709718
}
710719

711720
static void __exit virtio_vsock_exit(void)
712721
{
722+
vsock_core_exit();
713723
unregister_virtio_driver(&virtio_vsock_driver);
714724
destroy_workqueue(virtio_vsock_workqueue);
715725
}

0 commit comments

Comments
 (0)