Skip to contentSkip to conversation

drm/virtio: Reset device before deleting virtqueues on freeze

PATCH Applied Yuho Choi 3 participants 3 messages Sep 26 – Oct 13

Subsystems (5)
lore
Share & tools
lore

Yuho Choi

author
#0 lore raw

PATCH 1/1 drm/virtio: Reset device before deleting virtqueues on freeze

virtgpu_freeze() waits for the control and cursor queues to drain and then deletes the virtqueues, but nothing tells the device to stop first. del_vqs() frees the vring backing, but does not provide a generic device quiesce operation. In particular, modern virtio-pci keeps enabled queues active until the device is reset, so the device is left DRIVER_OK with its queues pointing at memory that has been freed and may be reused while the guest is suspended. virtio_device_restore() only resets the device later, on resume.

Reset the device before deleting the virtqueues, the way virtio_gpu_deinit() already does on removal.

Fixes cad6a879a7fb ("drm/virtio: Freeze and restore hooks to support suspend and resume")
---
 drivers/gpu/drm/virtio/virtgpu_drv.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/virtio/virtgpu_drv.c +1 -0
index 2aaa7cb08085..52c174f9bff7 100644
@@ -225,6 +225,7 @@ static int virtgpu_freeze(struct virtio_device *vdev)
 		goto err_resume;
 	}
 
+	virtio_reset_device(vdev);
 	vdev->config->del_vqs(vdev);
 
 	return 0;
Signature · 1 line
2.43.0
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 9 lines

virtgpu_freeze() waits for the control and cursor queues to drain and then deletes the virtqueues, but nothing tells the device to stop first. del_vqs() frees the vring backing, but does not provide a generic device quiesce operation. In particular, modern virtio-pci keeps enabled queues active until the device is reset, so the device is left DRIVER_OK with its queues pointing at memory that has been freed and may be reused while the guest is suspended. virtio_device_restore() only resets the device later, on resume.

Quoted 6 lines

Reset the device before deleting the virtqueues, the way virtio_gpu_deinit() already does on removal.

Fixes cad6a879a7fb ("drm/virtio: Freeze and restore hooks to support suspend and resume")

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Applied
#2 lore raw
In reply to Yuho Choi
Quoted 24 lines · Yuho Choi

virtgpu_freeze() waits for the control and cursor queues to drain and then deletes the virtqueues, but nothing tells the device to stop first. del_vqs() frees the vring backing, but does not provide a generic device quiesce operation. In particular, modern virtio-pci keeps enabled queues active until the device is reset, so the device is left DRIVER_OK with its queues pointing at memory that has been freed and may be reused while the guest is suspended. virtio_device_restore() only resets the device later, on resume.

Reset the device before deleting the virtqueues, the way virtio_gpu_deinit() already does on removal.

Fixes cad6a879a7fb ("drm/virtio: Freeze and restore hooks to support suspend and resume")
---
 drivers/gpu/drm/virtio/virtgpu_drv.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/virtio/virtgpu_drv.c +0 -0
index 2aaa7cb08085..52c174f9bff7 100644

drivers/gpu/drm/virtio/virtgpu_drv.c static int virtgpu_freeze(struct virtio_device *vdev) · line 231

Quoted 7 lines
drivers/gpu/drm/virtio/virtgpu_drv.c +1 -0
@@ -225,6 +225,7 @@ static int virtgpu_freeze(struct virtio_device *vdev)
 		goto err_resume;
 	}
 
+	virtio_reset_device(vdev);
 	vdev->config->del_vqs(vdev);
 
 	return 0;

Applied to misc-fixes, thanks!

Signature · 2 lines
Best regards,
Dmitry