Skip to content

Commit bd50c5d

Browse files
stefano-garzarellakuba-moo
authored andcommitted
vsock/virtio: add support for device suspend/resume
Implement .freeze and .restore callbacks of struct virtio_driver to support device suspend/resume. During suspension all connected sockets are reset and VQs deleted. During resume the VQs are re-initialized. Reported by: Vilas R K <[email protected]> Signed-off-by: Stefano Garzarella <[email protected]> Acked-by: Michael S. Tsirkin <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent a103209 commit bd50c5d

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

net/vmw_vsock/virtio_transport.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,49 @@ static void virtio_vsock_remove(struct virtio_device *vdev)
743743
kfree(vsock);
744744
}
745745

746+
#ifdef CONFIG_PM_SLEEP
747+
static int virtio_vsock_freeze(struct virtio_device *vdev)
748+
{
749+
struct virtio_vsock *vsock = vdev->priv;
750+
751+
mutex_lock(&the_virtio_vsock_mutex);
752+
753+
rcu_assign_pointer(the_virtio_vsock, NULL);
754+
synchronize_rcu();
755+
756+
virtio_vsock_vqs_del(vsock);
757+
758+
mutex_unlock(&the_virtio_vsock_mutex);
759+
760+
return 0;
761+
}
762+
763+
static int virtio_vsock_restore(struct virtio_device *vdev)
764+
{
765+
struct virtio_vsock *vsock = vdev->priv;
766+
int ret;
767+
768+
mutex_lock(&the_virtio_vsock_mutex);
769+
770+
/* Only one virtio-vsock device per guest is supported */
771+
if (rcu_dereference_protected(the_virtio_vsock,
772+
lockdep_is_held(&the_virtio_vsock_mutex))) {
773+
ret = -EBUSY;
774+
goto out;
775+
}
776+
777+
ret = virtio_vsock_vqs_init(vsock);
778+
if (ret < 0)
779+
goto out;
780+
781+
rcu_assign_pointer(the_virtio_vsock, vsock);
782+
783+
out:
784+
mutex_unlock(&the_virtio_vsock_mutex);
785+
return ret;
786+
}
787+
#endif /* CONFIG_PM_SLEEP */
788+
746789
static struct virtio_device_id id_table[] = {
747790
{ VIRTIO_ID_VSOCK, VIRTIO_DEV_ANY_ID },
748791
{ 0 },
@@ -760,6 +803,10 @@ static struct virtio_driver virtio_vsock_driver = {
760803
.id_table = id_table,
761804
.probe = virtio_vsock_probe,
762805
.remove = virtio_vsock_remove,
806+
#ifdef CONFIG_PM_SLEEP
807+
.freeze = virtio_vsock_freeze,
808+
.restore = virtio_vsock_restore,
809+
#endif
763810
};
764811

765812
static int __init virtio_vsock_init(void)

0 commit comments

Comments
 (0)