Lines Matching full:migration
2 * Migration support for VFIO devices
20 #include "migration/misc.h"
21 #include "migration/savevm.h"
22 #include "migration/vmstate.h"
23 #include "migration/qemu-file.h"
24 #include "migration/register.h"
25 #include "migration/blocker.h"
35 * Flags to be used as unique delimiters for VFIO devices in the migration
52 * This is an arbitrary size based on migration of mlx5 devices, where typically
53 * total device migration size is on the order of 100s of MB. Testing with
109 VFIOMigration *migration = vbasedev->migration; in vfio_migration_send_event() local
124 dev->id, qom_path, mig_state_to_qapi_state(migration->device_state)); in vfio_migration_send_event()
130 VFIOMigration *migration = vbasedev->migration; in vfio_migration_set_device_state() local
135 migration->device_state = state; in vfio_migration_set_device_state()
144 VFIOMigration *migration = vbasedev->migration; in vfio_migration_set_state() local
159 if (new_state == migration->device_state) { in vfio_migration_set_state()
204 if (migration->data_fd != -1) { in vfio_migration_set_state()
215 migration->data_fd = mig_state->data_fd; in vfio_migration_set_state()
248 VFIOMigration *migration = vbasedev->migration; in vfio_load_buffer() local
251 ret = qemu_file_get_to_fd(f, migration->data_fd, data_size); in vfio_load_buffer()
312 VFIOMigration *migration = vbasedev->migration; in vfio_migration_cleanup() local
314 close(migration->data_fd); in vfio_migration_cleanup()
315 migration->data_fd = -1; in vfio_migration_cleanup()
341 static int vfio_query_precopy_size(VFIOMigration *migration) in vfio_query_precopy_size() argument
347 migration->precopy_init_size = 0; in vfio_query_precopy_size()
348 migration->precopy_dirty_size = 0; in vfio_query_precopy_size()
350 if (ioctl(migration->data_fd, VFIO_MIG_GET_PRECOPY_INFO, &precopy)) { in vfio_query_precopy_size()
354 migration->precopy_init_size = precopy.initial_bytes; in vfio_query_precopy_size()
355 migration->precopy_dirty_size = precopy.dirty_bytes; in vfio_query_precopy_size()
361 static ssize_t vfio_save_block(QEMUFile *f, VFIOMigration *migration) in vfio_save_block() argument
365 data_size = read(migration->data_fd, migration->data_buffer, in vfio_save_block()
366 migration->data_buffer_size); in vfio_save_block()
373 if (!migration->event_precopy_empty_hit) { in vfio_save_block()
374 trace_vfio_save_block_precopy_empty_hit(migration->vbasedev->name); in vfio_save_block()
375 migration->event_precopy_empty_hit = true; in vfio_save_block()
387 migration->event_precopy_empty_hit = false; in vfio_save_block()
391 qemu_put_buffer(f, migration->data_buffer, data_size); in vfio_save_block()
394 trace_vfio_save_block(migration->vbasedev->name, data_size); in vfio_save_block()
399 static void vfio_update_estimated_pending_data(VFIOMigration *migration, in vfio_update_estimated_pending_data() argument
407 migration->precopy_init_size = 0; in vfio_update_estimated_pending_data()
408 migration->precopy_dirty_size = 0; in vfio_update_estimated_pending_data()
413 if (migration->precopy_init_size) { in vfio_update_estimated_pending_data()
414 uint64_t init_size = MIN(migration->precopy_init_size, data_size); in vfio_update_estimated_pending_data()
416 migration->precopy_init_size -= init_size; in vfio_update_estimated_pending_data()
420 migration->precopy_dirty_size -= MIN(migration->precopy_dirty_size, in vfio_update_estimated_pending_data()
426 VFIOMigration *migration = vbasedev->migration; in vfio_precopy_supported() local
428 return migration->mig_flags & VFIO_MIGRATION_PRE_COPY; in vfio_precopy_supported()
447 errp, "%s: VFIO migration is not supported with postcopy migration", in vfio_save_prepare()
455 "%s: VFIO migration is not supported with background snapshot", in vfio_save_prepare()
466 VFIOMigration *migration = vbasedev->migration; in vfio_save_setup() local
473 migration->data_buffer_size = MIN(VFIO_MIG_DEFAULT_DATA_BUFFER_SIZE, in vfio_save_setup()
475 migration->data_buffer = g_try_malloc0(migration->data_buffer_size); in vfio_save_setup()
476 if (!migration->data_buffer) { in vfio_save_setup()
477 error_setg(errp, "%s: Failed to allocate migration data buffer", in vfio_save_setup()
482 migration->event_save_iterate_started = false; in vfio_save_setup()
483 migration->event_precopy_empty_hit = false; in vfio_save_setup()
486 switch (migration->device_state) { in vfio_save_setup()
494 vfio_query_precopy_size(migration); in vfio_save_setup()
502 migration->device_state); in vfio_save_setup()
507 trace_vfio_save_setup(vbasedev->name, migration->data_buffer_size); in vfio_save_setup()
522 VFIOMigration *migration = vbasedev->migration; in vfio_save_cleanup() local
528 * after migration has completed, so it won't increase downtime. in vfio_save_cleanup()
530 if (migration->device_state == VFIO_DEVICE_STATE_STOP_COPY) { in vfio_save_cleanup()
539 g_free(migration->data_buffer); in vfio_save_cleanup()
540 migration->data_buffer = NULL; in vfio_save_cleanup()
541 migration->precopy_init_size = 0; in vfio_save_cleanup()
542 migration->precopy_dirty_size = 0; in vfio_save_cleanup()
543 migration->initial_data_sent = false; in vfio_save_cleanup()
552 VFIOMigration *migration = vbasedev->migration; in vfio_state_pending_estimate() local
559 migration->precopy_init_size + migration->precopy_dirty_size; in vfio_state_pending_estimate()
563 migration->precopy_init_size, in vfio_state_pending_estimate()
564 migration->precopy_dirty_size); in vfio_state_pending_estimate()
568 * Migration size of VFIO devices can be as little as a few KBs or as big as
577 VFIOMigration *migration = vbasedev->migration; in vfio_state_pending_exact() local
581 * If getting pending migration size fails, VFIO_MIG_STOP_COPY_SIZE is in vfio_state_pending_exact()
588 vfio_query_precopy_size(migration); in vfio_state_pending_exact()
592 stop_copy_size, migration->precopy_init_size, in vfio_state_pending_exact()
593 migration->precopy_dirty_size); in vfio_state_pending_exact()
604 * Note about migration rate limiting: VFIO migration buffer size is currently
605 * limited to 1MB, so there is no need to check if migration rate exceeded (as
607 * later changed to a bigger value, migration rate should be enforced here.
612 VFIOMigration *migration = vbasedev->migration; in vfio_save_iterate() local
615 if (!migration->event_save_iterate_started) { in vfio_save_iterate()
617 migration->event_save_iterate_started = true; in vfio_save_iterate()
620 data_size = vfio_save_block(f, migration); in vfio_save_iterate()
625 vfio_update_estimated_pending_data(migration, data_size); in vfio_save_iterate()
627 if (migrate_switchover_ack() && !migration->precopy_init_size && in vfio_save_iterate()
628 !migration->initial_data_sent) { in vfio_save_iterate()
630 migration->initial_data_sent = true; in vfio_save_iterate()
635 trace_vfio_save_iterate(vbasedev->name, migration->precopy_init_size, in vfio_save_iterate()
636 migration->precopy_dirty_size); in vfio_save_iterate()
638 return !migration->precopy_init_size && !migration->precopy_dirty_size; in vfio_save_iterate()
659 data_size = vfio_save_block(f, vbasedev->migration); in vfio_save_complete_precopy()
693 vbasedev->migration->device_state, errp); in vfio_load_setup()
807 VFIOMigration *migration = vbasedev->migration; in vfio_vmstate_change_prepare() local
812 new_state = migration->device_state == VFIO_DEVICE_STATE_PRE_COPY ? in vfio_vmstate_change_prepare()
819 * Migration should be aborted in this case, but vm_state_notify() in vfio_vmstate_change_prepare()
850 * Migration should be aborted in this case, but vm_state_notify() in vfio_vmstate_change()
863 VFIOMigration *migration = container_of(notifier, VFIOMigration, in vfio_migration_state_notifier() local
865 VFIODevice *vbasedev = migration->vbasedev; in vfio_migration_state_notifier()
889 g_free(vbasedev->migration); in vfio_migration_free()
890 vbasedev->migration = NULL; in vfio_migration_free()
930 VFIOMigration *migration; in vfio_migration_init() local
950 /* Basic migration functionality must be supported */ in vfio_migration_init()
955 vbasedev->migration = g_new0(VFIOMigration, 1); in vfio_migration_init()
956 migration = vbasedev->migration; in vfio_migration_init()
957 migration->vbasedev = vbasedev; in vfio_migration_init()
958 migration->device_state = VFIO_DEVICE_STATE_RUNNING; in vfio_migration_init()
959 migration->data_fd = -1; in vfio_migration_init()
960 migration->mig_flags = mig_flags; in vfio_migration_init()
975 prepare_cb = migration->mig_flags & VFIO_MIGRATION_P2P ? in vfio_migration_init()
978 migration->vm_state = qdev_add_vm_change_state_handler_full( in vfio_migration_init()
980 migration_add_notifier(&migration->migration_state, in vfio_migration_init()
988 VFIOMigration *migration = vbasedev->migration; in vfio_migration_deinit() local
990 migration_remove_notifier(&migration->migration_state); in vfio_migration_deinit()
991 qemu_del_vm_change_state_handler(migration->vm_state); in vfio_migration_deinit()
1023 * Return true when either migration initialized or blocker registered.
1033 error_setg(&err, "%s: Migration is disabled for VFIO device", in vfio_migration_realize()
1041 error_setg(&err, "%s: VFIO migration is not supported in kernel", in vfio_migration_realize()
1045 "%s: Migration couldn't be initialized for VFIO device, " in vfio_migration_realize()
1073 error_setg(&err, "%s: Migration is currently not supported " in vfio_migration_realize()
1092 if (vbasedev->migration) { in vfio_migration_exit()