Skip to contentSkip to conversation

virtio: do not reset stateful devices on resume

RFC PATCH In review Mikhail Golubev 4 participants 4 messages Dec 14, 2021 – Dec 16, 2021 virtio core

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 virtio: do not reset stateful devices on resume

From: Anton Yakovlev <[email protected]>

We assume that stateful devices can maintain their state while suspended. And for this reason they don't have a freeze callback. If such a device is reset during resume, the device state/context will be lost on the device side. And the virtual device will stop working.

---
 drivers/virtio/virtio.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/virtio/virtio.c +8 -0
index 236081afe9a2..defa15b56eb8 100644
@@ -472,6 +472,13 @@ int virtio_device_restore(struct virtio_device *dev)
 	struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
 	int ret;
 
+	/* Short path for stateful devices. Here we assume that if the device
+	 * does not have a freeze callback, its state was not changed when
+	 * suspended.
+	 */
+	if (drv && !drv->freeze)
+		goto on_config_enable;
+
 	/* We always start by resetting the device, in case a previous
 	 * driver messed it up. */
 	dev->config->reset(dev);
@@ -503,6 +510,7 @@ int virtio_device_restore(struct virtio_device *dev)
 	/* Finally, tell the device we're all set */
 	virtio_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK);
 
+on_config_enable:
 	virtio_config_enable(dev);
 
 	return 0;
Signature · 4 lines
2.34.1


-- 
#1 lore raw
Quoted 9 lines · Mikhail Golubev

From: Anton Yakovlev <[email protected]>

We assume that stateful devices can maintain their state while suspended. And for this reason they don't have a freeze callback. If such a device is reset during resume, the device state/context will be lost on the device side. And the virtual device will stop working.

A bit more specific? Which configs does this patch fix?

Quoted 35 lines
---
 drivers/virtio/virtio.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/virtio/virtio.c +8 -0
index 236081afe9a2..defa15b56eb8 100644
@@ -472,6 +472,13 @@ int virtio_device_restore(struct virtio_device *dev)
 	struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
 	int ret;
 
+	/* Short path for stateful devices. Here we assume that if the device
+	 * does not have a freeze callback, its state was not changed when
+	 * suspended.
+	 */
+	if (drv && !drv->freeze)
+		goto on_config_enable;
+
 	/* We always start by resetting the device, in case a previous
 	 * driver messed it up. */
 	dev->config->reset(dev);
@@ -503,6 +510,7 @@ int virtio_device_restore(struct virtio_device *dev)
 	/* Finally, tell the device we're all set */
 	virtio_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK);
 
+on_config_enable:
 	virtio_config_enable(dev);
 
 	return 0;
Signature · 4 lines
2.34.1


-- 
#2 lore raw
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Mikhail Golubev

From: Anton Yakovlev <[email protected]>

We assume that stateful devices can maintain their state while suspended. And for this reason they don't have a freeze callback. If such a device is reset during resume, the device state/context will be lost on the device side. And the virtual device will stop working.

Quoted 4 lines
Quoted 2 lines

A bit more specific? Which configs does this patch fix?

We had encountered an issue related to 'stateful' GPU 3d (virglrenderer) and video (gstreamer) devices.

BR,
Mikhail

Quoted 37 lines
Quoted 36 lines
---
 drivers/virtio/virtio.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/virtio/virtio.c +8 -0
index 236081afe9a2..defa15b56eb8 100644
@@ -472,6 +472,13 @@ int virtio_device_restore(struct virtio_device *dev)
 	struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
 	int ret;
 
+	/* Short path for stateful devices. Here we assume that if the device
+	 * does not have a freeze callback, its state was not changed when
+	 * suspended.
+	 */
+	if (drv && !drv->freeze)
+		goto on_config_enable;
+
 	/* We always start by resetting the device, in case a previous
 	 * driver messed it up. */
 	dev->config->reset(dev);
@@ -503,6 +510,7 @@ int virtio_device_restore(struct virtio_device *dev)
 	/* Finally, tell the device we're all set */
 	virtio_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK);
 
+on_config_enable:
 	virtio_config_enable(dev);
 
 	return 0;
Signature · 4 lines
2.34.1


-- 
#3 lore raw
Quoted 10 lines · Mikhail Golubev
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Mikhail Golubev

From: Anton Yakovlev <[email protected]>

We assume that stateful devices can maintain their state while suspended. And for this reason they don't have a freeze callback. If such a device is reset during resume, the device state/context will be lost on the device side. And the virtual device will stop working.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

A bit more specific? Which configs does this patch fix?

We had encountered an issue related to 'stateful' GPU 3d (virglrenderer) and video (gstreamer) devices.

Adding Gerd and Stefan.

I wonder if we suffer from a similar issue with virtio-fs.

Thanks

Quoted 44 lines

BR,
Mikhail

Quoted 30 lines
Quoted 30 lines
---
 drivers/virtio/virtio.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/virtio/virtio.c +8 -0
index 236081afe9a2..defa15b56eb8 100644
@@ -472,6 +472,13 @@ int virtio_device_restore(struct virtio_device *dev)
    struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
    int ret;
 
+   /* Short path for stateful devices. Here we assume that if the device
+    * does not have a freeze callback, its state was not changed when
+    * suspended.
+    */
+   if (drv && !drv->freeze)
+           goto on_config_enable;
+
    /* We always start by resetting the device, in case a previous
     * driver messed it up. */
    dev->config->reset(dev);
@@ -503,6 +510,7 @@ int virtio_device_restore(struct virtio_device *dev)
    /* Finally, tell the device we're all set */
    virtio_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK);
 
+on_config_enable:
    virtio_config_enable(dev);
 
Quoted 7 lines
Quoted 6 lines
drivers/virtio/virtio.c +0 -1
    return 0;
--

2.34.1

--

--