According to VFIO uAPI, precopy initial_bytes is considered as critical data that should be transferred and loaded prior to moving to STOP_COPY state to ensure precopy phase would be effective. As currently defined, initial_bytes can only decrease as it's being read from the data fd. However, there are cases where a new chunk of initial_bytes should be transferred during precopy. The new VFIO_PRECOPY_INFO_REINIT feature addresses this and allows reporting a new value for initial_bytes regardless of any previously reported values. Implement VFIO_PRECOPY_INFO_REINIT feature: 1. Opt-in for VFIO_DEVICE_FEATURE_MIG_PRECOPY_INFOv2 to make VFIO_PRECOPY_INFO_REINIT available. 2. Request a new switchover ACK if initial_bytes increases post of a previous switchover ACK. This ensures the device is not moved to STOP_COPY before initial_bytes has reached zero again. Acked-by: Peter Xu <peterx@redhat.com> Signed-off-by: Avihai Horon <avihaih@nvidia.com> Link: https://lore.kernel.org/qemu-devel/20260706085211.13905-13-avihaih@nvidia.com Signed-off-by: Cédric Le Goater <clg@redhat.com>
85 lines
2.8 KiB
C
85 lines
2.8 KiB
C
/*
|
|
* VFIO migration
|
|
*
|
|
* Copyright Red Hat, Inc. 2025
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
*/
|
|
|
|
#ifndef HW_VFIO_VFIO_MIGRATION_INTERNAL_H
|
|
#define HW_VFIO_VFIO_MIGRATION_INTERNAL_H
|
|
|
|
#ifdef CONFIG_LINUX
|
|
#include <linux/vfio.h>
|
|
#endif
|
|
|
|
#include "qemu/notify.h"
|
|
|
|
/*
|
|
* Flags to be used as unique delimiters for VFIO devices in the migration
|
|
* stream. These flags are composed as:
|
|
* 0xffffffff => MSB 32-bit all 1s
|
|
* 0xef10 => Magic ID, represents emulated (virtual) function IO
|
|
* 0x0000 => 16-bits reserved for flags
|
|
*
|
|
* The beginning of state information is marked by _DEV_CONFIG_STATE,
|
|
* _DEV_SETUP_STATE, or _DEV_DATA_STATE, respectively. The end of a
|
|
* certain state information is marked by _END_OF_STATE.
|
|
*/
|
|
#define VFIO_MIG_FLAG_END_OF_STATE (0xffffffffef100001ULL)
|
|
#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)
|
|
#define VFIO_MIG_FLAG_DEV_CONFIG_LOAD_READY (0xffffffffef100006ULL)
|
|
|
|
typedef struct VFIODevice VFIODevice;
|
|
typedef struct VFIOMultifd VFIOMultifd;
|
|
|
|
typedef struct VFIOMigration {
|
|
struct VFIODevice *vbasedev;
|
|
VMChangeStateEntry *vm_state;
|
|
NotifierWithReturn migration_state;
|
|
uint32_t device_state;
|
|
int data_fd;
|
|
void *data_buffer;
|
|
size_t data_buffer_size;
|
|
uint64_t mig_flags;
|
|
bool precopy_info_v2_used;
|
|
/*
|
|
* NOTE: all three sizes cached are reported from VFIO's uAPI, which
|
|
* are defined as estimate only. QEMU should not trust these values
|
|
* but only use them to do best-effort estimates. Always be prepared
|
|
* that these sizes may either grow or even shrink in reality while
|
|
* read()ing from the VFIO fds.
|
|
*/
|
|
uint64_t precopy_init_size;
|
|
uint64_t precopy_dirty_size;
|
|
uint64_t stopcopy_size;
|
|
bool multifd_transfer;
|
|
VFIOMultifd *multifd;
|
|
bool initial_data_sent;
|
|
bool request_switchover_ack;
|
|
|
|
bool event_save_iterate_started;
|
|
bool event_precopy_empty_hit;
|
|
} VFIOMigration;
|
|
|
|
bool vfio_migration_realize(VFIODevice *vbasedev, Error **errp);
|
|
void vfio_migration_exit(VFIODevice *vbasedev);
|
|
bool vfio_device_state_is_running(VFIODevice *vbasedev);
|
|
bool vfio_device_state_is_precopy(VFIODevice *vbasedev);
|
|
int vfio_save_device_config_state(QEMUFile *f, void *opaque, Error **errp);
|
|
int vfio_load_device_config_state(QEMUFile *f, void *opaque);
|
|
|
|
#ifdef CONFIG_LINUX
|
|
int vfio_migration_set_state(VFIODevice *vbasedev,
|
|
enum vfio_device_mig_state new_state,
|
|
enum vfio_device_mig_state recover_state,
|
|
Error **errp);
|
|
#endif
|
|
|
|
void vfio_migration_add_bytes_transferred(unsigned long val);
|
|
|
|
#endif /* HW_VFIO_VFIO_MIGRATION_INTERNAL_H */
|