virtio: Add support for no-reset virtio PCI PM
PATCH v2 1/1 virtio: Add support for no-reset virtio PCI PM
If a virtio_pci_device supports native PCI power management and has the No_Soft_Reset bit set, then skip resetting and reinitializing the device when suspending and restoring the device. This allows system-wide low power states like s2idle to be used in systems with stateful virtio devices that can't simply be re-initialized (e.g. virtio-fs).
---
v1 -> v2:
- Check the No_Soft_Reset bit
drivers/virtio/virtio_pci_common.c | 34 +++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-)
drivers/virtio/virtio_pci_common.c +33 -1
@@ -492,8 +492,40 @@ static int virtio_pci_restore(struct device *dev)return virtio_device_restore (&vp_dev->vdev); } +static bool vp_supports_pm_no_reset (struct device *dev) +{ +struct pci_dev *pci_dev =to_pci_dev (dev); +u16 pmcsr; + +if (!pci_dev->pm_cap) +return false; + +pci_read_config_word (pci_dev, pci_dev->pm_cap +PCI_PM_CTRL , &pmcsr); +if (PCI_POSSIBLE_ERROR (pmcsr)) { +dev_err (dev,"Unable to query pmcsr" ); +return false; + } + +return pmcsr &PCI_PM_CTRL_NO_SOFT_RESET ; +} + +static int virtio_pci_suspend (struct device *dev) +{ +return vp_supports_pm_no_reset (dev) ?0 :virtio_pci_freeze (dev); +} + +static int virtio_pci_resume (struct device *dev) +{ +return vp_supports_pm_no_reset (dev) ?0 :virtio_pci_restore (dev); +} +static const struct dev_pm_ops virtio_pci_pm_ops = { -SET_SYSTEM_SLEEP_PM_OPS (virtio_pci_freeze, virtio_pci_restore) + .suspend = virtio_pci_suspend, + .resume = virtio_pci_resume, + .freeze = virtio_pci_freeze, + .thaw = virtio_pci_restore, + .poweroff = virtio_pci_freeze, + .restore = virtio_pci_restore, };#endif
Signature · 1 line
2.43.0.472.g3155946c3a-goog
Quoted 8 lines · David Stevens
If a
virtio_pci_devicesupports native PCI power management and has theNo_Soft_Resetbit set, then skip resetting and reinitializing the device when suspending and restoring the device. This allows system-wide low power states like s2idle to be used in systems with stateful virtio devices that can't simply be re-initialized (e.g. virtio-fs).Signed-off-by David Stevens <[email protected]>
Thanks
Quoted 56 lines
---
v1 -> v2:
- Check theNo_Soft_Resetbitdrivers/virtio/virtio_pci_common.c | 34 +++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-)drivers/virtio/virtio_pci_common.c +33
-2@@ -492,8 +492,40 @@ static int virtio_pci_restore(struct device *dev)return virtio_device_restore (&vp_dev->vdev); } +static bool vp_supports_pm_no_reset (struct device *dev) +{ +struct pci_dev *pci_dev =to_pci_dev (dev); +u16 pmcsr; + +if (!pci_dev->pm_cap) +return false; + +pci_read_config_word (pci_dev, pci_dev->pm_cap +PCI_PM_CTRL , &pmcsr); +if (PCI_POSSIBLE_ERROR (pmcsr)) { +dev_err (dev,"Unable to query pmcsr" ); +return false; + } + +return pmcsr &PCI_PM_CTRL_NO_SOFT_RESET ; +} + +static int virtio_pci_suspend (struct device *dev) +{ +return vp_supports_pm_no_reset (dev) ?0 :virtio_pci_freeze (dev); +} + +static int virtio_pci_resume (struct device *dev) +{ +return vp_supports_pm_no_reset (dev) ?0 :virtio_pci_restore (dev); +} +static const struct dev_pm_ops virtio_pci_pm_ops = { -SET_SYSTEM_SLEEP_PM_OPS (virtio_pci_freeze, virtio_pci_restore) + .suspend = virtio_pci_suspend, + .resume = virtio_pci_resume, + .freeze = virtio_pci_freeze, + .thaw = virtio_pci_restore, + .poweroff = virtio_pci_freeze, + .restore = virtio_pci_restore, };#endif --2.43.0.472.g3155946c3a-goog
Michael S. Tsirkin
maintainerQuoted 7 lines · David Stevens
If a
virtio_pci_devicesupports native PCI power management and has theNo_Soft_Resetbit set, then skip resetting and reinitializing the device when suspending and restoring the device. This allows system-wide low power states like s2idle to be used in systems with stateful virtio devices that can't simply be re-initialized (e.g. virtio-fs).Signed-off-by David Stevens <[email protected]>
tagged, thanks!
I'm still debating with myself whether we can classify this as a bugfix ... better not risk it I guess.
Quoted 55 lines
---
v1 -> v2:
- Check theNo_Soft_Resetbitdrivers/virtio/virtio_pci_common.c | 34 +++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-)drivers/virtio/virtio_pci_common.c +33
-1@@ -492,8 +492,40 @@ static int virtio_pci_restore(struct device *dev)return virtio_device_restore (&vp_dev->vdev); } +static bool vp_supports_pm_no_reset (struct device *dev) +{ +struct pci_dev *pci_dev =to_pci_dev (dev); +u16 pmcsr; + +if (!pci_dev->pm_cap) +return false; + +pci_read_config_word (pci_dev, pci_dev->pm_cap +PCI_PM_CTRL , &pmcsr); +if (PCI_POSSIBLE_ERROR (pmcsr)) { +dev_err (dev,"Unable to query pmcsr" ); +return false; + } + +return pmcsr &PCI_PM_CTRL_NO_SOFT_RESET ; +} + +static int virtio_pci_suspend (struct device *dev) +{ +return vp_supports_pm_no_reset (dev) ?0 :virtio_pci_freeze (dev); +} + +static int virtio_pci_resume (struct device *dev) +{ +return vp_supports_pm_no_reset (dev) ?0 :virtio_pci_restore (dev); +} +static const struct dev_pm_ops virtio_pci_pm_ops = { -SET_SYSTEM_SLEEP_PM_OPS (virtio_pci_freeze, virtio_pci_restore) + .suspend = virtio_pci_suspend, + .resume = virtio_pci_resume, + .freeze = virtio_pci_freeze, + .thaw = virtio_pci_restore, + .poweroff = virtio_pci_freeze, + .restore = virtio_pci_restore, };#endif Signature · 1 line
2.43.0.472.g3155946c3a-goog
Quoted 8 lines · Michael S. Tsirkin
Quoted 6 lines · David Stevens
If a
virtio_pci_devicesupports native PCI power management and has theNo_Soft_Resetbit set, then skip resetting and reinitializing the device when suspending and restoring the device. This allows system-wide low power states like s2idle to be used in systems with stateful virtio devices that can't simply be re-initialized (e.g. virtio-fs).
Quoted 5 lines
Quoted 1 line
Signed-off-by David Stevens <[email protected]>tagged, thanks!
I'm still debating with myself whether we can classify this as a bugfix ... better not risk it I guess.
It might be suitable if there's a hypervisor that advertises no_soft_reset (but it seems Qemu doesn't).
Thanks
Quoted 57 lines
Quoted 56 lines
---
v1 -> v2:
- Check theNo_Soft_Resetbitdrivers/virtio/virtio_pci_common.c | 34 +++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-)drivers/virtio/virtio_pci_common.c +33
-2@@ -492,8 +492,40 @@ static int virtio_pci_restore(struct device *dev)return virtio_device_restore (&vp_dev->vdev); } +static bool vp_supports_pm_no_reset (struct device *dev) +{ +struct pci_dev *pci_dev =to_pci_dev (dev); +u16 pmcsr; + +if (!pci_dev->pm_cap) +return false; + +pci_read_config_word (pci_dev, pci_dev->pm_cap +PCI_PM_CTRL , &pmcsr); +if (PCI_POSSIBLE_ERROR (pmcsr)) { +dev_err (dev,"Unable to query pmcsr" ); +return false; + } + +return pmcsr &PCI_PM_CTRL_NO_SOFT_RESET ; +} + +static int virtio_pci_suspend (struct device *dev) +{ +return vp_supports_pm_no_reset (dev) ?0 :virtio_pci_freeze (dev); +} + +static int virtio_pci_resume (struct device *dev) +{ +return vp_supports_pm_no_reset (dev) ?0 :virtio_pci_restore (dev); +} +static const struct dev_pm_ops virtio_pci_pm_ops = { -SET_SYSTEM_SLEEP_PM_OPS (virtio_pci_freeze, virtio_pci_restore) + .suspend = virtio_pci_suspend, + .resume = virtio_pci_resume, + .freeze = virtio_pci_freeze, + .thaw = virtio_pci_restore, + .poweroff = virtio_pci_freeze, + .restore = virtio_pci_restore, };#endif --2.43.0.472.g3155946c3a-goog
Michael S. Tsirkin
maintainerQuoted 11 lines · Jason Wang
Quoted 10 lines · Michael S. Tsirkin
Quoted 7 lines · David Stevens
If a
virtio_pci_devicesupports native PCI power management and has theNo_Soft_Resetbit set, then skip resetting and reinitializing the device when suspending and restoring the device. This allows system-wide low power states like s2idle to be used in systems with stateful virtio devices that can't simply be re-initialized (e.g. virtio-fs).Signed-off-by David Stevens <[email protected]>
Quoted 8 lines
Quoted 3 lines
tagged, thanks!
I'm still debating with myself whether we can classify this as a bugfix ... better not risk it I guess.It might be suitable if there's a hypervisor that advertises
no_soft_reset(but it seems Qemu doesn't).Thanks
Yea... so a bugfix but no rush to merge it I think.
Quoted 57 lines
Quoted 57 lines
Quoted 56 lines
---
v1 -> v2:
- Check theNo_Soft_Resetbitdrivers/virtio/virtio_pci_common.c | 34 +++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-)drivers/virtio/virtio_pci_common.c +33
-2@@ -492,8 +492,40 @@ static int virtio_pci_restore(struct device *dev)return virtio_device_restore (&vp_dev->vdev); } +static bool vp_supports_pm_no_reset (struct device *dev) +{ +struct pci_dev *pci_dev =to_pci_dev (dev); +u16 pmcsr; + +if (!pci_dev->pm_cap) +return false; + +pci_read_config_word (pci_dev, pci_dev->pm_cap +PCI_PM_CTRL , &pmcsr); +if (PCI_POSSIBLE_ERROR (pmcsr)) { +dev_err (dev,"Unable to query pmcsr" ); +return false; + } + +return pmcsr &PCI_PM_CTRL_NO_SOFT_RESET ; +} + +static int virtio_pci_suspend (struct device *dev) +{ +return vp_supports_pm_no_reset (dev) ?0 :virtio_pci_freeze (dev); +} + +static int virtio_pci_resume (struct device *dev) +{ +return vp_supports_pm_no_reset (dev) ?0 :virtio_pci_restore (dev); +} +static const struct dev_pm_ops virtio_pci_pm_ops = { -SET_SYSTEM_SLEEP_PM_OPS (virtio_pci_freeze, virtio_pci_restore) + .suspend = virtio_pci_suspend, + .resume = virtio_pci_resume, + .freeze = virtio_pci_freeze, + .thaw = virtio_pci_restore, + .poweroff = virtio_pci_freeze, + .restore = virtio_pci_restore, };#endif --2.43.0.472.g3155946c3a-goog
Quoted 50 lines · David Stevens
If a
virtio_pci_devicesupports native PCI power management and has theNo_Soft_Resetbit set, then skip resetting and reinitializing the device when suspending and restoring the device. This allows system-wide low power states like s2idle to be used in systems with stateful virtio devices that can't simply be re-initialized (e.g. virtio-fs).Signed-off-by David Stevens <[email protected]>---
v1 -> v2:
- Check theNo_Soft_Resetbitdrivers/virtio/virtio_pci_common.c | 34 +++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-)drivers/virtio/virtio_pci_common.c +27
-0@@ -492,8 +492,40 @@ static int virtio_pci_restore(struct device *dev)return virtio_device_restore (&vp_dev->vdev); } +static bool vp_supports_pm_no_reset (struct device *dev) +{ +struct pci_dev *pci_dev =to_pci_dev (dev); +u16 pmcsr; + +if (!pci_dev->pm_cap) +return false; + +pci_read_config_word (pci_dev, pci_dev->pm_cap +PCI_PM_CTRL , &pmcsr); +if (PCI_POSSIBLE_ERROR (pmcsr)) { +dev_err (dev,"Unable to query pmcsr" ); +return false; + } + +return pmcsr &PCI_PM_CTRL_NO_SOFT_RESET ; +} + +static int virtio_pci_suspend (struct device *dev) +{ +return vp_supports_pm_no_reset (dev) ?0 :virtio_pci_freeze (dev); +} + +static int virtio_pci_resume (struct device *dev) +{ +return vp_supports_pm_no_reset (dev) ?0 :virtio_pci_restore (dev); +} +static const struct dev_pm_ops virtio_pci_pm_ops = {
drivers/virtio/virtio_pci_common.c static int virtio_pci_restore(struct device *dev) · line 531
Quoted 10 lines
drivers/virtio/virtio_pci_common.c +6
-1-SET_SYSTEM_SLEEP_PM_OPS (virtio_pci_freeze, virtio_pci_restore) + .suspend = virtio_pci_suspend, + .resume = virtio_pci_resume, + .freeze = virtio_pci_freeze, + .thaw = virtio_pci_restore, + .poweroff = virtio_pci_freeze, + .restore = virtio_pci_restore, };#endif
Am I correct with my assumption that this will make s2idle work with virtio-mem-pci as well?
Right now, all suspending is disabled, but really only s4/hibernate is problematic.
[root@vm-0 ~]# echo "s2idle" > /sys/power/mem_sleep [root@vm-0 ~]# echo "mem" > /sys/power/state
[ 101.822991] PM: suspend entry (s2idle) [ 101.828978] Filesystems sync: 0.004 seconds [ 101.831618] Freezing user space processes [ 101.834569] Freezing user space processes completed (elapsed 0.001 seconds) [ 101.836915] OOM killer disabled. [ 101.838072] Freezing remaining freezable tasks [ 101.841054] Freezing remaining freezable tasks completed (elapsed 0.001 seconds) [ 101.843538] printk: Suspending console(s) (use no_console_suspend to debug) [ 101.957676] virtio_mem virtio0: save/restore not supported. [ 101.957683] virtio-pci 0000:00:02.0: PM: pci_pm_suspend(): virtio_pci_freeze+0x0/0x50 returns -1 [ 101.957702] virtio-pci 0000:00:02.0: PM: dpm_run_callback(): pci_pm_suspend+0x0/0x170 returns -1 [ 101.957718] virtio-pci 0000:00:02.0: PM: failed to suspend async: error -1
Signature · 3 lines
Cheers, David / dhildenb
Quoted 69 lines · David Hildenbrand
Quoted 50 lines · David Stevens
If a
virtio_pci_devicesupports native PCI power management and has theNo_Soft_Resetbit set, then skip resetting and reinitializing the device when suspending and restoring the device. This allows system-wide low power states like s2idle to be used in systems with stateful virtio devices that can't simply be re-initialized (e.g. virtio-fs).Signed-off-by David Stevens <[email protected]>---
v1 -> v2:
- Check theNo_Soft_Resetbitdrivers/virtio/virtio_pci_common.c | 34 +++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-)drivers/virtio/virtio_pci_common.c +27
-0@@ -492,8 +492,40 @@ static int virtio_pci_restore(struct device *dev)return virtio_device_restore (&vp_dev->vdev); } +static bool vp_supports_pm_no_reset (struct device *dev) +{ +struct pci_dev *pci_dev =to_pci_dev (dev); +u16 pmcsr; + +if (!pci_dev->pm_cap) +return false; + +pci_read_config_word (pci_dev, pci_dev->pm_cap +PCI_PM_CTRL , &pmcsr); +if (PCI_POSSIBLE_ERROR (pmcsr)) { +dev_err (dev,"Unable to query pmcsr" ); +return false; + } + +return pmcsr &PCI_PM_CTRL_NO_SOFT_RESET ; +} + +static int virtio_pci_suspend (struct device *dev) +{ +return vp_supports_pm_no_reset (dev) ?0 :virtio_pci_freeze (dev); +} + +static int virtio_pci_resume (struct device *dev) +{ +return vp_supports_pm_no_reset (dev) ?0 :virtio_pci_restore (dev); +} +static const struct dev_pm_ops virtio_pci_pm_ops = {drivers/virtio/virtio_pci_common.c static int virtio_pci_restore(struct device *dev) · line 531
Quoted 10 lines
drivers/virtio/virtio_pci_common.c +6
-1-SET_SYSTEM_SLEEP_PM_OPS (virtio_pci_freeze, virtio_pci_restore) + .suspend = virtio_pci_suspend, + .resume = virtio_pci_resume, + .freeze = virtio_pci_freeze, + .thaw = virtio_pci_restore, + .poweroff = virtio_pci_freeze, + .restore = virtio_pci_restore, };#endif Am I correct with my assumption that this will make s2idle work with virtio-mem-pci as well?
Right now, all suspending is disabled, but really only s4/hibernate is problematic.
[root@vm-0 ~]# echo "s2idle" >
/sys/power/mem_sleep[root@vm-0 ~]# echo "mem" >/sys/power/state
Quoted 12 lines
[ 101.822991] PM: suspend entry (s2idle) [ 101.828978] Filesystems sync: 0.004 seconds [ 101.831618] Freezing user space processes [ 101.834569] Freezing user space processes completed (elapsed 0.001 seconds) [ 101.836915] OOM killer disabled. [ 101.838072] Freezing remaining freezable tasks [ 101.841054] Freezing remaining freezable tasks completed (elapsed 0.001 seconds) [ 101.843538] printk: Suspending console(s) (use no_console_suspend to debug) [ 101.957676] virtio_mem virtio0: save/restore not supported. [ 101.957683] virtio-pci 0000:00:02.0: PM: pci_pm_suspend(): virtio_pci_freeze+0x0/0x50 returns -1 [ 101.957702] virtio-pci 0000:00:02.0: PM: dpm_run_callback(): pci_pm_suspend+0x0/0x170 returns -1 [ 101.957718] virtio-pci 0000:00:02.0: PM: failed to suspend async: error -1
QEMU's virtio-pci devices don't advertise no_soft_reset, so this patch won't affect vanilla QEMU. But if you add PCI_PM_CTRL_NO_SOFT_RESET to the capability, then it should work. I'm working with crosvm, which doesn't have virtio-mem implemented, but this patch makes virtio-fs work with no extra kernel changes.
-David
Quoted 83 lines · David Stevens
Quoted 69 lines · David Hildenbrand
Quoted 50 lines · David Stevens
If a
virtio_pci_devicesupports native PCI power management and has theNo_Soft_Resetbit set, then skip resetting and reinitializing the device when suspending and restoring the device. This allows system-wide low power states like s2idle to be used in systems with stateful virtio devices that can't simply be re-initialized (e.g. virtio-fs).Signed-off-by David Stevens <[email protected]>---
v1 -> v2:- Check the No_Soft_Reset bit drivers/virtio/virtio_pci_common.c | 34 +++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-)drivers/virtio/virtio_pci_common.c +27
-0@@ -492,8 +492,40 @@ static int virtio_pci_restore(struct device *dev)return virtio_device_restore (&vp_dev->vdev); } +static bool vp_supports_pm_no_reset (struct device *dev) +{ +struct pci_dev *pci_dev =to_pci_dev (dev); +u16 pmcsr; + +if (!pci_dev->pm_cap) +return false; + +pci_read_config_word (pci_dev, pci_dev->pm_cap +PCI_PM_CTRL , &pmcsr); +if (PCI_POSSIBLE_ERROR (pmcsr)) { +dev_err (dev,"Unable to query pmcsr" ); +return false; + } + +return pmcsr &PCI_PM_CTRL_NO_SOFT_RESET ; +} + +static int virtio_pci_suspend (struct device *dev) +{ +return vp_supports_pm_no_reset (dev) ?0 :virtio_pci_freeze (dev); +} + +static int virtio_pci_resume (struct device *dev) +{ +return vp_supports_pm_no_reset (dev) ?0 :virtio_pci_restore (dev); +} +static const struct dev_pm_ops virtio_pci_pm_ops = {drivers/virtio/virtio_pci_common.c static int virtio_pci_restore(struct device *dev) · line 531
Quoted 10 lines
drivers/virtio/virtio_pci_common.c +6
-1-SET_SYSTEM_SLEEP_PM_OPS (virtio_pci_freeze, virtio_pci_restore) + .suspend = virtio_pci_suspend, + .resume = virtio_pci_resume, + .freeze = virtio_pci_freeze, + .thaw = virtio_pci_restore, + .poweroff = virtio_pci_freeze, + .restore = virtio_pci_restore, };#endif Am I correct with my assumption that this will make s2idle work with virtio-mem-pci as well?
Right now, all suspending is disabled, but really only s4/hibernate is problematic.
[root@vm-0 ~]# echo "s2idle" >
/sys/power/mem_sleep[root@vm-0 ~]# echo "mem" >/sys/power/stateQuoted 12 lines
[ 101.822991] PM: suspend entry (s2idle) [ 101.828978] Filesystems sync: 0.004 seconds [ 101.831618] Freezing user space processes [ 101.834569] Freezing user space processes completed (elapsed 0.001 seconds) [ 101.836915] OOM killer disabled. [ 101.838072] Freezing remaining freezable tasks [ 101.841054] Freezing remaining freezable tasks completed (elapsed 0.001 seconds) [ 101.843538] printk: Suspending console(s) (use no_console_suspend to debug) [ 101.957676] virtio_mem virtio0: save/restore not supported. [ 101.957683] virtio-pci 0000:00:02.0: PM: pci_pm_suspend(): virtio_pci_freeze+0x0/0x50 returns -1 [ 101.957702] virtio-pci 0000:00:02.0: PM: dpm_run_callback(): pci_pm_suspend+0x0/0x170 returns -1 [ 101.957718] virtio-pci 0000:00:02.0: PM: failed to suspend async: error -1
Quoted 5 lines
QEMU's virtio-pci devices don't advertise
no_soft_reset, so this patch won't affect vanilla QEMU. But if you addPCI_PM_CTRL_NO_SOFT_RESETto the capability, then it should work. I'm working with crosvm, which doesn't have virtio-mem implemented, but this patch makes virtio-fs work with no extra kernel changes.
Thanks for the explanation, makes sense to me.
Signature · 3 lines
Cheers, David / dhildenb