vfio: introduce new VFIO ioctl VFIO_DEVICE_PCI_STATUS_SET
RFC 3/5 vfio: introduce new VFIO ioctl VFIO_DEVICE_PCI_STATUS_SET
New VFIO ioctl VFIO_DEVICE_PCI_STATUS_SET is added to change the vfio pci device status during the migration, 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 | 17 +++++++++++++++++ linux-headers/linux/vfio.h | 15 +++++++++++++++ 2 files changed, 32 insertions(+)
hw/vfio/pci.c +17 -0
@@ -38,6 +38,7 @@static void vfio_disable_interrupts (VFIOPCIDevice *vdev);static void vfio_mmap_set_enabled (VFIOPCIDevice *vdev,bool enabled);static VMStateDescription vfio_pci_vmstate; +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
@@ -2866,6 +2867,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 ;
@@ -2948,6 +2950,21 @@ post_reset:vfio_pci_post_reset (vdev); } +static void vfio_vm_change_state_handler (void *pv,int running,RunState state) +{ +VFIOPCIDevice *vdev = pv; +struct vfio_pci_status_set *vfio_status; +int argsz =sizeof (*vfio_status); + + vfio_status =g_malloc0 (argsz); + vfio_status->argsz = argsz; + vfio_status->flags = running ?VFIO_DEVICE_PCI_START : +VFIO_DEVICE_PCI_STOP ; + +ioctl (vdev->vbasedev.fd,VFIO_DEVICE_PCI_STATUS_SET , vfio_status); +g_free (vfio_status); +} +static int vfio_device_put (QEMUFile *f,void *pv,size_t size,VMStateField *field,QJSON *vmdesc) {
linux-headers/linux/vfio.h +15 -0
@@ -487,6 +487,21 @@ struct vfio_pci_hot_reset {#define VFIO_DEVICE_PCI_HOT_RESET _IO(VFIO_TYPE, VFIO_BASE + 13) +/** +* VFIO_DEVICE_PCI_STATUS_SET - _IOW(VFIO_TYPE, VFIO_BASE + 14, +* struct vfio_pci_status_set) +* +* Return: 0 on success, -errno on failure. +*/ +struct vfio_pci_status_set { +__u32 argsz; +__u32 flags; +#define VFIO_DEVICE_PCI_STOP (1 << 0) +#define VFIO_DEVICE_PCI_START (1 << 1) +}; + +#define VFIO_DEVICE_PCI_STATUS_SET _IO(VFIO_TYPE, VFIO_BASE + 14) +/* -------- API for Type1 VFIO IOMMU -------- */ /**
Signature · 1 line
2.7.4
Quoted 69 lines · On Tue, 4 Apr 2017 18:27:30 +0800 Yulei Zhang <[email protected]> wrote:
New VFIO ioctl
VFIO_DEVICE_PCI_STATUS_SETis added to change the vfio pci device status during the migration, 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 | 17 +++++++++++++++++ linux-headers/linux/vfio.h | 15 +++++++++++++++ 2 files changed, 32 insertions(+)hw/vfio/pci.c +17
-0@@ -38,6 +38,7 @@static void vfio_disable_interrupts (VFIOPCIDevice *vdev);static void vfio_mmap_set_enabled (VFIOPCIDevice *vdev,bool enabled);static VMStateDescription vfio_pci_vmstate; +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 @@ -2866,6 +2867,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 ;@@ -2948,6 +2950,21 @@ post_reset:vfio_pci_post_reset (vdev); } +static void vfio_vm_change_state_handler (void *pv,int running,RunState state) +{ +VFIOPCIDevice *vdev = pv; +struct vfio_pci_status_set *vfio_status; +int argsz =sizeof (*vfio_status); + + vfio_status =g_malloc0 (argsz); + vfio_status->argsz = argsz; + vfio_status->flags = running ?VFIO_DEVICE_PCI_START : +VFIO_DEVICE_PCI_STOP ; + +ioctl (vdev->vbasedev.fd,VFIO_DEVICE_PCI_STATUS_SET , vfio_status); +g_free (vfio_status); +} +static int vfio_device_put (QEMUFile *f,void *pv,size_t size,VMStateField *field,QJSON *vmdesc) {linux-headers/linux/vfio.h +8
-0@@ -487,6 +487,21 @@ struct vfio_pci_hot_reset {#define VFIO_DEVICE_PCI_HOT_RESET _IO(VFIO_TYPE, VFIO_BASE + 13) +/** +* VFIO_DEVICE_PCI_STATUS_SET - _IOW(VFIO_TYPE, VFIO_BASE + 14, +* struct vfio_pci_status_set) +* +* Return: 0 on success, -errno on failure. +*/ +struct vfio_pci_status_set { +__u32 argsz;
linux-headers/linux/vfio.h struct vfio_pci_hot_reset { · line 507
Quoted 10 lines
linux-headers/linux/vfio.h +7
-0+__u32 flags; +#define VFIO_DEVICE_PCI_STOP (1 << 0) +#define VFIO_DEVICE_PCI_START (1 << 1) +}; + +#define VFIO_DEVICE_PCI_STATUS_SET _IO(VFIO_TYPE, VFIO_BASE + 14) +/* -------- API for Type1 VFIO IOMMU -------- */ /**
Why does this need to be an ioctl? We could simply define the first dword of the migration region as the device state and the user could read and write it. Thanks,
Alex
Quoted 98 lines
-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: Tuesday, June 27, 2017 4:19 AM
To: Zhang, Yulei <[email protected]>
Cc: [email protected]; Tian, Kevin <[email protected]>; [email protected]; [email protected]; Zheng, Xiao <[email protected]>; Wang, Zhi A <[email protected]>
Subject: Re: [Qemu-devel] [RFC 3/5] vfio: introduce new VFIO ioctlVFIO_DEVICE_PCI_STATUS_SETQuoted 16 lines · On Tue, 4 Apr 2017 18:27:30 +0800 Yulei Zhang <[email protected]> wrote:
New VFIO ioctl
VFIO_DEVICE_PCI_STATUS_SETis added to change the vfio pci device status during the migration, 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 | 17 +++++++++++++++++ linux-headers/linux/vfio.h | 15 +++++++++++++++ 2 files changed, 32 insertions(+)hw/vfio/pci.c +0
-0hw/vfio/pci.c line 41
Quoted 4 lines
hw/vfio/pci.c +1
-0@@ -38,6 +38,7 @@static void vfio_disable_interrupts (VFIOPCIDevice *vdev);static void vfio_mmap_set_enabled (VFIOPCIDevice *vdev,bool enabled);static VMStateDescription vfio_pci_vmstate; +static void vfio_vm_change_state_handler(void *pv, int running,RunState state);
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 @@ -2866,6 +2867,7 @@ static void vfio_realize(PCIDevice *pdev, Error**errp)
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);
hw/vfio/pci.c post_reset: · line 2953
Quoted 8 lines
hw/vfio/pci.c +1
-0return ;@@ -2948,6 +2950,21 @@ post_reset:vfio_pci_post_reset (vdev); } +static void vfio_vm_change_state_handler(void *pv, int running,RunState state)
Quoted 5 lines
hw/vfio/pci.c +5
-0+{ +VFIOPCIDevice *vdev = pv; +struct vfio_pci_status_set *vfio_status; +int argsz =sizeof (*vfio_status); +hw/vfio/pci.c post_reset:
Quoted 10 lines
hw/vfio/pci.c +9
-0+ vfio_status =g_malloc0 (argsz); + vfio_status->argsz = argsz; + vfio_status->flags = running ?VFIO_DEVICE_PCI_START : +VFIO_DEVICE_PCI_STOP ; + +ioctl (vdev->vbasedev.fd,VFIO_DEVICE_PCI_STATUS_SET , vfio_status); +g_free (vfio_status); +} + static int vfio_device_put(QEMUFile *f, void *pv, size_t size, VMStateField*field,
Quoted 27 lines
hw/vfio/pci.c +0
-0QJSON *vmdesc) {linux-headers/linux/vfio.h +15
-0@@ -487,6 +487,21 @@ struct vfio_pci_hot_reset {#define VFIO_DEVICE_PCI_HOT_RESET _IO(VFIO_TYPE, VFIO_BASE + 13) +/** +* VFIO_DEVICE_PCI_STATUS_SET - _IOW(VFIO_TYPE, VFIO_BASE + 14, +* struct vfio_pci_status_set) +* +* Return: 0 on success, -errno on failure. +*/ +struct vfio_pci_status_set { +__u32 argsz; +__u32 flags; +#define VFIO_DEVICE_PCI_STOP (1 << 0) +#define VFIO_DEVICE_PCI_START (1 << 1) +}; + +#define VFIO_DEVICE_PCI_STATUS_SET _IO(VFIO_TYPE, VFIO_BASE + 14) +/* -------- API for Type1 VFIO IOMMU -------- */
Quoted 7 lines
linux-headers/linux/vfio.h struct vfio_pci_hot_reset { · line 507
Quoted 1 line
linux-headers/linux/vfio.h +0
-0/** Why does this need to be an ioctl? We could simply define the first dword of the migration region as the device state and the user could read and write it. Thanks,
Alex
Sure, we can remove this ioctl.