diff options
author | William Henderson <william.henderson@nutanix.com> | 2023-09-15 16:07:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-15 16:07:01 +0100 |
commit | 190f85bf9c114bf7c981bb8908394368f84c0c04 (patch) | |
tree | 92273a811fc3a8af74a5f62cec8871f345d6999b /include/vfio-user.h | |
parent | 1569a37a54ecb63bd4008708c76339ccf7d06115 (diff) | |
download | libvfio-user-190f85bf9c114bf7c981bb8908394368f84c0c04.zip libvfio-user-190f85bf9c114bf7c981bb8908394368f84c0c04.tar.gz libvfio-user-190f85bf9c114bf7c981bb8908394368f84c0c04.tar.bz2 |
adapt to VFIO live migration v2 (#782)
This commit adapts the vfio-user protocol specification and the libvfio-user
implementation to v2 of the VFIO live migration interface, as used in the kernel
and QEMU.
The differences between v1 and v2 are discussed in this email thread [1], and we
slightly differ from upstream VFIO v2 in that instead of transferring data over
a new FD, we use the existing UNIX socket with new commands
VFIO_USER_MIG_DATA_READ/WRITE. We also don't yet use P2P states.
The updated spec was submitted to qemu-devel [2].
[1] https://lore.kernel.org/all/20220130160826.32449-9-yishaih@nvidia.com/
[2] https://lore.kernel.org/all/20230718094150.110183-1-william.henderson@nutanix.com/
Signed-off-by: William Henderson <william.henderson@nutanix.com>
Diffstat (limited to 'include/vfio-user.h')
-rw-r--r-- | include/vfio-user.h | 105 |
1 files changed, 87 insertions, 18 deletions
diff --git a/include/vfio-user.h b/include/vfio-user.h index a749938..0b115d3 100644 --- a/include/vfio-user.h +++ b/include/vfio-user.h @@ -66,7 +66,10 @@ enum vfio_user_command { VFIO_USER_DMA_READ = 11, VFIO_USER_DMA_WRITE = 12, VFIO_USER_DEVICE_RESET = 13, - VFIO_USER_DIRTY_PAGES = 14, + VFIO_USER_REGION_WRITE_MULTI = 15, + VFIO_USER_DEVICE_FEATURE = 16, + VFIO_USER_MIG_DATA_READ = 17, + VFIO_USER_MIG_DATA_WRITE = 18, VFIO_USER_MAX, }; @@ -200,31 +203,97 @@ typedef struct vfio_user_region_io_fds_reply { } sub_regions[]; } __attribute__((packed)) vfio_user_region_io_fds_reply_t; +/* Analogous to struct vfio_device_feature_dma_logging_range */ +struct vfio_user_device_feature_dma_logging_range { + uint64_t iova; + uint64_t length; +} __attribute__((packed)); -/* Analogous to vfio_iommu_type1_dirty_bitmap. */ -struct vfio_user_dirty_pages { - uint32_t argsz; -#ifndef VFIO_IOMMU_DIRTY_PAGES_FLAG_START -#define VFIO_IOMMU_DIRTY_PAGES_FLAG_START (1 << 0) -#define VFIO_IOMMU_DIRTY_PAGES_FLAG_STOP (1 << 1) -#define VFIO_IOMMU_DIRTY_PAGES_FLAG_GET_BITMAP (1 << 2) -#endif - uint32_t flags; +/* Analogous to struct vfio_device_feature_dma_logging_control */ +struct vfio_user_device_feature_dma_logging_control { + uint64_t page_size; + uint32_t num_ranges; + uint32_t reserved; + struct vfio_user_device_feature_dma_logging_range ranges[]; } __attribute__((packed)); -/* Analogous to struct vfio_iommu_type1_dirty_bitmap_get. */ -struct vfio_user_bitmap_range { +/* Analogous to struct vfio_device_feature_dma_logging_report */ +struct vfio_user_device_feature_dma_logging_report { uint64_t iova; - uint64_t size; - struct vfio_user_bitmap bitmap; + uint64_t length; + uint64_t page_size; + uint8_t bitmap[]; +} __attribute__((packed)); + +#ifndef VFIO_DEVICE_FEATURE_DMA_LOGGING_START +#define VFIO_DEVICE_FEATURE_DMA_LOGGING_START 6 +#define VFIO_DEVICE_FEATURE_DMA_LOGGING_STOP 7 +#define VFIO_DEVICE_FEATURE_DMA_LOGGING_REPORT 8 +#endif + +/* Analogous to struct vfio_device_feature */ +struct vfio_user_device_feature { + uint32_t argsz; + uint32_t flags; +#ifndef VFIO_DEVICE_FEATURE_MASK +#define VFIO_DEVICE_FEATURE_MASK (0xffff) /* 16-bit feature index */ +#define VFIO_DEVICE_FEATURE_GET (1 << 16) /* Get feature into data[] */ +#define VFIO_DEVICE_FEATURE_SET (1 << 17) /* Set feature from data[] */ +#define VFIO_DEVICE_FEATURE_PROBE (1 << 18) /* Probe feature support */ +#endif + uint8_t data[]; +} __attribute__((packed)); + +/* Analogous to struct vfio_device_feature_migration */ +struct vfio_user_device_feature_migration { + uint64_t flags; +#ifndef VFIO_REGION_TYPE_MIGRATION_DEPRECATED +#define VFIO_MIGRATION_STOP_COPY (1 << 0) +#define VFIO_MIGRATION_P2P (1 << 1) +#endif +/* + * PRE_COPY was added in a later kernel version, after + * VFIO_REGION_TYPE_MIGRATION_DEPRECATED had been introduced. + */ +#ifndef VFIO_MIGRATION_PRE_COPY +#define VFIO_MIGRATION_PRE_COPY (1 << 2) +#endif } __attribute__((packed)); +#ifndef VFIO_REGION_TYPE_MIGRATION_DEPRECATED +#define VFIO_DEVICE_FEATURE_MIGRATION 1 +#endif +_Static_assert(sizeof(struct vfio_user_device_feature_migration) == 8, + "bad vfio_user_device_feature_migration size"); -#ifndef VFIO_REGION_TYPE_MIGRATION +/* Analogous to struct vfio_device_feature_mig_state */ +struct vfio_user_device_feature_mig_state { + uint32_t device_state; + uint32_t data_fd; +} __attribute__((packed)); +#ifndef VFIO_DEVICE_FEATURE_MIG_DEVICE_STATE +#define VFIO_DEVICE_FEATURE_MIG_DEVICE_STATE 2 +#endif +_Static_assert(sizeof(struct vfio_user_device_feature_migration) == 8, + "bad vfio_user_device_feature_mig_state size"); -#define VFIO_REGION_TYPE_MIGRATION (3) -#define VFIO_REGION_SUBTYPE_MIGRATION (1) +/* Analogous to enum vfio_device_mig_state */ +enum vfio_user_device_mig_state { + VFIO_USER_DEVICE_STATE_ERROR = 0, + VFIO_USER_DEVICE_STATE_STOP = 1, + VFIO_USER_DEVICE_STATE_RUNNING = 2, + VFIO_USER_DEVICE_STATE_STOP_COPY = 3, + VFIO_USER_DEVICE_STATE_RESUMING = 4, + VFIO_USER_DEVICE_STATE_RUNNING_P2P = 5, + VFIO_USER_DEVICE_STATE_PRE_COPY = 6, + VFIO_USER_DEVICE_STATE_PRE_COPY_P2P = 7, + VFIO_USER_DEVICE_NUM_STATES = 8, +}; -#endif /* VFIO_REGION_TYPE_MIGRATION */ +struct vfio_user_mig_data { + uint32_t argsz; + uint32_t size; + uint8_t data[]; +} __attribute__((packed)); #ifdef __cplusplus } |