virtio: do not reset stateful devices on resume
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
@@ -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 --
Michael S. Tsirkin
maintainerQuoted 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.
Signed-off-by Anton Yakovlev <[email protected]>Signed-off-by Mikhail Golubev <[email protected]>
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@@ -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 --
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
Signed-off-by Anton Yakovlev <[email protected]>Signed-off-by Mikhail Golubev <[email protected]>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@@ -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 --
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
Signed-off-by Anton Yakovlev <[email protected]>Signed-off-by Mikhail Golubev <[email protected]>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,
MikhailQuoted 30 lines
Quoted 30 lines
--- drivers/virtio/virtio.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/virtio/virtio.c +8
-0@@ -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
-1return 0 ; --2.34.1
--
--