Skip to contentSkip to conversation

virtio_mmio: pm: Add notification handlers for restore and freeze

PATCH Superseded Mikhail Golubev 4 participants 4 messages Dec 13, 2021 – Dec 14, 2021 virtio core

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio_mmio: pm: Add notification handlers for restore and freeze

From: Yurii Danilovskyi <[email protected]>

Handle restore and freeze notifications from the PM core. Expose these to individual virtio drivers that can quiesce and resume vq operations.

---
 drivers/virtio/virtio_mmio.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/virtio/virtio_mmio.c +19 -0
index 56128b9c46eb..af79f8c2a2f2 100644
@@ -762,6 +762,24 @@ static void vm_unregister_cmdline_devices(void)
 
 #endif
 
+static int __maybe_unused virtio_mmio_freeze(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct virtio_mmio_device *vm_dev = platform_get_drvdata(pdev);
+
+	return virtio_device_freeze(&vm_dev->vdev);
+}
+
+static int __maybe_unused virtio_mmio_restore(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct virtio_mmio_device *vm_dev = platform_get_drvdata(pdev);
+
+	return virtio_device_restore(&vm_dev->vdev);
+}
+
+static SIMPLE_DEV_PM_OPS(virtio_mmio_pm_ops, virtio_mmio_freeze, virtio_mmio_restore);
+
 /* Platform driver */
 
 static const struct of_device_id virtio_mmio_match[] = {
@@ -785,6 +803,7 @@ static struct platform_driver virtio_mmio_driver = {
 		.name	= "virtio-mmio",
 		.of_match_table	= virtio_mmio_match,
 		.acpi_match_table = ACPI_PTR(virtio_mmio_acpi_match),
+		.pm = &virtio_mmio_pm_ops,
 	},
 };
 
Signature · 4 lines
2.34.1


-- 
#1 lore raw
Thank you for the patch! Yet something to improve:

