vfio queue
The following changes since commit 4d541f63e90c81112c298cbb35ed53e9c79deb00:
Merge tag 'for-upstream' of https://gitlab.com/bonzini/qemu into staging (2023-06-29 13:16:06 +0200)
are available in the Git repository at:
https://github.com/legoater/qemu/ tags/pull-vfio-20230630
for you to fetch changes up to 0cc889c8826cefa5b80110d31a62273b56aa1832:
vfio/pci: Free leaked timer in vfio_realize error path (2023-06-30 06:02:51 +0200)
----------------------------------------------------------------
vfio queue:
* migration: New switchover ack to reduce downtime
* VFIO migration pre-copy support
* Removal of the VFIO migration experimental flag
* Alternate offset for GPUDirect Cliques
* Misc fixes
----------------------------------------------------------------
Alex Williamson (3):
vfio: Implement a common device info helper hw/vfio/pci-quirks: Support alternate offset for GPUDirect Cliques
MAINTAINERS: Promote Cédric to VFIO co-maintainer
Avihai Horon (10):
migration: Add switchover ack capability
migration: Implement switchover ack logic
migration: Enable switchover ack capability
tests: Add migration switchover ack capability test vfio/migration: Refactor vfio_save_block() to return saved data size vfio/migration: Store VFIO migration flags in VFIOMigration vfio/migration: Add VFIO migration pre-copy support vfio/migration: Add support for switchover ack capability vfio/migration: Reset bytes_transferred properly vfio/migration: Make VFIO migration non-experimental
Shameer Kolothum (1):
vfio/pci: Call vfio_prepare_kvm_msi_virq_batch() in MSI retry path
Zhenzhong Duan (2):
vfio/pci: Fix a segfault in vfio_realize vfio/pci: Free leaked timer in vfio_realize error path
MAINTAINERS | 2 +- docs/devel/vfio-migration.rst | 45 +++++-- qapi/migration.json | 12 +- include/hw/vfio/vfio-common.h | 12 +- include/migration/register.h | 2 + migration/migration.h | 15 +++ migration/options.h | 1 + migration/savevm.h | 1 + hw/s390x/s390-pci-vfio.c | 37 +---- hw/vfio/common.c | 68 +++++++--- hw/vfio/migration.c | 305 ++++++++++++++++++++++++++++++++++++------ hw/vfio/pci-quirks.c | 41 +++++- hw/vfio/pci.c | 15 ++- migration/migration.c | 33 ++++- migration/options.c | 17 +++ migration/savevm.c | 55 ++++++++ migration/target.c | 17 ++- tests/qtest/migration-test.c | 31 +++++ hw/vfio/trace-events | 6 +- migration/trace-events | 3 + 20 files changed, 600 insertions(+), 118 deletions(-)
[PULL 16/16] vfio/pci: Free leaked timer in vfio_realize error path
From: Zhenzhong Duan <[email protected]>
When vfio_realize fails, the mmap_timer used for INTx optimization isn't freed. As this timer isn't activated yet, the potential impact is just a piece of leaked memory.
--- hw/vfio/pci.c | 3 +++ 1 file changed, 3 insertions(+)
hw/vfio/pci.c +3 -0
@@ -3224,6 +3224,9 @@ out_deregister:if (vdev->irqchip_change_notifier.notify) {kvm_irqchip_remove_change_notifier (&vdev->irqchip_change_notifier); } +if (vdev->intx.mmap_timer) { +timer_free (vdev->intx.mmap_timer); + } out_teardown:vfio_teardown_msi (vdev);vfio_bars_exit (vdev);
Signature · 1 line
2.41.0
[PULL 03/16] migration: Enable switchover ack capability
In reply to Cédric Le GoaterFrom: Avihai Horon <[email protected]>
Now that switchover ack logic has been implemented, enable the capability.
--- migration/options.c | 4 ---- 1 file changed, 4 deletions(-)
migration/options.c +0 -4
@@ -562,10 +562,6 @@ bool migrate_caps_check(bool *old_caps, bool *new_caps, Error **errp) "'return-path'");return false; } - -/* Disable this capability until it's implemented */ -error_setg (errp,"'switchover-ack' is not implemented yet" ); -return false; }return true;
Signature · 1 line
2.41.0
[PULL 06/16] vfio/migration: Store VFIO migration flags in VFIOMigration
In reply to Cédric Le GoaterFrom: Avihai Horon <[email protected]>
VFIO migration flags are queried once in vfio_migration_init(). Store them in VFIOMigration so they can be used later to check the device's migration capabilities without re-querying them.
This will be used in the next patch to check if the device supports precopy migration.
--- include/hw/vfio/vfio-common.h | 1 + hw/vfio/migration.c | 1 + 2 files changed, 2 insertions(+)
include/hw/vfio/vfio-common.h +1 -0
@@ -66,6 +66,7 @@ typedef struct VFIOMigration {int data_fd;void *data_buffer;size_t data_buffer_size; +uint64_t mig_flags; } VFIOMigration; typedef struct VFIOAddressSpace {
hw/vfio/migration.c +1 -0
@@ -603,6 +603,7 @@ static int vfio_migration_init(VFIODevice *vbasedev) migration->vbasedev = vbasedev; migration->device_state =VFIO_DEVICE_STATE_RUNNING ; migration->data_fd =-1 ; + migration->mig_flags = mig_flags; vbasedev->dirty_pages_supported =vfio_dma_logging_supported (vbasedev);
Signature · 1 line
2.41.0
[PULL 04/16] tests: Add migration switchover ack capability test
In reply to Cédric Le GoaterFrom: Avihai Horon <[email protected]>
Add migration switchover ack capability test. The test runs without devices that support this capability, but is still useful to make sure it didn't break anything.
--- tests/qtest/migration-test.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
tests/qtest/migration-test.c +31 -0
@@ -1693,6 +1693,33 @@ static void test_precopy_tcp_plain(void)test_precopy_common (&args); } +static void *test_migrate_switchover_ack_start (QTestState *from,QTestState *to) +{ + +migrate_set_capability (from,"return-path" , true); +migrate_set_capability (to,"return-path" , true); + +migrate_set_capability (from,"switchover-ack" , true); +migrate_set_capability (to,"switchover-ack" , true); + +return NULL ; +} + +static void test_precopy_tcp_switchover_ack (void ) +{ +MigrateCommon args = { + .listen_uri ="tcp:127.0.0.1:0" , + .start_hook = test_migrate_switchover_ack_start, +/* +* Source VM must be running in order to consider the switchover ACK +* when deciding to do switchover or not. +*/ + .live = true, + }; + +test_precopy_common (&args); +} +#ifdef CONFIG_GNUTLS static void test_precopy_tcp_tls_psk_match (void ) {
@@ -2737,6 +2764,10 @@ int main(int argc, char **argv)#endif /* CONFIG_GNUTLS */ qtest_add_func ("/migration/precopy/tcp/plain" , test_precopy_tcp_plain); + +qtest_add_func ("/migration/precopy/tcp/plain/switchover-ack" , + test_precopy_tcp_switchover_ack); +#ifdef CONFIG_GNUTLS qtest_add_func ("/migration/precopy/tcp/tls/psk/match" , test_precopy_tcp_tls_psk_match);
Signature · 1 line
2.41.0
[PULL 09/16] vfio: Implement a common device info helper
In reply to Cédric Le GoaterFrom: Alex Williamson <[email protected]>
A common helper implementing the realloc algorithm for handling capabilities.
--- include/hw/vfio/vfio-common.h | 1 + hw/s390x/s390-pci-vfio.c | 37 ++++------------------------ hw/vfio/common.c | 46 ++++++++++++++++++++++++++--------- 3 files changed, 41 insertions(+), 43 deletions(-)
include/hw/vfio/vfio-common.h +1 -0
@@ -216,6 +216,7 @@ void vfio_region_finalize(VFIORegion *region);void vfio_reset_handler (void *opaque);VFIOGroup *vfio_get_group (int groupid,AddressSpace *as,Error **errp);void vfio_put_group (VFIOGroup *group); +struct vfio_device_info *vfio_get_device_info (int fd);int vfio_get_device (VFIOGroup *group,const char *name,VFIODevice *vbasedev,Error **errp);
hw/s390x/s390-pci-vfio.c +5 -32
@@ -289,38 +289,11 @@ static void s390_pci_read_pfip(S390PCIBusDevice *pbdev,memcpy (pbdev->zpci_fn.pfip, cap->pfip,CLP_PFIP_NR_SEGMENTS ); } -static struct vfio_device_info *get_device_info (S390PCIBusDevice *pbdev, -uint32_t argsz) +static struct vfio_device_info *get_device_info (S390PCIBusDevice *pbdev) { -struct vfio_device_info *info =g_malloc0 (argsz); -VFIOPCIDevice *vfio_pci; -int fd; +VFIOPCIDevice *vfio_pci =container_of (pbdev->pdev, VFIOPCIDevice, pdev); - vfio_pci =container_of (pbdev->pdev, VFIOPCIDevice, pdev); - fd = vfio_pci->vbasedev.fd; - -/* -* If the specified argsz is not large enough to contain all capabilities -* it will be updated upon return from the ioctl. Retry until we have -* a big enough buffer to hold the entire capability chain. On error, -* just exit and rely on CLP defaults. -*/ -retry: - info->argsz = argsz; - -if (ioctl (fd,VFIO_DEVICE_GET_INFO , info)) { -trace_s390_pci_clp_dev_info (vfio_pci->vbasedev.name); -g_free (info); -return NULL ; - } - -if (info->argsz > argsz) { - argsz = info->argsz; - info =g_realloc (info, argsz); - goto retry; - } - -return info; +return vfio_get_device_info (vfio_pci->vbasedev.fd); }/*
@@ -335,7 +308,7 @@ bool s390_pci_get_host_fh(S390PCIBusDevice *pbdev, uint32_t *fh)assert (fh); - info =get_device_info (pbdev,sizeof (*info)); + info =get_device_info (pbdev);if (!info) {return false; }
@@ -356,7 +329,7 @@ void s390_pci_get_clp_info(S390PCIBusDevice *pbdev) { g_autofree struct vfio_device_info *info = NULL; - info =get_device_info (pbdev,sizeof (*info)); + info =get_device_info (pbdev);if (!info) {return ; }
hw/vfio/common.c +35 -11
71 lines not on this page · raw message
Signature · 1 line
2.41.0
[PULL 01/16] migration: Add switchover ack capability
In reply to Cédric Le GoaterFrom: Avihai Horon <[email protected]>
Migration downtime estimation is calculated based on bandwidth and remaining migration data. This assumes that loading of migration data in the destination takes a negligible amount of time and that downtime depends only on network speed.
While this may be true for RAM, it's not necessarily true for other migrated devices. For example, loading the data of a VFIO device in the destination might require from the device to allocate resources, prepare internal data structures and so on. These operations can take a significant amount of time which can increase migration downtime.
This patch adds a new capability "switchover ack" that prevents the source from stopping the VM and completing the migration until an ACK is received from the destination that it's OK to do so.
This can be used by migrated devices in various ways to reduce downtime. For example, a device can send initial precopy metadata to pre-allocate resources in the destination and use this capability to make sure that the pre-allocation is completed before the source VM is stopped, so it will have full effect.
This new capability relies on the return path capability to communicate from the destination back to the source.
The actual implementation of the capability will be added in the following patches.
--- qapi/migration.json | 12 +++++++++++- migration/options.h | 1 + migration/options.c | 21 +++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-)
qapi/migration.json +11 -1
@@ -487,6 +487,16 @@ # and should not affect the correctness of postcopy migration. # (since 7.1) # +# @switchover-ack: If enabled, migration will not stop the source VM +# and complete the migration until an ACK is received from the +# destination that it's OK to do so. Exactly when this ACK is +# sent depends on the migrated devices that use this feature. +# For example, a device can use it to make sure some of its data +# is sent and loaded in the destination before doing switchover. +# This can reduce downtime if devices that support this capability +# are present. 'return-path' capability must be enabled to use +# it. (since 8.1) +# # Features: # # @unstable: Members @x-colo and @x-ignore-shared are experimental.
@@ -502,7 +512,7 @@ 'dirty-bitmaps', 'postcopy-blocktime', 'late-block-activate', { 'name': 'x-ignore-shared', 'features': [ 'unstable' ] }, 'validate-uuid', 'background-snapshot', - 'zero-copy-send', 'postcopy-preempt'] } + 'zero-copy-send', 'postcopy-preempt', 'switchover-ack'] } ## # @MigrationCapabilityStatus:
migration/options.h +1 -0
@@ -40,6 +40,7 @@ bool migrate_postcopy_ram(void);bool migrate_rdma_pin_all (void );bool migrate_release_ram (void );bool migrate_return_path (void ); +bool migrate_switchover_ack (void );bool migrate_validate_uuid (void );bool migrate_xbzrle (void );bool migrate_zero_blocks (void );
migration/options.c +21 -0
@@ -185,6 +185,8 @@ Property migration_properties[] = {DEFINE_PROP_MIG_CAP ("x-zero-copy-send" ,MIGRATION_CAPABILITY_ZERO_COPY_SEND ), #endif +DEFINE_PROP_MIG_CAP ("x-switchover-ack" , +MIGRATION_CAPABILITY_SWITCHOVER_ACK ), DEFINE_PROP_END_OF_LIST(), };
@@ -308,6 +310,13 @@ bool migrate_return_path(void)return s->capabilities[MIGRATION_CAPABILITY_RETURN_PATH ]; } +bool migrate_switchover_ack (void ) +{ +MigrationState *s =migrate_get_current (); + +return s->capabilities[MIGRATION_CAPABILITY_SWITCHOVER_ACK ]; +} +bool migrate_validate_uuid (void ) {MigrationState *s =migrate_get_current ();
@@ -547,6 +556,18 @@ bool migrate_caps_check(bool *old_caps, bool *new_caps, Error **errp) } } +if (new_caps[MIGRATION_CAPABILITY_SWITCHOVER_ACK ]) { +if (!new_caps[MIGRATION_CAPABILITY_RETURN_PATH ]) { +error_setg (errp,"Capability 'switchover-ack' requires capability " +"'return-path'" ); +return false; + } + +/* Disable this capability until it's implemented */ +error_setg (errp,"'switchover-ack' is not implemented yet" ); +return false; + } +return true; }
Signature · 1 line
2.41.0
[PULL 05/16] vfio/migration: Refactor vfio_save_block() to return saved data size
In reply to Cédric Le GoaterFrom: Avihai Horon <[email protected]>
Refactor vfio_save_block() to return the size of saved data on success and -errno on error.
This will be used in next patch to implement VFIO migration pre-copy support.
--- hw/vfio/migration.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
hw/vfio/migration.c +9 -8
@@ -241,8 +241,8 @@ static int vfio_query_stop_copy_size(VFIODevice *vbasedev,return 0 ; } -/* Returns 1 if end-of-stream is reached, 0 if more data and -errno if error */ -static int vfio_save_block (QEMUFile *f,VFIOMigration *migration) +/* Returns the size of saved data on success and -errno on error */ +static ssize_t vfio_save_block (QEMUFile *f,VFIOMigration *migration) {ssize_t data_size;
@@ -252,7 +252,7 @@ static int vfio_save_block(QEMUFile *f, VFIOMigration *migration)return -errno; }if (data_size ==0 ) { -return 1 ; +return 0 ; }qemu_put_be64 (f,VFIO_MIG_FLAG_DEV_DATA_STATE );
@@ -262,7 +262,7 @@ static int vfio_save_block(QEMUFile *f, VFIOMigration *migration)trace_vfio_save_block (migration->vbasedev->name, data_size); -return qemu_file_get_error (f); +return qemu_file_get_error (f) ?: data_size; }/* ---------------------------------------------------------------------- */
@@ -335,6 +335,7 @@ static void vfio_state_pending_exact(void *opaque, uint64_t *must_precopy,static int vfio_save_complete_precopy (QEMUFile *f,void *opaque) {VFIODevice *vbasedev = opaque; +ssize_t data_size;int ret;/* We reach here with device state STOP only */
@@ -345,11 +346,11 @@ static int vfio_save_complete_precopy(QEMUFile *f, void *opaque) }do { - ret =vfio_save_block (f, vbasedev->migration); -if (ret <0 ) { -return ret; + data_size =vfio_save_block (f, vbasedev->migration); +if (data_size <0 ) { +return data_size; } - }while (!ret); + }while (data_size);qemu_put_be64 (f,VFIO_MIG_FLAG_END_OF_STATE ); ret =qemu_file_get_error (f);
Signature · 1 line
2.41.0
[PULL 02/16] migration: Implement switchover ack logic
In reply to Cédric Le GoaterFrom: Avihai Horon <[email protected]>
Implement switchover ack logic. This prevents the source from stopping the VM and completing the migration until an ACK is received from the destination that it's OK to do so.
To achieve this, a new SaveVMHandlers handler switchover_ack_needed() and a new return path message MIG_RP_MSG_SWITCHOVER_ACK are added.
The switchover_ack_needed() handler is called during migration setup in the destination to check if switchover ack is used by the migrated device.
When switchover is approved by all migrated devices in the destination that support this capability, the MIG_RP_MSG_SWITCHOVER_ACK return path message is sent to the source to notify it that it's OK to do switchover.
--- include/migration/register.h | 2 ++ migration/migration.h | 14 ++++++++++ migration/savevm.h | 1 + migration/migration.c | 32 +++++++++++++++++++-- migration/savevm.c | 54 ++++++++++++++++++++++++++++++++++++ migration/trace-events | 3 ++ 6 files changed, 104 insertions(+), 2 deletions(-)
include/migration/register.h +2 -0
@@ -71,6 +71,8 @@ typedef struct SaveVMHandlers {int (*load_cleanup)(void *opaque);/* Called when postcopy migration wants to resume from failure */ int (*resume_prepare)(MigrationState *s,void *opaque); +/* Checks if switchover ack should be used. Called only in dest */ +bool (*switchover_ack_needed)(void *opaque); } SaveVMHandlers; int register_savevm_live(const char *idstr,
migration/migration.h +14 -0
@@ -210,6 +210,13 @@ struct MigrationIncomingState {* contains valid information. */ QemuMutex page_request_mutex; + +/* +* Number of devices that have yet to approve switchover. When this reaches +* zero an ACK that it's OK to do switchover is sent to the source. No lock +* is needed as this field is updated serially. +*/ +unsigned int switchover_ack_pending_num; };MigrationIncomingState *migration_incoming_get_current (void );
@@ -440,6 +447,12 @@ struct MigrationState {/* QEMU_VM_VMDESCRIPTION content filled for all non-iterable devices. */ JSONWriter *vmdesc; + +/* +* Indicates whether an ACK from the destination that it's OK to do +* switchover has been received. +*/ +bool switchover_acked; };void migrate_set_state (int *state,int old_state,int new_state);
@@ -480,6 +493,7 @@ int migrate_send_rp_message_req_pages(MigrationIncomingState *mis,void migrate_send_rp_recv_bitmap (MigrationIncomingState *mis,char *block_name);void migrate_send_rp_resume_ack (MigrationIncomingState *mis,uint32_t value); +int migrate_send_rp_switchover_ack (MigrationIncomingState *mis);void dirty_bitmap_mig_before_vm_start (void );void dirty_bitmap_mig_cancel_outgoing (void );
migration/savevm.h +1 -0
@@ -65,6 +65,7 @@ int qemu_loadvm_state(QEMUFile *f);void qemu_loadvm_state_cleanup (void );int qemu_loadvm_state_main (QEMUFile *f,MigrationIncomingState *mis);int qemu_load_device_state (QEMUFile *f); +int qemu_loadvm_approve_switchover (void );int qemu_savevm_state_complete_precopy_non_iterable (QEMUFile *f,bool in_postcopy,bool inactivate_disks);
migration/migration.c +30 -2
@@ -78,6 +78,7 @@ enum mig_rp_message_type {MIG_RP_MSG_REQ_PAGES ,/* data (start: be64, len: be32) */ MIG_RP_MSG_RECV_BITMAP ,/* send recved_bitmap back to source */ MIG_RP_MSG_RESUME_ACK ,/* tell source that we are ready to resume */ +MIG_RP_MSG_SWITCHOVER_ACK ,/* Tell source it's OK to do switchover */ MIG_RP_MSG_MAX };
@@ -760,6 +761,11 @@ bool migration_has_all_channels(void)return true; } +int migrate_send_rp_switchover_ack (MigrationIncomingState *mis) +{ +return migrate_send_rp_message (mis,MIG_RP_MSG_SWITCHOVER_ACK ,0 ,NULL ); +} +/* * Send a 'SHUT' message on the return channel with the given value * to indicate that we've finished with the RP. Non-0 value indicates
@@ -1405,6 +1411,7 @@ void migrate_init(MigrationState *s) s->vm_old_state =-1 ; s->iteration_initial_bytes =0 ; s->threshold_size =0 ; + s->switchover_acked = false; }int migrate_add_blocker_internal (Error *reason,Error **errp)
@@ -1721,6 +1728,7 @@ static struct rp_cmd_args { [MIG_RP_MSG_REQ_PAGES_ID] = { .len = -1, .name = "REQ_PAGES_ID" }, [MIG_RP_MSG_RECV_BITMAP] = { .len = -1, .name = "RECV_BITMAP" }, [MIG_RP_MSG_RESUME_ACK] = { .len = 4, .name = "RESUME_ACK" }, + [MIG_RP_MSG_SWITCHOVER_ACK] = { .len = 0, .name = "SWITCHOVER_ACK" }, [MIG_RP_MSG_MAX] = { .len = -1, .name = "MAX" }, };
@@ -1959,6 +1967,11 @@ retry: }break ; +case MIG_RP_MSG_SWITCHOVER_ACK : + ms->switchover_acked = true; +trace_source_return_path_thread_switchover_acked (); +break ; +default :break ; }
@@ -2693,6 +2706,20 @@ static void migration_update_counters(MigrationState *s, bandwidth, s->threshold_size); } +static bool migration_can_switchover (MigrationState *s) +{ +if (!migrate_switchover_ack ()) { +return true; + } + +/* No reason to wait for switchover ACK if VM is stopped */ +if (!runstate_is_running ()) { +return true; + } + +return s->switchover_acked; +} +/* Migration thread iteration status */ typedef enum { MIG_ITERATE_RESUME, /* Resume current iteration */
@@ -2708,6 +2735,7 @@ static MigIterateState migration_iteration_run(MigrationState *s) {uint64_t must_precopy, can_postcopy;bool in_postcopy = s->state ==MIGRATION_STATUS_POSTCOPY_ACTIVE ; +bool can_switchover =migration_can_switchover (s);qemu_savevm_state_pending_estimate (&must_precopy, &can_postcopy);uint64_t pending_size = must_precopy + can_postcopy;
@@ -2720,14 +2748,14 @@ static MigIterateState migration_iteration_run(MigrationState *s)trace_migrate_pending_exact (pending_size, must_precopy, can_postcopy); } -if (!pending_size || pending_size < s->threshold_size) { +if ((!pending_size || pending_size < s->threshold_size) && can_switchover) {trace_migration_thread_low_pending (pending_size);migration_completion (s);return MIG_ITERATE_BREAK ; }/* Still a significant amount to transfer */ -if (!in_postcopy && must_precopy <= s->threshold_size && +if (!in_postcopy && must_precopy <= s->threshold_size && can_switchover &&qatomic_read (&s->start_postcopy)) {if (postcopy_start (s)) {error_report ("%s: postcopy failed to start" , __func__);
migration/savevm.c +54 -0
78 lines not on this page · raw message
migration/trace-events +3 -0
@@ -7,6 +7,7 @@ qemu_loadvm_state_section_partend(uint32_t section_id) "%u" qemu_loadvm_state_post_main(int ret) "%d" qemu_loadvm_state_section_startfull(uint32_t section_id, const char *idstr, uint32_t instance_id, uint32_t version_id) "%u(%s) %u %u" qemu_savevm_send_packaged(void) "" +loadvm_state_switchover_ack_needed(unsigned int switchover_ack_pending_num) "Switchover ack pending num=%u" loadvm_state_setup(void) "" loadvm_state_cleanup(void) "" loadvm_handle_cmd_packaged(unsigned int length) "%u"
@@ -23,6 +24,7 @@ loadvm_postcopy_ram_handle_discard_end(void) "" loadvm_postcopy_ram_handle_discard_header(const char *ramid, uint16_t len) "%s: %ud" loadvm_process_command(const char *s, uint16_t len) "com=%s len=%d" loadvm_process_command_ping(uint32_t val) "0x%x" +loadvm_approve_switchover(unsigned int switchover_ack_pending_num) "Switchover ack pending num=%u" postcopy_ram_listen_thread_exit(void) "" postcopy_ram_listen_thread_start(void) "" qemu_savevm_send_postcopy_advise(void) ""
@@ -180,6 +182,7 @@ source_return_path_thread_loop_top(void) "" source_return_path_thread_pong(uint32_t val) "0x%x" source_return_path_thread_shut(uint32_t val) "0x%x" source_return_path_thread_resume_ack(uint32_t v) "%"PRIu32 +source_return_path_thread_switchover_acked(void) "" migration_thread_low_pending(uint64_t pending) "%" PRIu64 migrate_transferred(uint64_t tranferred, uint64_t time_spent, uint64_t bandwidth, uint64_t size) "transferred %" PRIu64 " time_spent %" PRIu64 " bandwidth %" PRIu64 " max_size %" PRId64 process_incoming_migration_co_end(int ret, int ps) "ret=%d postcopy-state=%d"
Signature · 1 line
2.41.0
[PULL 10/16] hw/vfio/pci-quirks: Support alternate offset for GPUDirect Cliques
In reply to Cédric Le GoaterFrom: Alex Williamson <[email protected]>
NVIDIA Turing and newer GPUs implement the MSI-X capability at the offset previously reserved for use by hypervisors to implement the GPUDirect Cliques capability. A revised specification provides an alternate location. Add a config space walk to the quirk to check for conflicts, allowing us to fall back to the new location or generate an error at the quirk setup rather than when the real conflicting capability is added should there be no available location.
--- hw/vfio/pci-quirks.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-)
hw/vfio/pci-quirks.c +40 -1
@@ -1490,6 +1490,9 @@ void vfio_setup_resetfn_quirk(VFIOPCIDevice *vdev)* +---------------------------------+---------------------------------+ * * https://lists.gnu.org/archive/html/qemu-devel/2017-08/pdfUda5iEpgOS.pdf +* +* Specification for Turning and later GPU architectures: +* https://lists.gnu.org/archive/html/qemu-devel/2023-06/pdf142OR4O4c2.pdf */ static void get_nv_gpudirect_clique_id(Object *obj, Visitor *v, const char *name, void *opaque,
@@ -1530,7 +1533,9 @@ const PropertyInfo qdev_prop_nv_gpudirect_clique = {static int vfio_add_nv_gpudirect_cap (VFIOPCIDevice *vdev,Error **errp) {PCIDevice *pdev = &vdev->pdev; -int ret, pos =0xC8 ; +int ret, pos; +bool c8_conflict = false, d4_conflict = false; +uint8_t tmp;if (vdev->nv_gpudirect_clique ==0xFF ) {return 0 ;
@@ -1547,6 +1552,40 @@ static int vfio_add_nv_gpudirect_cap(VFIOPCIDevice *vdev, Error **errp)return -EINVAL ; } +/* +* Per the updated specification above, it's recommended to use offset +* D4h for Turing and later GPU architectures due to a conflict of the +* MSI-X capability at C8h. We don't know how to determine the GPU +* architecture, instead we walk the capability chain to mark conflicts +* and choose one or error based on the result. +* +* NB. Cap list head in pdev->config is already cleared, read from device. +*/ + ret =pread (vdev->vbasedev.fd, &tmp,1 , + vdev->config_offset +PCI_CAPABILITY_LIST ); +if (ret !=1 || !tmp) { +error_setg (errp,"NVIDIA GPUDirect Clique ID: error getting cap list" ); +return -EINVAL ; + } + +do { +if (tmp ==0xC8 ) { + c8_conflict = true; + }else if (tmp ==0xD4 ) { + d4_conflict = true; + } + tmp = pdev->config[tmp +PCI_CAP_LIST_NEXT ]; + }while (tmp); + +if (!c8_conflict) { + pos =0xC8 ; + }else if (!d4_conflict) { + pos =0xD4 ; + }else { +error_setg (errp,"NVIDIA GPUDirect Clique ID: invalid config space" ); +return -EINVAL ; + } + ret =pci_add_capability (pdev,PCI_CAP_ID_VNDR , pos,8 , errp);if (ret <0 ) {error_prepend (errp,"Failed to add NVIDIA GPUDirect cap: " );
Signature · 1 line
2.41.0
[PULL 11/16] vfio/pci: Call vfio_prepare_kvm_msi_virq_batch() in MSI retry path
In reply to Cédric Le GoaterFrom: Shameer Kolothum <[email protected]>
When vfio_enable_vectors() returns with less than requested nr_vectors we retry with what kernel reported back. But the retry path doesn't call vfio_prepare_kvm_msi_virq_batch() and this results in,
qemu-system-aarch64: vfio: Error: Failed to enable 4 MSI vectors, retry with 1
qemu-system-aarch64: ../hw/vfio/pci.c:602: vfio_commit_kvm_msi_virq_batch: Assertion `vdev->defer_kvm_irq_routing' failed
--- hw/vfio/pci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/vfio/pci.c +2 -2
@@ -663,6 +663,8 @@ static void vfio_msi_enable(VFIOPCIDevice *vdev)vfio_disable_interrupts (vdev); + vdev->nr_vectors =msi_nr_vectors_allocated (&vdev->pdev); +retry:/* * Setting vector notifiers needs to enable route for each vector. * Deferring to commit the KVM routes once rather than per vector
@@ -670,8 +672,6 @@ static void vfio_msi_enable(VFIOPCIDevice *vdev)*/ vfio_prepare_kvm_msi_virq_batch (vdev); - vdev->nr_vectors =msi_nr_vectors_allocated (&vdev->pdev); -retry: vdev->msi_vectors =g_new0 (VFIOMSIVector, vdev->nr_vectors);for (i =0 ; i < vdev->nr_vectors; i++) {
Signature · 1 line
2.41.0
Re: [PULL 11/16] vfio/pci: Call vfio_prepare_kvm_msi_virq_batch() in MSI retry path
Quoted 10 lines · Cédric Le Goater
From: Shameer Kolothum <[email protected]>
When
vfio_enable_vectors()returns with less than requestednr_vectorswe retry with what kernel reported back. But the retry path doesn't callvfio_prepare_kvm_msi_virq_batch()and this results in,qemu-system-aarch64: vfio: Error: Failed to enable 4 MSI vectors, retry with 1
qemu-system-aarch64:../hw/vfio/pci.c:602:vfio_commit_kvm_msi_virq_batch: Assertion `vdev->defer_kvm_irq_routing' failedFixes dc580d51f7dd ("vfio: defer to commit kvm irq routing when enable msi/msix")
Is it -stable material?
Thanks,
/mjt
[PULL 07/16] vfio/migration: Add VFIO migration pre-copy support
In reply to Cédric Le GoaterFrom: Avihai Horon <[email protected]>
Pre-copy support allows the VFIO device data to be transferred while the VM is running. This helps to accommodate VFIO devices that have a large amount of data that needs to be transferred, and it can reduce migration downtime.
Pre-copy support is optional in VFIO migration protocol v2. Implement pre-copy of VFIO migration protocol v2 and use it for devices that support it. Full description of it can be found in the following Linux commit: 4db52602a607 ("vfio: Extend the device migration protocol with PRE_COPY").
--- docs/devel/vfio-migration.rst | 35 +++++--- include/hw/vfio/vfio-common.h | 2 + hw/vfio/common.c | 6 +- hw/vfio/migration.c | 165 ++++++++++++++++++++++++++++++++-- hw/vfio/trace-events | 4 +- 5 files changed, 190 insertions(+), 22 deletions(-)
docs/devel/vfio-migration.rst +25 -10
@@ -7,12 +7,14 @@ the guest is running on source host and restoring this saved state on the destination host. This document details how saving and restoring of VFIO devices is done in QEMU. -Migration of VFIO devices currently consists of a single stop-and-copy phase. -During the stop-and-copy phase the guest is stopped and the entire VFIO device -data is transferred to the destination. - -The pre-copy phase of migration is currently not supported for VFIO devices. -Support for VFIO pre-copy will be added later on. +Migration of VFIO devices consists of two phases: the optional pre-copy phase, +and the stop-and-copy phase. The pre-copy phase is iterative and allows to +accommodate VFIO devices that have a large amount of data that needs to be +transferred. The iterative pre-copy phase of migration allows for the guest to +continue whilst the VFIO device state is transferred to the destination, this +helps to reduce the total downtime of the VM. VFIO devices opt-in to pre-copy +support by reporting the VFIO_MIGRATION_PRE_COPY flag in the +VFIO_DEVICE_FEATURE_MIGRATION ioctl. Note that currently VFIO migration is supported only for a single device. This is due to VFIO migration's lack of P2P support. However, P2P support is planned
@@ -29,10 +31,20 @@ VFIO implements the device hooks for the iterative approach as follows: * A ``load_setup`` function that sets the VFIO device on the destination in _RESUMING state. +* A ``state_pending_estimate`` function that reports an estimate of the + remaining pre-copy data that the vendor driver has yet to save for the VFIO + device. + * A ``state_pending_exact`` function that reads pending_bytes from the vendor driver, which indicates the amount of data that the vendor driver has yet to save for the VFIO device. +* An ``is_active_iterate`` function that indicates ``save_live_iterate`` is + active only when the VFIO device is in pre-copy states. + +* A ``save_live_iterate`` function that reads the VFIO device's data from the + vendor driver during iterative pre-copy phase. + * A ``save_state`` function to save the device config space if it is present. * A ``save_live_complete_precopy`` function that sets the VFIO device in
@@ -111,8 +123,10 @@ Flow of state changes during Live migration =========================================== Below is the flow of state change during live migration. -The values in the brackets represent the VM state, the migration state, and +The values in the parentheses represent the VM state, the migration state, and the VFIO device state, respectively. +The text in the square brackets represents the flow if the VFIO device supports +pre-copy. Live migration save path ------------------------
@@ -124,11 +138,12 @@ Live migration save path | migrate_init spawns migration_thread Migration thread then calls each device's .save_setup() - (RUNNING, _SETUP, _RUNNING) + (RUNNING, _SETUP, _RUNNING [_PRE_COPY]) | - (RUNNING, _ACTIVE, _RUNNING) - If device is active, get pending_bytes by .state_pending_exact() + (RUNNING, _ACTIVE, _RUNNING [_PRE_COPY]) + If device is active, get pending_bytes by .state_pending_{estimate,exact}() If total pending_bytes >= threshold_size, call .save_live_iterate() + [Data of VFIO device for pre-copy phase is copied] Iterate till total pending bytes converge and are less than threshold | On migration completion, vCPU stops and calls .save_live_complete_precopy for
include/hw/vfio/vfio-common.h +2 -0
@@ -67,6 +67,8 @@ typedef struct VFIOMigration {void *data_buffer;size_t data_buffer_size;uint64_t mig_flags; +uint64_t precopy_init_size; +uint64_t precopy_dirty_size; } VFIOMigration; typedef struct VFIOAddressSpace {
hw/vfio/common.c +4 -2
@@ -492,7 +492,8 @@ static bool vfio_devices_all_dirty_tracking(VFIOContainer *container) }if (vbasedev->pre_copy_dirty_page_tracking ==ON_OFF_AUTO_OFF && - migration->device_state ==VFIO_DEVICE_STATE_RUNNING ) { + (migration->device_state ==VFIO_DEVICE_STATE_RUNNING || + migration->device_state ==VFIO_DEVICE_STATE_PRE_COPY )) {return false; } }
@@ -537,7 +538,8 @@ static bool vfio_devices_all_running_and_mig_active(VFIOContainer *container)return false; } -if (migration->device_state ==VFIO_DEVICE_STATE_RUNNING ) { +if (migration->device_state ==VFIO_DEVICE_STATE_RUNNING || + migration->device_state ==VFIO_DEVICE_STATE_PRE_COPY ) {continue ; }else {return false;
hw/vfio/migration.c +156 -9
247 lines not on this page · raw message
hw/vfio/trace-events +3 -1
@@ -162,6 +162,8 @@ vfio_save_block(const char *name, int data_size) " (%s) data_size %d" vfio_save_cleanup(const char *name) " (%s)" vfio_save_complete_precopy(const char *name, int ret) " (%s) ret %d" vfio_save_device_config_state(const char *name) " (%s)" +vfio_save_iterate(const char *name, uint64_t precopy_init_size, uint64_t precopy_dirty_size) " (%s) precopy initial size 0x%"PRIx64" precopy dirty size 0x%"PRIx64 vfio_save_setup(const char *name, uint64_t data_buffer_size) " (%s) data buffer size 0x%"PRIx64 -vfio_state_pending_exact(const char *name, uint64_t precopy, uint64_t postcopy, uint64_t stopcopy_size) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64" stopcopy size 0x%"PRIx64 +vfio_state_pending_estimate(const char *name, uint64_t precopy, uint64_t postcopy, uint64_t precopy_init_size, uint64_t precopy_dirty_size) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64" precopy initial size 0x%"PRIx64" precopy dirty size 0x%"PRIx64 +vfio_state_pending_exact(const char *name, uint64_t precopy, uint64_t postcopy, uint64_t stopcopy_size, uint64_t precopy_init_size, uint64_t precopy_dirty_size) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64" stopcopy size 0x%"PRIx64" precopy initial size 0x%"PRIx64" precopy dirty size 0x%"PRIx64 vfio_vmstate_change(const char *name, int running, const char *reason, const char *dev_state) " (%s) running %d reason %s device state %s"
Signature · 1 line
2.41.0
[PULL 14/16] MAINTAINERS: Promote Cédric to VFIO co-maintainer
In reply to Cédric Le GoaterFrom: Alex Williamson <[email protected]>
Cédric has stepped up involvement in vfio, reviewing and managing patches, as well as pull requests. This work deserves gratitude and punishment with a promotion to co-maintainer ;)
--- MAINTAINERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
MAINTAINERS +1 -1
@@ -2051,7 +2051,7 @@ F: hw/usb/dev-serial.c VFIO M: Alex Williamson <[email protected]> -R: Cédric Le Goater <[email protected]> +M: Cédric Le Goater <[email protected]> S: Supported F: hw/vfio/* F: include/hw/vfio/
Signature · 1 line
2.41.0
[PULL 08/16] vfio/migration: Add support for switchover ack capability
In reply to Cédric Le GoaterFrom: Avihai Horon <[email protected]>
Loading of a VFIO device's data can take a substantial amount of time as the device may need to allocate resources, prepare internal data structures, etc. This can increase migration downtime, especially for VFIO devices with a lot of resources.
To solve this, VFIO migration uAPI defines "initial bytes" as part of its precopy data stream. Initial bytes can be used in various ways to improve VFIO migration performance. For example, it can be used to transfer device metadata to pre-allocate resources in the destination. However, for this to work we need to make sure that all initial bytes are sent and loaded in the destination before the source VM is stopped.
Use migration switchover ack capability to make sure a VFIO device's initial bytes are sent and loaded in the destination before the source stops the VM and attempts to complete the migration.
This can significantly reduce migration downtime for some devices.
--- docs/devel/vfio-migration.rst | 10 +++++++++ include/hw/vfio/vfio-common.h | 1 + hw/vfio/migration.c | 39 ++++++++++++++++++++++++++++++++++- 3 files changed, 49 insertions(+), 1 deletion(-)
docs/devel/vfio-migration.rst +10 -0
@@ -16,6 +16,13 @@ helps to reduce the total downtime of the VM. VFIO devices opt-in to pre-copy support by reporting the VFIO_MIGRATION_PRE_COPY flag in the VFIO_DEVICE_FEATURE_MIGRATION ioctl. +When pre-copy is supported, it's possible to further reduce downtime by +enabling "switchover-ack" migration capability. +VFIO migration uAPI defines "initial bytes" as part of its pre-copy data stream +and recommends that the initial bytes are sent and loaded in the destination +before stopping the source VM. Enabling this migration capability will +guarantee that and thus, can potentially reduce downtime even further. + Note that currently VFIO migration is supported only for a single device. This is due to VFIO migration's lack of P2P support. However, P2P support is planned to be added later on.
@@ -45,6 +52,9 @@ VFIO implements the device hooks for the iterative approach as follows: * A ``save_live_iterate`` function that reads the VFIO device's data from the vendor driver during iterative pre-copy phase. +* A ``switchover_ack_needed`` function that checks if the VFIO device uses + "switchover-ack" migration capability when this capability is enabled. + * A ``save_state`` function to save the device config space if it is present. * A ``save_live_complete_precopy`` function that sets the VFIO device in
include/hw/vfio/vfio-common.h +1 -0
@@ -69,6 +69,7 @@ typedef struct VFIOMigration {uint64_t mig_flags;uint64_t precopy_init_size;uint64_t precopy_dirty_size; +bool initial_data_sent; } VFIOMigration; typedef struct VFIOAddressSpace {
hw/vfio/migration.c +38 -1
@@ -18,6 +18,8 @@#include "sysemu/runstate.h" #include "hw/vfio/vfio-common.h" #include "migration/migration.h" +#include "migration/options.h" +#include "migration/savevm.h" #include "migration/vmstate.h" #include "migration/qemu-file.h" #include "migration/register.h"
@@ -45,6 +47,7 @@#define VFIO_MIG_FLAG_DEV_CONFIG_STATE (0xffffffffef100002ULL)#define VFIO_MIG_FLAG_DEV_SETUP_STATE (0xffffffffef100003ULL)#define VFIO_MIG_FLAG_DEV_DATA_STATE (0xffffffffef100004ULL) +#define VFIO_MIG_FLAG_DEV_INIT_DATA_SENT (0xffffffffef100005ULL)/* * This is an arbitrary size based on migration of mlx5 devices, where typically
@@ -384,6 +387,7 @@ static void vfio_save_cleanup(void *opaque) migration->data_buffer =NULL ; migration->precopy_init_size =0 ; migration->precopy_dirty_size =0 ; + migration->initial_data_sent = false;vfio_migration_cleanup (vbasedev);trace_vfio_save_cleanup (vbasedev->name); }
@@ -457,10 +461,17 @@ static int vfio_save_iterate(QEMUFile *f, void *opaque)if (data_size <0 ) {return data_size; } -qemu_put_be64 (f,VFIO_MIG_FLAG_END_OF_STATE );vfio_update_estimated_pending_data (migration, data_size); +if (migrate_switchover_ack () && !migration->precopy_init_size && + !migration->initial_data_sent) { +qemu_put_be64 (f,VFIO_MIG_FLAG_DEV_INIT_DATA_SENT ); + migration->initial_data_sent = true; + }else { +qemu_put_be64 (f,VFIO_MIG_FLAG_END_OF_STATE ); + } +trace_vfio_save_iterate (vbasedev->name, migration->precopy_init_size, migration->precopy_dirty_size);
@@ -579,6 +590,24 @@ static int vfio_load_state(QEMUFile *f, void *opaque, int version_id) }break ; } +case VFIO_MIG_FLAG_DEV_INIT_DATA_SENT : + { +if (!vfio_precopy_supported (vbasedev) || + !migrate_switchover_ack ()) { +error_report ("%s: Received INIT_DATA_SENT but switchover ack " +"is not used" , vbasedev->name); +return -EINVAL ; + } + + ret =qemu_loadvm_approve_switchover (); +if (ret) { +error_report ( +"%s: qemu_loadvm_approve_switchover failed, err=%d (%s)" , + vbasedev->name, ret,strerror (-ret)); + } + +return ret; + }default :error_report ("%s: Unknown tag 0x%" PRIx64, vbasedev->name, data);return -EINVAL ;
@@ -593,6 +622,13 @@ static int vfio_load_state(QEMUFile *f, void *opaque, int version_id)return ret; } +static bool vfio_switchover_ack_needed (void *opaque) +{ +VFIODevice *vbasedev = opaque; + +return vfio_precopy_supported (vbasedev); +} +static const SaveVMHandlers savevm_vfio_handlers = { .save_setup = vfio_save_setup, .save_cleanup = vfio_save_cleanup,
@@ -605,6 +641,7 @@ static const SaveVMHandlers savevm_vfio_handlers = { .load_setup = vfio_load_setup, .load_cleanup = vfio_load_cleanup, .load_state = vfio_load_state, + .switchover_ack_needed = vfio_switchover_ack_needed, };/* ---------------------------------------------------------------------- */
Signature · 1 line
2.41.0
[PULL 15/16] vfio/pci: Fix a segfault in vfio_realize
In reply to Cédric Le GoaterFrom: Zhenzhong Duan <[email protected]>
The kvm irqchip notifier is only registered if the device supports INTx, however it's unconditionally removed in vfio realize error path. If the assigned device does not support INTx, this will cause QEMU to crash when vfio realize fails. Change it to conditionally remove the notifier only if the notify hook is setup.
Before fix:
(qemu) device_add vfio-pci,host=81:11.1,id=vfio1,bus=root1,xres=1 Connection closed by foreign host.
After fix:
(qemu) device_add vfio-pci,host=81:11.1,id=vfio1,bus=root1,xres=1
Error: vfio 0000:81:11.1: xres and yres properties require display=on (qemu)
--- hw/vfio/pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
hw/vfio/pci.c +3 -1
@@ -3221,7 +3221,9 @@ static void vfio_realize(PCIDevice *pdev, Error **errp) out_deregister:pci_device_set_intx_routing_notifier (&vdev->pdev,NULL ); -kvm_irqchip_remove_change_notifier (&vdev->irqchip_change_notifier); +if (vdev->irqchip_change_notifier.notify) { +kvm_irqchip_remove_change_notifier (&vdev->irqchip_change_notifier); + } out_teardown:vfio_teardown_msi (vdev);vfio_bars_exit (vdev);
Signature · 1 line
2.41.0
[PULL 12/16] vfio/migration: Reset bytes_transferred properly
In reply to Cédric Le GoaterFrom: Avihai Horon <[email protected]>
Currently, VFIO bytes_transferred is not reset properly:
1. bytes_transferred is not reset after a VM snapshot (so a migration following a snapshot will report incorrect value).
2. bytes_transferred is a single counter for all VFIO devices, however upon migration failure it is reset multiple times, by each VFIO device.
Fix it by introducing a new function vfio_reset_bytes_transferred() and calling it during migration and snapshot start.
Remove existing bytes_transferred reset in VFIO migration state notifier, which is not needed anymore.
--- include/hw/vfio/vfio-common.h | 1 + migration/migration.h | 1 + hw/vfio/migration.c | 6 +++++- migration/migration.c | 1 + migration/savevm.c | 1 + migration/target.c | 17 +++++++++++++++-- 6 files changed, 24 insertions(+), 3 deletions(-)
include/hw/vfio/vfio-common.h +1 -0
@@ -229,6 +229,7 @@ int vfio_block_multiple_devices_migration(Error **errp);void vfio_unblock_multiple_devices_migration (void );int vfio_block_giommu_migration (Error **errp);int64_t vfio_mig_bytes_transferred (void ); +void vfio_reset_bytes_transferred (void );#ifdef CONFIG_LINUX int vfio_get_region_info(VFIODevice *vbasedev, int index,
migration/migration.h +1 -0
@@ -514,6 +514,7 @@ bool migration_rate_limit(void);void migration_cancel (const Error *error);void populate_vfio_info (MigrationInfo *info); +void reset_vfio_bytes_transferred (void );void postcopy_temp_page_reset (PostcopyTmpPage *tmp_page);#endif
hw/vfio/migration.c +5 -1
@@ -697,7 +697,6 @@ static void vfio_migration_state_notifier(Notifier *notifier, void *data)case MIGRATION_STATUS_CANCELLING :case MIGRATION_STATUS_CANCELLED :case MIGRATION_STATUS_FAILED : - bytes_transferred =0 ;/* * If setting the device in RUNNING state fails, the device should * be reset. To do so, use ERROR state as a recover state.
@@ -818,6 +817,11 @@ int64_t vfio_mig_bytes_transferred(void)return bytes_transferred; } +void vfio_reset_bytes_transferred (void ) +{ + bytes_transferred =0 ; +} +int vfio_migration_realize (VFIODevice *vbasedev,Error **errp) {int ret = -ENOTSUP ;
migration/migration.c +1 -0
@@ -1628,6 +1628,7 @@ static bool migrate_prepare(MigrationState *s, bool blk, bool blk_inc,*/ memset (&mig_stats,0 ,sizeof (mig_stats));memset (&compression_counters,0 ,sizeof (compression_counters)); +reset_vfio_bytes_transferred ();return true; }
migration/savevm.c +1 -0
@@ -1622,6 +1622,7 @@ static int qemu_savevm_state(QEMUFile *f, Error **errp)migrate_init (ms);memset (&mig_stats,0 ,sizeof (mig_stats));memset (&compression_counters,0 ,sizeof (compression_counters)); +reset_vfio_bytes_transferred (); ms->to_dst_file = f;qemu_mutex_unlock_iothread ();
migration/target.c +15 -2
@@ -14,12 +14,25 @@#include "hw/vfio/vfio-common.h" #endif +#ifdef CONFIG_VFIO void populate_vfio_info (MigrationInfo *info) { -#ifdef CONFIG_VFIO if (vfio_mig_active ()) { info->vfio =g_malloc0 (sizeof (*info->vfio)); info->vfio->transferred =vfio_mig_bytes_transferred (); } -#endif } + +void reset_vfio_bytes_transferred (void ) +{ +vfio_reset_bytes_transferred (); +} +#else +void populate_vfio_info (MigrationInfo *info) +{ +} + +void reset_vfio_bytes_transferred (void ) +{ +} +#endif
Signature · 1 line
2.41.0
[PULL 13/16] vfio/migration: Make VFIO migration non-experimental
In reply to Cédric Le GoaterFrom: Avihai Horon <[email protected]>
The major parts of VFIO migration are supported today in QEMU. This includes basic VFIO migration, device dirty page tracking and precopy support.
Thus, at this point in time, it seems appropriate to make VFIO migration
non-experimental: remove the x prefix from enable_migration property, change it to ON_OFF_AUTO and let the default value be AUTO.
In addition, make the following adjustments:
1. When enable_migration is ON and migration is not supported, fail VFIO device realization.
2. When enable_migration is AUTO (i.e., not explicitly enabled), require device dirty tracking support. This is because device dirty tracking is currently the only method to do dirty page tracking, which is essential for migrating in a reasonable downtime. Setting enable_migration to ON will not require device dirty tracking.
3. Make migration error and blocker messages more elaborate.
4. Remove error prints in vfio_migration_query_flags().
5. Rename trace_vfio_migration_probe() to trace_vfio_migration_realize().
--- include/hw/vfio/vfio-common.h | 6 +-- hw/vfio/common.c | 16 ++++++- hw/vfio/migration.c | 79 +++++++++++++++++++++++------------ hw/vfio/pci.c | 4 +- hw/vfio/trace-events | 2 +- 5 files changed, 73 insertions(+), 34 deletions(-)
include/hw/vfio/vfio-common.h +3 -3
@@ -139,7 +139,7 @@ typedef struct VFIODevice {bool needs_reset;bool no_mmap;bool ram_block_discard_allowed; -bool enable_migration; +OnOffAuto enable_migration;VFIODeviceOps *ops;unsigned int num_irqs;unsigned int num_regions;
@@ -225,9 +225,9 @@ typedef QLIST_HEAD(VFIOGroupList, VFIOGroup) VFIOGroupList;extern VFIOGroupList vfio_group_list;bool vfio_mig_active (void ); -int vfio_block_multiple_devices_migration (Error **errp); +int vfio_block_multiple_devices_migration (VFIODevice *vbasedev,Error **errp);void vfio_unblock_multiple_devices_migration (void ); -int vfio_block_giommu_migration (Error **errp); +int vfio_block_giommu_migration (VFIODevice *vbasedev,Error **errp);int64_t vfio_mig_bytes_transferred (void );void vfio_reset_bytes_transferred (void );
hw/vfio/common.c +14 -2
@@ -381,7 +381,7 @@ static unsigned int vfio_migratable_device_num(void)return device_num; } -int vfio_block_multiple_devices_migration (Error **errp) +int vfio_block_multiple_devices_migration (VFIODevice *vbasedev,Error **errp) {int ret;
@@ -390,6 +390,12 @@ int vfio_block_multiple_devices_migration(Error **errp)return 0 ; } +if (vbasedev->enable_migration ==ON_OFF_AUTO_ON ) { +error_setg (errp,"Migration is currently not supported with multiple " +"VFIO devices" ); +return -EINVAL ; + } +error_setg (&multiple_devices_migration_blocker,"Migration is currently not supported with multiple " "VFIO devices" );
@@ -427,7 +433,7 @@ static bool vfio_viommu_preset(void)return false; } -int vfio_block_giommu_migration (Error **errp) +int vfio_block_giommu_migration (VFIODevice *vbasedev,Error **errp) {int ret;
@@ -436,6 +442,12 @@ int vfio_block_giommu_migration(Error **errp)return 0 ; } +if (vbasedev->enable_migration ==ON_OFF_AUTO_ON ) { +error_setg (errp, +"Migration is currently not supported with vIOMMU enabled" ); +return -EINVAL ; + } +error_setg (&giommu_migration_blocker,"Migration is currently not supported with vIOMMU enabled" ); ret =migrate_add_blocker (giommu_migration_blocker, errp);
hw/vfio/migration.c +53 -26
113 lines not on this page · raw message
hw/vfio/pci.c +2 -2
@@ -3347,8 +3347,8 @@ static Property vfio_pci_dev_properties[] = { VFIO_FEATURE_ENABLE_REQ_BIT, true),DEFINE_PROP_BIT ("x-igd-opregion" , VFIOPCIDevice, features,VFIO_FEATURE_ENABLE_IGD_OPREGION_BIT , false), -DEFINE_PROP_BOOL ("x-enable-migration" , VFIOPCIDevice, - vbasedev.enable_migration, false), +DEFINE_PROP_ON_OFF_AUTO ("enable-migration" , VFIOPCIDevice, + vbasedev.enable_migration,ON_OFF_AUTO_AUTO ),DEFINE_PROP_BOOL ("x-no-mmap" , VFIOPCIDevice, vbasedev.no_mmap, false),DEFINE_PROP_BOOL ("x-balloon-allowed" , VFIOPCIDevice, vbasedev.ram_block_discard_allowed, false),
hw/vfio/trace-events +1 -1
@@ -155,7 +155,7 @@ vfio_load_cleanup(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_size, int ret) " (%s) size 0x%"PRIx64" ret %d" -vfio_migration_probe(const char *name) " (%s)" +vfio_migration_realize(const char *name) " (%s)" vfio_migration_set_state(const char *name, const char *state) " (%s) state %s" vfio_migration_state_notifier(const char *name, const char *state) " (%s) state %s" vfio_save_block(const char *name, int data_size) " (%s) data_size %d"
Signature · 1 line
2.41.0
Richard Henderson
AppliedQuoted 12 lines · Cédric Le Goater
The following changes since commit
4d541f63e90c81112c298cbb35ed53e9c79deb00:Merge tag 'for-upstream' ofhttps://gitlab.com/bonzini/qemu into staging (2023-06-29 13:16:06 +0200)are available in the Git repository at:
https://github.com/legoater/qemu/ tags/pull-vfio-20230630for you to fetch changes up to
0cc889c8826cefa5b80110d31a62273b56aa1832:vfio/pci: Free leaked timer in vfio_realize error path (2023-06-30 06:02:51 +0200)
Quoted 8 lines
----------------------------------------------------------------
vfio queue:* migration: New switchover ack to reduce downtime
* VFIO migration pre-copy support
* Removal of the VFIO migration experimental flag
* Alternate offset for GPUDirect Cliques
* Misc fixes
Applied, thanks. Please update https://wiki.qemu.org/ChangeLog/8.1 as appropriate.
r~