Enhances the vfio-virtio driver to support live migration
Subsystems (5)
Yishai Hadas
maintainercover Enhances the vfio-virtio driver to support live migration
This series enhances the vfio-virtio driver to support live migration for virtio-net Virtual Functions (VFs) that are migration-capable.
This series follows the Virtio 1.4 specification to implement the necessary device parts commands, enabling a device to participate in the live migration process.
The key VFIO features implemented include: VFIO_MIGRATION_STOP_COPY, VFIO_MIGRATION_P2P, VFIO_MIGRATION_PRE_COPY.
The implementation integrates with the VFIO subsystem via vfio_pci_core and incorporates Virtio-specific logic to handle the migration process.
Migration functionality follows the definitions in uapi/vfio.h and uses the Virtio VF-to-PF admin queue command channel for executing the device parts related commands.
Patch Overview:
The first four patches focus on the Virtio layer and address the following:
- Define the layout of the device parts commands required as part of the migration process.
- Provide APIs to enable upper layers (e.g., VFIO, net) to execute the related device parts commands.
The last three patches focus on the VFIO layer:
- Extend the vfio-virtio driver to support live migration for Virtio-net VFs.
- Move legacy I/O operations to a separate file, which is compiled only when VIRTIO_PCI_ADMIN_LEGACY is configured, ensuring that live migration depends solely on VIRTIO_PCI.
Additional Notes:
- The kernel protocol between the source and target devices includes a header containing metadata such as record size, tag, and flags. The record size allows the target to read a complete image from the source before passing device part data. This follows the Virtio specification, which mandates that partial device parts are not supplied. The tag and flags serve as placeholders for future extensions to the kernel protocol between the source and target, ensuring backward and forward compatibility.
- Both the source and target comply with the Virtio specification by using a device part object with a unique ID during the migration process. As this resource is limited to a maximum of 255, its lifecycle is confined to periods when live migration is active.
- According to the Virtio specification, a device has only two states:
RUNNING and STOPPED. Consequently, certain VFIO transitions (e.g., RUNNING_P2P->STOP, STOP->RUNNING_P2P) are treated as no-ops. When transitioning to RUNNING_P2P, the device state is set to STOP and remains STOPPED until it transitions back from RUNNING_P2P->RUNNING, at which point it resumes its RUNNING state.
- Furthermore, the Virtio specification does not support reading partial or incremental device contexts. This means that during the PRE_COPY state, the vfio-virtio driver reads the full device state. This step is beneficial because it allows the device to send some "initial data" before moving to the STOP_COPY state, thus reducing downtime by preparing early. To avoid an infinite number of device calls during PRE_COPY, the vfio-virtio driver limits this flow to a maximum of 128 calls. After reaching this limit, the driver will report zero bytes remaining in PRE_COPY, signaling to QEMU to transition to STOP_COPY.
- Support for dirty page tracking during migration will be provided via the IOMMUFD framework.
- This series has been successfully tested on Virtio-net VF devices.
Yishai
Yishai Hadas (7):
virtio_pci: Introduce device parts access commands
virtio: Extend the admin command to include the result size
virtio: Manage device and driver capabilities via the admin commands
virtio-pci: Introduce APIs to execute device parts admin commands vfio/virtio: Add support for the basic live migration functionality vfio/virtio: Add PRE_COPY support for live migration vfio/virtio: Enable live migration once VIRTIO_PCI was configured
drivers/vfio/pci/virtio/Kconfig | 4 +- drivers/vfio/pci/virtio/Makefile | 3 +- drivers/vfio/pci/virtio/common.h | 127 +++ drivers/vfio/pci/virtio/legacy_io.c | 420 +++++++++ drivers/vfio/pci/virtio/main.c | 496 ++-------- drivers/vfio/pci/virtio/migrate.c | 1339 +++++++++++++++++++++++++++ drivers/virtio/virtio_pci_common.h | 19 +- drivers/virtio/virtio_pci_modern.c | 457 ++++++++- include/linux/virtio.h | 1 + include/linux/virtio_pci_admin.h | 11 + include/uapi/linux/virtio_pci.h | 131 +++ 11 files changed, 2593 insertions(+), 415 deletions(-) create mode 100644 drivers/vfio/pci/virtio/common.h create mode 100644 drivers/vfio/pci/virtio/legacy_io.c create mode 100644 drivers/vfio/pci/virtio/migrate.c
Signature · 1 line
2.27.0
Yishai Hadas
maintainerPATCH 1/7 virtio_pci: Introduce device parts access commands
Introduce device parts access commands via the admin queue.
These commands and their structure adhere to the Virtio 1.4 specification.
--- include/uapi/linux/virtio_pci.h | 131 ++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+)
include/uapi/linux/virtio_pci.h +131 -0
@@ -40,6 +40,7 @@#define _LINUX_VIRTIO_PCI_H#include <linux/types.h> +#include <linux/kernel.h> #ifndef VIRTIO_PCI_NO_LEGACY
@@ -240,6 +241,17 @@ struct virtio_pci_cfg_cap {#define VIRTIO_ADMIN_CMD_LEGACY_DEV_CFG_READ 0x5#define VIRTIO_ADMIN_CMD_LEGACY_NOTIFY_INFO 0x6 +/* Device parts access commands. */ +#define VIRTIO_ADMIN_CMD_CAP_ID_LIST_QUERY 0x7 +#define VIRTIO_ADMIN_CMD_DEVICE_CAP_GET 0x8 +#define VIRTIO_ADMIN_CMD_DRIVER_CAP_SET 0x9 +#define VIRTIO_ADMIN_CMD_RESOURCE_OBJ_CREATE 0xa +#define VIRTIO_ADMIN_CMD_RESOURCE_OBJ_DESTROY 0xd +#define VIRTIO_ADMIN_CMD_DEV_PARTS_METADATA_GET 0xe +#define VIRTIO_ADMIN_CMD_DEV_PARTS_GET 0xf +#define VIRTIO_ADMIN_CMD_DEV_PARTS_SET 0x10 +#define VIRTIO_ADMIN_CMD_DEV_MODE_SET 0x11 +struct virtio_admin_cmd_hdr {__le16 opcode;/*
@@ -286,4 +298,123 @@ struct virtio_admin_cmd_notify_info_result {struct virtio_admin_cmd_notify_info_data entries[VIRTIO_ADMIN_CMD_MAX_NOTIFY_INFO ]; }; +#define VIRTIO_DEV_PARTS_CAP 0x0000 + +struct virtio_dev_parts_cap { +__u8 get_parts_resource_objects_limit; +__u8 set_parts_resource_objects_limit; +}; + +#define MAX_CAP_ID __KERNEL_DIV_ROUND_UP(VIRTIO_DEV_PARTS_CAP + 1, 64) + +struct virtio_admin_cmd_query_cap_id_result { +__le64 supported_caps[MAX_CAP_ID ]; +}; + +struct virtio_admin_cmd_cap_get_data { +__le16 id; +__u8 reserved[6 ]; +}; + +struct virtio_admin_cmd_cap_set_data { +__le16 id; +__u8 reserved[6 ]; +__u8 cap_specific_data[]; +}; + +struct virtio_admin_cmd_resource_obj_cmd_hdr { +__le16 type; +__u8 reserved[2 ]; +__le32 id;/* Indicates unique resource object id per resource object type */ +}; + +struct virtio_admin_cmd_resource_obj_create_data { +struct virtio_admin_cmd_resource_obj_cmd_hdr hdr; +__le64 flags; +__u8 resource_obj_specific_data[]; +}; + +#define VIRTIO_RESOURCE_OBJ_DEV_PARTS 0 + +#define VIRTIO_RESOURCE_OBJ_DEV_PARTS_TYPE_GET 0 +#define VIRTIO_RESOURCE_OBJ_DEV_PARTS_TYPE_SET 1 + +struct virtio_resource_obj_dev_parts { +__u8 type; +__u8 reserved[7 ]; +}; + +#define VIRTIO_ADMIN_CMD_DEV_PARTS_METADATA_TYPE_SIZE 0 +#define VIRTIO_ADMIN_CMD_DEV_PARTS_METADATA_TYPE_COUNT 1 +#define VIRTIO_ADMIN_CMD_DEV_PARTS_METADATA_TYPE_LIST 2 + +struct virtio_admin_cmd_dev_parts_metadata_data { +struct virtio_admin_cmd_resource_obj_cmd_hdr hdr; +__u8 type; +__u8 reserved[7 ]; +}; + +#define VIRTIO_DEV_PART_F_OPTIONAL 0 + +struct virtio_dev_part_hdr { +__le16 part_type; +__u8 flags; +__u8 reserved; +union { +struct { +__le32 offset; +__le32 reserved; + } pci_common_cfg; +struct { +__le16 index; +__u8 reserved[6 ]; + } vq_index; + } selector; +__le32 length; +}; + +struct virtio_dev_part { +struct virtio_dev_part_hdr hdr; +__u8 value[]; +}; + +struct virtio_admin_cmd_dev_parts_metadata_result { +union { +struct { +__le32 size; +__le32 reserved; + } parts_size; +struct { +__le32 count; +__le32 reserved; + } hdr_list_count; +struct { +__le32 count; +__le32 reserved; +struct virtio_dev_part_hdr hdrs[]; + } hdr_list; + }; +}; + +#define VIRTIO_ADMIN_CMD_DEV_PARTS_GET_TYPE_SELECTED 0 +#define VIRTIO_ADMIN_CMD_DEV_PARTS_GET_TYPE_ALL 1 + +struct virtio_admin_cmd_dev_parts_get_data { +struct virtio_admin_cmd_resource_obj_cmd_hdr hdr; +__u8 type; +__u8 reserved[7 ]; +struct virtio_dev_part_hdr hdr_list[]; +}; + +struct virtio_admin_cmd_dev_parts_set_data { +struct virtio_admin_cmd_resource_obj_cmd_hdr hdr; +struct virtio_dev_part parts[]; +}; + +#define VIRTIO_ADMIN_CMD_DEV_MODE_F_STOPPED 0 + +struct virtio_admin_cmd_dev_mode_set_data { +__u8 flags; +}; +#endif
Signature · 1 line
2.27.0
Yishai Hadas
maintainerPATCH 2/7 virtio: Extend the admin command to include the result size
In reply to Yishai HadasExtend the admin command by incorporating a result size field.
This allows higher layers to determine the actual result size from the backend when this information is not included in the result_sg.
The additional information introduced here will be used in subsequent patches of this series.
--- drivers/virtio/virtio_pci_modern.c | 4 +++- include/linux/virtio.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/virtio/virtio_pci_modern.c +3 -1
@@ -64,8 +64,10 @@ void vp_modern_avq_done(struct virtqueue *vq)spin_lock_irqsave (&admin_vq->lock, flags);do {virtqueue_disable_cb (vq); -while ((cmd =virtqueue_get_buf (vq, &len))) +while ((cmd =virtqueue_get_buf (vq, &len))) { + cmd->result_sg_size = len;complete (&cmd->completion); + } }while (!virtqueue_enable_cb (vq));spin_unlock_irqrestore (&admin_vq->lock, flags); }
include/linux/virtio.h +1 -0
@@ -111,6 +111,7 @@ struct virtio_admin_cmd {struct scatterlist *data_sg;struct scatterlist *result_sg;struct completion completion; +u32 result_sg_size;int ret; };
Signature · 1 line
2.27.0
Yishai Hadas
maintainerPATCH 3/7 virtio: Manage device and driver capabilities via the admin commands
In reply to Yishai HadasManage device and driver capabilities via the admin commands.
The device exposes its supported features and resource object limits via an administrative command called VIRTIO_ADMIN_CMD_CAP_ID_LIST_QUERY, using the 'self group type.'
Each capability is identified by a unique ID, and the driver communicates the functionality and resource limits it plans to utilize.
The capability VIRTIO_DEV_PARTS_CAP specifically represents the device's parts resource object limit.
Manage the device's parts resource object ID using a common IDA for both get and set operations.
--- drivers/virtio/virtio_pci_common.h | 13 +++- drivers/virtio/virtio_pci_modern.c | 105 +++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+), 2 deletions(-)
drivers/virtio/virtio_pci_common.h +11 -2
@@ -48,6 +48,9 @@ struct virtio_pci_admin_vq {/* Protects virtqueue access. */ spinlock_t lock;u64 supported_cmds; +u64 supported_caps; +u8 max_dev_parts_objects; +struct ida dev_parts_ida;/* Name of the admin queue: avq.$vq_index. */ char name[10 ];u16 vq_index;
@@ -167,15 +170,21 @@ struct virtio_device *virtio_pci_vf_get_pf_dev(struct pci_dev *pdev); BIT_ULL(VIRTIO_ADMIN_CMD_LEGACY_DEV_CFG_READ) | \ BIT_ULL(VIRTIO_ADMIN_CMD_LEGACY_NOTIFY_INFO)) +#define VIRTIO_DEV_PARTS_ADMIN_CMD_BITMAP \ + (BIT_ULL(VIRTIO_ADMIN_CMD_CAP_ID_LIST_QUERY) | \ + BIT_ULL(VIRTIO_ADMIN_CMD_DRIVER_CAP_SET) | \ + BIT_ULL(VIRTIO_ADMIN_CMD_DEVICE_CAP_GET)) +/* Unlike modern drivers which support hardware virtio devices, legacy drivers * assume software-based devices: e.g. they don't use proper memory barriers * on ARM, use big endian on PPC, etc. X86 drivers are mostly ok though, more * or less by chance. For now, only support legacy IO on X86. */ #ifdef CONFIG_VIRTIO_PCI_ADMIN_LEGACY -#define VIRTIO_ADMIN_CMD_BITMAP VIRTIO_LEGACY_ADMIN_CMD_BITMAP +#define VIRTIO_ADMIN_CMD_BITMAP (VIRTIO_LEGACY_ADMIN_CMD_BITMAP | \ + VIRTIO_DEV_PARTS_ADMIN_CMD_BITMAP)#else -#define VIRTIO_ADMIN_CMD_BITMAP 0 +#define VIRTIO_ADMIN_CMD_BITMAP VIRTIO_DEV_PARTS_ADMIN_CMD_BITMAP#endif void vp_modern_avq_done (struct virtqueue *vq);
drivers/virtio/virtio_pci_modern.c +105 -0
117 lines not on this page · raw message
Signature · 1 line
2.27.0
Yishai Hadas
maintainerPATCH 4/7 virtio-pci: Introduce APIs to execute device parts admin commands
In reply to Yishai HadasIntroduce APIs to handle the execution of device parts admin commands.
These APIs cover functionalities such as mode setting, object creation and destruction, and operations like parts get/set and metadata retrieval.
These APIs will be utilized in upcoming patches within this series.
--- drivers/virtio/virtio_pci_common.h | 8 +- drivers/virtio/virtio_pci_modern.c | 348 +++++++++++++++++++++++++++++ include/linux/virtio_pci_admin.h | 11 + 3 files changed, 366 insertions(+), 1 deletion(-)
drivers/virtio/virtio_pci_common.h +7 -1
@@ -173,7 +173,13 @@ struct virtio_device *virtio_pci_vf_get_pf_dev(struct pci_dev *pdev);#define VIRTIO_DEV_PARTS_ADMIN_CMD_BITMAP \ (BIT_ULL(VIRTIO_ADMIN_CMD_CAP_ID_LIST_QUERY) | \ BIT_ULL(VIRTIO_ADMIN_CMD_DRIVER_CAP_SET) | \ - BIT_ULL(VIRTIO_ADMIN_CMD_DEVICE_CAP_GET)) + BIT_ULL(VIRTIO_ADMIN_CMD_DEVICE_CAP_GET) | \ + BIT_ULL(VIRTIO_ADMIN_CMD_RESOURCE_OBJ_CREATE) | \ + BIT_ULL(VIRTIO_ADMIN_CMD_RESOURCE_OBJ_DESTROY) | \ + BIT_ULL(VIRTIO_ADMIN_CMD_DEV_PARTS_METADATA_GET) | \ + BIT_ULL(VIRTIO_ADMIN_CMD_DEV_PARTS_GET) | \ + BIT_ULL(VIRTIO_ADMIN_CMD_DEV_PARTS_SET) | \ + BIT_ULL(VIRTIO_ADMIN_CMD_DEV_MODE_SET))/* Unlike modern drivers which support hardware virtio devices, legacy drivers * assume software-based devices: e.g. they don't use proper memory barriers
drivers/virtio/virtio_pci_modern.c +348 -0
360 lines not on this page · raw message
include/linux/virtio_pci_admin.h +11 -0
@@ -20,4 +20,15 @@ int virtio_pci_admin_legacy_io_notify_info(struct pci_dev *pdev, u64 *bar_offset);#endif +bool virtio_pci_admin_has_dev_parts (struct pci_dev *pdev); +int virtio_pci_admin_mode_set (struct pci_dev *pdev,u8 mode); +int virtio_pci_admin_obj_create (struct pci_dev *pdev,u16 obj_type,u8 operation_type, +u32 *obj_id); +int virtio_pci_admin_obj_destroy (struct pci_dev *pdev,u16 obj_type,u32 id); +int virtio_pci_admin_dev_parts_metadata_get (struct pci_dev *pdev,u16 obj_type, +u32 id,u8 metadata_type,u32 *out); +int virtio_pci_admin_dev_parts_get (struct pci_dev *pdev,u16 obj_type,u32 id, +u8 get_type,struct scatterlist *res_sg,u32 *res_size); +int virtio_pci_admin_dev_parts_set (struct pci_dev *pdev,struct scatterlist *data_sg); +#endif /* _LINUX_VIRTIO_PCI_ADMIN_H */
Signature · 1 line
2.27.0
Yishai Hadas
maintainerPATCH 5/7 vfio/virtio: Add support for the basic live migration functionality
In reply to Yishai HadasAdd support for basic live migration functionality in VFIO over virtio-net devices, aligned with the virtio device specification 1.4.
This includes the following VFIO features:VFIO_MIGRATION_STOP_COPY, VFIO_MIGRATION_P2P.
The implementation registers with the VFIO subsystem using vfio_pci_core and then incorporates the virtio-specific logic for the migration process.
The migration follows the definitions in uapi/vfio.h and leverages the virtio VF-to-PF admin queue command channel for execution device parts related commands.
Additional Notes:
-----------------
The kernel protocol between the source and target devices contains a header with metadata, including record size, tag, and flags.
The record size allows the target to recognize and read a complete image from the source before passing the device part data. This adheres to the virtio device specification, which mandates that partial device parts cannot be supplied.
The tag and flags serve as placeholders for future extensions of the kernel protocol between the source and target, ensuring backward and forward compatibility.
Both the source and target comply with the virtio device specification by using a device part object with a unique ID as part of the migration process. Since this resource is limited to a maximum of 255, its lifecycle is confined to periods with an active live migration flow.
According to the virtio specification, a device has only two modes:
RUNNING and STOPPED. As a result, certain VFIO transitions (i.e., RUNNING_P2P->STOP, STOP->RUNNING_P2P) are treated as no-ops. When transitioning to RUNNING_P2P, the device state is set to STOP, and it will remain STOPPED until the transition out of RUNNING_P2P->RUNNING, at which point it returns to RUNNING.
--- drivers/vfio/pci/virtio/Makefile | 2 +- drivers/vfio/pci/virtio/common.h | 104 +++ drivers/vfio/pci/virtio/main.c | 144 ++-- drivers/vfio/pci/virtio/migrate.c | 1119 +++++++++++++++++++++++++++++ 4 files changed, 1318 insertions(+), 51 deletions(-) create mode 100644 drivers/vfio/pci/virtio/common.h create mode 100644 drivers/vfio/pci/virtio/migrate.c
drivers/vfio/pci/virtio/Makefile +1 -1
@@ -1,3 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_VIRTIO_VFIO_PCI) += virtio-vfio-pci.o -virtio-vfio-pci-y := main.o +virtio-vfio-pci-y := main.o migrate.o
drivers/vfio/pci/virtio/common.h new file +104 -0
104 lines not on this page · raw message
drivers/vfio/pci/virtio/main.c +94 -50
200 lines not on this page · raw message
drivers/vfio/pci/virtio/migrate.c new file +1119 -0
1,119 lines not on this page · raw message
Signature · 1 line
2.27.0
Yishai Hadas
maintainerPATCH 6/7 vfio/virtio: Add PRE_COPY support for live migration
In reply to Yishai HadasAdd PRE_COPY support for live migration.
This functionality may reduce the downtime upon STOP_COPY as of letting the target machine to get some 'initial data' from the source once the machine is still in its RUNNING state and let it prepares itself pre-ahead to get the final STOP_COPY data.
--- drivers/vfio/pci/virtio/common.h | 4 + drivers/vfio/pci/virtio/migrate.c | 234 +++++++++++++++++++++++++++++- 2 files changed, 231 insertions(+), 7 deletions(-)
drivers/vfio/pci/virtio/common.h +4 -0
@@ -10,6 +10,8 @@enum virtiovf_migf_state {VIRTIOVF_MIGF_STATE_ERROR =1 , +VIRTIOVF_MIGF_STATE_PRECOPY =2 , +VIRTIOVF_MIGF_STATE_COMPLETE =3 , };enum virtiovf_load_state {
@@ -57,6 +59,7 @@ struct virtiovf_migration_file {/* synchronize access to the file state */ struct mutex lock;loff_t max_pos; +u64 pre_copy_initial_bytes;u64 record_size;u32 record_tag; u8 has_obj_id:1;
@@ -90,6 +93,7 @@ struct virtiovf_pci_core_device {/* protect migration state */ struct mutex state_mutex;enum vfio_device_mig_state mig_state; +u16 num_pre_copy_calls;/* protect the reset_done flow */ spinlock_t reset_lock;struct virtiovf_migration_file *resuming_migf;
drivers/vfio/pci/virtio/migrate.c +227 -7
334 lines not on this page · raw message
Signature · 1 line
2.27.0
Yishai Hadas
maintainerPATCH 7/7 vfio/virtio: Enable live migration once VIRTIO_PCI was configured
In reply to Yishai HadasNow that the driver supports live migration, only the legacy IO functionality depends on config VIRTIO_PCI_ADMIN_LEGACY.
Move the legacy IO into a separate file to be compiled only once VIRTIO_PCI_ADMIN_LEGACY was configured and let the live migration depends only on VIRTIO_PCI.
--- drivers/vfio/pci/virtio/Kconfig | 4 +- drivers/vfio/pci/virtio/Makefile | 1 + drivers/vfio/pci/virtio/common.h | 19 ++ drivers/vfio/pci/virtio/legacy_io.c | 420 ++++++++++++++++++++++++++++ drivers/vfio/pci/virtio/main.c | 406 ++------------------------- 5 files changed, 462 insertions(+), 388 deletions(-) create mode 100644 drivers/vfio/pci/virtio/legacy_io.c
drivers/vfio/pci/virtio/Kconfig +3 -1
@@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only config VIRTIO_VFIO_PCI tristate "VFIO support for VIRTIO NET PCI devices" - depends on VIRTIO_PCI && VIRTIO_PCI_ADMIN_LEGACY + depends on VIRTIO_PCI select VFIO_PCI_CORE help This provides support for exposing VIRTIO NET VF devices which support
@@ -11,5 +11,7 @@ config VIRTIO_VFIO_PCI As of that this driver emulates I/O BAR in software to let a VF be seen as a transitional device by its users and let it work with a legacy driver. + In addition, it provides migration support for VIRTIO NET VF devices + using the VFIO framework. If you don't know what to do here, say N.
drivers/vfio/pci/virtio/Makefile +1 -0
@@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_VIRTIO_VFIO_PCI) += virtio-vfio-pci.o virtio-vfio-pci-y := main.o migrate.o +virtio-vfio-pci-$(CONFIG_VIRTIO_PCI_ADMIN_LEGACY) += legacy_io.o
drivers/vfio/pci/virtio/common.h +19 -0
@@ -77,6 +77,7 @@ struct virtiovf_migration_file {struct virtiovf_pci_core_device {struct vfio_pci_core_device core_device; +#ifdef CONFIG_VIRTIO_PCI_ADMIN_LEGACY u8 *bar0_virtual_buf;/* synchronize access to the virtual buf */ struct mutex bar_mutex;
@@ -86,6 +87,7 @@ struct virtiovf_pci_core_device {__le16 pci_cmd;u8 bar0_virtual_buf_size;u8 notify_bar; +#endif /* LM related */ u8 migrate_cap:1;
@@ -105,4 +107,21 @@ void virtiovf_open_migration(struct virtiovf_pci_core_device *virtvdev);void virtiovf_close_migration (struct virtiovf_pci_core_device *virtvdev);void virtiovf_migration_reset_done (struct pci_dev *pdev); +#ifdef CONFIG_VIRTIO_PCI_ADMIN_LEGACY +int virtiovf_open_legacy_io (struct virtiovf_pci_core_device *virtvdev); +long virtiovf_vfio_pci_core_ioctl (struct vfio_device *core_vdev, +unsigned int cmd,unsigned long arg); +int virtiovf_pci_ioctl_get_region_info (struct vfio_device *core_vdev, +unsigned int cmd,unsigned long arg); +ssize_t virtiovf_pci_core_write (struct vfio_device *core_vdev, +const char __user *buf,size_t count, +loff_t *ppos); +ssize_t virtiovf_pci_core_read (struct vfio_device *core_vdev,char __user *buf, +size_t count,loff_t *ppos); +int virtiovf_init_legacy_io (struct virtiovf_pci_core_device *virtvdev, +bool *sup_legacy_io); +void virtiovf_release_legacy_io (struct virtiovf_pci_core_device *virtvdev); +void virtiovf_legacy_io_reset_done (struct pci_dev *pdev); +#endif +#endif /* VIRTIO_VFIO_COMMON_H */
drivers/vfio/pci/virtio/legacy_io.c new file +420 -0
420 lines not on this page · raw message
drivers/vfio/pci/virtio/main.c +19 -387
459 lines not on this page · raw message
Signature · 1 line
2.27.0
Quoted 7 lines · On Sun, 27 Oct 2024 12:07:44 +0200 Yishai Hadas <[email protected]> wrote:
- According to the Virtio specification, a device has only two states:
RUNNING and STOPPED. Consequently, certain VFIO transitions (e.g.,RUNNING_P2P->STOP,STOP->RUNNING_P2P) are treated as no-ops. When transitioning toRUNNING_P2P, the device state is set to STOP and remains STOPPED until it transitions back fromRUNNING_P2P->RUNNING, at which point it resumes its RUNNING state.
Does this assume the virtio device is not a DMA target for another device? If so, how can we make such an assumption? Otherwise, what happens on a DMA write to the stopped virtio device?
Quoted 9 lines
- Furthermore, the Virtio specification does not support reading partial or incremental device contexts. This means that during the
PRE_COPYstate, the vfio-virtio driver reads the full device state. This step is beneficial because it allows the device to send some "initial data" before moving to theSTOP_COPYstate, thus reducing downtime by preparing early. To avoid an infinite number of device calls duringPRE_COPY, the vfio-virtio driver limits this flow to a maximum of 128 calls. After reaching this limit, the driver will report zero bytes remaining inPRE_COPY, signaling to QEMU to transition toSTOP_COPY.
If the virtio spec doesn't support partial contexts, what makes it beneficial here? Can you qualify to what extent this initial data improves the overall migration performance?
If it is beneficial, why is it beneficial to send initial data more than once? In particular, what heuristic supports capping iterations at 128? The code also only indicates this is to prevent infinite iterations. Would it be better to rate-limit calls, by reporting no data available for some time interval after the previous call? Thanks,
Alex
Jason Gunthorpe
reviewerQuoted 10 lines · Alex Williamson
Quoted 7 lines · On Sun, 27 Oct 2024 12:07:44 +0200 Yishai Hadas <[email protected]> wrote:
- According to the Virtio specification, a device has only two states:
RUNNING and STOPPED. Consequently, certain VFIO transitions (e.g.,RUNNING_P2P->STOP,STOP->RUNNING_P2P) are treated as no-ops. When transitioning toRUNNING_P2P, the device state is set to STOP and remains STOPPED until it transitions back fromRUNNING_P2P->RUNNING, at which point it resumes its RUNNING state.
Quoted 3 lines
Does this assume the virtio device is not a DMA target for another device? If so, how can we make such an assumption? Otherwise, what happens on a DMA write to the stopped virtio device?
I was told the virtio spec says that during VFIO STOP it only stops doing outgoing DMA, it still must accept incoming operations.
It was a point of debate if the additional step (stop everything vs stop outgoing only) was necessary and the virtio folks felt that stop outgoing was good enough.
Quoted 2 lines
If the virtio spec doesn't support partial contexts, what makes it beneficial here?
It stil lets the receiver 'warm up', like allocating memory and approximately sizing things.
Quoted 2 lines
If it is beneficial, why is it beneficial to send initial data more than once?
I guess because it is allowed to change and the benefit is highest when the pre copy data closely matches the final data..
Rate limiting does seem better to me
Jason
Quoted 5 lines · On Mon, 28 Oct 2024 13:23:54 -0300 Jason Gunthorpe <[email protected]> wrote:
Quoted 2 lines · Alex Williamson
If the virtio spec doesn't support partial contexts, what makes it beneficial here?
Quoted 8 lines
It stil lets the receiver 'warm up', like allocating memory and approximately sizing things.
Quoted 2 lines
If it is beneficial, why is it beneficial to send initial data more than once?
I guess because it is allowed to change and the benefit is highest when the pre copy data closely matches the final data..
It would be useful to see actual data here. For instance, what is the latency advantage to allocating anything in the warm-up and what's the probability that allocation is simply refreshed versus starting over?
Re-sending the initial data up to some arbitrary cap sounds more like we're making a policy decision in the driver to consume more migration bandwidth for some unknown latency trade-off at stop-copy. I wonder if that advantage disappears if the pre-copy data is at all stale relative to the current device state. Thanks,
Alex
Quoted 18 lines
From: Alex Williamson <[email protected]>
Sent: Monday, October 28, 2024 10:24 PMQuoted 11 lines · On Mon, 28 Oct 2024 13:23:54 -0300 Jason Gunthorpe <[email protected]> wrote:
Quoted 2 lines · Alex Williamson
If the virtio spec doesn't support partial contexts, what makes it beneficial here?
It stil lets the receiver 'warm up', like allocating memory and approximately sizing things.
Quoted 2 lines
If it is beneficial, why is it beneficial to send initial data more than once?
Quoted 7 lines
Quoted 2 lines
I guess because it is allowed to change and the benefit is highest when the pre copy data closely matches the final data..
It would be useful to see actual data here. For instance, what is the latency advantage to allocating anything in the warm-up and what's the probability that allocation is simply refreshed versus starting over?
Allocating everything during the warm-up phase, compared to no allocation, reduced the total VM downtime from 439 ms to 128 ms. This was tested using two PCI VF hardware devices per VM.
The benefit comes from the device state staying mostly the same.
We tested with different configurations from 1 to 4 devices per VM, varied with vcpus and memory. Also, more detailed test results are captured in Figure-2 on page 6 at [1].
The commit log for patch-7 should have captured the perf summary table for the value of the 7th patch.
Yishai,
If you are planning to send next revision, please add it.
Quoted 6 lines
Re-sending the initial data up to some arbitrary cap sounds more like we're making a policy decision in the driver to consume more migration bandwidth for some unknown latency trade-off at stop-copy. I wonder if that advantage disappears if the pre-copy data is at all stale relative to the current device state. Thanks,
You're right. If the pre-copy data differs significantly from the current device state, the benefits might be lost. However, this can also depend on the device's design. A more advanced device could apply a low-pass filter to avoid unnecessary refreshes.
Quoted 1 line
Alex
[1] https://netdevconf.info/0x18/docs/netdev-0x18-paper22-talk-paper.pdf
Quoted 29 lines · On Mon, 28 Oct 2024 17:46:57 +0000 Parav Pandit <[email protected]> wrote:
Quoted 17 lines
From: Alex Williamson <[email protected]>
Sent: Monday, October 28, 2024 10:24 PMQuoted 11 lines · On Mon, 28 Oct 2024 13:23:54 -0300 Jason Gunthorpe <[email protected]> wrote:
Quoted 2 lines · Alex Williamson
If the virtio spec doesn't support partial contexts, what makes it beneficial here?
It stil lets the receiver 'warm up', like allocating memory and approximately sizing things.
Quoted 2 lines
If it is beneficial, why is it beneficial to send initial data more than once?
Quoted 7 lines
Quoted 2 lines
I guess because it is allowed to change and the benefit is highest when the pre copy data closely matches the final data..
It would be useful to see actual data here. For instance, what is the latency advantage to allocating anything in the warm-up and what's the probability that allocation is simply refreshed versus starting over?
Allocating everything during the warm-up phase, compared to no allocation, reduced the total VM downtime from 439 ms to 128 ms. This was tested using two PCI VF hardware devices per VM.
Quoted 5 lines
The benefit comes from the device state staying mostly the same.
We tested with different configurations from 1 to 4 devices per VM, varied with vcpus and memory. Also, more detailed test results are captured in Figure-2 on page 6 at [1].
Those numbers seems to correspond to column 1 of Figure 2 in the referenced document, but that's looking only at downtime. To me that chart seems to show a step function where there's ~400ms of downtime per device, which suggests we're serializing device resume in the stop-copy phase on the target without pre-copy.
Figure 3 appears to look at total VM migration time, where pre-copy tends to show marginal improvements in smaller configurations, but up to 60% worse overall migration time as the vCPU, device, and VM memory size increase. The paper comes to the conclusion:
It can be concluded that either of increasing the VM memory or device configuration has equal effect on the VM total migration time, but no effect on the VM downtime due to pre-copy enablement.
Noting specifically "downtime" here ignores that the overall migration time actually got worse with pre-copy.
Between columns 10 & 11 the device count is doubled. With pre-copy enabled, the migration time increases by 135% while with pre-copy disabled we only only see a 113% increase. Between columns 11 & 12 the VM memory is further doubled. This results in another 33% increase in migration time with pre-copy enabled and only a 3% increase with pre-copy disabled. For the most part this entire figure shows that overall migration time with pre-copy enabled is either on par with or worse than the same with pre-copy disabled.
We then move on to Tables 1 & 2, which are again back to specifically showing timing of operations related to downtime rather than overall migration time. The notable thing here seems to be that we've amortized the 300ms per device load time across the pre-copy phase, leaving only 11ms per device contributing to downtime.
However, the paper also goes into this tangent:
Our observations indicate that enabling device-level pre-copy results in more pre-copy operations of the system RAM and device state. This leads to a 50% reduction in memory (RAM) copy time in the device pre-copy method in the micro-benchmark results, saving 100 milliseconds of downtime.
I'd argue that this is an anti-feature. A less generous interpretation is that pre-copy extended the migration time, likely resulting in more RAM transfer during pre-copy, potentially to the point that the VM undershot its prescribed downtime. Further analysis should also look at the total data transferred for the migration and adherence to the configured VM downtime, rather than just the absolute downtime.
At the end of the paper, I think we come to the same conclusion shown in Figure 1, where device load seems to be serialized and therefore significantly limits scalability. That could be parallelized, but even 300-400ms for loading all devices is still too much contribution to downtime. I'd therefore agree that pre-loading the device during pre-copy improves the scaling by an order of magnitude, but it doesn't solve the scaling problem. Also, it should not come with the cost of drawing out pre-copy and thus the overall migration time to this extent. The reduction in downtime related to RAM copy time should be evidence that the pre-copy behavior here has exceeded its scope and is interfering with the balance between pre- and post- copy elsewhere. Thanks,
Alex
Quoted 3 lines
[1] https://netdevconf.info/0x18/docs/netdev-0x18-paper22-talk-paper.pdf
Quoted 37 lines
From: Alex Williamson <[email protected]>
Sent: Wednesday, October 30, 2024 1:58 AMQuoted 17 lines · On Mon, 28 Oct 2024 17:46:57 +0000 Parav Pandit <[email protected]> wrote:
Quoted 17 lines
From: Alex Williamson <[email protected]>
Sent: Monday, October 28, 2024 10:24 PMQuoted 11 lines · On Mon, 28 Oct 2024 13:23:54 -0300 Jason Gunthorpe <[email protected]> wrote:
Quoted 2 lines · Alex Williamson
If the virtio spec doesn't support partial contexts, what makes it beneficial here?
It stil lets the receiver 'warm up', like allocating memory and approximately sizing things.
Quoted 2 lines
If it is beneficial, why is it beneficial to send initial data more than once?
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
I guess because it is allowed to change and the benefit is highest when the pre copy data closely matches the final data..
It would be useful to see actual data here. For instance, what is the latency advantage to allocating anything in the warm-up and what's the probability that allocation is simply refreshed versus starting
over?
Quoted 6 lines
Quoted 1 line
Allocating everything during the warm-up phase, compared to no allocation, reduced the total VM downtime from 439 ms to 128 ms. This was tested using two PCI VF hardware devices per VM.
Quoted 8 lines
Quoted 5 lines
The benefit comes from the device state staying mostly the same.
We tested with different configurations from 1 to 4 devices per VM, varied with vcpus and memory. Also, more detailed test results are captured in Figure-2 on page 6 at [1].
Those numbers seems to correspond to column 1 of Figure 2 in the referenced document, but that's looking only at downtime.
Yes.
What do you mean by only looking at the downtime?
The intention was to measure the downtime in various configurations.
Do you mean, we should have looked at migration bandwidth, migration amount of data, migration time too? If so, yes, some of them were not considered as the focus was on two things:
a. total VM downtime
b. total migration time
But with recent tests, we looked at more things. Explained more below.
Quoted 5 lines
To me that chart
seems to show a step function where there's ~400ms of downtime per device, which suggests we're serializing device resume in the stop-copy phase on the target without pre-copy.
Yes. even without serialization, when there is single device, same bottleneck can be observed. And your orthogonal suggestion of using parallelism is very useful.
The paper captures this aspect in text on page 7 after the Table 2.
Quoted 13 lines
Figure 3 appears to look at total VM migration time, where pre-copy tends to show marginal improvements in smaller configurations, but up to 60% worse overall migration time as the vCPU, device, and VM memory size increase. The paper comes to the conclusion:
It can be concluded that either of increasing the VM memory or device configuration has equal effect on the VM total migration time, but no effect on the VM downtime due to pre-copy enablement.
Noting specifically "downtime" here ignores that the overall migration time actually got worse with pre-copy.
Quoted 9 lines
Between columns 10 & 11 the device count is doubled. With pre-copy enabled, the migration time increases by 135% while with pre-copy disabled we only only see a 113% increase. Between columns 11 & 12 the VM memory is further doubled. This results in another 33% increase in migration time with pre-copy enabled and only a 3% increase with pre-copy disabled. For the most part this entire figure shows that overall migration time with pre-copy enabled is either on par with or worse than the same with pre-copy disabled.
I will answer this part in more detail towards the end of the email.
Quoted 3 lines
We then move on to Tables 1 & 2, which are again back to specifically showing timing of operations related to downtime rather than overall migration time.
Yes, because the objective was to analyze the effects and improvements on downtime of various configurations of device, VM, pre-copy.
Quoted 4 lines
The notable thing here seems to be that we've amortized
the 300ms per device load time across the pre-copy phase, leaving only 11ms per device contributing to downtime.
Correct.
Quoted 8 lines
However, the paper also goes into this tangent:
Our observations indicate that enabling device-level pre-copy results in more pre-copy operations of the system RAM and device state. This leads to a 50% reduction in memory (RAM) copy time in the device pre-copy method in the micro-benchmark results, saving 100 milliseconds of downtime.
Quoted 4 lines
I'd argue that this is an anti-feature. A less generous interpretation is that pre-copy extended the migration time, likely resulting in more RAM transfer during pre-copy, potentially to the point that the VM undershot its prescribed downtime.
VM downtime was close to the configured downtime, on slightly higher side.
Quoted 4 lines
Further analysis should also look at the total data transferred for the migration and adherence to the configured VM downtime, rather than just the absolute downtime.
We did look the device side total data transferred to see how many iterations of pre-copy done.
Quoted 6 lines
At the end of the paper, I think we come to the same conclusion shown in Figure 1, where device load seems to be serialized and therefore significantly limits scalability. That could be parallelized, but even 300-400ms for loading all devices is still too much contribution to downtime. I'd therefore agree that pre-loading the device during pre-copy improves the scaling by an order of magnitude,
Yep.
Quoted 1 line
but it doesn't solve the scaling problem.
Yes, your suggestion is very valid.
Parallel operation from the qemu would make the downtime even smaller. The paper also highlighted this in page 7 after Table-2.
Quoted 3 lines
Also, it should not
come with the cost of drawing out pre-copy and thus the overall migration time to this extent.
Right. You pointed out rightly.
So we did several more tests in last 2 days for insights you provided. And found an interesting outcome.
In 30+ samples, we collected for each,
(a) pre-copy enabled and
(b) pre-copy disabled.
This was done for column 10 and 11.
The VM total migration time varied in range of 13 seconds to 60 seconds. Most noticeably with pre-copy off also it varied in such large range.
In the paper it was pure co-incidence that every time pre-copy=on had higher migration time compared to pre-copy=on. This led us to misguide that pre-copy influenced the higher migration time.
After some reason, we found the QEMU anomaly which was fixed/overcome by the knob " avail-switchover-bandwidth". Basically the bandwidth calculation was not accurate, due to which the migration time fluctuated a lot. This problem and solution are described in [2].
Following the solution_2,
We ran exact same tests of column 10 and 11, with " avail-switchover-bandwidth" configured. With that for both the modes pre-copy=on and off the total migration time stayed constant to 14-15 seconds.
And this conclusion aligns with your analysis that "pre-copy should not extent the migration time to this much". Great finding, proving that figure_3 was incomplete in the paper.
Quoted 3 lines
The reduction in downtime related to RAM copy time
should be evidence that the pre-copy behavior here has exceeded its scope and is interfering with the balance between pre- and post- copy elsewhere.
As I explained above, pre-copy did its job, it didn't interfere. It was just not enough and right samples to analyze back then. Now it is resolved. Thanks a lot for the direction.
Quoted 8 lines
Thanks,
Alex
Quoted 4 lines
[1]
https://netdevconf.info/0x18/docs/netdev-0x18-paper22-talk-paper.pdf
Quoted 38 lines · On Thu, 31 Oct 2024 15:04:51 +0000 Parav Pandit <[email protected]> wrote:
Quoted 38 lines
From: Alex Williamson <[email protected]>
Sent: Wednesday, October 30, 2024 1:58 AMQuoted 17 lines · On Mon, 28 Oct 2024 17:46:57 +0000 Parav Pandit <[email protected]> wrote:
Quoted 17 lines
From: Alex Williamson <[email protected]>
Sent: Monday, October 28, 2024 10:24 PMQuoted 11 lines · On Mon, 28 Oct 2024 13:23:54 -0300 Jason Gunthorpe <[email protected]> wrote:
Quoted 2 lines · Alex Williamson
If the virtio spec doesn't support partial contexts, what makes it beneficial here?
It stil lets the receiver 'warm up', like allocating memory and approximately sizing things.
Quoted 2 lines
If it is beneficial, why is it beneficial to send initial data more than once?
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
I guess because it is allowed to change and the benefit is highest when the pre copy data closely matches the final data..
It would be useful to see actual data here. For instance, what is the latency advantage to allocating anything in the warm-up and what's the probability that allocation is simply refreshed versus starting
over?
Quoted 8 lines
Quoted 1 line
Allocating everything during the warm-up phase, compared to no allocation, reduced the total VM downtime from 439 ms to 128 ms. This was tested using two PCI VF hardware devices per VM.
The benefit comes from the device state staying mostly the same.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
We tested with different configurations from 1 to 4 devices per VM, varied with vcpus and memory. Also, more detailed test results are captured in Figure-2 on page 6 at [1].
Those numbers seems to correspond to column 1 of Figure 2 in the referenced document, but that's looking only at downtime.
Yes.
What do you mean by only looking at the downtime?
It's just a prelude to my interpretation that the paper is focusing mostly on the benefits to downtime and downplaying the apparent longer overall migration time while rationalizing the effect on RAM migration downtime.
Quoted 7 lines
The intention was to measure the downtime in various configurations.
Do you mean, we should have looked at migration bandwidth, migration amount of data, migration time too? If so, yes, some of them were not considered as the focus was on two things:
a. total VM downtime
b. total migration timeBut with recent tests, we looked at more things. Explained more below.
Good. Yes, there should be a more holistic approach, improving the thing we intend to improve without degrading other aspects.
Quoted 87 lines
Quoted 5 lines
To me that chart
seems to show a step function where there's ~400ms of downtime per device, which suggests we're serializing device resume in the stop-copy phase on the target without pre-copy.Yes. even without serialization, when there is single device, same bottleneck can be observed. And your orthogonal suggestion of using parallelism is very useful.
The paper captures this aspect in text on page 7 after the Table 2.Quoted 13 lines
Figure 3 appears to look at total VM migration time, where pre-copy tends to show marginal improvements in smaller configurations, but up to 60% worse overall migration time as the vCPU, device, and VM memory size increase. The paper comes to the conclusion:
It can be concluded that either of increasing the VM memory or device configuration has equal effect on the VM total migration time, but no effect on the VM downtime due to pre-copy enablement.
Noting specifically "downtime" here ignores that the overall migration time actually got worse with pre-copy.
Quoted 9 lines
Between columns 10 & 11 the device count is doubled. With pre-copy enabled, the migration time increases by 135% while with pre-copy disabled we only only see a 113% increase. Between columns 11 & 12 the VM memory is further doubled. This results in another 33% increase in migration time with pre-copy enabled and only a 3% increase with pre-copy disabled. For the most part this entire figure shows that overall migration time with pre-copy enabled is either on par with or worse than the same with pre-copy disabled.
I will answer this part in more detail towards the end of the email.
Quoted 3 lines
We then move on to Tables 1 & 2, which are again back to specifically showing timing of operations related to downtime rather than overall migration time.
Yes, because the objective was to analyze the effects and improvements on downtime of various configurations of device, VM, pre-copy.
Quoted 4 lines
The notable thing here seems to be that we've amortized
the 300ms per device load time across the pre-copy phase, leaving only 11ms per device contributing to downtime.Correct.
Quoted 8 lines
However, the paper also goes into this tangent:
Our observations indicate that enabling device-level pre-copy results in more pre-copy operations of the system RAM and device state. This leads to a 50% reduction in memory (RAM) copy time in the device pre-copy method in the micro-benchmark results, saving 100 milliseconds of downtime.
Quoted 4 lines
I'd argue that this is an anti-feature. A less generous interpretation is that pre-copy extended the migration time, likely resulting in more RAM transfer during pre-copy, potentially to the point that the VM undershot its prescribed downtime.
VM downtime was close to the configured downtime, on slightly higher side.
Quoted 4 lines
Further analysis should also look at the total data transferred for the migration and adherence to the configured VM downtime, rather than just the absolute downtime.
We did look the device side total data transferred to see how many iterations of pre-copy done.
Quoted 6 lines
At the end of the paper, I think we come to the same conclusion shown in Figure 1, where device load seems to be serialized and therefore significantly limits scalability. That could be parallelized, but even 300-400ms for loading all devices is still too much contribution to downtime. I'd therefore agree that pre-loading the device during pre-copy improves the scaling by an order of magnitude,
Yep.
Quoted 1 line
but it doesn't solve the scaling problem.
Yes, your suggestion is very valid.
Parallel operation from the qemu would make the downtime even smaller. The paper also highlighted this in page 7 after Table-2.Quoted 3 lines
Also, it should not
come with the cost of drawing out pre-copy and thus the overall migration time to this extent.Right. You pointed out rightly.
So we did several more tests in last 2 days for insights you provided. And found an interesting outcome.In 30+ samples, we collected for each,
(a) pre-copy enabled and
(b) pre-copy disabled.
Quoted 7 lines
This was done for column 10 and 11.
The VM total migration time varied in range of 13 seconds to 60 seconds. Most noticeably with pre-copy off also it varied in such large range.
In the paper it was pure co-incidence that every time pre-copy=on had higher migration time compared to pre-copy=on. This led us to
Assuming typo here, =on vs =off.
Quoted 13 lines
misguide that pre-copy influenced the higher migration time.
After some reason, we found the QEMU anomaly which was fixed/overcome by the knob " avail-switchover-bandwidth". Basically the bandwidth calculation was not accurate, due to which the migration time fluctuated a lot. This problem and solution are described in [2].
Following the
solution_2,
We ran exact same tests of column 10 and 11, with " avail-switchover-bandwidth" configured. With that for both the modes pre-copy=on and off the total migration time stayed constant to 14-15 seconds.
Quoted 3 lines
And this conclusion aligns with your analysis that "pre-copy should not extent the migration time to this much". Great finding, proving that
figure_3was incomplete in the paper.
Great! So with this the difference in downtime related to RAM migration in the trailing tables of the paper becomes negligible? Is this using the originally proposed algorithm of migrating device data up to 128 consecutive times or is it using rate-limiting of device data in pre-copy? Any notable differences between those algorithms?
Quoted 7 lines
Quoted 4 lines
The reduction in downtime related to RAM copy time should be evidence that the pre-copy behavior here has exceeded its scope and is interfering with the balance between pre- and post- copy elsewhere.
As I explained above, pre-copy did its job, it didn't interfere. It was just not enough and right samples to analyze back then. Now it is resolved. Thanks a lot for the direction.
Glad we could arrive at a better understanding overall. Thanks,
Alex
Quoted 49 lines
From: Alex Williamson <[email protected]>
Sent: Friday, November 1, 2024 9:55 PMQuoted 43 lines · On Thu, 31 Oct 2024 15:04:51 +0000 Parav Pandit <[email protected]> wrote:
Quoted 43 lines
From: Alex Williamson <[email protected]>
Sent: Wednesday, October 30, 2024 1:58 AMQuoted 17 lines · On Mon, 28 Oct 2024 17:46:57 +0000 Parav Pandit <[email protected]> wrote:
Quoted 17 lines
From: Alex Williamson <[email protected]>
Sent: Monday, October 28, 2024 10:24 PMQuoted 11 lines · On Mon, 28 Oct 2024 13:23:54 -0300 Jason Gunthorpe <[email protected]> wrote:
Quoted 2 lines · Alex Williamson
If the virtio spec doesn't support partial contexts, what makes it beneficial here?
It stil lets the receiver 'warm up', like allocating memory and approximately sizing things.
Quoted 2 lines
If it is beneficial, why is it beneficial to send initial data more than once?
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
I guess because it is allowed to change and the benefit is highest when the pre copy data closely matches the final data..
It would be useful to see actual data here. For instance, what is the latency advantage to allocating anything in the warm-up and what's the probability that allocation is simply refreshed versus starting
over?
Quoted 11 lines
Quoted 1 line
Allocating everything during the warm-up phase, compared to no allocation, reduced the total VM downtime from 439 ms to 128 ms. This was tested using two PCI VF hardware devices per VM.
The benefit comes from the device state staying mostly the same.
We tested with different configurations from 1 to 4 devices per VM, varied with vcpus and memory. Also, more detailed test results are captured in Figure-2 on page 6 at [1].
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
Those numbers seems to correspond to column 1 of Figure 2 in the referenced document, but that's looking only at downtime.
Yes.
What do you mean by only looking at the downtime?It's just a prelude to my interpretation that the paper is focusing mostly on the benefits to downtime and downplaying the apparent longer overall migration time while rationalizing the effect on RAM migration downtime.
Now after the new debug we shared, we know the other areas too.
Quoted 4 lines
Quoted 2 lines
The intention was to measure the downtime in various configurations. Do you mean, we should have looked at migration bandwidth, migration
amount of data, migration time too?
Quoted 1 line
If so, yes, some of them were not considered as the focus was on two
Quoted 9 lines
things:
Quoted 4 lines
a. total VM downtime
b. total migration timeBut with recent tests, we looked at more things. Explained more below.
Good. Yes, there should be a more holistic approach, improving the thing we intend to improve without degrading other aspects.
Yes.
Quoted 96 lines
Quoted 6 lines
Quoted 5 lines
To me that chart
seems to show a step function where there's ~400ms of downtime per device, which suggests we're serializing device resume in the stop-copy phase on the target without pre-copy.Yes. even without serialization, when there is single device, same bottleneck
can be observed.
Quoted 6 lines
And your orthogonal suggestion of using parallelism is very useful. The paper captures this aspect in text on page 7 after the Table 2.
Quoted 3 lines
Figure 3 appears to look at total VM migration time, where pre-copy tends to show marginal improvements in smaller configurations, but up to 60% worse overall migration time as the vCPU, device, and VM
memory size increase.
Quoted 19 lines
Quoted 10 lines
The paper comes to the conclusion:
It can be concluded that either of increasing the VM memory or device configuration has equal effect on the VM total migration time, but no effect on the VM downtime due to pre-copy enablement.
Noting specifically "downtime" here ignores that the overall migration time actually got worse with pre-copy.
Quoted 9 lines
Between columns 10 & 11 the device count is doubled. With pre-copy enabled, the migration time increases by 135% while with pre-copy disabled we only only see a 113% increase. Between columns 11 & 12 the VM memory is further doubled. This results in another 33% increase in migration time with pre-copy enabled and only a 3% increase with pre-copy disabled. For the most part this entire figure shows that overall migration time with pre-copy enabled is either on par with or worse than the same with pre-copy disabled.
Quoted 4 lines
I will answer this part in more detail towards the end of the email.
Quoted 2 lines
We then move on to Tables 1 & 2, which are again back to specifically showing timing of operations related to downtime rather than
overall
Quoted 2 lines
Quoted 1 line
migration time.
Yes, because the objective was to analyze the effects and improvements on
downtime of various configurations of device, VM, pre-copy.
Quoted 18 lines
Quoted 5 lines
The notable thing here seems to be that we've amortized the 300ms per device load time across the pre-copy phase, leaving only 11ms per device contributing to downtime.
Correct.
Quoted 11 lines
However, the paper also goes into this tangent:
Our observations indicate that enabling device-level pre-copy results in more pre-copy operations of the system RAM and device state. This leads to a 50% reduction in memory (RAM) copy time in the device pre-copy method in the micro-benchmark results, saving 100 milliseconds of downtime.
I'd argue that this is an anti-feature. A less generous interpretation is that pre-copy extended the migration time, likely resulting in more RAM transfer during pre-copy, potentially to the point
that the VM undershot its
Quoted 8 lines
Quoted 1 line
prescribed downtime.
VM downtime was close to the configured downtime, on slightly higher side.
Quoted 4 lines
Further analysis should also look at the total data transferred for the migration and adherence to the configured VM downtime, rather than just the absolute downtime.
We did look the device side total data transferred to see how many iterations
of pre-copy done.
Quoted 6 lines
Quoted 6 lines
At the end of the paper, I think we come to the same conclusion shown in Figure 1, where device load seems to be serialized and therefore significantly limits scalability. That could be parallelized, but even 300-400ms for loading all devices is still too much contribution to downtime. I'd therefore agree that pre-loading
the device during pre-copy improves the scaling by an order
Quoted 20 lines
Quoted 1 line
of magnitude,
Yep.
Quoted 1 line
but it doesn't solve the scaling problem.
Yes, your suggestion is very valid.
Parallel operation from the qemu would make the downtime even smaller. The paper also highlighted this in page 7 after Table-2.Quoted 3 lines
Also, it should not
come with the cost of drawing out pre-copy and thus the overall migration time to this extent.Right. You pointed out rightly.
So we did several more tests in last 2 days for insights you provided. And found an interesting outcome.In 30+ samples, we collected for each,
(a) pre-copy enabled and
(b) pre-copy disabled.This was done for column 10 and 11.
Quoted 8 lines
Quoted 5 lines
The VM total migration time varied in range of 13 seconds to 60 seconds. Most noticeably with pre-copy off also it varied in such large range.
In the paper it was pure co-incidence that every time pre-copy=on had higher migration time compared to pre-copy=on. This led us to
Assuming typo here, =on vs =off.
Correct it is pre-copy=off.
Quoted 13 lines
Quoted 13 lines
misguide that pre-copy influenced the higher migration time.
After some reason, we found the QEMU anomaly which was fixed/overcome by the knob " avail-switchover-bandwidth". Basically the bandwidth calculation was not accurate, due to which the migration time fluctuated a lot. This problem and solution are described in [2].
Following the
solution_2,
We ran exact same tests of column 10 and 11, with " avail-switchover-bandwidth" configured. With that for both the modes pre-copy=on and off the total migration time stayed constant to 14-15 seconds.
Quoted 6 lines
Quoted 3 lines
And this conclusion aligns with your analysis that "pre-copy should not extent the migration time to this much". Great finding, proving that
figure_3was incomplete in the paper.Great! So with this the difference in downtime related to RAM migration in the trailing tables of the paper becomes negligible?
Yes.
Quoted 3 lines
Is this using the originally
proposed algorithm of migrating device data up to 128 consecutive times or is it using rate-limiting of device data in pre-copy?
Both. Yishai has new rate limiting based algorithm which also has similar results.
Quoted 3 lines
Any notable differences
between those algorithms?
No significant differences.
Vfio level data transfer size is less now, as the frequency is reduced with your suggested algorithm.
Quoted 11 lines
Quoted 7 lines
Quoted 4 lines
The reduction in downtime related to RAM copy time should be evidence that the pre-copy behavior here has exceeded its scope and is interfering with the balance between pre- and post- copy elsewhere.
As I explained above, pre-copy did its job, it didn't interfere. It was just not enough and right samples to analyze back then. Now it is resolved. Thanks a lot for the direction.
Glad we could arrive at a better understanding overall. Thanks,
Alex
Yishai Hadas
maintainerQuoted 12 lines · Jason Gunthorpe
Quoted 4 lines · Alex Williamson
On Sun, 27 Oct 2024 12:07:44 +0200
Yishai Hadas <[email protected]> wrote:
If the virtio spec doesn't support partial contexts, what makes it beneficial here?It stil lets the receiver 'warm up', like allocating memory and approximately sizing things.
Quoted 2 lines
If it is beneficial, why is it beneficial to send initial data more than once?
Quoted 6 lines
I guess because it is allowed to change and the benefit is highest when the pre copy data closely matches the final data..
Rate limiting does seem better to me
Jason
Right, given that the device state is likely to remain mostly unchanged over a certain period, using a rate limiter could be a sensible approach.
So, in V1, I plan to replace the hard-coded limit value of 128 with a rate limiter by reporting no data available for some time interval after the previous call.
I would start with a one second interval, which seems to be reasonable for that kind of device.
Yishai
Quoted 2 lines · On Sun, 27 Oct 2024 12:07:44 +0200 Yishai Hadas <[email protected]> wrote:
This series enhances the vfio-virtio driver to support live migration for virtio-net Virtual Functions (VFs) that are migration-capable.
What's the status of making virtio-net VFs in QEMU migration capable?
There would be some obvious benefits for the vfio migration ecosystem if we could validate migration of a functional device (ie. not mtty) in an L2 guest with no physical hardware dependencies. Thanks,
Alex
Yishai Hadas
maintainerQuoted 7 lines · Alex Williamson
Quoted 2 lines · On Sun, 27 Oct 2024 12:07:44 +0200 Yishai Hadas <[email protected]> wrote:
This series enhances the vfio-virtio driver to support live migration for virtio-net Virtual Functions (VFs) that are migration-capable.
What's the status of making virtio-net VFs in QEMU migration capable?
Currently, we don’t have plans to make virtio-net VFs in QEMU migration-capable.
Quoted 7 lines
There would be some obvious benefits for the vfio migration ecosystem if we could validate migration of a functional device (ie. not mtty) in an L2 guest with no physical hardware dependencies. Thanks,
Alex
Right, software testing could be beneficial, however, we are not the ones who own or perform software simulation and its related tasks inside QEMU.
So, this task could be considered in the future once its HOST side is actually accepted.
Yishai