Hi Mikhail,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linux/master]
[also build test ERROR on linus/master v5.16-rc5]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Mikhail-Golubev/virtio_mmio-pm-Add-notification-handlers-for-restore-and-freeze/20211214-001636
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 136057256686de39cc3a07c2e39ef6bc43003ff6
config: m68k-randconfig-r033-20211213 (https://download.01.org/0day-ci/archive/20211214/202112140201.xeCfVzym-lkp(a)intel.com/config)
compiler: m68k-linux-gcc (GCC) 11.2.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/86cd610f19003c4d848c13e5e00e38e9bc41f54e
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Mikhail-Golubev/virtio_mmio-pm-Add-notification-handlers-for-restore-and-freeze/20211214-001636 git checkout 86cd610f19003c4d848c13e5e00e38e9bc41f54e
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=m68k SHELL=/bin/bash drivers/virtio/

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

drivers/virtio/virtio_mmio.c: In function 'virtio_mmio_freeze':

>> drivers/virtio/virtio_mmio.c:770:16: error: implicit declaration of function 'virtio_device_freeze'; did you mean 'virtio_device_ready'? [-Werror=implicit-function-declaration]
     770 |         return virtio_device_freeze(&vm_dev->vdev);
         |                ^~~~~~~~~~~~~~~~~~~~
         |                virtio_device_ready
   drivers/virtio/virtio_mmio.c: In function 'virtio_mmio_restore':
>> drivers/virtio/virtio_mmio.c:778:16: error: implicit declaration of function 'virtio_device_restore'; did you mean 'virtio_mmio_restore'? [-Werror=implicit-function-declaration]
     778 |         return virtio_device_restore(&vm_dev->vdev);
         |                ^~~~~~~~~~~~~~~~~~~~~
         |                virtio_mmio_restore

cc1: some warnings being treated as errors

vim +770 drivers/virtio/virtio_mmio.c

764
765 static int __maybe_unused virtio_mmio_freeze(struct device *dev)
766 {
767 struct platform_device *pdev = to_platform_device(dev);
768 struct virtio_mmio_device *vm_dev = platform_get_drvdata(pdev);
769

 > 770		return virtio_device_freeze(&vm_dev->vdev);
   771	}
   772	
   773	static int __maybe_unused virtio_mmio_restore(struct device *dev)
   774	{
   775		struct platform_device *pdev = to_platform_device(dev);
   776		struct virtio_mmio_device *vm_dev = platform_get_drvdata(pdev);
   777	
 > 778		return virtio_device_restore(&vm_dev->vdev);

779 }
780

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#2 lore raw
In reply to Mikhail Golubev
Quoted 42 lines · Mikhail Golubev

From: Yurii Danilovskyi <[email protected]>

Handle restore and freeze notifications from the PM core. Expose these to individual virtio drivers that can quiesce and resume vq operations.

---
 drivers/virtio/virtio_mmio.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/virtio/virtio_mmio.c +18 -0
index 56128b9c46eb..af79f8c2a2f2 100644
@@ -762,6 +762,24 @@ static void vm_unregister_cmdline_devices(void)
 
 #endif
 
+static int __maybe_unused virtio_mmio_freeze(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct virtio_mmio_device *vm_dev = platform_get_drvdata(pdev);
+
+	return virtio_device_freeze(&vm_dev->vdev);
+}
+
+static int __maybe_unused virtio_mmio_restore(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct virtio_mmio_device *vm_dev = platform_get_drvdata(pdev);
+
+	return virtio_device_restore(&vm_dev->vdev);
+}
+
+static SIMPLE_DEV_PM_OPS(virtio_mmio_pm_ops, virtio_mmio_freeze, virtio_mmio_restore);
+
 /* Platform driver */
 
 static const struct of_device_id virtio_mmio_match[] = {

drivers/virtio/virtio_mmio.c static struct platform_driver virtio_mmio_driver = { · line 808

Quoted 6 lines
drivers/virtio/virtio_mmio.c +1 -0
@@ -785,6 +803,7 @@ static struct platform_driver virtio_mmio_driver = {
 		.name	= "virtio-mmio",
 		.of_match_table	= virtio_mmio_match,
 		.acpi_match_table = ACPI_PTR(virtio_mmio_acpi_match),
+		.pm = &virtio_mmio_pm_ops,
 	},
 };

All this code needs to be within ifdef CONFIG_PM_SLEEP. Alternatively, tweak virtio.h to expose virtio_device_freeze/virtio_device_restore unconditionally.

Quoted 6 lines
Signature · 5 lines
-- 
2.34.1


-- 
#3 lore raw
Quoted 41 lines · Michael S. Tsirkin
Quoted 40 lines · Mikhail Golubev

From: Yurii Danilovskyi <[email protected]>

Handle restore and freeze notifications from the PM core. Expose these to individual virtio drivers that can quiesce and resume vq operations.

---
 drivers/virtio/virtio_mmio.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/virtio/virtio_mmio.c +18 -0
index 56128b9c46eb..af79f8c2a2f2 100644
@@ -762,6 +762,24 @@ static void vm_unregister_cmdline_devices(void)
 
 #endif
 
+static int __maybe_unused virtio_mmio_freeze(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct virtio_mmio_device *vm_dev = platform_get_drvdata(pdev);
+
+	return virtio_device_freeze(&vm_dev->vdev);
+}
+
+static int __maybe_unused virtio_mmio_restore(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct virtio_mmio_device *vm_dev = platform_get_drvdata(pdev);
+
+	return virtio_device_restore(&vm_dev->vdev);
+}
+
+static SIMPLE_DEV_PM_OPS(virtio_mmio_pm_ops, virtio_mmio_freeze, virtio_mmio_restore);
+
 /* Platform driver */
 
Quoted 12 lines

drivers/virtio/virtio_mmio.c static struct platform_driver virtio_mmio_driver = { · line 808

Quoted 8 lines
drivers/virtio/virtio_mmio.c +1 -0
 static const struct of_device_id virtio_mmio_match[] = {
@@ -785,6 +803,7 @@ static struct platform_driver virtio_mmio_driver = {
 		.name	= "virtio-mmio",
 		.of_match_table	= virtio_mmio_match,
 		.acpi_match_table = ACPI_PTR(virtio_mmio_acpi_match),
+		.pm = &virtio_mmio_pm_ops,
 	},
 };

All this code needs to be within ifdef CONFIG_PM_SLEEP. Alternatively, tweak virtio.h to expose virtio_device_freeze/virtio_device_restore unconditionally.

Added ifdef CONFIG_PM_SLEEP in the patch v2 for simplicity and to be more aligned with other PM code in drivers/virtio.

Quoted 9 lines
Quoted 8 lines
Signature · 5 lines
-- 
2.34.1


--