diff options
author | John Levon <john.levon@nutanix.com> | 2021-06-02 15:04:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-02 15:04:10 +0100 |
commit | b8234a75d9ec2c95cb889c0cef27927f34ad9cbc (patch) | |
tree | a2cd490a958e3b3c08595451c62f7e62108bebe2 /include | |
parent | 8ac2360a8aefbd2dd11c65f2b2e21565c36c0ee6 (diff) | |
download | libvfio-user-b8234a75d9ec2c95cb889c0cef27927f34ad9cbc.zip libvfio-user-b8234a75d9ec2c95cb889c0cef27927f34ad9cbc.tar.gz libvfio-user-b8234a75d9ec2c95cb889c0cef27927f34ad9cbc.tar.bz2 |
clean up migration register definitions (#550)
We should explicitly define the expected migration register contents for API
users who aren't using the callbacks. Clean up some related lint.
Signed-off-by: John Levon <john.levon@nutanix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/libvfio-user.h | 67 | ||||
-rw-r--r-- | include/vfio-user.h | 49 |
2 files changed, 49 insertions, 67 deletions
diff --git a/include/libvfio-user.h b/include/libvfio-user.h index c9e8ca2..9c2628a 100644 --- a/include/libvfio-user.h +++ b/include/libvfio-user.h @@ -263,20 +263,19 @@ typedef ssize_t (vfu_region_access_cb_t)(vfu_ctx_t *vfu_ctx, char *buf, * Regions VFU_PCI_DEV_MIGR_REGION_IDX and VFU_GENERIC_DEV_MIGR_REG_IDX, * corresponding to the migration region, enable live migration support for * the device. The migration region must contain at the beginning the migration - * registers (struct vfio_device_migration_info defined in <linux/vfio.h>) and - * the remaining part of the region can be arbitrarily used by the device - * implementation. The region provided must have at least - * vfu_get_migr_register_area_size() bytes available at the start of the region - * (this size is guaranteed to be page-aligned). If mmap_areas is given, it - * must _not_ include this part of the region. + * registers (struct vfio_user_migration_info) and the remaining part of the + * region can be arbitrarily used by the device implementation. The region + * provided must have at least vfu_get_migr_register_area_size() bytes available + * at the start of the region (this size is guaranteed to be page-aligned). If + * mmap_areas is given, it must _not_ include this part of the region. * * libvfio-user offers two ways for the migration region to be used: * 1. natively: the device implementation must handle accesses to the * migration registers and migration data via the region callbacks. The * semantics of these registers are explained in <linux/vfio.h>. - * 2. via the vfu_migration_t callbacks: the device implementation registers - * a set of callbacks by calling vfu_setup_device_migration. The region's - * read/write callbacks are never called. + * 2. via the vfu_migration_callbacks_t callbacks: the device implementation + * registers a set of callbacks by calling vfu_setup_device_migration. + * The region's read/write callbacks are never called. * * @vfu_ctx: the libvfio-user context * @region_idx: region index @@ -300,13 +299,6 @@ vfu_setup_region(vfu_ctx_t *vfu_ctx, int region_idx, size_t size, struct iovec *mmap_areas, uint32_t nr_mmap_areas, int fd, uint64_t offset); -/* - * Returns the size of the area needed to hold the migration registers at the - * beginning of the migration region; guaranteed to be page aligned. - */ -size_t -vfu_get_migr_register_area_size(void); - typedef enum vfu_reset_type { /* * Client requested a device reset (for example, as part of a guest VM @@ -456,15 +448,6 @@ int vfu_setup_device_nr_irqs(vfu_ctx_t *vfu_ctx, enum vfu_dev_irq_type type, uint32_t count); -/* - * FIXME the names of migration callback functions are probably far too long, - * but for now it helps with the implementation. - */ -/** - * Migration callback function. - * @vfu_ctx: the libvfio-user context - */ -typedef int (vfu_migration_callback_t)(vfu_ctx_t *vfu_ctx); typedef enum { VFU_MIGR_STATE_STOP, @@ -474,7 +457,6 @@ typedef enum { VFU_MIGR_STATE_RESUME } vfu_migr_state_t; - #define VFU_MIGR_CALLBACKS_VERS 1 /* @@ -568,6 +550,39 @@ typedef struct { } vfu_migration_callbacks_t; + +#ifndef VFIO_DEVICE_STATE_STOP + +#define VFIO_DEVICE_STATE_STOP (0) +#define VFIO_DEVICE_STATE_RUNNING (1 << 0) +#define VFIO_DEVICE_STATE_SAVING (1 << 1) +#define VFIO_DEVICE_STATE_RESUMING (1 << 2) +#define VFIO_DEVICE_STATE_MASK ((1 << 3) - 1) + +#endif /* VFIO_DEVICE_STATE_STOP */ + +/* + * The currently defined migration registers; if using migration callbacks, + * these are handled internally by the library. + * + * This is analogous to struct vfio_device_migration_info. + */ +struct vfio_user_migration_info { + /* VFIO_DEVICE_STATE_* */ + uint32_t device_state; + uint32_t reserved; + uint64_t pending_bytes; + uint64_t data_offset; + uint64_t data_size; +}; + +/* + * Returns the size of the area needed to hold the migration registers at the + * beginning of the migration region; guaranteed to be page aligned. + */ +size_t +vfu_get_migr_register_area_size(void); + /** * vfu_setup_device_migration provides an abstraction over the migration * protocol: the user specifies a set of callbacks which are called in response diff --git a/include/vfio-user.h b/include/vfio-user.h index 71112ef..7be7cf7 100644 --- a/include/vfio-user.h +++ b/include/vfio-user.h @@ -159,9 +159,9 @@ struct vfio_user_irq_info { 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) +#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; } __attribute__((packed)); @@ -173,45 +173,12 @@ struct vfio_user_bitmap_range { struct vfio_user_bitmap bitmap; } __attribute__((packed)); -#if LINUX_VERSION_CODE < KERNEL_VERSION(5,8,0) - -/* copied from <linux/vfio.h> */ - -#define VFIO_DEVICE_STATE_STOP (0) -#define VFIO_DEVICE_STATE_RUNNING (1 << 0) -#define VFIO_DEVICE_STATE_SAVING (1 << 1) -#define VFIO_DEVICE_STATE_RESUMING (1 << 2) -#define VFIO_DEVICE_STATE_MASK (VFIO_DEVICE_STATE_RUNNING | \ - VFIO_DEVICE_STATE_SAVING | \ - VFIO_DEVICE_STATE_RESUMING) - -#define VFIO_DEVICE_STATE_VALID(state) \ - (state & VFIO_DEVICE_STATE_RESUMING ? \ - (state & VFIO_DEVICE_STATE_MASK) == VFIO_DEVICE_STATE_RESUMING : 1) - -#define VFIO_DEVICE_STATE_IS_ERROR(state) \ - ((state & VFIO_DEVICE_STATE_MASK) == (VFIO_DEVICE_STATE_SAVING | \ - VFIO_DEVICE_STATE_RESUMING)) - -#define VFIO_DEVICE_STATE_SET_ERROR(state) \ - ((state & ~VFIO_DEVICE_STATE_MASK) | VFIO_DEVICE_SATE_SAVING | \ - VFIO_DEVICE_STATE_RESUMING) - -/* RHEL kernels have some of it backported */ -#ifndef VFIO_REGION_TYPE_MIGRATION /* not a RHEL kernel */ -#define VFIO_REGION_TYPE_MIGRATION (3) -#define VFIO_REGION_SUBTYPE_MIGRATION (1) - -struct vfio_device_migration_info { - __u32 device_state; /* VFIO device state */ - __u32 reserved; - __u64 pending_bytes; - __u64 data_offset; - __u64 data_size; -}; -#endif /* not a RHEL kernel */ +#ifndef VFIO_REGION_TYPE_MIGRATION + +#define VFIO_REGION_TYPE_MIGRATION (3) +#define VFIO_REGION_SUBTYPE_MIGRATION (1) -#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(5,8,0) */ +#endif /* VFIO_REGION_TYPE_MIGRATION */ #ifdef __cplusplus } |