vfio: Add vm status change callback to stop/restart the mdev device
RFC PATCH v4 2/4 vfio: Add vm status change callback to stop/restart the mdev device
VM status change handler is added to change the vfio pci device status during the migration, write the demanded device status to the DEVICE STATUS subregion to stop the device on the source side before fetch its status and start the deivce on the target side after restore its status.
--- hw/vfio/pci.c | 20 ++++++++++++++++++++ include/hw/vfio/vfio-common.h | 1 + linux-headers/linux/vfio.h | 6 ++++++ roms/seabios | 2 +- 4 files changed, 28 insertions(+), 1 deletion(-)
hw/vfio/pci.c +20 -0
@@ -38,6 +38,7 @@static void vfio_disable_interrupts (VFIOPCIDevice *vdev);static void vfio_mmap_set_enabled (VFIOPCIDevice *vdev,bool enabled); +static void vfio_vm_change_state_handler (void *pv,int running,RunState state);/* * Disabling BAR mmaping can be slow, but toggling it around INTx can
@@ -2896,6 +2897,7 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)vfio_register_err_notifier (vdev);vfio_register_req_notifier (vdev);vfio_setup_resetfn_quirk (vdev); +qemu_add_vm_change_state_handler (vfio_vm_change_state_handler, vdev);return ;
@@ -2982,6 +2984,24 @@ post_reset:vfio_pci_post_reset (vdev); } +static void vfio_vm_change_state_handler (void *pv,int running,RunState state) +{ +VFIOPCIDevice *vdev = pv; +VFIODevice *vbasedev = &vdev->vbasedev; +uint8_t dev_state; +uint8_t sz =1 ; + + dev_state = running ?VFIO_DEVICE_START :VFIO_DEVICE_STOP ; + +if (pwrite (vdev->vbasedev.fd, &dev_state, + sz, vdev->device_state.offset) != sz) { +error_report ("vfio: Failed to %s device" , running ?"start" :"stop" ); +return ; + } + + vbasedev->device_state = dev_state; +} +static void vfio_instance_init (Object *obj) {PCIDevice *pci_dev =PCI_DEVICE (obj);
include/hw/vfio/vfio-common.h +1 -0
@@ -125,6 +125,7 @@ typedef struct VFIODevice {unsigned int num_irqs;unsigned int num_regions;unsigned int flags; +bool device_state; } VFIODevice;struct VFIODeviceOps {
linux-headers/linux/vfio.h +6 -0
@@ -304,6 +304,12 @@ struct vfio_region_info_cap_type {/* Mdev sub-type for device state save and restore */ #define VFIO_REGION_SUBTYPE_DEVICE_STATE (4) +/* Offset in region to save device state */ +#define VFIO_DEVICE_STATE_OFFSET 1 + +#define VFIO_DEVICE_START 0 +#define VFIO_DEVICE_STOP 1 +/** * VFIO_DEVICE_GET_IRQ_INFO - _IOWR(VFIO_TYPE, VFIO_BASE + 9, * struct vfio_irq_info)
roms/seabios +1 -1
@@ -1 +1 @@ -Subproject commit 63451fca13c75870e1703eb3e20584d91179aebc +Subproject commit 5f4c7b13cdf9c450eb55645f4362ea58fa61b79b
Signature · 1 line
2.7.4
Quoted 46 lines · Yulei Zhang
VM status change handler is added to change the vfio pci device status during the migration, write the demanded device status to the DEVICE STATUS subregion to stop the device on the source side before fetch its status and start the deivce on the target side after restore its status.
Signed-off-by Yulei Zhang <[email protected]>--- hw/vfio/pci.c | 20 ++++++++++++++++++++ include/hw/vfio/vfio-common.h | 1 + linux-headers/linux/vfio.h | 6 ++++++ roms/seabios | 2 +- 4 files changed, 28 insertions(+), 1 deletion(-)hw/vfio/pci.c +10
-0@@ -38,6 +38,7 @@static void vfio_disable_interrupts (VFIOPCIDevice *vdev);static void vfio_mmap_set_enabled (VFIOPCIDevice *vdev,bool enabled); +static void vfio_vm_change_state_handler (void *pv,int running,RunState state);/* * Disabling BAR mmaping can be slow, but toggling it around INTx can @@ -2896,6 +2897,7 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)vfio_register_err_notifier (vdev);vfio_register_req_notifier (vdev);vfio_setup_resetfn_quirk (vdev); +qemu_add_vm_change_state_handler (vfio_vm_change_state_handler, vdev);return ;@@ -2982,6 +2984,24 @@ post_reset:vfio_pci_post_reset (vdev); } +static void vfio_vm_change_state_handler (void *pv,int running,RunState state) +{ +VFIOPCIDevice *vdev = pv; +VFIODevice *vbasedev = &vdev->vbasedev; +uint8_t dev_state; +uint8_t sz =1 ; + + dev_state = running ?VFIO_DEVICE_START :VFIO_DEVICE_STOP ;
hw/vfio/pci.c post_reset: · line 3004
Quoted 10 lines
hw/vfio/pci.c +10
-0+ +if (pwrite (vdev->vbasedev.fd, &dev_state, + sz, vdev->device_state.offset) != sz) { +error_report ("vfio: Failed to %s device" , running ?"start" :"stop" ); +return ; + } + + vbasedev->device_state = dev_state; +} +
Is it expected to trap device_state region by vendor driver? Can this information be communicated to vendor driver through an ioctl?
Here only device state is conveyed to vendor driver but knowing 'RunState' in vendor driver is very useful and vendor driver can take necessary action accordingly like RUN_STATE_PAUSED indicating that VM is in paused state, similarly RUN_STATE_SUSPENDED, RUN_STATE_FINISH_MIGRATE, RUN_STATE_IO_ERROR. If these states are handled properly, all the cases can be supported with same interface like VM suspend-resume, VM pause-restore.
Thanks,
Kirti
Quoted 40 lines
hw/vfio/pci.c +0
-0static void vfio_instance_init (Object *obj) {PCIDevice *pci_dev =PCI_DEVICE (obj);include/hw/vfio/vfio-common.h +1
-0@@ -125,6 +125,7 @@ typedef struct VFIODevice {unsigned int num_irqs;unsigned int num_regions;unsigned int flags; +bool device_state; } VFIODevice;struct VFIODeviceOps {linux-headers/linux/vfio.h +6
-0@@ -304,6 +304,12 @@ struct vfio_region_info_cap_type {/* Mdev sub-type for device state save and restore */ #define VFIO_REGION_SUBTYPE_DEVICE_STATE (4) +/* Offset in region to save device state */ +#define VFIO_DEVICE_STATE_OFFSET 1 + +#define VFIO_DEVICE_START 0 +#define VFIO_DEVICE_STOP 1 +/** * VFIO_DEVICE_GET_IRQ_INFO - _IOWR(VFIO_TYPE, VFIO_BASE + 9, * struct vfio_irq_info) roms/seabios +1
-1@@ -1 +1 @@ -Subproject commit 63451fca13c75870e1703eb3e20584d91179aebc +Subproject commit 5f4c7b13cdf9c450eb55645f4362ea58fa61b79b
Quoted 52 lines · On Mon, 16 Apr 2018 20:14:27 +0530 Kirti Wankhede <[email protected]> wrote:
Quoted 51 lines · Yulei Zhang
VM status change handler is added to change the vfio pci device status during the migration, write the demanded device status to the DEVICE STATUS subregion to stop the device on the source side before fetch its status and start the deivce on the target side after restore its status.
Signed-off-by Yulei Zhang <[email protected]>--- hw/vfio/pci.c | 20 ++++++++++++++++++++ include/hw/vfio/vfio-common.h | 1 + linux-headers/linux/vfio.h | 6 ++++++ roms/seabios | 2 +- 4 files changed, 28 insertions(+), 1 deletion(-)hw/vfio/pci.c +15
-0@@ -38,6 +38,7 @@static void vfio_disable_interrupts (VFIOPCIDevice *vdev);static void vfio_mmap_set_enabled (VFIOPCIDevice *vdev,bool enabled); +static void vfio_vm_change_state_handler (void *pv,int running,RunState state);/* * Disabling BAR mmaping can be slow, but toggling it around INTx can @@ -2896,6 +2897,7 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)vfio_register_err_notifier (vdev);vfio_register_req_notifier (vdev);vfio_setup_resetfn_quirk (vdev); +qemu_add_vm_change_state_handler (vfio_vm_change_state_handler, vdev);return ;@@ -2982,6 +2984,24 @@ post_reset:vfio_pci_post_reset (vdev); } +static void vfio_vm_change_state_handler (void *pv,int running,RunState state) +{ +VFIOPCIDevice *vdev = pv; +VFIODevice *vbasedev = &vdev->vbasedev; +uint8_t dev_state; +uint8_t sz =1 ; + + dev_state = running ?VFIO_DEVICE_START :VFIO_DEVICE_STOP ; + +if (pwrite (vdev->vbasedev.fd, &dev_state, + sz, vdev->device_state.offset) != sz) { +error_report ("vfio: Failed to %s device" , running ?"start" :"stop" ); +return ;
Quoted 8 lines
hw/vfio/pci.c post_reset: · line 3004
Quoted 5 lines
hw/vfio/pci.c +5
-0+ } + + vbasedev->device_state = dev_state; +} +Is it expected to trap
device_stateregion by vendor driver? Can this information be communicated to vendor driver through an ioctl?
Either the mdev vendor driver or vfio bus driver (ie. vfio-pci) would be providing REGION_INFO for this region, so the vendor driver is already in full control here using existing ioctls. I don't see that we need new ioctls, we just need to fully define the API of the proposed regions here.
Quoted 7 lines
Here only device state is conveyed to vendor driver but knowing 'RunState' in vendor driver is very useful and vendor driver can take necessary action accordingly like
RUN_STATE_PAUSEDindicating that VM is in paused state, similarlyRUN_STATE_SUSPENDED,RUN_STATE_FINISH_MIGRATE,RUN_STATE_IO_ERROR. If these states are handled properly, all the cases can be supported with same interface like VM suspend-resume, VM pause-restore.
I agree, but let's remember that we're talking about device state, not VM state. vfio is a userspace device interface, not specifically a virtual machine interface, so states should be in terms of the device. The API of this region needs to be clearly defined and using only 1 byte at the start of the region is not very forward looking. Thanks,
Alex
Quoted 40 lines
Quoted 40 lines
hw/vfio/pci.c +0
-0static void vfio_instance_init (Object *obj) {PCIDevice *pci_dev =PCI_DEVICE (obj);include/hw/vfio/vfio-common.h +1
-0@@ -125,6 +125,7 @@ typedef struct VFIODevice {unsigned int num_irqs;unsigned int num_regions;unsigned int flags; +bool device_state; } VFIODevice;struct VFIODeviceOps {linux-headers/linux/vfio.h +6
-0@@ -304,6 +304,12 @@ struct vfio_region_info_cap_type {/* Mdev sub-type for device state save and restore */ #define VFIO_REGION_SUBTYPE_DEVICE_STATE (4) +/* Offset in region to save device state */ +#define VFIO_DEVICE_STATE_OFFSET 1 + +#define VFIO_DEVICE_START 0 +#define VFIO_DEVICE_STOP 1 +/** * VFIO_DEVICE_GET_IRQ_INFO - _IOWR(VFIO_TYPE, VFIO_BASE + 9, * struct vfio_irq_info) roms/seabios +1
-1@@ -1 +1 @@ -Subproject commit 63451fca13c75870e1703eb3e20584d91179aebc +Subproject commit 5f4c7b13cdf9c450eb55645f4362ea58fa61b79b
Quoted 82 lines
-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Tuesday, April 17, 2018 4:23 AM
To: Kirti Wankhede <[email protected]>
Cc: Zhang, Yulei <[email protected]>; [email protected]; Tian, Kevin <[email protected]>; [email protected]; [email protected]; Wang, Zhi A <[email protected]>; [email protected]; [email protected]
Subject: Re: [RFC PATCH V4 2/4] vfio: Add vm status change callback to stop/restart the mdev deviceQuoted 21 lines · On Mon, 16 Apr 2018 20:14:27 +0530 Kirti Wankhede <[email protected]> wrote:
Quoted 20 lines · Yulei Zhang
VM status change handler is added to change the vfio pci device status during the migration, write the demanded device status to the DEVICE STATUS subregion to stop the device on the source side before fetch its status and start the deivce on the target side after restore its status.
Signed-off-by Yulei Zhang <[email protected]>--- hw/vfio/pci.c | 20 ++++++++++++++++++++ include/hw/vfio/vfio-common.h | 1 + linux-headers/linux/vfio.h | 6 ++++++ roms/seabios | 2 +- 4 files changed, 28 insertions(+), 1 deletion(-)hw/vfio/pci.c +0
-0@@ -38,6 +38,7 @@Quoted 3 lines
hw/vfio/pci.c
Quoted 3 lines
hw/vfio/pci.c +1
-0static void vfio_disable_interrupts (VFIOPCIDevice *vdev);static void vfio_mmap_set_enabled (VFIOPCIDevice *vdev,bool enabled); +static void vfio_vm_change_state_handler(void *pv, int running,RunState state);
Quoted 4 lines
hw/vfio/pci.c static void vfio_realize(PCIDevice *pdev, Error
Quoted 4 lines
hw/vfio/pci.c +0
-0/* * Disabling BAR mmaping can be slow, but toggling it around INTx can @@ -2896,6 +2897,7 @@ static void vfio_realize(PCIDevice *pdev, Error**errp)
Quoted 4 lines
hw/vfio/pci.c static void vfio_realize(PCIDevice *pdev, Error **errp)
Quoted 4 lines
hw/vfio/pci.c +1
-0vfio_register_err_notifier (vdev);vfio_register_req_notifier (vdev);vfio_setup_resetfn_quirk (vdev); +
qemu_add_vm_change_state_handler(vfio_vm_change_state_handler, vdev);Quoted 8 lines
hw/vfio/pci.c post_reset: · line 2987
Quoted 8 lines
hw/vfio/pci.c +1
-0return ;@@ -2982,6 +2984,24 @@ post_reset:vfio_pci_post_reset (vdev); } +static void vfio_vm_change_state_handler(void *pv, int running,RunState state)
Quoted 12 lines
Quoted 12 lines
hw/vfio/pci.c +12
-0+{ +VFIOPCIDevice *vdev = pv; +VFIODevice *vbasedev = &vdev->vbasedev; +uint8_t dev_state; +uint8_t sz =1 ; + + dev_state = running ?VFIO_DEVICE_START :VFIO_DEVICE_STOP ; + +if (pwrite (vdev->vbasedev.fd, &dev_state, + sz, vdev->device_state.offset) != sz) { +error_report ("vfio: Failed to %s device" , running ?"start" :"stop" ); +return ;Quoted 8 lines
hw/vfio/pci.c post_reset: · line 3004
Quoted 5 lines
hw/vfio/pci.c +5
-0+ } + + vbasedev->device_state = dev_state; +} +Is it expected to trap
device_stateregion by vendor driver? Can this information be communicated to vendor driver through an ioctl?
Quoted 6 lines
Either the mdev vendor driver or vfio bus driver (ie. vfio-pci) would be providing
REGION_INFOfor this region, so the vendor driver is already in full control here using existing ioctls. I don't see that we need new ioctls, we just need to fully define the API of the proposed regions here.
If the device state region is mmaped, we may not be able to use region device state offset to convey the running state. It may need a new ioctl to set the device state.
Quoted 58 lines
Quoted 3 lines
Here only device state is conveyed to vendor driver but knowing 'RunState' in vendor driver is very useful and vendor driver can take necessary action accordingly like
RUN_STATE_PAUSEDindicating that VMis
Quoted 4 lines
in paused state, similarly
RUN_STATE_SUSPENDED,RUN_STATE_FINISH_MIGRATE,RUN_STATE_IO_ERROR. If these states are handled properly, all the cases can be supported with same interface like VM suspend-resume, VM pause-restore.I agree, but let's remember that we're talking about device state, not VM state. vfio is a userspace device interface, not specifically a virtual machine interface, so states should be in terms of the device. The API of this region needs to be clearly defined and using only 1 byte at the start of the region is not very forward looking. Thanks,
Alex
Quoted 4 lines
include/hw/vfio/vfio-
Quoted 4 lines
hw/vfio/pci.c +0
-0static void vfio_instance_init (Object *obj) {PCIDevice *pci_dev =PCI_DEVICE (obj);include/hw/vfio/vfio- renamed from include/hw/vfio/vfio-common.h +0
-0
common.hQuoted 36 lines
Quoted 36 lines
index f3a2ac9..9c14a8f 100644
include/hw/vfio/vfio-common.h +1
-0@@ -125,6 +125,7 @@ typedef struct VFIODevice {unsigned int num_irqs;unsigned int num_regions;unsigned int flags; +bool device_state; } VFIODevice;struct VFIODeviceOps {linux-headers/linux/vfio.h +6
-0@@ -304,6 +304,12 @@ struct vfio_region_info_cap_type {/* Mdev sub-type for device state save and restore */ #define VFIO_REGION_SUBTYPE_DEVICE_STATE (4) +/* Offset in region to save device state */ +#define VFIO_DEVICE_STATE_OFFSET 1 + +#define VFIO_DEVICE_START 0 +#define VFIO_DEVICE_STOP 1 +/** * VFIO_DEVICE_GET_IRQ_INFO - _IOWR(VFIO_TYPE, VFIO_BASE + 9, * struct vfio_irq_info) roms/seabios +1
-1@@ -1 +1 @@ -Subproject commit 63451fca13c75870e1703eb3e20584d91179aebc +Subproject commit 5f4c7b13cdf9c450eb55645f4362ea58fa61b79b
Quoted 86 lines · Yulei
Quoted 80 lines
-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Tuesday, April 17, 2018 4:23 AM
To: Kirti Wankhede <[email protected]>
Cc: Zhang, Yulei <[email protected]>; [email protected]; Tian, Kevin <[email protected]>; [email protected]; [email protected]; Wang, Zhi A <[email protected]>; [email protected]; [email protected]
Subject: Re: [RFC PATCH V4 2/4] vfio: Add vm status change callback to stop/restart the mdev deviceQuoted 21 lines · On Mon, 16 Apr 2018 20:14:27 +0530 Kirti Wankhede <[email protected]> wrote:
Quoted 20 lines · Yulei Zhang
VM status change handler is added to change the vfio pci device status during the migration, write the demanded device status to the DEVICE STATUS subregion to stop the device on the source side before fetch its status and start the deivce on the target side after restore its status.
Signed-off-by Yulei Zhang <[email protected]>--- hw/vfio/pci.c | 20 ++++++++++++++++++++ include/hw/vfio/vfio-common.h | 1 + linux-headers/linux/vfio.h | 6 ++++++ roms/seabios | 2 +- 4 files changed, 28 insertions(+), 1 deletion(-)hw/vfio/pci.c +0
-0@@ -38,6 +38,7 @@Quoted 3 lines
hw/vfio/pci.c
Quoted 3 lines
hw/vfio/pci.c +1
-0static void vfio_disable_interrupts (VFIOPCIDevice *vdev);static void vfio_mmap_set_enabled (VFIOPCIDevice *vdev,bool enabled); +static void vfio_vm_change_state_handler(void *pv, int running,RunState state);
Quoted 4 lines
hw/vfio/pci.c static void vfio_realize(PCIDevice *pdev, Error
Quoted 4 lines
hw/vfio/pci.c +0
-0/* * Disabling BAR mmaping can be slow, but toggling it around INTx can @@ -2896,6 +2897,7 @@ static void vfio_realize(PCIDevice *pdev, Error**errp)
Quoted 4 lines
hw/vfio/pci.c static void vfio_realize(PCIDevice *pdev, Error **errp)
Quoted 4 lines
hw/vfio/pci.c +1
-0vfio_register_err_notifier (vdev);vfio_register_req_notifier (vdev);vfio_setup_resetfn_quirk (vdev); +
qemu_add_vm_change_state_handler(vfio_vm_change_state_handler, vdev);Quoted 8 lines
hw/vfio/pci.c post_reset: · line 2987
Quoted 8 lines
hw/vfio/pci.c +1
-0return ;@@ -2982,6 +2984,24 @@ post_reset:vfio_pci_post_reset (vdev); } +static void vfio_vm_change_state_handler(void *pv, int running,RunState state)
Quoted 12 lines
Quoted 12 lines
hw/vfio/pci.c +12
-0+{ +VFIOPCIDevice *vdev = pv; +VFIODevice *vbasedev = &vdev->vbasedev; +uint8_t dev_state; +uint8_t sz =1 ; + + dev_state = running ?VFIO_DEVICE_START :VFIO_DEVICE_STOP ; + +if (pwrite (vdev->vbasedev.fd, &dev_state, + sz, vdev->device_state.offset) != sz) { +error_report ("vfio: Failed to %s device" , running ?"start" :"stop" ); +return ;Quoted 8 lines
hw/vfio/pci.c post_reset: · line 3004
Quoted 5 lines
hw/vfio/pci.c +5
-0+ } + + vbasedev->device_state = dev_state; +} +Is it expected to trap
device_stateregion by vendor driver? Can this information be communicated to vendor driver through an ioctl?Quoted 6 lines
Either the mdev vendor driver or vfio bus driver (ie. vfio-pci) would be providing
REGION_INFOfor this region, so the vendor driver is already in full control here using existing ioctls. I don't see that we need new ioctls, we just need to fully define the API of the proposed regions here.
Quoted 3 lines
If the device state region is mmaped, we may not be able to use region device state offset to convey the running state. It may need a new ioctl to set the device state.
The vendor driver defines the mmap'ability of the region, the vendor driver is still in control. The API of the region and the implementation by the vendor driver should account for handling mmap'able sections within the region. Thanks,
Alex
Quoted 59 lines
Quoted 58 lines
Quoted 3 lines
Here only device state is conveyed to vendor driver but knowing 'RunState' in vendor driver is very useful and vendor driver can take necessary action accordingly like
RUN_STATE_PAUSEDindicating that VMis
Quoted 4 lines
in paused state, similarly
RUN_STATE_SUSPENDED,RUN_STATE_FINISH_MIGRATE,RUN_STATE_IO_ERROR. If these states are handled properly, all the cases can be supported with same interface like VM suspend-resume, VM pause-restore.I agree, but let's remember that we're talking about device state, not VM state. vfio is a userspace device interface, not specifically a virtual machine interface, so states should be in terms of the device. The API of this region needs to be clearly defined and using only 1 byte at the start of the region is not very forward looking. Thanks,
Alex
Quoted 4 lines
include/hw/vfio/vfio-
Quoted 4 lines
hw/vfio/pci.c +0
-0static void vfio_instance_init (Object *obj) {PCIDevice *pci_dev =PCI_DEVICE (obj);include/hw/vfio/vfio- renamed from include/hw/vfio/vfio-common.h +0
-0
common.hQuoted 36 lines
Quoted 36 lines
index f3a2ac9..9c14a8f 100644
include/hw/vfio/vfio-common.h +1
-0@@ -125,6 +125,7 @@ typedef struct VFIODevice {unsigned int num_irqs;unsigned int num_regions;unsigned int flags; +bool device_state; } VFIODevice;struct VFIODeviceOps {linux-headers/linux/vfio.h +6
-0@@ -304,6 +304,12 @@ struct vfio_region_info_cap_type {/* Mdev sub-type for device state save and restore */ #define VFIO_REGION_SUBTYPE_DEVICE_STATE (4) +/* Offset in region to save device state */ +#define VFIO_DEVICE_STATE_OFFSET 1 + +#define VFIO_DEVICE_START 0 +#define VFIO_DEVICE_STOP 1 +/** * VFIO_DEVICE_GET_IRQ_INFO - _IOWR(VFIO_TYPE, VFIO_BASE + 9, * struct vfio_irq_info) roms/seabios +1
-1@@ -1 +1 @@ -Subproject commit 63451fca13c75870e1703eb3e20584d91179aebc +Subproject commit 5f4c7b13cdf9c450eb55645f4362ea58fa61b79b
Quoted 93 lines · Alex Williamson
Quoted 86 lines · Yulei
Quoted 80 lines
-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Tuesday, April 17, 2018 4:23 AM
To: Kirti Wankhede <[email protected]>
Cc: Zhang, Yulei <[email protected]>; [email protected]; Tian, Kevin <[email protected]>; [email protected]; [email protected]; Wang, Zhi A <[email protected]>; [email protected]; [email protected]
Subject: Re: [RFC PATCH V4 2/4] vfio: Add vm status change callback to stop/restart the mdev deviceQuoted 21 lines · On Mon, 16 Apr 2018 20:14:27 +0530 Kirti Wankhede <[email protected]> wrote:
Quoted 20 lines · Yulei Zhang
VM status change handler is added to change the vfio pci device status during the migration, write the demanded device status to the DEVICE STATUS subregion to stop the device on the source side before fetch its status and start the deivce on the target side after restore its status.
Signed-off-by Yulei Zhang <[email protected]>--- hw/vfio/pci.c | 20 ++++++++++++++++++++ include/hw/vfio/vfio-common.h | 1 + linux-headers/linux/vfio.h | 6 ++++++ roms/seabios | 2 +- 4 files changed, 28 insertions(+), 1 deletion(-)hw/vfio/pci.c +0
-0@@ -38,6 +38,7 @@Quoted 3 lines
hw/vfio/pci.c
Quoted 3 lines
hw/vfio/pci.c +1
-0static void vfio_disable_interrupts (VFIOPCIDevice *vdev);static void vfio_mmap_set_enabled (VFIOPCIDevice *vdev,bool enabled); +static void vfio_vm_change_state_handler(void *pv, int running,RunState state);
Quoted 4 lines
hw/vfio/pci.c static void vfio_realize(PCIDevice *pdev, Error
Quoted 4 lines
hw/vfio/pci.c +0
-0/* * Disabling BAR mmaping can be slow, but toggling it around INTx can @@ -2896,6 +2897,7 @@ static void vfio_realize(PCIDevice *pdev, Error**errp)
Quoted 4 lines
hw/vfio/pci.c static void vfio_realize(PCIDevice *pdev, Error **errp)
Quoted 4 lines
hw/vfio/pci.c +1
-0vfio_register_err_notifier (vdev);vfio_register_req_notifier (vdev);vfio_setup_resetfn_quirk (vdev); +
qemu_add_vm_change_state_handler(vfio_vm_change_state_handler, vdev);Quoted 8 lines
hw/vfio/pci.c post_reset: · line 2987
Quoted 8 lines
hw/vfio/pci.c +1
-0return ;@@ -2982,6 +2984,24 @@ post_reset:vfio_pci_post_reset (vdev); } +static void vfio_vm_change_state_handler(void *pv, int running,RunState state)
Quoted 12 lines
Quoted 12 lines
hw/vfio/pci.c +12
-0+{ +VFIOPCIDevice *vdev = pv; +VFIODevice *vbasedev = &vdev->vbasedev; +uint8_t dev_state; +uint8_t sz =1 ; + + dev_state = running ?VFIO_DEVICE_START :VFIO_DEVICE_STOP ; + +if (pwrite (vdev->vbasedev.fd, &dev_state, + sz, vdev->device_state.offset) != sz) { +error_report ("vfio: Failed to %s device" , running ?"start" :"stop" ); +return ;Quoted 8 lines
hw/vfio/pci.c post_reset: · line 3004
Quoted 5 lines
hw/vfio/pci.c +5
-0+ } + + vbasedev->device_state = dev_state; +} +Is it expected to trap
device_stateregion by vendor driver? Can this information be communicated to vendor driver through an ioctl?Quoted 6 lines
Either the mdev vendor driver or vfio bus driver (ie. vfio-pci) would be providing
REGION_INFOfor this region, so the vendor driver is already in full control here using existing ioctls. I don't see that we need new ioctls, we just need to fully define the API of the proposed regions here.Quoted 3 lines
If the device state region is mmaped, we may not be able to use region device state offset to convey the running state. It may need a new ioctl to set the device state.
Quoted 8 lines
The vendor driver defines the mmap'ability of the region, the vendor driver is still in control. The API of the region and the implementation by the vendor driver should account for handling mmap'able sections within the region. Thanks,
Alex
If this same region should be used for communicating state or other parameters instead of ioctl, may be first page of this region need to be reserved. Mmappable region's start address should be page aligned. Is this API going to utilize 4K of the reserved part of this region? Instead of carving out part of section from the region, are there any disadvantages of adding an ioctl?
May be defining a single ioctl and using different flags (GET_*/SET_*) would work?
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 3 lines
Here only device state is conveyed to vendor driver but knowing 'RunState' in vendor driver is very useful and vendor driver can take necessary action accordingly like
RUN_STATE_PAUSEDindicating that VMis
Quoted 4 lines
in paused state, similarly
RUN_STATE_SUSPENDED,RUN_STATE_FINISH_MIGRATE,RUN_STATE_IO_ERROR. If these states are handled properly, all the cases can be supported with same interface like VM suspend-resume, VM pause-restore.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
I agree, but let's remember that we're talking about device state, not VM state. vfio is a userspace device interface, not specifically a virtual machine interface, so states should be in terms of the device. The API of this region needs to be clearly defined and using only 1 byte at the start of the region is not very forward looking. Thanks,
Alex
Sorry for using wrong term in my previous reply, 'RunState' is actually CPU state and not VM state. In terms of vfio device interface knowing CPU state would be helpful, right?
Thanks,
Kirti
Quoted 43 lines
Quoted 42 lines
Quoted 41 lines
Quoted 4 lines
include/hw/vfio/vfio-
Quoted 4 lines
hw/vfio/pci.c +0
-0static void vfio_instance_init (Object *obj) {PCIDevice *pci_dev =PCI_DEVICE (obj);include/hw/vfio/vfio- renamed from include/hw/vfio/vfio-common.h +0
-0
common.hQuoted 36 lines
Quoted 36 lines
index f3a2ac9..9c14a8f 100644
include/hw/vfio/vfio-common.h +1
-0@@ -125,6 +125,7 @@ typedef struct VFIODevice {unsigned int num_irqs;unsigned int num_regions;unsigned int flags; +bool device_state; } VFIODevice;struct VFIODeviceOps {linux-headers/linux/vfio.h +6
-0@@ -304,6 +304,12 @@ struct vfio_region_info_cap_type {/* Mdev sub-type for device state save and restore */ #define VFIO_REGION_SUBTYPE_DEVICE_STATE (4) +/* Offset in region to save device state */ +#define VFIO_DEVICE_STATE_OFFSET 1 + +#define VFIO_DEVICE_START 0 +#define VFIO_DEVICE_STOP 1 +/** * VFIO_DEVICE_GET_IRQ_INFO - _IOWR(VFIO_TYPE, VFIO_BASE + 9, * struct vfio_irq_info) roms/seabios +1
-1@@ -1 +1 @@ -Subproject commit 63451fca13c75870e1703eb3e20584d91179aebc +Subproject commit 5f4c7b13cdf9c450eb55645f4362ea58fa61b79b
Quoted 103 lines · On Wed, 18 Apr 2018 00:44:35 +0530 Kirti Wankhede <[email protected]> wrote:
Quoted 93 lines · Alex Williamson
Quoted 86 lines · Yulei
Quoted 80 lines
-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Tuesday, April 17, 2018 4:23 AM
To: Kirti Wankhede <[email protected]>
Cc: Zhang, Yulei <[email protected]>; [email protected]; Tian, Kevin <[email protected]>; [email protected]; [email protected]; Wang, Zhi A <[email protected]>; [email protected]; [email protected]
Subject: Re: [RFC PATCH V4 2/4] vfio: Add vm status change callback to stop/restart the mdev deviceQuoted 21 lines · On Mon, 16 Apr 2018 20:14:27 +0530 Kirti Wankhede <[email protected]> wrote:
Quoted 20 lines · Yulei Zhang
VM status change handler is added to change the vfio pci device status during the migration, write the demanded device status to the DEVICE STATUS subregion to stop the device on the source side before fetch its status and start the deivce on the target side after restore its status.
Signed-off-by Yulei Zhang <[email protected]>--- hw/vfio/pci.c | 20 ++++++++++++++++++++ include/hw/vfio/vfio-common.h | 1 + linux-headers/linux/vfio.h | 6 ++++++ roms/seabios | 2 +- 4 files changed, 28 insertions(+), 1 deletion(-)hw/vfio/pci.c +0
-0@@ -38,6 +38,7 @@Quoted 3 lines
hw/vfio/pci.c
Quoted 3 lines
hw/vfio/pci.c +1
-0static void vfio_disable_interrupts (VFIOPCIDevice *vdev);static void vfio_mmap_set_enabled (VFIOPCIDevice *vdev,bool enabled); +static void vfio_vm_change_state_handler(void *pv, int running,RunState state);
Quoted 4 lines
hw/vfio/pci.c static void vfio_realize(PCIDevice *pdev, Error
Quoted 4 lines
hw/vfio/pci.c +0
-0/* * Disabling BAR mmaping can be slow, but toggling it around INTx can @@ -2896,6 +2897,7 @@ static void vfio_realize(PCIDevice *pdev, Error**errp)
Quoted 4 lines
hw/vfio/pci.c static void vfio_realize(PCIDevice *pdev, Error **errp)
Quoted 4 lines
hw/vfio/pci.c +1
-0vfio_register_err_notifier (vdev);vfio_register_req_notifier (vdev);vfio_setup_resetfn_quirk (vdev); +
qemu_add_vm_change_state_handler(vfio_vm_change_state_handler, vdev);Quoted 8 lines
hw/vfio/pci.c post_reset: · line 2987
Quoted 8 lines
hw/vfio/pci.c +1
-0return ;@@ -2982,6 +2984,24 @@ post_reset:vfio_pci_post_reset (vdev); } +static void vfio_vm_change_state_handler(void *pv, int running,RunState state)
Quoted 12 lines
Quoted 12 lines
hw/vfio/pci.c +12
-0+{ +VFIOPCIDevice *vdev = pv; +VFIODevice *vbasedev = &vdev->vbasedev; +uint8_t dev_state; +uint8_t sz =1 ; + + dev_state = running ?VFIO_DEVICE_START :VFIO_DEVICE_STOP ; + +if (pwrite (vdev->vbasedev.fd, &dev_state, + sz, vdev->device_state.offset) != sz) { +error_report ("vfio: Failed to %s device" , running ?"start" :"stop" ); +return ;Quoted 8 lines
hw/vfio/pci.c post_reset: · line 3004
Quoted 5 lines
hw/vfio/pci.c +5
-0+ } + + vbasedev->device_state = dev_state; +} +Is it expected to trap
device_stateregion by vendor driver? Can this information be communicated to vendor driver through an ioctl?Quoted 6 lines
Either the mdev vendor driver or vfio bus driver (ie. vfio-pci) would be providing
REGION_INFOfor this region, so the vendor driver is already in full control here using existing ioctls. I don't see that we need new ioctls, we just need to fully define the API of the proposed regions here.Quoted 3 lines
If the device state region is mmaped, we may not be able to use region device state offset to convey the running state. It may need a new ioctl to set the device state.
Quoted 8 lines
The vendor driver defines the mmap'ability of the region, the vendor driver is still in control. The API of the region and the implementation by the vendor driver should account for handling mmap'able sections within the region. Thanks,
Alex
Quoted 8 lines
If this same region should be used for communicating state or other parameters instead of ioctl, may be first page of this region need to be reserved. Mmappable region's start address should be page aligned. Is this API going to utilize 4K of the reserved part of this region? Instead of carving out part of section from the region, are there any disadvantages of adding an ioctl?
May be defining a single ioctl and using different flags (GET_*/SET_*) would work?
Yes, ioctls are something that should be feared and reviewed with great scrutiny and we should feel bad if we do a poor job defining them and burn ioctl numbers whereas we have 32bits worth of region sub-types and 31 bits of region types to churn through within our own address space and we can easily deprecate losing designs without much harm. Thus, I want to see that an ioctl is really the best way to perform the task rather than just being the default answer to everything. Is it really a problem if data starts at some offset into the region? That sounds like part of the region API that I want to see defined. The region can start with a header containing explicit save state version and device information, writable registers for relaying state information, an offset to the start of the vendor data field, etc. If we can make a GPU work via a definition of registers and doorbells and framebuffers in an MMIO region then surely we can figure out a virtual register and buffer definition to do save and restore of the device. Otherwise, why is an ioctl the best tool for this task?
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 3 lines
Here only device state is conveyed to vendor driver but knowing 'RunState' in vendor driver is very useful and vendor driver can take necessary action accordingly like
RUN_STATE_PAUSEDindicating that VMis
Quoted 4 lines
in paused state, similarly
RUN_STATE_SUSPENDED,RUN_STATE_FINISH_MIGRATE,RUN_STATE_IO_ERROR. If these states are handled properly, all the cases can be supported with same interface like VM suspend-resume, VM pause-restore.I agree, but let's remember that we're talking about device state, not VM state. vfio is a userspace device interface, not specifically a virtual machine interface, so states should be in terms of the device. The API of this region needs to be clearly defined and using only 1 byte at the start of the region is not very forward looking. Thanks,
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Alex
Sorry for using wrong term in my previous reply, 'RunState' is actually CPU state and not VM state. In terms of vfio device interface knowing CPU state would be helpful, right?
Why? CPU state is describing something disassociated with the device. QEMU will interpret the CPU state into something it wants the device to do. The VFIO interface should be defined in terms of the state you want to impose on the device. What the CPU is doing is not the device's problem. Make sense? Thanks,
Alex
Quoted 115 lines · Alex Williamson
Quoted 103 lines · On Wed, 18 Apr 2018 00:44:35 +0530 Kirti Wankhede <[email protected]> wrote:
Quoted 93 lines · Alex Williamson
Quoted 86 lines · Yulei
Quoted 80 lines
-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Tuesday, April 17, 2018 4:23 AM
To: Kirti Wankhede <[email protected]>
Cc: Zhang, Yulei <[email protected]>; [email protected]; Tian, Kevin <[email protected]>; [email protected]; [email protected]; Wang, Zhi A <[email protected]>; [email protected]; [email protected]
Subject: Re: [RFC PATCH V4 2/4] vfio: Add vm status change callback to stop/restart the mdev deviceQuoted 21 lines · On Mon, 16 Apr 2018 20:14:27 +0530 Kirti Wankhede <[email protected]> wrote:
Quoted 20 lines · Yulei Zhang
VM status change handler is added to change the vfio pci device status during the migration, write the demanded device status to the DEVICE STATUS subregion to stop the device on the source side before fetch its status and start the deivce on the target side after restore its status.
Signed-off-by Yulei Zhang <[email protected]>--- hw/vfio/pci.c | 20 ++++++++++++++++++++ include/hw/vfio/vfio-common.h | 1 + linux-headers/linux/vfio.h | 6 ++++++ roms/seabios | 2 +- 4 files changed, 28 insertions(+), 1 deletion(-)hw/vfio/pci.c +0
-0@@ -38,6 +38,7 @@Quoted 3 lines
hw/vfio/pci.c line 41
Quoted 3 lines
hw/vfio/pci.c +1
-0static void vfio_disable_interrupts (VFIOPCIDevice *vdev);static void vfio_mmap_set_enabled (VFIOPCIDevice *vdev,bool enabled); +static void vfio_vm_change_state_handler(void *pv, int running,RunState state);
Quoted 4 lines
hw/vfio/pci.c static void vfio_realize(PCIDevice *pdev, Error
Quoted 4 lines
hw/vfio/pci.c +0
-0/* * Disabling BAR mmaping can be slow, but toggling it around INTx can @@ -2896,6 +2897,7 @@ static void vfio_realize(PCIDevice *pdev, Error**errp)
Quoted 4 lines
hw/vfio/pci.c static void vfio_realize(PCIDevice *pdev, Error · line 2900
Quoted 4 lines
hw/vfio/pci.c +1
-0vfio_register_err_notifier (vdev);vfio_register_req_notifier (vdev);vfio_setup_resetfn_quirk (vdev); +
qemu_add_vm_change_state_handler(vfio_vm_change_state_handler, vdev);Quoted 8 lines
hw/vfio/pci.c post_reset: · line 2987
Quoted 8 lines
hw/vfio/pci.c +1
-0return ;@@ -2982,6 +2984,24 @@ post_reset:vfio_pci_post_reset (vdev); } +static void vfio_vm_change_state_handler(void *pv, int running,RunState state)
Quoted 12 lines
Quoted 12 lines
hw/vfio/pci.c +12
-0+{ +VFIOPCIDevice *vdev = pv; +VFIODevice *vbasedev = &vdev->vbasedev; +uint8_t dev_state; +uint8_t sz =1 ; + + dev_state = running ?VFIO_DEVICE_START :VFIO_DEVICE_STOP ; + +if (pwrite (vdev->vbasedev.fd, &dev_state, + sz, vdev->device_state.offset) != sz) { +error_report ("vfio: Failed to %s device" , running ?"start" :"stop" ); +return ;Quoted 8 lines
hw/vfio/pci.c post_reset: · line 3004
Quoted 5 lines
hw/vfio/pci.c +5
-0+ } + + vbasedev->device_state = dev_state; +} +Is it expected to trap
device_stateregion by vendor driver? Can this information be communicated to vendor driver through an ioctl?Quoted 6 lines
Either the mdev vendor driver or vfio bus driver (ie. vfio-pci) would be providing
REGION_INFOfor this region, so the vendor driver is already in full control here using existing ioctls. I don't see that we need new ioctls, we just need to fully define the API of the proposed regions here.Quoted 3 lines
If the device state region is mmaped, we may not be able to use region device state offset to convey the running state. It may need a new ioctl to set the device state.
Quoted 8 lines
The vendor driver defines the mmap'ability of the region, the vendor driver is still in control. The API of the region and the implementation by the vendor driver should account for handling mmap'able sections within the region. Thanks,
Alex
Quoted 8 lines
If this same region should be used for communicating state or other parameters instead of ioctl, may be first page of this region need to be reserved. Mmappable region's start address should be page aligned. Is this API going to utilize 4K of the reserved part of this region? Instead of carving out part of section from the region, are there any disadvantages of adding an ioctl?
May be defining a single ioctl and using different flags (GET_*/SET_*) would work?
Quoted 5 lines
Yes, ioctls are something that should be feared and reviewed with great scrutiny and we should feel bad if we do a poor job defining them and burn ioctl numbers whereas we have 32bits worth of region sub-types and 31 bits of region types to churn through within our own address space and we can easily deprecate losing designs without much harm.
Makes sense.
Quoted 3 lines
Thus, I want to see that an ioctl is really the best way to perform the task rather than just being the default answer to everything. Is it really a problem if data starts at some offset into the region?
remap_pfn_range() or remap_vmalloc_range() expects target user address and physical address of kernel memory to be page aligned. Mappable region's start address should be page aligned.
That
Quoted 7 lines
sounds like part of the region API that I want to see defined. The region can start with a header containing explicit save state version and device information, writable registers for relaying state information, an offset to the start of the vendor data field, etc. If we can make a GPU work via a definition of registers and doorbells and framebuffers in an MMIO region then surely we can figure out a virtual register and buffer definition to do save and restore of the device.
All these regions mmapped are page aligned.
Quoted 2 lines
Otherwise, why is an ioctl the best tool for this task?
I agree that maintaining ioctl is difficult and burning ioctl number problem.
So lets reserve first page and start defining API, then we can know how much from 4K will be consumed for the APIs.
Quoted 22 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 3 lines
Here only device state is conveyed to vendor driver but knowing 'RunState' in vendor driver is very useful and vendor driver can take necessary action accordingly like
RUN_STATE_PAUSEDindicating that VMis
Quoted 4 lines
in paused state, similarly
RUN_STATE_SUSPENDED,RUN_STATE_FINISH_MIGRATE,RUN_STATE_IO_ERROR. If these states are handled properly, all the cases can be supported with same interface like VM suspend-resume, VM pause-restore.I agree, but let's remember that we're talking about device state, not VM state. vfio is a userspace device interface, not specifically a virtual machine interface, so states should be in terms of the device. The API of this region needs to be clearly defined and using only 1 byte at the start of the region is not very forward looking. Thanks,
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Alex
Sorry for using wrong term in my previous reply, 'RunState' is actually CPU state and not VM state. In terms of vfio device interface knowing CPU state would be helpful, right?
Quoted 5 lines
Why? CPU state is describing something disassociated with the device. QEMU will interpret the CPU state into something it wants the device to do. The VFIO interface should be defined in terms of the state you want to impose on the device. What the CPU is doing is not the device's problem. Make sense? Thanks,
CPU state does help to take action in pre-copy phase in different cases. Like in save VM case and suspend VM case, during pre-copy phase CPU is in RUN_STATE_PAUSED / RUN_STATE_SUSPENDED state while in case of live migration during pre-copy phase CPU is RUN_STATE_RUNNING state. In pre-copy phase if CPU is already paused then this phase can be skipped by returning pending bytes as 0 because nothing is going to be dirtied after CPUs are paused and transfer all device state in stop-and-copy phase.
Thanks,
Kirti
Quoted 124 lines · On Wed, 18 Apr 2018 02:41:44 +0530 Kirti Wankhede <[email protected]> wrote:
Quoted 115 lines · Alex Williamson
Quoted 103 lines · On Wed, 18 Apr 2018 00:44:35 +0530 Kirti Wankhede <[email protected]> wrote:
Quoted 93 lines · Alex Williamson
Quoted 86 lines · Yulei
Quoted 80 lines
-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Tuesday, April 17, 2018 4:23 AM
To: Kirti Wankhede <[email protected]>
Cc: Zhang, Yulei <[email protected]>; [email protected]; Tian, Kevin <[email protected]>; [email protected]; [email protected]; Wang, Zhi A <[email protected]>; [email protected]; [email protected]
Subject: Re: [RFC PATCH V4 2/4] vfio: Add vm status change callback to stop/restart the mdev deviceQuoted 21 lines · On Mon, 16 Apr 2018 20:14:27 +0530 Kirti Wankhede <[email protected]> wrote:
Quoted 20 lines · Yulei Zhang
VM status change handler is added to change the vfio pci device status during the migration, write the demanded device status to the DEVICE STATUS subregion to stop the device on the source side before fetch its status and start the deivce on the target side after restore its status.
Signed-off-by Yulei Zhang <[email protected]>--- hw/vfio/pci.c | 20 ++++++++++++++++++++ include/hw/vfio/vfio-common.h | 1 + linux-headers/linux/vfio.h | 6 ++++++ roms/seabios | 2 +- 4 files changed, 28 insertions(+), 1 deletion(-)hw/vfio/pci.c +0
-0@@ -38,6 +38,7 @@Quoted 3 lines
hw/vfio/pci.c line 41
Quoted 3 lines
hw/vfio/pci.c +1
-0static void vfio_disable_interrupts (VFIOPCIDevice *vdev);static void vfio_mmap_set_enabled (VFIOPCIDevice *vdev,bool enabled); +static void vfio_vm_change_state_handler(void *pv, int running,RunState state);
Quoted 4 lines
hw/vfio/pci.c static void vfio_realize(PCIDevice *pdev, Error
Quoted 4 lines
hw/vfio/pci.c +0
-0/* * Disabling BAR mmaping can be slow, but toggling it around INTx can @@ -2896,6 +2897,7 @@ static void vfio_realize(PCIDevice *pdev, Error**errp)
Quoted 4 lines
hw/vfio/pci.c static void vfio_realize(PCIDevice *pdev, Error · line 2900
Quoted 4 lines
hw/vfio/pci.c +1
-0vfio_register_err_notifier (vdev);vfio_register_req_notifier (vdev);vfio_setup_resetfn_quirk (vdev); +
qemu_add_vm_change_state_handler(vfio_vm_change_state_handler, vdev);Quoted 8 lines
hw/vfio/pci.c post_reset: · line 2987
Quoted 8 lines
hw/vfio/pci.c +1
-0return ;@@ -2982,6 +2984,24 @@ post_reset:vfio_pci_post_reset (vdev); } +static void vfio_vm_change_state_handler(void *pv, int running,RunState state)
Quoted 12 lines
Quoted 12 lines
hw/vfio/pci.c +12
-0+{ +VFIOPCIDevice *vdev = pv; +VFIODevice *vbasedev = &vdev->vbasedev; +uint8_t dev_state; +uint8_t sz =1 ; + + dev_state = running ?VFIO_DEVICE_START :VFIO_DEVICE_STOP ; + +if (pwrite (vdev->vbasedev.fd, &dev_state, + sz, vdev->device_state.offset) != sz) { +error_report ("vfio: Failed to %s device" , running ?"start" :"stop" ); +return ;Quoted 8 lines
hw/vfio/pci.c post_reset: · line 3004
Quoted 5 lines
hw/vfio/pci.c +5
-0+ } + + vbasedev->device_state = dev_state; +} +Is it expected to trap
device_stateregion by vendor driver? Can this information be communicated to vendor driver through an ioctl?Quoted 6 lines
Either the mdev vendor driver or vfio bus driver (ie. vfio-pci) would be providing
REGION_INFOfor this region, so the vendor driver is already in full control here using existing ioctls. I don't see that we need new ioctls, we just need to fully define the API of the proposed regions here.Quoted 3 lines
If the device state region is mmaped, we may not be able to use region device state offset to convey the running state. It may need a new ioctl to set the device state.
Quoted 8 lines
The vendor driver defines the mmap'ability of the region, the vendor driver is still in control. The API of the region and the implementation by the vendor driver should account for handling mmap'able sections within the region. Thanks,
Alex
Quoted 8 lines
If this same region should be used for communicating state or other parameters instead of ioctl, may be first page of this region need to be reserved. Mmappable region's start address should be page aligned. Is this API going to utilize 4K of the reserved part of this region? Instead of carving out part of section from the region, are there any disadvantages of adding an ioctl?
May be defining a single ioctl and using different flags (GET_*/SET_*) would work?Quoted 5 lines
Yes, ioctls are something that should be feared and reviewed with great scrutiny and we should feel bad if we do a poor job defining them and burn ioctl numbers whereas we have 32bits worth of region sub-types and 31 bits of region types to churn through within our own address space and we can easily deprecate losing designs without much harm.
Makes sense.
Quoted 7 lines
Quoted 3 lines
Thus, I want to see that an ioctl is really the best way to perform the task rather than just being the default answer to everything. Is it really a problem if data starts at some offset into the region?
remap_pfn_range()orremap_vmalloc_range()expects target user address and physical address of kernel memory to be page aligned. Mappable region's start address should be page aligned.
Sure, but whether to support mmap of the save region is a property of the vendor driver.
Quoted 11 lines
That
Quoted 7 lines
sounds like part of the region API that I want to see defined. The region can start with a header containing explicit save state version and device information, writable registers for relaying state information, an offset to the start of the vendor data field, etc. If we can make a GPU work via a definition of registers and doorbells and framebuffers in an MMIO region then surely we can figure out a virtual register and buffer definition to do save and restore of the device.
All these regions mmapped are page aligned.
Quoted 7 lines
Quoted 2 lines
Otherwise, why is an ioctl the best tool for this task?
I agree that maintaining ioctl is difficult and burning ioctl number problem.
So lets reserve first page and start defining API, then we can know how much from 4K will be consumed for the APIs.
Or rather define the API to include a start offset in the header so the vendor driver can choose whatever it wants/needs and we aren't tied to x86 PAGE_SIZE.
Quoted 28 lines
Quoted 22 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 3 lines
Here only device state is conveyed to vendor driver but knowing 'RunState' in vendor driver is very useful and vendor driver can take necessary action accordingly like
RUN_STATE_PAUSEDindicating that VMis
Quoted 4 lines
in paused state, similarly
RUN_STATE_SUSPENDED,RUN_STATE_FINISH_MIGRATE,RUN_STATE_IO_ERROR. If these states are handled properly, all the cases can be supported with same interface like VM suspend-resume, VM pause-restore.I agree, but let's remember that we're talking about device state, not VM state. vfio is a userspace device interface, not specifically a virtual machine interface, so states should be in terms of the device. The API of this region needs to be clearly defined and using only 1 byte at the start of the region is not very forward looking. Thanks,
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Alex
Sorry for using wrong term in my previous reply, 'RunState' is actually CPU state and not VM state. In terms of vfio device interface knowing CPU state would be helpful, right?
Quoted 5 lines
Why? CPU state is describing something disassociated with the device. QEMU will interpret the CPU state into something it wants the device to do. The VFIO interface should be defined in terms of the state you want to impose on the device. What the CPU is doing is not the device's problem. Make sense? Thanks,
Quoted 7 lines
CPU state does help to take action in pre-copy phase in different cases. Like in save VM case and suspend VM case, during pre-copy phase CPU is in
RUN_STATE_PAUSED/RUN_STATE_SUSPENDEDstate while in case of live migration during pre-copy phase CPU isRUN_STATE_RUNNINGstate. In pre-copy phase if CPU is already paused then this phase can be skipped by returning pending bytes as 0 because nothing is going to be dirtied after CPUs are paused and transfer all device state in stop-and-copy phase.
I don't understand what's so difficult about redefining these in terms of the device. You want some sort of live device state if the CPU is running and a way to freeze the device and get differences or whatever when it's frozen. QEMU can map CPU state to device state. I'm just asking that we not define the vfio device state interface in terms of a VM or CPU state, translate it what it means for the device state. Thanks,
Alex
Quoted 131 lines · Alex Williamson
Quoted 128 lines · On Wed, 18 Apr 2018 02:41:44 +0530 Kirti Wankhede <[email protected]> wrote:
Quoted 115 lines · Alex Williamson
Quoted 103 lines · On Wed, 18 Apr 2018 00:44:35 +0530 Kirti Wankhede <[email protected]> wrote:
Quoted 93 lines · Alex Williamson
Quoted 86 lines · Yulei
Quoted 80 lines
-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Tuesday, April 17, 2018 4:23 AM
To: Kirti Wankhede <[email protected]>
Cc: Zhang, Yulei <[email protected]>; [email protected]; Tian, Kevin <[email protected]>; [email protected]; [email protected]; Wang, Zhi A <[email protected]>; [email protected]; [email protected]
Subject: Re: [RFC PATCH V4 2/4] vfio: Add vm status change callback to stop/restart the mdev deviceQuoted 21 lines · On Mon, 16 Apr 2018 20:14:27 +0530 Kirti Wankhede <[email protected]> wrote:
Quoted 20 lines · Yulei Zhang
VM status change handler is added to change the vfio pci device status during the migration, write the demanded device status to the DEVICE STATUS subregion to stop the device on the source side before fetch its status and start the deivce on the target side after restore its status.
Signed-off-by Yulei Zhang <[email protected]>--- hw/vfio/pci.c | 20 ++++++++++++++++++++ include/hw/vfio/vfio-common.h | 1 + linux-headers/linux/vfio.h | 6 ++++++ roms/seabios | 2 +- 4 files changed, 28 insertions(+), 1 deletion(-)hw/vfio/pci.c +0
-0@@ -38,6 +38,7 @@Quoted 3 lines
hw/vfio/pci.c line 41
Quoted 3 lines
hw/vfio/pci.c +1
-0static void vfio_disable_interrupts (VFIOPCIDevice *vdev);static void vfio_mmap_set_enabled (VFIOPCIDevice *vdev,bool enabled); +static void vfio_vm_change_state_handler(void *pv, int running,RunState state);
Quoted 4 lines
hw/vfio/pci.c static void vfio_realize(PCIDevice *pdev, Error
Quoted 4 lines
hw/vfio/pci.c +0
-0/* * Disabling BAR mmaping can be slow, but toggling it around INTx can @@ -2896,6 +2897,7 @@ static void vfio_realize(PCIDevice *pdev, Error**errp)
Quoted 4 lines
hw/vfio/pci.c static void vfio_realize(PCIDevice *pdev, Error · line 2900
Quoted 4 lines
hw/vfio/pci.c +1
-0vfio_register_err_notifier (vdev);vfio_register_req_notifier (vdev);vfio_setup_resetfn_quirk (vdev); +
qemu_add_vm_change_state_handler(vfio_vm_change_state_handler, vdev);Quoted 8 lines
hw/vfio/pci.c post_reset: · line 2987
Quoted 8 lines
hw/vfio/pci.c +1
-0return ;@@ -2982,6 +2984,24 @@ post_reset:vfio_pci_post_reset (vdev); } +static void vfio_vm_change_state_handler(void *pv, int running,RunState state)
Quoted 12 lines
Quoted 12 lines
hw/vfio/pci.c +12
-0+{ +VFIOPCIDevice *vdev = pv; +VFIODevice *vbasedev = &vdev->vbasedev; +uint8_t dev_state; +uint8_t sz =1 ; + + dev_state = running ?VFIO_DEVICE_START :VFIO_DEVICE_STOP ; + +if (pwrite (vdev->vbasedev.fd, &dev_state, + sz, vdev->device_state.offset) != sz) { +error_report ("vfio: Failed to %s device" , running ?"start" :"stop" ); +return ;Quoted 8 lines
hw/vfio/pci.c post_reset: · line 3004
Quoted 5 lines
hw/vfio/pci.c +5
-0+ } + + vbasedev->device_state = dev_state; +} +Is it expected to trap
device_stateregion by vendor driver? Can this information be communicated to vendor driver through an ioctl?Quoted 6 lines
Either the mdev vendor driver or vfio bus driver (ie. vfio-pci) would be providing
REGION_INFOfor this region, so the vendor driver is already in full control here using existing ioctls. I don't see that we need new ioctls, we just need to fully define the API of the proposed regions here.Quoted 3 lines
If the device state region is mmaped, we may not be able to use region device state offset to convey the running state. It may need a new ioctl to set the device state.
Quoted 8 lines
The vendor driver defines the mmap'ability of the region, the vendor driver is still in control. The API of the region and the implementation by the vendor driver should account for handling mmap'able sections within the region. Thanks,
Alex
Quoted 8 lines
If this same region should be used for communicating state or other parameters instead of ioctl, may be first page of this region need to be reserved. Mmappable region's start address should be page aligned. Is this API going to utilize 4K of the reserved part of this region? Instead of carving out part of section from the region, are there any disadvantages of adding an ioctl?
May be defining a single ioctl and using different flags (GET_*/SET_*) would work?Quoted 5 lines
Yes, ioctls are something that should be feared and reviewed with great scrutiny and we should feel bad if we do a poor job defining them and burn ioctl numbers whereas we have 32bits worth of region sub-types and 31 bits of region types to churn through within our own address space and we can easily deprecate losing designs without much harm.
Makes sense.
Quoted 3 lines
Thus, I want to see that an ioctl is really the best way to perform the task rather than just being the default answer to everything. Is it really a problem if data starts at some offset into the region?
Quoted 7 lines
Quoted 3 lines
remap_pfn_range()orremap_vmalloc_range()expects target user address and physical address of kernel memory to be page aligned. Mappable region's start address should be page aligned.Sure, but whether to support mmap of the save region is a property of the vendor driver.
Then code here should support both mechanisms to read/write on this region. If region is not mmapped that would need two memcpy to copy data, one memcpy in vendor driver on pread() and other memcpy by qemu_put_buffer() at source and similarly two memcpy for writing back data during restoration at destination.
I would prefer to mmap data part of region because that would need one memcpy by qemu_[put, get]_buffer()
Quoted 14 lines
Quoted 14 lines
That
Quoted 7 lines
sounds like part of the region API that I want to see defined. The region can start with a header containing explicit save state version and device information, writable registers for relaying state information, an offset to the start of the vendor data field, etc. If we can make a GPU work via a definition of registers and doorbells and framebuffers in an MMIO region then surely we can figure out a virtual register and buffer definition to do save and restore of the device.
All these regions mmapped are page aligned.
Quoted 2 lines
Otherwise, why is an ioctl the best tool for this task?
Quoted 9 lines
Quoted 4 lines
I agree that maintaining ioctl is difficult and burning ioctl number problem.
So lets reserve first page and start defining API, then we can know how much from 4K will be consumed for the APIs.Or rather define the API to include a start offset in the header so the vendor driver can choose whatever it wants/needs and we aren't tied to x86
PAGE_SIZE.
Good point. Yes, that should work.
Quoted 36 lines
Quoted 28 lines
Quoted 22 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 3 lines
Here only device state is conveyed to vendor driver but knowing 'RunState' in vendor driver is very useful and vendor driver can take necessary action accordingly like
RUN_STATE_PAUSEDindicating that VMis
Quoted 4 lines
in paused state, similarly
RUN_STATE_SUSPENDED,RUN_STATE_FINISH_MIGRATE,RUN_STATE_IO_ERROR. If these states are handled properly, all the cases can be supported with same interface like VM suspend-resume, VM pause-restore.I agree, but let's remember that we're talking about device state, not VM state. vfio is a userspace device interface, not specifically a virtual machine interface, so states should be in terms of the device. The API of this region needs to be clearly defined and using only 1 byte at the start of the region is not very forward looking. Thanks,
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Alex
Sorry for using wrong term in my previous reply, 'RunState' is actually CPU state and not VM state. In terms of vfio device interface knowing CPU state would be helpful, right?
Quoted 5 lines
Why? CPU state is describing something disassociated with the device. QEMU will interpret the CPU state into something it wants the device to do. The VFIO interface should be defined in terms of the state you want to impose on the device. What the CPU is doing is not the device's problem. Make sense? Thanks,
Quoted 7 lines
CPU state does help to take action in pre-copy phase in different cases. Like in save VM case and suspend VM case, during pre-copy phase CPU is in
RUN_STATE_PAUSED/RUN_STATE_SUSPENDEDstate while in case of live migration during pre-copy phase CPU isRUN_STATE_RUNNINGstate. In pre-copy phase if CPU is already paused then this phase can be skipped by returning pending bytes as 0 because nothing is going to be dirtied after CPUs are paused and transfer all device state in stop-and-copy phase.
Quoted 7 lines
I don't understand what's so difficult about redefining these in terms of the device. You want some sort of live device state if the CPU is running and a way to freeze the device and get differences or whatever when it's frozen. QEMU can map CPU state to device state. I'm just asking that we not define the vfio device state interface in terms of a VM or CPU state, translate it what it means for the device state. Thanks,
Ok. Got your point.
Thanks,
Kirti