vfio: introduce a new VFIO region for migration support
RFC 1/5 vfio: introduce a new VFIO region for migration support
New VFIO region VFIO_PCI_DEVICE_STATE_REGION_INDEX is added to fetch and restore the pci device status during the live migration.
--- hw/vfio/pci.c | 17 +++++++++++++++++ hw/vfio/pci.h | 1 + linux-headers/linux/vfio.h | 5 ++++- 3 files changed, 22 insertions(+), 1 deletion(-)
hw/vfio/pci.c +17 -0
@@ -2360,6 +2360,23 @@ static void vfio_populate_device(VFIOPCIDevice *vdev, Error **errp)QLIST_INIT (&vdev->bars[i].quirks); } +/* device state region setup */ +if (vbasedev->flags &VFIO_DEVICE_FLAGS_MIGRATABLE ) { +char *name =g_strdup_printf ("%s BAR %d" , vbasedev->name,VFIO_PCI_DEVICE_STATE_REGION_INDEX ); + + ret =vfio_region_setup (OBJECT (vdev), vbasedev, + &vdev->device_state.region,VFIO_PCI_DEVICE_STATE_REGION_INDEX , name); +g_free (name); + +if (ret) { +error_setg_errno (errp, -ret,"failed to get region %d info" , +VFIO_PCI_DEVICE_STATE_REGION_INDEX ); +return ; + } + +QLIST_INIT (&vdev->device_state.quirks); + } + ret =vfio_get_region_info (vbasedev,VFIO_PCI_CONFIG_REGION_INDEX , ®_info);if (ret) {
hw/vfio/pci.h +1 -0
@@ -115,6 +115,7 @@ typedef struct VFIOPCIDevice {int interrupt;/* Current interrupt type */ VFIOBAR bars[PCI_NUM_REGIONS -1 ];/* No ROM */ VFIOVGA *vga;/* 0xa0000, 0x3b0, 0x3c0 */ +VFIOBAR device_state;void *igd_opregion;PCIHostDeviceAddress host;EventNotifier err_notifier;
linux-headers/linux/vfio.h +4 -1
@@ -198,6 +198,8 @@ struct vfio_device_info {#define VFIO_DEVICE_FLAGS_PCI (1 << 1)/* vfio-pci device */ #define VFIO_DEVICE_FLAGS_PLATFORM (1 << 2)/* vfio-platform device */ #define VFIO_DEVICE_FLAGS_AMBA (1 << 3)/* vfio-amba device */ +#define VFIO_DEVICE_FLAGS_CCW (1 << 4)/* vfio-ccw device */ +#define VFIO_DEVICE_FLAGS_MIGRATABLE (1 << 5)/* Device supports migrate */ __u32 num_regions;/* Max region index + 1 */ __u32 num_irqs;/* Max IRQ index + 1 */ };
@@ -433,7 +435,8 @@ enum {* between described ranges are unimplemented. */ VFIO_PCI_VGA_REGION_INDEX , -VFIO_PCI_NUM_REGIONS =9 /* Fixed user ABI, region indexes >=9 use */ +VFIO_PCI_DEVICE_STATE_REGION_INDEX , +VFIO_PCI_NUM_REGIONS =10 /* Fixed user ABI, region indexes >=9 use */ /* device specific cap to define content. */ };
Signature · 1 line
2.7.4
Alex Williamson
NAKQuoted 43 lines · On Tue, 4 Apr 2017 18:26:57 +0800 Yulei Zhang <[email protected]> wrote:
New VFIO region
VFIO_PCI_DEVICE_STATE_REGION_INDEXis added to fetch and restore the pci device status during the live migration.Signed-off-by Yulei Zhang <[email protected]>--- hw/vfio/pci.c | 17 +++++++++++++++++ hw/vfio/pci.h | 1 + linux-headers/linux/vfio.h | 5 ++++- 3 files changed, 22 insertions(+), 1 deletion(-)hw/vfio/pci.c +17
-0@@ -2360,6 +2360,23 @@ static void vfio_populate_device(VFIOPCIDevice *vdev, Error **errp)QLIST_INIT (&vdev->bars[i].quirks); } +/* device state region setup */ +if (vbasedev->flags &VFIO_DEVICE_FLAGS_MIGRATABLE ) { +char *name =g_strdup_printf ("%s BAR %d" , vbasedev->name,VFIO_PCI_DEVICE_STATE_REGION_INDEX ); + + ret =vfio_region_setup (OBJECT (vdev), vbasedev, + &vdev->device_state.region,VFIO_PCI_DEVICE_STATE_REGION_INDEX , name); +g_free (name); + +if (ret) { +error_setg_errno (errp, -ret,"failed to get region %d info" , +VFIO_PCI_DEVICE_STATE_REGION_INDEX ); +return ; + } + +QLIST_INIT (&vdev->device_state.quirks); + } + ret =vfio_get_region_info (vbasedev,VFIO_PCI_CONFIG_REGION_INDEX , ®_info);if (ret) {hw/vfio/pci.h +0
-0
hw/vfio/pci.h typedef struct VFIOPCIDevice { · line 118
Quoted 4 lines
hw/vfio/pci.h +1
-0@@ -115,6 +115,7 @@ typedef struct VFIOPCIDevice {int interrupt;/* Current interrupt type */ VFIOBAR bars[PCI_NUM_REGIONS -1 ];/* No ROM */ VFIOVGA *vga;/* 0xa0000, 0x3b0, 0x3c0 */ +VFIOBAR device_state;
But it's not a BAR...
Quoted 17 lines
hw/vfio/pci.h +0
-0void *igd_opregion;PCIHostDeviceAddress host;EventNotifier err_notifier;linux-headers/linux/vfio.h +2
-0@@ -198,6 +198,8 @@ struct vfio_device_info {#define VFIO_DEVICE_FLAGS_PCI (1 << 1)/* vfio-pci device */ #define VFIO_DEVICE_FLAGS_PLATFORM (1 << 2)/* vfio-platform device */ #define VFIO_DEVICE_FLAGS_AMBA (1 << 3)/* vfio-amba device */ +#define VFIO_DEVICE_FLAGS_CCW (1 << 4)/* vfio-ccw device */ +#define VFIO_DEVICE_FLAGS_MIGRATABLE (1 << 5)/* Device supports migrate */ __u32 num_regions;/* Max region index + 1 */ __u32 num_irqs;/* Max IRQ index + 1 */ };
linux-headers/linux/vfio.h enum { · line 442
Quoted 9 lines
linux-headers/linux/vfio.h +2
-1@@ -433,7 +435,8 @@ enum {* between described ranges are unimplemented. */ VFIO_PCI_VGA_REGION_INDEX , -VFIO_PCI_NUM_REGIONS =9 /* Fixed user ABI, region indexes >=9 use */ +VFIO_PCI_DEVICE_STATE_REGION_INDEX , +VFIO_PCI_NUM_REGIONS =10 /* Fixed user ABI, region indexes >=9 use */ /* device specific cap to define content. */ };
Nak, please read the comment on the line you changed. We're not adding any more static region indexes, anything new should be added with device specific capabilities. Look at how we do opregions and various other IGD related regions. There's also no reason to add a flag, the existence of the device specific region should indicate that it supports migration. Also, we call these device specific, but I would still encourage a shared format, userspace doesn't want to support a different mechanism for each device. Thanks,
Alex
Quoted 109 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 1/5] vfio: introduce a new VFIO region for migration supportQuoted 1 line · On Tue, 4 Apr 2017 18:26:57 +0800 Yulei Zhang <[email protected]> wrote:
New VFIO region
VFIO_PCI_DEVICE_STATE_REGION_INDEXis added tofetch
hw/vfio/pci.c static void vfio_populate_device(VFIOPCIDevice
Quoted 14 lines
and restore the pci device status during the live migration.
Signed-off-by Yulei Zhang <[email protected]>--- hw/vfio/pci.c | 17 +++++++++++++++++ hw/vfio/pci.h | 1 + linux-headers/linux/vfio.h | 5 ++++- 3 files changed, 22 insertions(+), 1 deletion(-)hw/vfio/pci.c +0
-0@@ -2360,6 +2360,23 @@ static void vfio_populate_device(VFIOPCIDevice*vdev, Error **errp)
hw/vfio/pci.c static void vfio_populate_device(VFIOPCIDevice *vdev, Error **errp)
Quoted 6 lines
hw/vfio/pci.c +3
-0QLIST_INIT (&vdev->bars[i].quirks); } +/* device state region setup */ +if (vbasedev->flags &VFIO_DEVICE_FLAGS_MIGRATABLE ) { + char *name = g_strdup_printf("%s BAR %d", vbasedev->name,
VFIO_PCI_DEVICE_STATE_REGION_INDEX);hw/vfio/pci.c static void vfio_populate_device(VFIOPCIDevice *vdev, Error **errp)
Quoted 3 lines
hw/vfio/pci.c +3
-0+ + ret = vfio_region_setup(OBJECT(vdev), vbasedev, + &vdev->device_state.region,
VFIO_PCI_DEVICE_STATE_REGION_INDEX, name);Quoted 19 lines
hw/vfio/pci.c +11
-0+g_free (name); + +if (ret) { +error_setg_errno (errp, -ret,"failed to get region %d info" , +VFIO_PCI_DEVICE_STATE_REGION_INDEX ); +return ; + } + +QLIST_INIT (&vdev->device_state.quirks); + } + ret =vfio_get_region_info (vbasedev,VFIO_PCI_CONFIG_REGION_INDEX , ®_info);if (ret) {hw/vfio/pci.h +0
-0hw/vfio/pci.h typedef struct VFIOPCIDevice { · line 118
Quoted 4 lines
hw/vfio/pci.h +1
-0@@ -115,6 +115,7 @@ typedef struct VFIOPCIDevice {int interrupt;/* Current interrupt type */ VFIOBAR bars[PCI_NUM_REGIONS -1 ];/* No ROM */ VFIOVGA *vga;/* 0xa0000, 0x3b0, 0x3c0 */ +VFIOBAR device_state;But it's not a BAR...
linux-headers/linux/vfio.h struct vfio_device_info { · line 199
Quoted 10 lines
hw/vfio/pci.h +0
-0void *igd_opregion;PCIHostDeviceAddress host;EventNotifier err_notifier;linux-headers/linux/vfio.h +0
-0@@ -198,6 +198,8 @@ struct vfio_device_info {#define VFIO_DEVICE_FLAGS_PCI (1 << 1)/* vfio-pci device */ #define VFIO_DEVICE_FLAGS_PLATFORM (1 << 2)/* vfio-platform device */
linux-headers/linux/vfio.h struct vfio_device_info {
Quoted 3 lines
linux-headers/linux/vfio.h +2
-0#define VFIO_DEVICE_FLAGS_AMBA (1 << 3)/* vfio-amba device */ +#define VFIO_DEVICE_FLAGS_CCW (1 << 4)/* vfio-ccw device */ +#define VFIO_DEVICE_FLAGS_MIGRATABLE (1 << 5)/* Device supports migrate */
linux-headers/linux/vfio.h enum { · line 436
Quoted 8 lines
linux-headers/linux/vfio.h +0
-1__u32 num_regions;/* Max region index + 1 */ __u32 num_irqs;/* Max IRQ index + 1 */ };@@ -433,7 +435,8 @@ enum {* between described ranges are unimplemented. */ VFIO_PCI_VGA_REGION_INDEX, -VFIO_PCI_NUM_REGIONS =9 /* Fixed user ABI, region indexes >=9 use */
linux-headers/linux/vfio.h enum { · line 439
Quoted 2 lines
linux-headers/linux/vfio.h +2
-0+VFIO_PCI_DEVICE_STATE_REGION_INDEX , +VFIO_PCI_NUM_REGIONS =10 /* Fixed user ABI, region indexes >=9 use */
linux-headers/linux/vfio.h enum { · line 442
Quoted 3 lines
linux-headers/linux/vfio.h +0
-0/* device specific cap to define content. */ };Nak, please read the comment on the line you changed. We're not adding any more static region indexes, anything new should be added with device specific capabilities. Look at how we do opregions and various other IGD related regions. There's also no reason to add a flag, the existence of the device specific region should indicate that it supports migration. Also, we call these device specific, but I would still encourage a shared format, userspace doesn't want to support a different mechanism for each device. Thanks,
Quoted 1 line
Alex
Thanks, Alex. I will revise it accordingly.