Add a plugin to support out-of-band live migration for VFIO pass-through device
cover Add a plugin to support out-of-band live migration for VFIO pass-through device
Migration of a VFIO passthrough device can be supported by using a device specific kernel driver to save/restore the device state thru device specific interfaces. But this approach doesn't work for devices that lack a state migration interface, e.g. NVMe.
On the other hand, Infrastructure Process Unit (IPU) or Data Processing Unit (DPU) vendors may choose to implement an out-of-band interface from the SoC to help manage the state of such non-migratable devices e.g. via gRPC or JSON-RPC protocols.
This RFC attempts to support such out-of-band migration interface by introducing the concept of migration backends in vfio. The existing logic around vfio migration uAPI is now called the 'local' backend while a new 'out-of-band' backend is further introduced allowing vfio to redirect VMState ops to an external plugin.
Currently, the backend migration Ops is defined close to SaveVMHandlers. We also considered whether there is value of abstracting it in a lower level e.g. close to vfio migration uAPI but no clear conclusion. Hence this is one part which we'd like to hear suggestions.
This proposal adopts a plugin mechanism (an example can be found in [1]) given that IPU/DPU vendors usually implement proprietary migration interfaces without a standard. But we are also open if an alternative option makes better sense, e.g. via loadable modules (with Qemu supporting gRPC or JSON-RPC support) or an IPC mechanism similar to vhost-user.
The following graph describes the overall component relationship:
+----------------------------------------------------+
| QEMU |
| +------------------------------------------------+ |
| | VFIO Live Migration Framework | |
| | +--------------------------------------+ | |
| | | VFIOMigrationOps | | |
| | +-------^---------------------^--------+ | |
| | | | | |
| | +-------v-------+ +-------v--------+ | |
| | | LM Backend Via| | LM Backend Via | | |
| | | Device Fd | | Plugins | | |
| | +-------^-------+ | +----------+ | |
| | | | |Plugin Ops+----+-+------------+
| | | +-----+----------+ | | |
| | | | | +---------v----------+
| +------------+-----------------------------------+ | | Vendor Specific |
| | | | Plugins(.so) |
+--------------+-------------------------------------+ +----------+---------+
UserSpace | |
----------------+--------------------------------------------- |
Kernel | |
| |
+----------v----------------------+ |
| Kernel VFIO Driver | |
| +-------------------------+ | |
| | | | | Network
| | Vendor-Specific Driver | | |
| | | | |
| +----------^--------------+ | |
| | | |
+---------------+-----------------+ |
| |
| |
---------------------+----------------------------------------- |
Hardware | |
| +-----+-----+-----+----+-----+ |
+----------v------+ | VF0 | VF1 | VF2 | ...| VFn | |
| Traditional | +-----+-----+-----+----+-----+ |
| PCIe Devices | | | |
+-----------------+ | +--------+------------+ | |
| | | Agent |<-+----+
| | +------------+ |
| | | |
| | SOC | |
| +---------------------+ |
| IPU |
+----------------------------+Two command-line parameters (x-plugin-path and x-plugin-arg) are introduced to enable the out-of-band backend. If specified, vfio will attempt to use the out-of-band backend.
The following is an example of VFIO command-line parameters for OOB-Approach:
-device vfio-pci,id=$ID,host=$bdf,x-enable-migration,x-plugin-path=$plugin_path,x-plugin-arg=$plugin_arg
[1] https://github.com/raolei-intel/vfio-lm-plugin-example.git
Lei Rao (13):
vfio/migration: put together checks of migration initialization
conditions
vfio/migration: move migration struct allocation out of
vfio_migration_init
vfio/migration: move vfio_get_dev_region_info out of
vfio_migration_probe
vfio/migration: Separated functions that relate to the In-Band
approach
vfio/migration: rename functions that relate to the In-Band approach vfio/migration: introduce VFIOMigrationOps layer in VFIO live
migration framework
vfio/migration: move the statistics of bytes_transferred to generic
VFIO migration layer
vfio/migration: split migration handler registering from
vfio_migration_init
vfio/migration: move the functions of In-Band approach to a new file vfio/pci: introduce command-line parameters to specify migration
method
vfio/migration: add a plugin layer to support out-of-band live
migration
vfio/migration: add some trace-events for vfio migration plugin vfio/migration: make the region and plugin member of struct
VFIOMigration to be a union
docs/devel/vfio-migration-plugin.rst | 165 +++++++ hw/vfio/meson.build | 2 + hw/vfio/migration-local.c | 456 +++++++++++++++++++ hw/vfio/migration-plugin.c | 266 +++++++++++ hw/vfio/migration.c | 577 ++++++------------------ hw/vfio/pci.c | 2 + hw/vfio/trace-events | 9 +- include/hw/vfio/vfio-common.h | 37 +- include/hw/vfio/vfio-migration-plugin.h | 21 + 9 files changed, 1096 insertions(+), 439 deletions(-) create mode 100644 docs/devel/vfio-migration-plugin.rst create mode 100644 hw/vfio/migration-local.c create mode 100644 hw/vfio/migration-plugin.c create mode 100644 include/hw/vfio/vfio-migration-plugin.h
Signature · 1 line
2.32.0
RFC PATCH 1/13 vfio/migration: put together checks of migration initialization conditions
Current VFIO live migration initialization code is tightly coupled with local migration region handling. It is necessary to decouple it to facilitate the introduction of a generic VFIO live migration framework so that other approaches can be possible besides the In-Band approach.
This patch puts various checks of migration initialization conditions into one function vfio_migration_check().
--- hw/vfio/migration.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-)
hw/vfio/migration.c +17 -6
@@ -787,6 +787,21 @@ static void vfio_migration_exit(VFIODevice *vbasedev) vbasedev->migration =NULL ; } +static int vfio_migration_check (VFIODevice *vbasedev) +{ +VFIOContainer *container = vbasedev->group->container; + +if (!vbasedev->enable_migration || !container->dirty_pages_supported) { +return -EINVAL ; + } + +if (!vbasedev->ops->vfio_get_object) { +return -EINVAL ; + } + +return 0 ; +} +static int vfio_migration_init (VFIODevice *vbasedev,struct vfio_region_info *info) {
@@ -796,10 +811,6 @@ static int vfio_migration_init(VFIODevice *vbasedev,char id[256 ] ="" ; g_autofree char *path = NULL, *oid = NULL; -if (!vbasedev->ops->vfio_get_object) { -return -EINVAL ; - } - obj = vbasedev->ops->vfio_get_object (vbasedev);if (!obj) {return -EINVAL ;
@@ -857,11 +868,11 @@ int64_t vfio_mig_bytes_transferred(void)int vfio_migration_probe (VFIODevice *vbasedev,Error **errp) { -VFIOContainer *container = vbasedev->group->container;struct vfio_region_info *info =NULL ;int ret = -ENOTSUP ; -if (!vbasedev->enable_migration || !container->dirty_pages_supported) { + ret =vfio_migration_check (vbasedev); +if (ret) { goto add_blocker; }
Signature · 1 line
2.32.0
RFC PATCH 2/13 vfio/migration: move migration struct allocation out of vfio_migration_init
In reply to Lei RaoMigration struct is a common data structure. Memory allocation of migration struct is not unique to In-Band approach. So, move it from vfio_migration_init() to vfio_migration_probe().
--- hw/vfio/migration.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
hw/vfio/migration.c +6 -6
@@ -807,17 +807,15 @@ static int vfio_migration_init(VFIODevice *vbasedev, {int ret;Object *obj; -VFIOMigration *migration;char id[256 ] ="" ; g_autofree char *path = NULL, *oid = NULL; +VFIOMigration *migration = vbasedev->migration; obj = vbasedev->ops->vfio_get_object (vbasedev);if (!obj) {return -EINVAL ; } - vbasedev->migration =g_new0 (VFIOMigration,1 ); - ret =vfio_region_setup (obj, vbasedev, &vbasedev->migration->region, info->index,"migration" );if (ret) {
@@ -833,9 +831,6 @@ static int vfio_migration_init(VFIODevice *vbasedev, goto err; } - migration = vbasedev->migration; - migration->vbasedev = vbasedev; - oid =vmstate_if_get_id (VMSTATE_IF (DEVICE (obj)));if (oid) { path =g_strdup_printf ("%s/vfio" , oid);
@@ -876,6 +871,9 @@ int vfio_migration_probe(VFIODevice *vbasedev, Error **errp) goto add_blocker; } + vbasedev->migration =g_new0 (VFIOMigration,1 ); + vbasedev->migration->vbasedev = vbasedev; + ret = vfio_get_dev_region_info(vbasedev, VFIO_REGION_TYPE_MIGRATION_DEPRECATED, VFIO_REGION_SUBTYPE_MIGRATION_DEPRECATED,
@@ -903,6 +901,8 @@ add_blocker:error_free (vbasedev->migration_blocker); vbasedev->migration_blocker =NULL ; } +g_free (vbasedev->migration); + vbasedev->migration =NULL ;return ret; }
Signature · 1 line
2.32.0
RFC PATCH 3/13 vfio/migration: move vfio_get_dev_region_info out of vfio_migration_probe
In reply to Lei Raovfio_get_dev_region_info() in vfio_migration_probe() is a specific operation of In-Band approach. So, it's better to put it in vfio_migration_init() because most of the setup of In-Band approach are handled there. The vfio_migration_init will be rename to vfio_migration_probe_local().
--- hw/vfio/migration.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-)
hw/vfio/migration.c +15 -15
@@ -802,12 +802,12 @@ static int vfio_migration_check(VFIODevice *vbasedev)return 0 ; } -static int vfio_migration_init (VFIODevice *vbasedev, -struct vfio_region_info *info) +static int vfio_migration_init (VFIODevice *vbasedev) {int ret;Object *obj;char id[256 ] ="" ; +struct vfio_region_info *info =NULL ; g_autofree char *path = NULL, *oid = NULL;VFIOMigration *migration = vbasedev->migration;
@@ -816,6 +816,14 @@ static int vfio_migration_init(VFIODevice *vbasedev,return -EINVAL ; } + ret =vfio_get_dev_region_info (vbasedev, +VFIO_REGION_TYPE_MIGRATION_DEPRECATED , +VFIO_REGION_SUBTYPE_MIGRATION_DEPRECATED , + &info); +if (ret) { +return -EINVAL ; + } + ret =vfio_region_setup (obj, vbasedev, &vbasedev->migration->region, info->index,"migration" );if (ret) {
@@ -847,10 +855,14 @@ static int vfio_migration_init(VFIODevice *vbasedev, vbasedev); migration->migration_state.notify = vfio_migration_state_notifier;add_migration_state_change_notifier (&migration->migration_state); + +trace_vfio_migration_probe (vbasedev->name, info->index); +g_free (info);return 0 ; err:vfio_migration_exit (vbasedev); +g_free (info);return ret; }
@@ -863,7 +875,6 @@ int64_t vfio_mig_bytes_transferred(void)int vfio_migration_probe (VFIODevice *vbasedev,Error **errp) { -struct vfio_region_info *info =NULL ;int ret = -ENOTSUP ; ret =vfio_migration_check (vbasedev);
@@ -874,27 +885,16 @@ int vfio_migration_probe(VFIODevice *vbasedev, Error **errp) vbasedev->migration =g_new0 (VFIOMigration,1 ); vbasedev->migration->vbasedev = vbasedev; - ret =vfio_get_dev_region_info (vbasedev, -VFIO_REGION_TYPE_MIGRATION_DEPRECATED , -VFIO_REGION_SUBTYPE_MIGRATION_DEPRECATED , - &info); -if (ret) { - goto add_blocker; - } - - ret =vfio_migration_init (vbasedev, info); + ret =vfio_migration_init (vbasedev);if (ret) { goto add_blocker; } -trace_vfio_migration_probe (vbasedev->name, info->index); -g_free (info);return 0 ; add_blocker:error_setg (&vbasedev->migration_blocker,"VFIO device doesn't support migration" ); -g_free (info); ret =migrate_add_blocker (vbasedev->migration_blocker, errp);if (ret <0 ) {
Signature · 1 line
2.32.0
RFC PATCH 4/13 vfio/migration: Separated functions that relate to the In-Band approach
In reply to Lei RaoSplit functions of In-Band approach from common function, to prepare for the introduction of generic VFIO live migration layer and another Sub-Ops.
--- hw/vfio/migration.c | 64 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 15 deletions(-)
hw/vfio/migration.c +49 -15
@@ -394,7 +394,7 @@ static int vfio_load_device_config_state(QEMUFile *f, void *opaque)return qemu_file_get_error (f); } -static void vfio_migration_cleanup (VFIODevice *vbasedev) +static void vfio_migration_cleanup_local (VFIODevice *vbasedev) {VFIOMigration *migration = vbasedev->migration;
@@ -403,17 +403,17 @@ static void vfio_migration_cleanup(VFIODevice *vbasedev) } } +static void vfio_migration_cleanup (VFIODevice *vbasedev) +{ +vfio_migration_cleanup_local (vbasedev); +} +/* ---------------------------------------------------------------------- */ -static int vfio_save_setup (QEMUFile *f,void *opaque) +static int vfio_migration_save_setup_local (VFIODevice *vbasedev) { -VFIODevice *vbasedev = opaque;VFIOMigration *migration = vbasedev->migration; -int ret; - -trace_vfio_save_setup (vbasedev->name); - -qemu_put_be64 (f,VFIO_MIG_FLAG_DEV_SETUP_STATE ); +int ret =-1 ;if (migration->region.mmaps) {/*
@@ -430,6 +430,24 @@ static int vfio_save_setup(QEMUFile *f, void *opaque)error_report ("%s: Falling back to slow path" , vbasedev->name); } } +return ret; +} + +static int vfio_save_setup (QEMUFile *f,void *opaque) +{ +VFIODevice *vbasedev = opaque; +int ret; + +trace_vfio_save_setup (vbasedev->name); + +qemu_put_be64 (f,VFIO_MIG_FLAG_DEV_SETUP_STATE ); + + ret =vfio_migration_save_setup_local (vbasedev); +if (ret) { +error_report ("%s: Failed to vfio lm save setup:%s" , + vbasedev->name,strerror (-ret)); +return ret; + } ret =vfio_migration_set_state (vbasedev,VFIO_DEVICE_STATE_MASK ,VFIO_DEVICE_STATE_V1_SAVING );
@@ -592,11 +610,10 @@ static void vfio_save_state(QEMUFile *f, void *opaque) } } -static int vfio_load_setup (QEMUFile *f,void *opaque) +static int vfio_migration_load_setup_local (VFIODevice *vbasedev) { -VFIODevice *vbasedev = opaque;VFIOMigration *migration = vbasedev->migration; -int ret =0 ; +int ret =-1 ;if (migration->region.mmaps) { ret =vfio_region_mmap (&migration->region);
@@ -607,14 +624,26 @@ static int vfio_load_setup(QEMUFile *f, void *opaque)error_report ("%s: Falling back to slow path" , vbasedev->name); } } +return ret; +} + +static int vfio_load_setup (QEMUFile *f,void *opaque) +{ +VFIODevice *vbasedev = opaque; +int ret =0 ; + + ret =vfio_migration_load_setup_local (vbasedev); +if (ret <0 ) { +error_report ("%s: Failed to migration load setup" , vbasedev->name); +return ret; + } ret =vfio_migration_set_state (vbasedev, ~VFIO_DEVICE_STATE_MASK ,VFIO_DEVICE_STATE_V1_RESUMING );if (ret) {error_report ("%s: Failed to set state RESUMING" , vbasedev->name); -if (migration->region.mmaps) { -vfio_region_unmap (&migration->region); - } +vfio_migration_cleanup (vbasedev); +return ret; }return ret; }
@@ -777,12 +806,17 @@ static void vfio_migration_state_notifier(Notifier *notifier, void *data) } } -static void vfio_migration_exit (VFIODevice *vbasedev) +static void vfio_migration_exit_local (VFIODevice *vbasedev) {VFIOMigration *migration = vbasedev->migration;vfio_region_exit (&migration->region);vfio_region_finalize (&migration->region); +} + +static void vfio_migration_exit (VFIODevice *vbasedev) +{ +vfio_migration_exit_local (vbasedev);g_free (vbasedev->migration); vbasedev->migration =NULL ; }
Signature · 1 line
2.32.0
RFC PATCH 5/13 vfio/migration: rename functions that relate to the In-Band approach
In reply to Lei RaoRename some functions that are related to the In-Band approach to facilitate introducing generic vfio live migration layer.
Rename vfio_migration_set_state to vfio_migration_set_state_local, vfio_save_buffer to vfio_migration_save_buffer_local, vfio_load_buffer to vfio_migration_load_buffer_local, vfio_update_pending to vfio_migration_update_pending_local, vfio_migration_init to vfio_migration_probe_local, vfio_migration_exit to vfio_migration_exit_local.
--- hw/vfio/migration.c | 74 +++++++++++++++++++++++--------------------- hw/vfio/trace-events | 6 ++-- 2 files changed, 42 insertions(+), 38 deletions(-)
hw/vfio/migration.c +39 -35
@@ -107,8 +107,8 @@ static int vfio_mig_rw(VFIODevice *vbasedev, __u8 *buf, size_t count,* an error is returned. */ -static int vfio_migration_set_state (VFIODevice *vbasedev,uint32_t mask, -uint32_t value) +static int vfio_migration_set_state_local (VFIODevice *vbasedev,uint32_t mask, +uint32_t value) {VFIOMigration *migration = vbasedev->migration;VFIORegion *region = &migration->region;
@@ -193,7 +193,8 @@ static void *get_data_section_size(VFIORegion *region, uint64_t data_offset,return ptr; } -static int vfio_save_buffer (QEMUFile *f,VFIODevice *vbasedev,uint64_t *size) +static int vfio_migration_save_buffer_local (QEMUFile *f,VFIODevice *vbasedev, +uint64_t *size) {VFIOMigration *migration = vbasedev->migration;VFIORegion *region = &migration->region;
@@ -212,8 +213,8 @@ static int vfio_save_buffer(QEMUFile *f, VFIODevice *vbasedev, uint64_t *size)return ret; } -trace_vfio_save_buffer (vbasedev->name, data_offset, data_size, - migration->pending_bytes); +trace_vfio_save_buffer_local (vbasedev->name, data_offset, data_size, + migration->pending_bytes);qemu_put_be64 (f, data_size); sz = data_size;
@@ -260,8 +261,8 @@ static int vfio_save_buffer(QEMUFile *f, VFIODevice *vbasedev, uint64_t *size)return ret; } -static int vfio_load_buffer (QEMUFile *f,VFIODevice *vbasedev, -uint64_t data_size) +static int vfio_migration_load_buffer_local (QEMUFile *f,VFIODevice *vbasedev, +uint64_t data_size) {VFIORegion *region = &vbasedev->migration->region;uint64_t data_offset =0 , size, report_size;
@@ -288,7 +289,8 @@ static int vfio_load_buffer(QEMUFile *f, VFIODevice *vbasedev, data_size =0 ; } -trace_vfio_load_state_device_data (vbasedev->name, data_offset, size); +trace_vfio_load_state_device_data_local (vbasedev->name, data_offset, + size);while (size) {void *buf;
@@ -331,7 +333,7 @@ static int vfio_load_buffer(QEMUFile *f, VFIODevice *vbasedev,return 0 ; } -static int vfio_update_pending (VFIODevice *vbasedev) +static int vfio_migration_update_pending_local (VFIODevice *vbasedev) {VFIOMigration *migration = vbasedev->migration;VFIORegion *region = &migration->region;
@@ -449,8 +451,8 @@ static int vfio_save_setup(QEMUFile *f, void *opaque)return ret; } - ret =vfio_migration_set_state (vbasedev,VFIO_DEVICE_STATE_MASK , -VFIO_DEVICE_STATE_V1_SAVING ); + ret =vfio_migration_set_state_local (vbasedev,VFIO_DEVICE_STATE_MASK , +VFIO_DEVICE_STATE_V1_SAVING );if (ret) {error_report ("%s: Failed to set state SAVING" , vbasedev->name);return ret;
@@ -484,7 +486,7 @@ static void vfio_save_pending(QEMUFile *f, void *opaque,VFIOMigration *migration = vbasedev->migration;int ret; - ret =vfio_update_pending (vbasedev); + ret =vfio_migration_update_pending_local (vbasedev);if (ret) {return ; }
@@ -505,7 +507,7 @@ static int vfio_save_iterate(QEMUFile *f, void *opaque)qemu_put_be64 (f,VFIO_MIG_FLAG_DEV_DATA_STATE );if (migration->pending_bytes ==0 ) { - ret =vfio_update_pending (vbasedev); + ret =vfio_migration_update_pending_local (vbasedev);if (ret) {return ret; }
@@ -518,10 +520,10 @@ static int vfio_save_iterate(QEMUFile *f, void *opaque) } } - ret =vfio_save_buffer (f, vbasedev, &data_size); + ret =vfio_migration_save_buffer_local (f, vbasedev, &data_size);if (ret) { -error_report ("%s: vfio_save_buffer failed %s" , vbasedev->name, -strerror (errno)); +error_report ("%s: vfio_miragion_save_buffer_local failed %s" , + vbasedev->name,strerror (errno));return ret; }
@@ -534,8 +536,8 @@ static int vfio_save_iterate(QEMUFile *f, void *opaque)/* * Reset pending_bytes as .save_live_pending is not called during savevm or -* snapshot case, in such case vfio_update_pending() at the start of this -* function updates pending_bytes. +* snapshot case, in such case vfio_migration_update_pending_local() at the +* start of this function updates pending_bytes. */ migration->pending_bytes =0 ;trace_vfio_save_iterate (vbasedev->name, data_size);
@@ -549,22 +551,23 @@ static int vfio_save_complete_precopy(QEMUFile *f, void *opaque)uint64_t data_size;int ret; - ret =vfio_migration_set_state (vbasedev, ~VFIO_DEVICE_STATE_V1_RUNNING , -VFIO_DEVICE_STATE_V1_SAVING ); + ret =vfio_migration_set_state_local (vbasedev, + ~VFIO_DEVICE_STATE_V1_RUNNING , +VFIO_DEVICE_STATE_V1_SAVING );if (ret) {error_report ("%s: Failed to set state STOP and SAVING" , vbasedev->name);return ret; } - ret =vfio_update_pending (vbasedev); + ret =vfio_migration_update_pending_local (vbasedev);if (ret) {return ret; }while (migration->pending_bytes >0 ) {qemu_put_be64 (f,VFIO_MIG_FLAG_DEV_DATA_STATE ); - ret =vfio_save_buffer (f, vbasedev, &data_size); + ret =vfio_migration_save_buffer_local (f, vbasedev, &data_size);if (ret <0 ) {error_report ("%s: Failed to save buffer" , vbasedev->name);return ret;
@@ -574,7 +577,7 @@ static int vfio_save_complete_precopy(QEMUFile *f, void *opaque)break ; } - ret =vfio_update_pending (vbasedev); + ret =vfio_migration_update_pending_local (vbasedev);if (ret) {return ret; }
@@ -587,7 +590,8 @@ static int vfio_save_complete_precopy(QEMUFile *f, void *opaque)return ret; } - ret =vfio_migration_set_state (vbasedev, ~VFIO_DEVICE_STATE_V1_SAVING ,0 ); + ret =vfio_migration_set_state_local (vbasedev, ~VFIO_DEVICE_STATE_V1_SAVING , +0 );if (ret) {error_report ("%s: Failed to set state STOPPED" , vbasedev->name);return ret;
@@ -638,7 +642,7 @@ static int vfio_load_setup(QEMUFile *f, void *opaque)return ret; } - ret =vfio_migration_set_state (vbasedev, ~VFIO_DEVICE_STATE_MASK , + ret =vfio_migration_set_state_local (vbasedev, ~VFIO_DEVICE_STATE_MASK ,VFIO_DEVICE_STATE_V1_RESUMING );if (ret) {error_report ("%s: Failed to set state RESUMING" , vbasedev->name);
@@ -690,7 +694,7 @@ static int vfio_load_state(QEMUFile *f, void *opaque, int version_id)uint64_t data_size =qemu_get_be64 (f);if (data_size) { - ret =vfio_load_buffer (f, vbasedev, data_size); + ret =vfio_migration_load_buffer_local (f, vbasedev, data_size);if (ret <0 ) {return ret; }
@@ -765,7 +769,7 @@ static void vfio_vmstate_change(void *opaque, bool running, RunState state) } } - ret =vfio_migration_set_state (vbasedev, mask, value); + ret =vfio_migration_set_state_local (vbasedev, mask, value);if (ret) {/* * Migration should be aborted in this case, but vm_state_notify()
@@ -796,10 +800,10 @@ static void vfio_migration_state_notifier(Notifier *notifier, void *data)case MIGRATION_STATUS_CANCELLED :case MIGRATION_STATUS_FAILED : bytes_transferred =0 ; - ret =vfio_migration_set_state (vbasedev, - ~(VFIO_DEVICE_STATE_V1_SAVING | -VFIO_DEVICE_STATE_V1_RESUMING ), -VFIO_DEVICE_STATE_V1_RUNNING ); + ret =vfio_migration_set_state_local (vbasedev, + ~(VFIO_DEVICE_STATE_V1_SAVING | +VFIO_DEVICE_STATE_V1_RESUMING ), +VFIO_DEVICE_STATE_V1_RUNNING );if (ret) {error_report ("%s: Failed to set state RUNNING" , vbasedev->name); }
@@ -836,7 +840,7 @@ static int vfio_migration_check(VFIODevice *vbasedev)return 0 ; } -static int vfio_migration_init (VFIODevice *vbasedev) +static int vfio_migration_probe_local (VFIODevice *vbasedev) {int ret;Object *obj;
@@ -890,12 +894,12 @@ static int vfio_migration_init(VFIODevice *vbasedev) migration->migration_state.notify = vfio_migration_state_notifier;add_migration_state_change_notifier (&migration->migration_state); -trace_vfio_migration_probe (vbasedev->name, info->index); +trace_vfio_migration_probe_local (vbasedev->name, info->index);g_free (info);return 0 ; err: -vfio_migration_exit (vbasedev); +vfio_migration_exit_local (vbasedev);g_free (info);return ret; }
@@ -919,7 +923,7 @@ int vfio_migration_probe(VFIODevice *vbasedev, Error **errp) vbasedev->migration =g_new0 (VFIOMigration,1 ); vbasedev->migration->vbasedev = vbasedev; - ret =vfio_migration_init (vbasedev); + ret =vfio_migration_probe_local (vbasedev);if (ret) { goto add_blocker; }
hw/vfio/trace-events +3 -3
@@ -148,13 +148,13 @@ vfio_display_edid_update(uint32_t prefx, uint32_t prefy) "%ux%u" vfio_display_edid_write_error(void) "" # migration.c -vfio_migration_probe(const char *name, uint32_t index) " (%s) Region %d" +vfio_migration_probe_local(const char *name, uint32_t index) " (%s) Region %d" vfio_migration_set_state(const char *name, uint32_t state) " (%s) state %d" vfio_vmstate_change(const char *name, int running, const char *reason, uint32_t dev_state) " (%s) running %d reason %s device state %d" vfio_migration_state_notifier(const char *name, const char *state) " (%s) state %s" vfio_save_setup(const char *name) " (%s)" vfio_save_cleanup(const char *name) " (%s)" -vfio_save_buffer(const char *name, uint64_t data_offset, uint64_t data_size, uint64_t pending) " (%s) Offset 0x%"PRIx64" size 0x%"PRIx64" pending 0x%"PRIx64 +vfio_save_buffer_local(const char *name, uint64_t data_offset, uint64_t data_size, uint64_t pending) " (%s) Offset 0x%"PRIx64" size 0x%"PRIx64" pending 0x%"PRIx64 vfio_update_pending(const char *name, uint64_t pending) " (%s) pending 0x%"PRIx64 vfio_save_device_config_state(const char *name) " (%s)" vfio_save_pending(const char *name, uint64_t precopy, uint64_t postcopy, uint64_t compatible) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64" compatible 0x%"PRIx64
@@ -162,7 +162,7 @@ vfio_save_iterate(const char *name, int data_size) " (%s) data_size %d" vfio_save_complete_precopy(const char *name) " (%s)" vfio_load_device_config_state(const char *name) " (%s)" vfio_load_state(const char *name, uint64_t data) " (%s) data 0x%"PRIx64 -vfio_load_state_device_data(const char *name, uint64_t data_offset, uint64_t data_size) " (%s) Offset 0x%"PRIx64" size 0x%"PRIx64 +vfio_load_state_device_data_local(const char *name, uint64_t data_offset, uint64_t data_size) " (%s) Offset 0x%"PRIx64" size 0x%"PRIx64 vfio_load_cleanup(const char *name) " (%s)" vfio_get_dirty_bitmap(int fd, uint64_t iova, uint64_t size, uint64_t bitmap_size, uint64_t start) "container fd=%d, iova=0x%"PRIx64" size= 0x%"PRIx64" bitmap_size=0x%"PRIx64" start=0x%"PRIx64 vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu dirty @ 0x%"PRIx64" - 0x%"PRIx64
Signature · 1 line
2.32.0
RFC PATCH 6/13 vfio/migration: introduce VFIOMigrationOps layer in VFIO live migration framework
In reply to Lei RaoAdd an abstraction layer, VFIOMigrationOps, to the VFIO live migration framework. Also adapt the In-Band approach to this abstraction layer by defining its own VFIOMigrationOps callbacks.
--- hw/vfio/migration.c | 203 +++++++++++++++++++++------------- include/hw/vfio/vfio-common.h | 14 +++ 2 files changed, 142 insertions(+), 75 deletions(-)
hw/vfio/migration.c +128 -75
@@ -407,7 +407,11 @@ static void vfio_migration_cleanup_local(VFIODevice *vbasedev)static void vfio_migration_cleanup (VFIODevice *vbasedev) { -vfio_migration_cleanup_local (vbasedev); +VFIOMigration *migration = vbasedev->migration; + +if (migration->ops->cleanup) { + migration->ops->cleanup (vbasedev); + } }/* ---------------------------------------------------------------------- */
@@ -438,24 +442,29 @@ static int vfio_migration_save_setup_local(VFIODevice *vbasedev)static int vfio_save_setup (QEMUFile *f,void *opaque) {VFIODevice *vbasedev = opaque; +VFIOMigration *migration = vbasedev->migration;int ret;trace_vfio_save_setup (vbasedev->name);qemu_put_be64 (f,VFIO_MIG_FLAG_DEV_SETUP_STATE ); - ret =vfio_migration_save_setup_local (vbasedev); -if (ret) { -error_report ("%s: Failed to vfio lm save setup:%s" , - vbasedev->name,strerror (-ret)); -return ret; +if (migration->ops->save_setup) { + ret = migration->ops->save_setup (vbasedev); +if (ret) { +error_report ("%s: Failed to vfio lm save setup:%s" , + vbasedev->name,strerror (-ret)); +return ret; + } } - ret =vfio_migration_set_state_local (vbasedev,VFIO_DEVICE_STATE_MASK , -VFIO_DEVICE_STATE_V1_SAVING ); -if (ret) { -error_report ("%s: Failed to set state SAVING" , vbasedev->name); -return ret; +if (migration->ops->set_state) { + ret = migration->ops->set_state (vbasedev,VFIO_DEVICE_STATE_MASK , +VFIO_DEVICE_STATE_V1_SAVING ); +if (ret) { +error_report ("%s: Failed to set state SAVING" , vbasedev->name); +return ret; + } }qemu_put_be64 (f,VFIO_MIG_FLAG_END_OF_STATE );
@@ -486,9 +495,11 @@ static void vfio_save_pending(QEMUFile *f, void *opaque,VFIOMigration *migration = vbasedev->migration;int ret; - ret =vfio_migration_update_pending_local (vbasedev); -if (ret) { -return ; +if (migration->ops->update_pending) { + ret = migration->ops->update_pending (vbasedev); +if (ret) { +return ; + } } *res_precopy_only += migration->pending_bytes;
@@ -507,9 +518,11 @@ static int vfio_save_iterate(QEMUFile *f, void *opaque)qemu_put_be64 (f,VFIO_MIG_FLAG_DEV_DATA_STATE );if (migration->pending_bytes ==0 ) { - ret =vfio_migration_update_pending_local (vbasedev); -if (ret) { -return ret; +if (migration->ops->update_pending) { + ret = migration->ops->update_pending (vbasedev); +if (ret) { +return ret; + } }if (migration->pending_bytes ==0 ) {
@@ -520,11 +533,13 @@ static int vfio_save_iterate(QEMUFile *f, void *opaque) } } - ret =vfio_migration_save_buffer_local (f, vbasedev, &data_size); -if (ret) { -error_report ("%s: vfio_miragion_save_buffer_local failed %s" , - vbasedev->name,strerror (errno)); -return ret; +if (migration->ops->save_buffer) { + ret = migration->ops->save_buffer (f, vbasedev, &data_size); +if (ret) { +error_report ("%s: vfio_miragion_save_buffer_local failed %s" , + vbasedev->name,strerror (errno)); +return ret; + } }qemu_put_be64 (f,VFIO_MIG_FLAG_END_OF_STATE );
@@ -551,35 +566,43 @@ static int vfio_save_complete_precopy(QEMUFile *f, void *opaque)uint64_t data_size;int ret; - ret =vfio_migration_set_state_local (vbasedev, - ~VFIO_DEVICE_STATE_V1_RUNNING , -VFIO_DEVICE_STATE_V1_SAVING ); -if (ret) { -error_report ("%s: Failed to set state STOP and SAVING" , - vbasedev->name); -return ret; +if (migration->ops->set_state) { + ret = migration->ops->set_state (vbasedev, + ~VFIO_DEVICE_STATE_V1_RUNNING , +VFIO_DEVICE_STATE_V1_SAVING ); +if (ret) { +error_report ("%s: Failed to set state STOP and SAVING" , + vbasedev->name); +return ret; + } } - ret =vfio_migration_update_pending_local (vbasedev); -if (ret) { -return ret; +if (migration->ops->update_pending) { + ret = migration->ops->update_pending (vbasedev); +if (ret) { +return ret; + } }while (migration->pending_bytes >0 ) {qemu_put_be64 (f,VFIO_MIG_FLAG_DEV_DATA_STATE ); - ret =vfio_migration_save_buffer_local (f, vbasedev, &data_size); -if (ret <0 ) { -error_report ("%s: Failed to save buffer" , vbasedev->name); -return ret; +if (migration->ops->save_buffer) { + ret = migration->ops->save_buffer (f, vbasedev, &data_size); +if (ret <0 ) { +error_report ("%s: Failed to save buffer" , vbasedev->name); +return ret; + } }if (data_size ==0 ) {break ; } - ret =vfio_migration_update_pending_local (vbasedev); -if (ret) { -return ret; +if (migration->ops->update_pending) { + ret = migration->ops->update_pending (vbasedev); +if (ret) { +return ret; + } } }
@@ -590,11 +613,13 @@ static int vfio_save_complete_precopy(QEMUFile *f, void *opaque)return ret; } - ret =vfio_migration_set_state_local (vbasedev, ~VFIO_DEVICE_STATE_V1_SAVING , -0 ); -if (ret) { -error_report ("%s: Failed to set state STOPPED" , vbasedev->name); -return ret; +if (migration->ops->set_state) { + ret = migration->ops->set_state (vbasedev, ~VFIO_DEVICE_STATE_V1_SAVING , +0 ); +if (ret) { +error_report ("%s: Failed to set state STOPPED" , vbasedev->name); +return ret; + } }trace_vfio_save_complete_precopy (vbasedev->name);
@@ -634,20 +659,25 @@ static int vfio_migration_load_setup_local(VFIODevice *vbasedev)static int vfio_load_setup (QEMUFile *f,void *opaque) {VFIODevice *vbasedev = opaque; +VFIOMigration *migration = vbasedev->migration;int ret =0 ; - ret =vfio_migration_load_setup_local (vbasedev); -if (ret <0 ) { -error_report ("%s: Failed to migration load setup" , vbasedev->name); -return ret; +if (migration->ops->load_setup) { + ret = migration->ops->load_setup (vbasedev); +if (ret <0 ) { +error_report ("%s: Failed to migration load setup" , vbasedev->name); +return ret; + } } - ret =vfio_migration_set_state_local (vbasedev, ~VFIO_DEVICE_STATE_MASK , -VFIO_DEVICE_STATE_V1_RESUMING ); -if (ret) { -error_report ("%s: Failed to set state RESUMING" , vbasedev->name); -vfio_migration_cleanup (vbasedev); -return ret; +if (migration->ops->set_state) { + ret = migration->ops->set_state (vbasedev, ~VFIO_DEVICE_STATE_MASK , +VFIO_DEVICE_STATE_V1_RESUMING ); +if (ret) { +error_report ("%s: Failed to set state RESUMING" , vbasedev->name); +vfio_migration_cleanup (vbasedev); +return ret; + } }return ret; }
@@ -692,11 +722,14 @@ static int vfio_load_state(QEMUFile *f, void *opaque, int version_id)case VFIO_MIG_FLAG_DEV_DATA_STATE : {uint64_t data_size =qemu_get_be64 (f); +VFIOMigration *migration = vbasedev->migration;if (data_size) { - ret =vfio_migration_load_buffer_local (f, vbasedev, data_size); -if (ret <0 ) { -return ret; +if (migration->ops->load_buffer) { + ret = migration->ops->load_buffer (f, vbasedev, data_size); +if (ret <0 ) { +return ret; + } } }break ;
@@ -736,7 +769,7 @@ static void vfio_vmstate_change(void *opaque, bool running, RunState state)uint32_t value, mask;int ret; -if (vbasedev->migration->vm_running == running) { +if (migration->vm_running == running) {return ; }
@@ -769,17 +802,19 @@ static void vfio_vmstate_change(void *opaque, bool running, RunState state) } } - ret =vfio_migration_set_state_local (vbasedev, mask, value); -if (ret) { -/* -* Migration should be aborted in this case, but vm_state_notify() -* currently does not support reporting failures. -*/ -error_report ("%s: Failed to set device state 0x%x" , vbasedev->name, - (migration->device_state & mask) | value); -qemu_file_set_error (migrate_get_current ()->to_dst_file, ret); +if (migration->ops->set_state) { + ret = migration->ops->set_state (vbasedev, mask, value); +if (ret) { +/* +* Migration should be aborted in this case, but vm_state_notify() +* currently does not support reporting failures. +*/ +error_report ("%s: Failed to set device state 0x%x" , vbasedev->name, + (migration->device_state & mask) | value); +qemu_file_set_error (migrate_get_current ()->to_dst_file, ret); + } } - vbasedev->migration->vm_running = running; + migration->vm_running = running;trace_vfio_vmstate_change (vbasedev->name, running,RunState_str (state), (migration->device_state & mask) | value); }
@@ -800,12 +835,14 @@ static void vfio_migration_state_notifier(Notifier *notifier, void *data)case MIGRATION_STATUS_CANCELLED :case MIGRATION_STATUS_FAILED : bytes_transferred =0 ; - ret =vfio_migration_set_state_local (vbasedev, - ~(VFIO_DEVICE_STATE_V1_SAVING | -VFIO_DEVICE_STATE_V1_RESUMING ), -VFIO_DEVICE_STATE_V1_RUNNING ); -if (ret) { -error_report ("%s: Failed to set state RUNNING" , vbasedev->name); +if (migration->ops->set_state) { + ret = migration->ops->set_state (vbasedev, + ~(VFIO_DEVICE_STATE_V1_SAVING | +VFIO_DEVICE_STATE_V1_RESUMING ), +VFIO_DEVICE_STATE_V1_RUNNING ); +if (ret) { +error_report ("%s: Failed to set state RUNNING" , vbasedev->name); + } } } }
@@ -820,7 +857,11 @@ static void vfio_migration_exit_local(VFIODevice *vbasedev)static void vfio_migration_exit (VFIODevice *vbasedev) { -vfio_migration_exit_local (vbasedev); +VFIOMigration *migration = vbasedev->migration; + +if (migration->ops->exit) { + migration->ops->exit (vbasedev); + }g_free (vbasedev->migration); vbasedev->migration =NULL ; }
@@ -840,6 +881,17 @@ static int vfio_migration_check(VFIODevice *vbasedev)return 0 ; } +static VFIOMigrationOps vfio_local_method = { + .save_setup = vfio_migration_save_setup_local, + .load_setup = vfio_migration_load_setup_local, + .update_pending = vfio_migration_update_pending_local, + .save_buffer = vfio_migration_save_buffer_local, + .load_buffer = vfio_migration_load_buffer_local, + .set_state = vfio_migration_set_state_local, + .cleanup = vfio_migration_cleanup_local, + .exit = vfio_migration_exit_local, +}; +static int vfio_migration_probe_local (VFIODevice *vbasedev) {int ret;
@@ -895,6 +947,7 @@ static int vfio_migration_probe_local(VFIODevice *vbasedev)add_migration_state_change_notifier (&migration->migration_state);trace_vfio_migration_probe_local (vbasedev->name, info->index); + migration->ops = &vfio_local_method;g_free (info);return 0 ;
include/hw/vfio/vfio-common.h +14 -0
@@ -58,10 +58,13 @@ typedef struct VFIORegion {uint8_t nr;/* cache the region number for debug */ } VFIORegion; +typedef struct VFIOMigrationOps VFIOMigrationOps ; + typedef struct VFIOMigration { struct VFIODevice *vbasedev; VMChangeStateEntry *vm_state; VFIORegion region; + VFIOMigrationOps *ops; uint32_t device_state; int vm_running; Notifier migration_state;
@@ -154,6 +157,17 @@ struct VFIODeviceOps {int (*vfio_load_config)(VFIODevice *vdev,QEMUFile *f); }; +typedef struct VFIOMigrationOps { +int (*save_setup)(VFIODevice *vbasedev); +int (*load_setup)(VFIODevice *vbasedev); +int (*update_pending)(VFIODevice *vbasedev); +int (*save_buffer)(QEMUFile *f,VFIODevice *vbasedev,uint64_t *size); +int (*load_buffer)(QEMUFile *f,VFIODevice *vbasedev,uint64_t data_size); +int (*set_state)(VFIODevice *vbasedev,uint32_t mask,uint32_t value); +void (*cleanup)(VFIODevice *vbasedev); +void (*exit)(VFIODevice *vbasedev); +}VFIOMigrationOps ; + typedef struct VFIOGroup { int fd; int groupid;
Signature · 1 line
2.32.0
RFC PATCH 7/13 vfio/migration: move the statistics of bytes_transferred to generic VFIO migration layer
In reply to Lei RaoThe statistics of bytes transferred conceptually belong to The VFIO live migration framework, and should not belong to any specific implementation such In-Band approach, so move it out from vfio_migration_region_save_buffer(), which makes it easier to add other implementations.
--- hw/vfio/migration.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/vfio/migration.c +2 -1
@@ -257,7 +257,6 @@ static int vfio_migration_save_buffer_local(QEMUFile *f, VFIODevice *vbasedev, *size = data_size; } - bytes_transferred += data_size;return ret; }
@@ -540,6 +539,7 @@ static int vfio_save_iterate(QEMUFile *f, void *opaque) vbasedev->name, strerror(errno));return ret; } + bytes_transferred += data_size; }qemu_put_be64 (f,VFIO_MIG_FLAG_END_OF_STATE );
@@ -592,6 +592,7 @@ static int vfio_save_complete_precopy(QEMUFile *f, void *opaque)error_report ("%s: Failed to save buffer" , vbasedev->name);return ret; } + bytes_transferred += data_size; }if (data_size ==0 ) {
Signature · 1 line
2.32.0
RFC PATCH 8/13 vfio/migration: split migration handler registering from vfio_migration_init
In reply to Lei Raovfio_migration_init() is mainly related to initialization of In-Band approach. Migration handler registering may also be used by other approaches. so split it from vfio_migration_init() and move it to vfio_migration_probe().
--- hw/vfio/migration.c | 56 ++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 19 deletions(-)
hw/vfio/migration.c +37 -19
@@ -882,6 +882,38 @@ static int vfio_migration_check(VFIODevice *vbasedev)return 0 ; } +static int vfio_migration_register_handlers (VFIODevice *vbasedev) +{ +Object *obj; +char id[256 ] ="" ; + g_autofree char *path = NULL, *oid = NULL; +VFIOMigration *migration = vbasedev->migration; + + obj = vbasedev->ops->vfio_get_object (vbasedev); +if (!obj) { +return -EINVAL ; + } + + oid =vmstate_if_get_id (VMSTATE_IF (DEVICE (obj))); +if (oid) { + path =g_strdup_printf ("%s/vfio" , oid); + }else { + path =g_strdup ("vfio" ); + } +strpadcpy (id,sizeof (id), path,'\0' ); + +register_savevm_live (id,VMSTATE_INSTANCE_ID_ANY ,1 , &savevm_vfio_handlers, + vbasedev); + + migration->vm_state =qdev_add_vm_change_state_handler (vbasedev->dev, + vfio_vmstate_change, + vbasedev); + migration->migration_state.notify = vfio_migration_state_notifier; +add_migration_state_change_notifier (&migration->migration_state); + +return 0 ; +} +static VFIOMigrationOps vfio_local_method = { .save_setup = vfio_migration_save_setup_local, .load_setup = vfio_migration_load_setup_local,
@@ -897,9 +929,7 @@ static int vfio_migration_probe_local(VFIODevice *vbasedev) {int ret;Object *obj; -char id[256 ] ="" ;struct vfio_region_info *info =NULL ; - g_autofree char *path = NULL, *oid = NULL;VFIOMigration *migration = vbasedev->migration; obj = vbasedev->ops->vfio_get_object (vbasedev);
@@ -930,23 +960,6 @@ static int vfio_migration_probe_local(VFIODevice *vbasedev) goto err; } - oid =vmstate_if_get_id (VMSTATE_IF (DEVICE (obj))); -if (oid) { - path =g_strdup_printf ("%s/vfio" , oid); - }else { - path =g_strdup ("vfio" ); - } -strpadcpy (id,sizeof (id), path,'\0' ); - -register_savevm_live (id,VMSTATE_INSTANCE_ID_ANY ,1 , &savevm_vfio_handlers, - vbasedev); - - migration->vm_state =qdev_add_vm_change_state_handler (vbasedev->dev, - vfio_vmstate_change, - vbasedev); - migration->migration_state.notify = vfio_migration_state_notifier; -add_migration_state_change_notifier (&migration->migration_state); -trace_vfio_migration_probe_local (vbasedev->name, info->index); migration->ops = &vfio_local_method;g_free (info);
@@ -982,6 +995,11 @@ int vfio_migration_probe(VFIODevice *vbasedev, Error **errp) goto add_blocker; } + ret =vfio_migration_register_handlers (vbasedev); +if (ret) { + goto add_blocker; + } +return 0 ; add_blocker:
Signature · 1 line
2.32.0
RFC PATCH 9/13 vfio/migration: move the functions of In-Band approach to a new file
In reply to Lei RaoMoving the functions of In-Band approach into a new file to match with the new abstraction layer of migration ops.
--- hw/vfio/meson.build | 1 + hw/vfio/migration-local.c | 453 ++++++++++++++++++++++++++++++++++ hw/vfio/migration.c | 421 ------------------------------- include/hw/vfio/vfio-common.h | 1 + 4 files changed, 455 insertions(+), 421 deletions(-) create mode 100644 hw/vfio/migration-local.c
hw/vfio/meson.build +1 -0
@@ -3,6 +3,7 @@ vfio_ss.add(files( 'common.c', 'spapr.c', 'migration.c', + 'migration-local.c', )) vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files( 'display.c',
hw/vfio/migration-local.c new file +453 -0
453 lines not on this page · raw message
hw/vfio/migration.c +0 -421
457 lines not on this page · raw message
include/hw/vfio/vfio-common.h +1 -0
@@ -256,6 +256,7 @@ int vfio_spapr_remove_window(VFIOContainer *container, hwaddr offset_within_address_space);int vfio_migration_probe (VFIODevice *vbasedev,Error **errp); +int vfio_migration_probe_local (VFIODevice *vbasedev);void vfio_migration_finalize (VFIODevice *vbasedev);#endif /* HW_VFIO_VFIO_COMMON_H */
Signature · 1 line
2.32.0
RFC PATCH 10/13 vfio/pci: introduce command-line parameters to specify migration method
In reply to Lei RaoAdd command-line parameters (x-plugin-path and x-plugin-arg) of migration plugin for VFIO PCI functions. x-plugin-path indicates the path of a dynamic load library and x-plugin-arg is the necessary parameter to load and use it. A typical example is, if the plugin communicates with the agent running on IPU/DPU backend SOC through network, the argument should be the IP and Port of agent. The usage as follows:
-device vfio-pci,id=$ID,host=$bdf,x-enable-migration,\
x-plugin-path=$plugin_path,x-plugin-arg=<IP:Port>
--- hw/vfio/pci.c | 2 ++ include/hw/vfio/vfio-common.h | 6 ++++++ 2 files changed, 8 insertions(+)
hw/vfio/pci.c +2 -0
@@ -3309,6 +3309,8 @@ static Property vfio_pci_dev_properties[] = { qdev_prop_nv_gpudirect_clique, uint8_t),DEFINE_PROP_OFF_AUTO_PCIBAR ("x-msix-relocation" , VFIOPCIDevice, msix_relo,OFF_AUTOPCIBAR_OFF ), +DEFINE_PROP_STRING ("x-plugin-path" , VFIOPCIDevice, vbasedev.desc.path), + DEFINE_PROP_STRING("x-plugin-arg", VFIOPCIDevice, vbasedev.desc.arg),/* * TODO - support passed fds... is this necessary? * DEFINE_PROP_STRING("vfiofd", VFIOPCIDevice, vfiofd_name),
include/hw/vfio/vfio-common.h +6 -0
@@ -58,6 +58,11 @@ typedef struct VFIORegion {uint8_t nr;/* cache the region number for debug */ } VFIORegion; +struct vfio_migration_plugin_desc { +char *path; +char *arg; +}; +typedef struct VFIOMigrationOps VFIOMigrationOps ; typedef struct VFIOMigration {
@@ -144,6 +149,7 @@ typedef struct VFIODevice {unsigned int num_regions;unsigned int flags;VFIOMigration *migration; +struct vfio_migration_plugin_desc desc;Error *migration_blocker;OnOffAuto pre_copy_dirty_page_tracking; } VFIODevice;
Signature · 1 line
2.32.0
RFC PATCH 11/13 vfio/migration: add a plugin layer to support out-of-band live migration
In reply to Lei RaoIntroduce a plugin mechanism under VFIOMigrationOps layer. Each vendor can provide a dynamic load library that implements the communication driver to talk with IPU/DPU backend agent for saving and restoring device state during live migration.
There are three interfaces between QEMU VFIO and a migration plugin:
- VFIOLMPluginGetVersion:
This is a function type. Plugin must expose a function symbol named "vfio_lm_get_plugin_version" with this function type to return the interface version supported by the plugin.
- VFIOLMPluginGetOps:
This is a function type. Plugin must expose a function symbol named "vfio_lm_get_plugin_ops" with this function type to return a pointer to VFIOMigrationPluginOps struct.
- VFIOMigrationPluginOps:
This is a struct type containing a set of callbacks that plugin exposes. The callbacks will be invoked by QEMU VFIO during live migration for saving and restoring device states.
The interfaces are defined in include/hw/vfio/vfio-migration-plugin.h.
When QEMU loads a migration plugin, it will first find and invoke function symbol named "vfio_lm_get_plugin_version" to check the interface version that plugin supports. And then find and invoke function symbol named "vfio_lm_get_plugin_ops" to get vendor device specific VFIOMigrationPluginOps which will be used for saving/restoring device states during live migration.
--- docs/devel/vfio-migration-plugin.rst | 165 +++++++++++++++ hw/vfio/meson.build | 1 + hw/vfio/migration-plugin.c | 262 ++++++++++++++++++++++++ hw/vfio/migration.c | 13 +- include/hw/vfio/vfio-common.h | 12 ++ include/hw/vfio/vfio-migration-plugin.h | 21 ++ 6 files changed, 471 insertions(+), 3 deletions(-) create mode 100644 docs/devel/vfio-migration-plugin.rst create mode 100644 hw/vfio/migration-plugin.c create mode 100644 include/hw/vfio/vfio-migration-plugin.h
docs/devel/vfio-migration-plugin.rst new file +165 -0
@@ -0,0 +1,165 @@ +============================ +VFIO Device Migration Plugins +============================ + +Contents: +========= +* Introduction +* Usage +* Plugin based VFIO Live Migration Flow +* Interface Description between QEMU and Plugins + +Introduction: +============ + +Plugin based VFIO live migration is an extension to VFIO live migration +mechanism, which is described in ``docs/devel/vfio-migration.rst``. It provides +an out-of-band migration solution for PCIe functions exposed by Infrastructure +Processing Units (IPU) and Data Processing Units (DPU). + +IPU/DPU usually has an SoC in the backend where a Linux system usually runs +out-of-band agents to provision and configure the interfaces and communicate +with a host management stack such as gRPC or JSON-RPC. Plugin based VFIO live +migration leverage the agents in the Soc to save/restore PCIe device states. + +This is a new feature for VFIO live migration and it allows device vendors to +develop out-of-tree plugins that can be dynamically loaded into a running QEMU +process during VFIO passthrough devices live migration. + +This document describes the interfaces between QEMU VFIO live migration +framework and the plugins. + +Usage: +====== + +An example to use VFIO migration plugin is as the following command line: + +-device vfio-pci-emu,x-enable-migration=on,x-plugin-path=$plugin_path,x-plugin-arg=$plugin_arg + +Where, + +- the 'x-enable-migration' controls whether the VFIO device supports live + migration (Not supported by default). + +- 'x-plugin-path' indicates the path of the plugin on the host. + +- 'x-plugin-arg' is a parameter required by QEMU to load and use the out-of-tree + plugin, if the plugin communicates with the backend on IPU/DPU by network, + this parameter should be <IP: Port>. + +Plugin based VFIO Live Migration Flow: +====================================== + +The following ASCII graph describes the overall component relationship: + + +----------------------------------------------------+ + | QEMU | + | +------------------------------------------------+ | + | | VFIO Live Migration Framework | | + | | +--------------------------------------+ | | + | | | VFIOMigrationOps | | | + | | +-------^---------------------^--------+ | | + | | | | | | + | | +-------v-------+ +-------v--------+ | | + | | | VFIO LM Based | | VFIO LM Based | | | + | | |On Local Region| | On Plugin | | | + | | +-------^-------+ | +----------+ | | + | | | | |Plugin Ops+----+-+------------+ + | | | +-----+----------+ | | | + | | | | | +---------v----------+ + | +------------+-----------------------------------+ | | Vendor Specific | + | | | | Plugins(.so) | + +--------------+-------------------------------------+ +----------+---------+ + UserSpace | | +----------------+--------------------------------------------- | + Kernel | | + | | + +----------v----------------------+ | + | Kernel VFIO Driver | | + | +-------------------------+ | | + | | | | | Network + | | Vendor-Specific Driver | | | + | | | | | + | +----------^--------------+ | | + | | | | + +---------------+-----------------+ | + | | + | | +---------------------+----------------------------------------- | + Hardware | | + | +-----+-----+-----+----+-----+ | + +----------v------+ | VF0 | VF1 | VF2 | ...| VFn | | + | Traditional | +-----+-----+-----+----+-----+ | + | PCIe Devices | | | | + +-----------------+ | +--------+------------+ | | + | | | Agent |<-+----+ + | | +------------+ | + | | | | + | | SOC | | + | +---------------------+ | + | IPU/DPU | + +----------------------------+ + +Two QEMU command line options (x-plugin-path and x-plugin-arg) are introduced to +specify the corresponding plugin and its parameters for a passthrough device. +If they are specified, the plugin will be loaded in vfio_migration_probe(), +which will check the plugin version and get the pointer to the plugin's +VFIOMigrationPluginOps. If any failure during the probing, the plugin will not +be loaded, and this PCIe device will be marked as no supporting of live +migration. + +When live migration happens, VFIO live migration framework will invoke the +callbacks defined in VFIOMigrationPluginOps to save/restore the device states, +as described in the following section. + +Interface Description between QEMU and Plugins: +============================================= + +The interfaces between QEMU VFIO live migration framework and vendor-specific +plugin are defined as follows: + + - VFIOLMPluginGetVersion: + This is a function type. Plugins must expose a function symbol named + ``vfio_lm_get_plugin_version`` with this function type to return the + interface version supported by the plugin. + - VFIOLMPluginGetOps: + This is a function type. Plugins must expose a function symbol named + ``vfio_lm_get_plugin_ops`` with this function type to return a pointer + to VFIOMigrationPluginOps struct. + - VFIOMigrationPluginOps: + This is a struct type containing a set of callbacks that plugin + exposes. The callbacks will be invoked by QEMU VFIO during live + migration for saving and restoring device states. + +The interfaces are defined in include/hw/vfio/vfio-migration-plugin.h. + +When QEMU loads a migration plugin, it will first find and invoke a function +symbol named ``vfio_lm_get_plugin_version`` to check the interface version that +plugin supports. The core code will refuse to load a plugin if it doesn't export +the symbol or the version doesn't match the one QEMU supports. + +Then QEMU finds and invokes function symbol named ``vfio_lm_get_plugin_ops`` to +get vendor device-specific VFIOMigrationPluginOps which will be used for +saving/restoring device states. + +VFIOMigrationPluginOps is defined as follows: + +typedef struct VFIOMigrationPluginOps { + void *(*init)(char *devid, char *arg); + int (*save)(void *handle, uint8_t *state, uint64_t len); + int (*load)(void *handle, uint8_t *state, uint64_t len); + int (*update_pending)(void *handle, uint64_t *pending_bytes); + int (*set_state)(void *handle, uint32_t value); + int (*get_state)(void *handle, uint32_t *value); + int (*cleanup)(void *handle); +} VFIOMigrationPluginOps; + +Here: + - init(): set the PCIe device BDF and args, and get the plugin handle. + - save(): save the VFIO passthrough device states on the source. + - load(): restore the VFIO passthrough device states on the destination. + - set_state(): set the PCIe device states including SAVING, RUNNING, + STOP, and RESUMING. + - get_state(): get the PCIe device states. + - update_pending(): get the remaining bytes during data transfer. + - cleanup(): unload the plugin and release some resources.
hw/vfio/meson.build +1 -0
@@ -4,6 +4,7 @@ vfio_ss.add(files( 'spapr.c', 'migration.c', 'migration-local.c', + 'migration-plugin.c', )) vfio_ss.add(when: 'CONFIG_VFIO_PCI', if_true: files( 'display.c',
hw/vfio/migration-plugin.c new file +262 -0
262 lines not on this page · raw message
hw/vfio/migration.c +10 -3
@@ -569,9 +569,16 @@ int vfio_migration_probe(VFIODevice *vbasedev, Error **errp) vbasedev->migration =g_new0 (VFIOMigration,1 ); vbasedev->migration->vbasedev = vbasedev; - ret =vfio_migration_probe_local (vbasedev); -if (ret) { - goto add_blocker; +if (vbasedev->desc.arg !=NULL && vbasedev->desc.path !=NULL ) { + ret =vfio_migration_probe_plugin (vbasedev); +if (ret) { + goto add_blocker; + } + }else { + ret =vfio_migration_probe_local (vbasedev); +if (ret) { + goto add_blocker; + } } ret =vfio_migration_register_handlers (vbasedev);
include/hw/vfio/vfio-common.h +12 -0
@@ -22,6 +22,7 @@#define HW_VFIO_VFIO_COMMON_H #include "exec/memory.h" +#include "qemu/iov.h" #include "qemu/queue.h" #include "qemu/notify.h" #include "ui/console.h"
@@ -30,6 +31,9 @@#include <linux/vfio.h> #endif #include "sysemu/sysemu.h" +#include "vfio-migration-plugin.h" +#include <gmodule.h> +#include <glib.h> #define VFIO_MSG_PREFIX "vfio %s: "
@@ -58,6 +62,12 @@ typedef struct VFIORegion {uint8_t nr;/* cache the region number for debug */ } VFIORegion; +typedef struct VFIOMigrationPlugin { +GModule *module; +VFIOMigrationPluginOps *ops; +void *handle; +}VFIOMigrationPlugin ; +struct vfio_migration_plugin_desc {char *path;char *arg;
@@ -70,6 +80,7 @@ typedef struct VFIOMigration {VMChangeStateEntry *vm_state;VFIORegion region;VFIOMigrationOps *ops; +VFIOMigrationPlugin *plugin;uint32_t device_state;int vm_running;Notifier migration_state;
@@ -263,6 +274,7 @@ int vfio_spapr_remove_window(VFIOContainer *container,int vfio_migration_probe (VFIODevice *vbasedev,Error **errp);int vfio_migration_probe_local (VFIODevice *vbasedev); +int vfio_migration_probe_plugin (VFIODevice *vbasedev);void vfio_migration_finalize (VFIODevice *vbasedev);#endif /* HW_VFIO_VFIO_COMMON_H */
include/hw/vfio/vfio-migration-plugin.h new file +21 -0
@@ -0,0 +1,21 @@ +#ifndef HW_VFIO_PLUGIN_MIGRATION_H +#define HW_VFIO_PLUGIN_MIGRATION_H + +#include <stdint.h> + +#define VFIO_LM_PLUGIN_API_VERSION 0 + +typedef struct VFIOMigrationPluginOps { +void *(*init)(char *devid,char *arg); +int (*save)(void *handle,uint8_t *state,uint64_t len); +int (*load)(void *handle,uint8_t *state,uint64_t len); +int (*update_pending)(void *handle,uint64_t *pending_bytes); +int (*set_state)(void *handle,uint32_t value); +int (*get_state)(void *handle,uint32_t *value); +int (*cleanup)(void *handle); +}VFIOMigrationPluginOps ; + +typedef int (*VFIOLMPluginGetVersion )(void ); +typedef VFIOMigrationPluginOps * (*VFIOLMPluginGetOps )(void ); + +#endif
Signature · 1 line
2.32.0
RFC PATCH 12/13 vfio/migration: add some trace-events for vfio migration plugin
In reply to Lei RaoAdd some trace-events including trace_vfio_migration_plugin_probe trace_vfio_plugin_save_buffer, trace_vfio_plugin_load_state_device_data trace_vfio_update_pending, and trace_vfio_migration_set_state to make debugging easier.
--- hw/vfio/migration-plugin.c | 10 +++++++--- hw/vfio/trace-events | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-)
hw/vfio/migration-plugin.c +7 -3
@@ -19,6 +19,7 @@#include "qapi/error.h" #include "hw/vfio/vfio-migration-plugin.h" #include "sysemu/sysemu.h" +#include "trace.h" #define CHUNK_SIZE (1024 * 1024)
@@ -128,7 +129,7 @@ static int vfio_migration_update_pending_plugin(VFIODevice *vbasedev)return ret; } migration->pending_bytes = pending_bytes; - +trace_vfio_update_pending (vbasedev->name, pending_bytes);return 0 ; }
@@ -159,7 +160,7 @@ static int vfio_migration_set_state_plugin(VFIODevice *vbasedev, uint32_t mask, } vbasedev->migration->device_state = device_state; - +trace_vfio_migration_set_state (vbasedev->name, device_state);return 0 ; }
@@ -179,6 +180,7 @@ static int vfio_migration_save_buffer_plugin(QEMUFile *f, VFIODevice *vbasedev,qemu_put_be64 (f, data_size); tmp_size = data_size; +trace_vfio_save_buffer_plugin (vbasedev->name, data_size);while (tmp_size) {uint64_t sz = tmp_size <=CHUNK_SIZE ? tmp_size :CHUNK_SIZE ;void *buf =g_try_malloc (sz);
@@ -214,6 +216,7 @@ static int vfio_migration_load_buffer_plugin(QEMUFile *f, VFIODevice *vbasedev,int ret =0 ;VFIOMigrationPlugin *plugin = vbasedev->migration->plugin; +trace_vfio_load_state_device_data_plugin (vbasedev->name, data_size);while (data_size) {uint64_t sz = data_size <=CHUNK_SIZE ? data_size :CHUNK_SIZE ;void *buf =g_try_malloc (sz);
@@ -257,6 +260,7 @@ int vfio_migration_probe_plugin(VFIODevice *vbasedev) } migration->ops = &vfio_plugin_method; - +trace_vfio_migration_probe_plugin (vbasedev->name, vbasedev->desc.path, + vbasedev->desc.arg);return 0 ; }
hw/vfio/trace-events +3 -0
@@ -149,12 +149,14 @@ vfio_display_edid_write_error(void) "" # migration.c vfio_migration_probe_local(const char *name, uint32_t index) " (%s) Region %d" +vfio_migration_probe_plugin(const char *name, const char *path, const char *arg) " (%s) Plugin path=%s arg=%s" vfio_migration_set_state(const char *name, uint32_t state) " (%s) state %d" vfio_vmstate_change(const char *name, int running, const char *reason, uint32_t dev_state) " (%s) running %d reason %s device state %d" vfio_migration_state_notifier(const char *name, const char *state) " (%s) state %s" vfio_save_setup(const char *name) " (%s)" vfio_save_cleanup(const char *name) " (%s)" vfio_save_buffer_local(const char *name, uint64_t data_offset, uint64_t data_size, uint64_t pending) " (%s) Offset 0x%"PRIx64" size 0x%"PRIx64" pending 0x%"PRIx64 +vfio_save_buffer_plugin(const char *name, uint64_t data_size) " (%s) data size 0x%"PRIx64 vfio_update_pending(const char *name, uint64_t pending) " (%s) pending 0x%"PRIx64 vfio_save_device_config_state(const char *name) " (%s)" vfio_save_pending(const char *name, uint64_t precopy, uint64_t postcopy, uint64_t compatible) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64" compatible 0x%"PRIx64
@@ -163,6 +165,7 @@ vfio_save_complete_precopy(const char *name) " (%s)" vfio_load_device_config_state(const char *name) " (%s)" vfio_load_state(const char *name, uint64_t data) " (%s) data 0x%"PRIx64 vfio_load_state_device_data_local(const char *name, uint64_t data_offset, uint64_t data_size) " (%s) Offset 0x%"PRIx64" size 0x%"PRIx64 +vfio_load_state_device_data_plugin(const char *name, uint64_t data_size) " (%s) data size 0x%"PRIx64 vfio_load_cleanup(const char *name) " (%s)" vfio_get_dirty_bitmap(int fd, uint64_t iova, uint64_t size, uint64_t bitmap_size, uint64_t start) "container fd=%d, iova=0x%"PRIx64" size= 0x%"PRIx64" bitmap_size=0x%"PRIx64" start=0x%"PRIx64 vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu dirty @ 0x%"PRIx64" - 0x%"PRIx64
Signature · 1 line
2.32.0
RFC PATCH 13/13 vfio/migration: make the region and plugin member of struct VFIOMigration to be a union
In reply to Lei RaoSince a VFIO device either uses In-Band or Out-of-Band live migration. So, the region and plugin in VFIOMigration can be put into a union.
--- hw/vfio/migration-local.c | 33 ++++++++++++++++++--------------- include/hw/vfio/vfio-common.h | 6 ++++-- 2 files changed, 22 insertions(+), 17 deletions(-)
hw/vfio/migration-local.c +18 -15
@@ -98,7 +98,7 @@ static int vfio_migration_set_state_local(VFIODevice *vbasedev, uint32_t mask, uint32_t value) {VFIOMigration *migration = vbasedev->migration; -VFIORegion *region = &migration->region; +VFIORegion *region = migration->region;off_t dev_state_off = region->fd_offset +VFIO_MIG_STRUCT_OFFSET (device_state);uint32_t device_state;
@@ -184,7 +184,7 @@ static int vfio_migration_save_buffer_local(QEMUFile *f, VFIODevice *vbasedev, uint64_t *size) {VFIOMigration *migration = vbasedev->migration; -VFIORegion *region = &migration->region; +VFIORegion *region = migration->region;uint64_t data_offset =0 , data_size =0 , sz;int ret;
@@ -250,7 +250,7 @@ static int vfio_migration_save_buffer_local(QEMUFile *f, VFIODevice *vbasedev,static int vfio_migration_load_buffer_local (QEMUFile *f,VFIODevice *vbasedev,uint64_t data_size) { -VFIORegion *region = &vbasedev->migration->region; +VFIORegion *region = vbasedev->migration->region;uint64_t data_offset =0 , size, report_size;int ret;
@@ -322,7 +322,7 @@ static int vfio_migration_load_buffer_local(QEMUFile *f, VFIODevice *vbasedev,static int vfio_migration_update_pending_local (VFIODevice *vbasedev) {VFIOMigration *migration = vbasedev->migration; -VFIORegion *region = &migration->region; +VFIORegion *region = migration->region;uint64_t pending_bytes =0 ;int ret;
@@ -342,8 +342,8 @@ static void vfio_migration_cleanup_local(VFIODevice *vbasedev) {VFIOMigration *migration = vbasedev->migration; -if (migration->region.mmaps) { -vfio_region_unmap (&migration->region); +if (migration->region->mmaps) { +vfio_region_unmap (migration->region); } }
@@ -352,14 +352,14 @@ static int vfio_migration_save_setup_local(VFIODevice *vbasedev)VFIOMigration *migration = vbasedev->migration;int ret =-1 ; -if (migration->region.mmaps) { +if (migration->region->mmaps) {/* * Calling vfio_region_mmap() from migration thread. Memory API called * from this function require locking the iothread when called from * outside the main loop thread. */ qemu_mutex_lock_iothread (); - ret =vfio_region_mmap (&migration->region); + ret =vfio_region_mmap (migration->region);qemu_mutex_unlock_iothread ();if (ret) { error_report("%s: Failed to mmap VFIO migration region: %s",
@@ -375,11 +375,11 @@ static int vfio_migration_load_setup_local(VFIODevice *vbasedev)VFIOMigration *migration = vbasedev->migration;int ret =-1 ; -if (migration->region.mmaps) { - ret =vfio_region_mmap (&migration->region); +if (migration->region->mmaps) { + ret =vfio_region_mmap (migration->region);if (ret) {error_report ("%s: Failed to mmap VFIO migration region %d: %s" , - vbasedev->name, migration->region.nr, + vbasedev->name, migration->region->nr,strerror (-ret));error_report ("%s: Falling back to slow path" , vbasedev->name); }
@@ -391,8 +391,10 @@ static void vfio_migration_exit_local(VFIODevice *vbasedev) {VFIOMigration *migration = vbasedev->migration; -vfio_region_exit (&migration->region); -vfio_region_finalize (&migration->region); +vfio_region_exit (migration->region); +vfio_region_finalize (migration->region); +g_free (migration->region); + migration->region =NULL ; }static VFIOMigrationOps vfio_local_method = {
@@ -426,7 +428,8 @@ int vfio_migration_probe_local(VFIODevice *vbasedev)return -EINVAL ; } - ret =vfio_region_setup (obj, vbasedev, &vbasedev->migration->region, + migration->region =g_new0 (VFIORegion,1 ); + ret =vfio_region_setup (obj, vbasedev, vbasedev->migration->region, info->index,"migration" );if (ret) { error_report("%s: Failed to setup VFIO migration region %d: %s",
@@ -434,7 +437,7 @@ int vfio_migration_probe_local(VFIODevice *vbasedev) goto err; } -if (!vbasedev->migration->region.size) { +if (!vbasedev->migration->region->size) {error_report ("%s: Invalid zero-sized VFIO migration region %d" , vbasedev->name, info->index); ret = -EINVAL ;
include/hw/vfio/vfio-common.h +4 -2
@@ -78,9 +78,11 @@ typedef struct VFIOMigrationOps VFIOMigrationOps; typedef struct VFIOMigration { struct VFIODevice *vbasedev; VMChangeStateEntry *vm_state; - VFIORegion region; VFIOMigrationOps *ops; - VFIOMigrationPlugin *plugin; + union { + VFIORegion *region; + VFIOMigrationPlugin *plugin; + }; uint32_t device_state; int vm_running; Notifier migration_state;
Signature · 1 line
2.32.0
Quoted 21 lines · On Tue, 24 May 2022 14:18:35 +0800 Lei Rao <[email protected]> wrote:
Migration of a VFIO passthrough device can be supported by using a device specific kernel driver to save/restore the device state thru device specific interfaces. But this approach doesn't work for devices that lack a state migration interface, e.g. NVMe.
On the other hand, Infrastructure Process Unit (IPU) or Data Processing Unit (DPU) vendors may choose to implement an out-of-band interface from the SoC to help manage the state of such non-migratable devices e.g. via gRPC or JSON-RPC protocols.
This RFC attempts to support such out-of-band migration interface by introducing the concept of migration backends in vfio. The existing logic around vfio migration uAPI is now called the 'local' backend while a new 'out-of-band' backend is further introduced allowing vfio to redirect VMState ops to an external plugin.
Currently, the backend migration Ops is defined close to SaveVMHandlers. We also considered whether there is value of abstracting it in a lower level e.g. close to vfio migration uAPI but no clear conclusion. Hence this is one part which we'd like to hear suggestions.
Quoted 5 lines
This proposal adopts a plugin mechanism (an example can be found in [1]) given that IPU/DPU vendors usually implement proprietary migration interfaces without a standard. But we are also open if an alternative option makes better sense, e.g. via loadable modules (with Qemu supporting gRPC or JSON-RPC support) or an IPC mechanism similar to vhost-user.
AFAIU, QEMU is not interested in supporting plugin modules, especially proprietary ones. I don't see that a case has really been made that this cannot be done in-band, through a vfio-pci variant driver, possibly making use of proprietary interfaces to a userspace agent if necessary (though please don't ask such to be accepted in-tree for the kernel either). A vfio-user device server might also host such proprietary, device specific agents while supporting the standard, in-band migration interface. Thanks,
Alex
Quoted 101 lines
The following graph describes the overall component relationship:
+----------------------------------------------------+ | QEMU | | +------------------------------------------------+ | | | VFIO Live Migration Framework | | | | +--------------------------------------+ | | | | | VFIOMigrationOps | | | | | +-------^---------------------^--------+ | | | | | | | | | | +-------v-------+ +-------v--------+ | | | | | LM Backend Via| | LM Backend Via | | | | | | Device Fd | | Plugins | | | | | +-------^-------+ | +----------+ | | | | | | |Plugin Ops+----+-+------------+ | | | +-----+----------+ | | | | | | | | +---------v----------+ | +------------+-----------------------------------+ | | Vendor Specific | | | | | Plugins(.so) | +--------------+-------------------------------------+ +----------+---------+ UserSpace | | ----------------+--------------------------------------------- | Kernel | | | | +----------v----------------------+ | | Kernel VFIO Driver | | | +-------------------------+ | | | | | | | Network | | Vendor-Specific Driver | | | | | | | | | +----------^--------------+ | | | | | | +---------------+-----------------+ | | | | | ---------------------+----------------------------------------- | Hardware | | | +-----+-----+-----+----+-----+ | +----------v------+ | VF0 | VF1 | VF2 | ...| VFn | | | Traditional | +-----+-----+-----+----+-----+ | | PCIe Devices | | | | +-----------------+ | +--------+------------+ | | | | | Agent |<-+----+ | | +------------+ | | | | | | | SOC | | | +---------------------+ | | IPU | +----------------------------+Two command-line parameters (x-plugin-path and x-plugin-arg) are introduced to enable the out-of-band backend. If specified, vfio will attempt to use the out-of-band backend.
The following is an example of VFIO command-line parameters for OOB-Approach:
-device vfio-pci,id=$ID,host=$bdf,x-enable-migration,x-plugin-path=$plugin_path,x-plugin-arg=$plugin_arg
[1] https://github.com/raolei-intel/vfio-lm-plugin-example.git
Lei Rao (13):
vfio/migration: put together checks of migration initialization
conditions
vfio/migration: move migration struct allocation out of
vfio_migration_init
vfio/migration: movevfio_get_dev_region_infoout of
vfio_migration_probe
vfio/migration: Separated functions that relate to the In-Band
approach
vfio/migration: rename functions that relate to the In-Band approach vfio/migration: introduce VFIOMigrationOps layer in VFIO live
migration framework
vfio/migration: move the statistics ofbytes_transferredto generic
VFIO migration layer
vfio/migration: split migration handler registering from
vfio_migration_init
vfio/migration: move the functions of In-Band approach to a new file vfio/pci: introduce command-line parameters to specify migration
method
vfio/migration: add a plugin layer to support out-of-band live
migration
vfio/migration: add some trace-events for vfio migration plugin vfio/migration: make the region and plugin member of struct
VFIOMigration to be a uniondocs/devel/vfio-migration-plugin.rst | 165 +++++++ hw/vfio/meson.build | 2 + hw/vfio/migration-local.c | 456 +++++++++++++++++++ hw/vfio/migration-plugin.c | 266 +++++++++++ hw/vfio/migration.c | 577 ++++++------------------ hw/vfio/pci.c | 2 + hw/vfio/trace-events | 9 +- include/hw/vfio/vfio-common.h | 37 +- include/hw/vfio/vfio-migration-plugin.h | 21 + 9 files changed, 1096 insertions(+), 439 deletions(-) create mode 100644 docs/devel/vfio-migration-plugin.rst create mode 100644 hw/vfio/migration-local.c create mode 100644 hw/vfio/migration-plugin.c create mode 100644 include/hw/vfio/vfio-migration-plugin.h
Quoted 49 lines
-----Original Message-----
From: Qemu-devel <qemu-devel- [email protected]> On Behalf Of Alex Williamson
Sent: Thursday, May 26, 2022 11:44 AM
To: Rao, Lei <[email protected]>
Cc: Tian, Kevin <[email protected]>; Dong, Eddie <[email protected]>; Zeng, Jason <[email protected]>; [email protected]; [email protected]; Li, Yadong <[email protected]>; Liu, Yi L <[email protected]>; qemu- [email protected]
Subject: Re: [RFC PATCH 00/13] Add a plugin to support out-of-band live migration for VFIO pass-through deviceQuoted 11 lines · On Tue, 24 May 2022 14:18:35 +0800 Lei Rao <[email protected]> wrote:
Migration of a VFIO passthrough device can be supported by using a device specific kernel driver to save/restore the device state thru device specific interfaces. But this approach doesn't work for devices that lack a state migration interface, e.g. NVMe.
On the other hand, Infrastructure Process Unit (IPU) or Data Processing Unit
(DPU) vendors may choose to implement an out-of-band interface from the SoC to help manage the state of such non-migratable devices e.g. via gRPC or JSON-RPC protocols.Quoted 3 lines
This RFC attempts to support such out-of-band migration interface by introducing the concept of migration backends in vfio. The existing logic around vfio migration uAPI is now called the 'local' backend while a
new 'out-of-band'
Quoted 7 lines
backend is further introduced allowing vfio to redirect VMState ops to an external plugin.
Currently, the backend migration Ops is defined close to SaveVMHandlers. We also considered whether there is value of abstracting it in a lower level e.g. close to vfio migration uAPI but no clear conclusion. Hence this is one part which we'd like to hear
suggestions.
Quoted 6 lines
This proposal adopts a plugin mechanism (an example can be found in [1]) given that IPU/DPU vendors usually implement proprietary migration interfaces without a standard. But we are also open if an alternative option makes better sense, e.g. via loadable modules (with Qemu supporting gRPC or JSON-RPC support) or an IPC mechanism similar
to vhost-user.
Quoted 8 lines
AFAIU, QEMU is not interested in supporting plugin modules, especially proprietary ones. I don't see that a case has really been made that this cannot be done in-band, through a vfio-pci variant driver, possibly making use of proprietary interfaces to a userspace agent if necessary (though please don't ask such to be accepted in-tree for the kernel either). A vfio- user device server might also host such proprietary, device specific agents while supporting the standard, in-band migration interface. Thanks,
Thanks Alex. Removing plug-in module is not a problem.
Do you mean to implement the migration and protocol handling inside Qemu-client (probably vfio-client after the VFIO-user is merged)? Or to build as part of libvfio-user? We can also build it as a separate process of Qemu-server as part of Multi-Process Qemu.
In here, the protocol between host CPU and SoC is based on gRPC, which support Rust code in client (Host CPU side here) more than C/C++. Do you have any suggestion to better support Rust code with Qemu C/C++ code?
Thx Eddie
Quoted 107 lines
Alex
Quoted 51 lines
The following graph describes the overall component relationship:
+----------------------------------------------------+ | QEMU | | +------------------------------------------------+ | | | VFIO Live Migration Framework | | | | +--------------------------------------+ | | | | | VFIOMigrationOps | | | | | +-------^---------------------^--------+ | | | | | | | | | | +-------v-------+ +-------v--------+ | | | | | LM Backend Via| | LM Backend Via | | | | | | Device Fd | | Plugins | | | | | +-------^-------+ | +----------+ | | | | | | |Plugin Ops+----+-+------------+ | | | +-----+----------+ | | | | | | | | +---------v----------+ | +------------+-----------------------------------+ | | Vendor Specific | | | | | Plugins(.so) | +--------------+-------------------------------------+ +----------+---------+ UserSpace | | ----------------+--------------------------------------------- | Kernel | | | | +----------v----------------------+ | | Kernel VFIO Driver | | | +-------------------------+ | | | | | | | Network | | Vendor-Specific Driver | | | | | | | | | +----------^--------------+ | | | | | | +---------------+-----------------+ | | | | | ---------------------+----------------------------------------- | Hardware | | | +-----+-----+-----+----+-----+ | +----------v------+ | VF0 | VF1 | VF2 | ...| VFn | | | Traditional | +-----+-----+-----+----+-----+ | | PCIe Devices | | | | +-----------------+ | +--------+------------+ | | | | | Agent |<-+----+ | | +------------+ | | | | | | | SOC | | | +---------------------+ | | IPU | +----------------------------+Quoted 5 lines
Two command-line parameters (x-plugin-path and x-plugin-arg) are introduced to enable the out-of-band backend. If specified, vfio will attempt to use the out-of-band backend.
The following is an example of VFIO command-line parameters for OOB-
Approach:
Quoted 47 lines
-device
vfio-pci,id=$ID,host=$bdf,x-enable-migration,x-plugin-path=$plugin_pat h,x-plugin-arg=$plugin_arg[1] https://github.com/raolei-intel/vfio-lm-plugin-example.git
Lei Rao (13):
vfio/migration: put together checks of migration initialization
conditions
vfio/migration: move migration struct allocation out of
vfio_migration_init
vfio/migration: movevfio_get_dev_region_infoout of
vfio_migration_probe
vfio/migration: Separated functions that relate to the In-Band
approach
vfio/migration: rename functions that relate to the In-Band approach vfio/migration: introduce VFIOMigrationOps layer in VFIO live
migration framework
vfio/migration: move the statistics ofbytes_transferredto generic
VFIO migration layer
vfio/migration: split migration handler registering from
vfio_migration_init
vfio/migration: move the functions of In-Band approach to a new file vfio/pci: introduce command-line parameters to specify migration
method
vfio/migration: add a plugin layer to support out-of-band live
migration
vfio/migration: add some trace-events for vfio migration plugin vfio/migration: make the region and plugin member of struct
VFIOMigration to be a uniondocs/devel/vfio-migration-plugin.rst | 165 +++++++ hw/vfio/meson.build | 2 + hw/vfio/migration-local.c | 456 +++++++++++++++++++ hw/vfio/migration-plugin.c | 266 +++++++++++ hw/vfio/migration.c | 577 ++++++------------------ hw/vfio/pci.c | 2 + hw/vfio/trace-events | 9 +- include/hw/vfio/vfio-common.h | 37 +- include/hw/vfio/vfio-migration-plugin.h | 21 + 9 files changed, 1096 insertions(+), 439 deletions(-) create mode 100644 docs/devel/vfio-migration-plugin.rst create mode 100644 hw/vfio/migration-local.c create mode 100644
hw/vfio/migration-plugin.ccreate mode 100644include/hw/vfio/vfio-migration-plugin.h
Quoted 21 lines · Eddie
Quoted 12 lines
-----Original Message-----
From: Qemu-devel <qemu-devel- [email protected]> On Behalf Of Alex WilliamsonQuoted 5 lines · On Tue, 24 May 2022 14:18:35 +0800 Lei Rao <[email protected]> wrote:
This proposal adopts a plugin mechanism (an example can be found in [1]) given that IPU/DPU vendors usually implement proprietary migration interfaces without a standard. But we are also open if an alternative option makes better sense, e.g. via loadable modules (with Qemu supporting gRPC or JSON-RPC support) or an IPC mechanism similar
to vhost-user.
Quoted 8 lines
AFAIU, QEMU is not interested in supporting plugin modules, especially proprietary ones. I don't see that a case has really been made that this cannot be done in-band, through a vfio-pci variant driver, possibly making use of proprietary interfaces to a userspace agent if necessary (though please don't ask such to be accepted in-tree for the kernel either). A vfio- user device server might also host such proprietary, device specific agents while supporting the standard, in-band migration interface. Thanks,
Quoted 6 lines
Thanks Alex. Removing plug-in module is not a problem.
Do you mean to implement the migration and protocol handling inside Qemu-client (probably vfio-client after the VFIO-user is merged)? Or to build as part of libvfio-user? We can also build it as a separate process of Qemu-server as part of Multi-Process Qemu.
AIUI, the QEMU "client" in a vfio-user configuration is simply QEMU itself. The vfio-user "server" provides the actual device implementation, which could support different license models, depending on what libraries or existing code is incorporated to implement that server. The QEMU remote machine type is simply a QEMU-based implementation of a vfio-user server. The vfio-user server is analogous to a vfio-pci variant driver in the kernel/ioctl interface model. The vfio-user client should be device agnostic, possibly with similar exceptions we have today via device specific quirk handling for the vfio kernel interface.
Quoted 4 lines
In here, the protocol between host CPU and SoC is based on gRPC, which support Rust code in client (Host CPU side here) more than C/C++. Do you have any suggestion to better support Rust code with Qemu C/C++ code?
I'm not qualified to provide suggestions regarding Rust code integration with QEMU, but I think that's only required if the device specific migration support is on the "client". As above, I don't think that's the correct model, the vfio migration protocol is meant to support any device specific requirements on the device end of the connection, ie. the "server" end for vfio-user, which can be an entirely separate, non-QEMU based process. I think there are also ways to write kernel drivers in Rust, so possibly a kernel interface vfio-pci variant driver could also work. Thanks,
Alex
Hi, Alex,
Quoted 37 lines
From: Alex Williamson <[email protected]>
Sent: Thursday, June 2, 2022 2:01 AMQuoted 3 lines · Eddie
Quoted 3 lines
-----Original Message-----
From: Qemu-devel <qemu-devel- [email protected]> On Behalf Of AlexWilliamson
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines · On Tue, 24 May 2022 14:18:35 +0800 Lei Rao <[email protected]> wrote:
This proposal adopts a plugin mechanism (an example can be found in [1]) given that IPU/DPU vendors usually implement proprietary migration interfaces without a standard. But we are also open if an alternative option makes better sense, e.g. via loadable modules (with Qemu supporting gRPC or JSON-RPC support) or an IPC mechanism
similar
Quoted 5 lines
Quoted 5 lines
to vhost-user.
AFAIU, QEMU is not interested in supporting plugin modules, especially proprietary ones. I don't see that a case has really been made that this cannot be done in-band, through a vfio-pci variant driver, possibly
making
Quoted 6 lines
Quoted 5 lines
use of proprietary interfaces to a userspace agent if necessary (though please don't ask such to be accepted in-tree for the kernel either). A vfio- user device server might also host such proprietary, device specific agents while supporting the standard, in-band migration interface. Thanks,
Quoted 6 lines
Thanks Alex. Removing plug-in module is not a problem.
Do you mean to implement the migration and protocol handling inside Qemu-client (probably vfio-client after the VFIO-user is merged)? Or to build as part of libvfio-user? We can also build it as a separate process of Qemu-server as part of Multi-Process Qemu.
Quoted 11 lines
AIUI, the QEMU "client" in a vfio-user configuration is simply QEMU itself. The vfio-user "server" provides the actual device implementation, which could support different license models, depending on what libraries or existing code is incorporated to implement that server. The QEMU remote machine type is simply a QEMU-based implementation of a vfio-user server. The vfio-user server is analogous to a vfio-pci variant driver in the kernel/ioctl interface model. The vfio-user client should be device agnostic, possibly with similar exceptions we have today via device specific quirk handling for the vfio kernel interface.
Sounds like vfio-user is currently defined around virtual device oriented usages, e.g.:
- Client accesses virtual pci regions via VFIO_USER_REGION_READ/WRITE or mmap if the server passes a shmem fd for a given region in VFIO_USER_DEVICE_GET_REGION_INFO;
- Client maps DMA memory to server via VFIO_USER_DMA_MAP/UNMAP;
- Server access client memory via VFIO_USER_DMA_READ/WRITE or
mmap if client passes a fd for the DMA region when doing DMA_MAP;
- Server delivers virtual interrupt to client via IPC e.g. eventfd;
But in this usage it is still expected to allow Qemu directly access the physical device for performance. Turning to vfio-user suggests that it may need to support a model where from kernel p.o.v the physical device is assigned to vfio-user server but in the end vfio-user client actually operates the device (or, 'partially').
'partially' comes from that mmap must be done by Qemu otherwise we lose all the performance merit of passthrough while DMA map and interrupt delivery may be still routed via server (for DMA map this requires that the server can mmap the client's memory). Such indirect routes does bring some overhead but it's less obvious than losing mmap.
I'm not sure how it works w/o additional kernel-side cooperation though. Currently there is only one fd to represent the entire kernel vfio device then how could the server delegate pci regions to another process (client) for mmap?
If the server just passes the vfio device fd to the client then it's not vfio-user any more.
Did I misunderstand your idea?
Thanks
Kevin
Quoted 63 lines
-----Original Message-----
From: Alex Williamson <[email protected]>
Sent: Wednesday, June 1, 2022 11:01 AM
To: Dong, Eddie <[email protected]>
Cc: Rao, Lei <[email protected]>; Tian, Kevin <[email protected]>; Zeng, Jason <[email protected]>; [email protected]; [email protected]; Li, Yadong <[email protected]>; Liu, Yi L <[email protected]>; qemu- [email protected]
Subject: Re: [RFC PATCH 00/13] Add a plugin to support out-of-band live migration for VFIO pass-through deviceQuoted 25 lines · Eddie
Quoted 15 lines
-----Original Message-----
From: Qemu-devel <qemu-devel- [email protected]> On Behalf Of Alex bounces+WilliamsonQuoted 7 lines · On Tue, 24 May 2022 14:18:35 +0800 Lei Rao <[email protected]> wrote:
This proposal adopts a plugin mechanism (an example can be found in
[1]) given that IPU/DPU vendors usually implement proprietary migration interfaces without a standard. But we are also open if an alternative option makes better sense, e.g. via loadable modules (with Qemu supporting gRPC or JSON-RPC support) or an IPC mechanism similarto vhost-user.
Quoted 9 lines
AFAIU, QEMU is not interested in supporting plugin modules, especially proprietary ones. I don't see that a case has really been made that this cannot be done in-band, through a vfio-pci variant driver, possibly making use of proprietary interfaces to a userspace agent if necessary (though please don't ask such to be accepted in-tree for the kernel either). A vfio- user device server might also host such proprietary, device specific agents while supporting the standard, in-band migration interface. Thanks,
Quoted 6 lines
Thanks Alex. Removing plug-in module is not a problem.
Do you mean to implement the migration and protocol handling inside Qemu-client (probably vfio-client after the VFIO-user is merged)? Or to build as part of libvfio-user? We can also build it as a separate process of Qemu-server as part of Multi-Process Qemu.
AIUI, the QEMU "client" in a vfio-user configuration is simply QEMU itself. The vfio-user "server" provides the actual device implementation, which could support different license models, depending on what libraries or existing code is incorporated to implement that server. The QEMU remote machine type is simply a QEMU-based implementation of a vfio-user server. The vfio-user server is analogous to a vfio-pci variant driver in the kernel/ioctl interface model. The vfio-user client should be device agnostic, possibly with similar exceptions we have today via device specific quirk handling for the vfio kernel interface.
Quoted 4 lines
In here, the protocol between host CPU and SoC is based on gRPC, which support Rust code in client (Host CPU side here) more than C/C++. Do you have any suggestion to better support Rust code with Qemu C/C++ code?
Quoted 9 lines
I'm not qualified to provide suggestions regarding Rust code integration with QEMU, but I think that's only required if the device specific migration support is on the "client". As above, I don't think that's the correct model, the vfio migration protocol is meant to support any device specific requirements on the device end of the connection, ie. the "server" end for vfio-user, which can be an entirely separate, non-QEMU based process. I think there are also ways to write kernel drivers in Rust, so possibly a kernel interface vfio-pci variant driver could also work. Thanks,
Alex:
Thanks for your suggestion. Yes, agree Qemu (client) is, by nature, neutral to physical device knowledge.
With more thinking, it seems that:
1: Solution to have a separate kernel driver:
The way the host CPU talking with the SoC chip of the device is going thru TCP/IP network, plus high level protocol (gRPC or Json..). This is going to be very complicated and might be hard to be accepted by community.
2: Implement as a full qemu-server device model.
This way works if we implement a full device model in vfio-user, but given that the device (NVME for now) works in VFIO passthru mode for performance, the issue Kevin Tian raised in another email is a real concern too.
3: Implement partial (or supplemental) feature in Qemu-server device model.
This solution defines a Qemu/VFIO migration interface between the client and server for migration. Client migration-proxy uses hardware transparent interface to talk with the remote-migration server. The remote server may manage device-specific (protocol specific to be more precisely) components to talk with different hardware backend. In this case, we rely on today's VFIO module to manage the device and manipulate the device thru kernel driver. During migration, it will use the migration-proxy to get/set state etc... Users can configure the additional Qemu command line parameter to choose a remote migration-proxy for a VFIO device.
Can you suggest?
Thx Eddie