vfio/migration: Implement VFIO migration protocol v2
v10 cover vfio/migration: Implement VFIO migration protocol v2
Hello,
This v10 is rebased over Juan's pull request [1] which made some changes to the migration handlers. Therefore, I had to do some more significant changes to the main patch (#9) and thus removed Cedric's R-b. The full changelog is below.
Following VFIO migration protocol v2 acceptance in kernel, this series implements VFIO migration according to the new v2 protocol and replaces the now deprecated v1 implementation.
The main differences between v1 and v2 migration protocols are:
1. VFIO device state is represented as a finite state machine instead of a bitmap.
2. The migration interface with kernel is done using VFIO_DEVICE_FEATURE ioctl and normal read() and write() instead of the migration region used in v1.
3. Pre-copy is made optional in v2 protocol. Support for pre-copy will be added later on.
Full description of the v2 protocol and the differences from v1 can be found here [2].
Patch list:
Patch 1 updates linux headers so we will have the MIG_DATA_SIZE ioctl.
Patches 2-8 are prep patches fixing bugs, adding QEMUFile function that will be used later and refactoring v1 protocol code to make it easier to add v2 protocol.
Patches 9-12 implement v2 protocol and remove v1 protocol.
Thanks.
Changes from v9 [3]:
- Rebased on latest master branch. As part of it:
1. Dropped patch #2 as it was merged in Juan's pull req already.
2. Dropped patch #11 (vfio_save_pending() optimization). With Juan's changes we can achieve this optimization by implementing only .state_pending_exact() handler and not a .state_pending_estimate() handler (see comment in code).
3. Some function refactoring to be aligned with Juan's changes.
- Made multiple_devices_migration_blocker static (Cedric).
- Addressed Alex's comments:
1. Changed multiple devices migration block/unblock logic.
2. Removed recover_state local variable in vfio_save_complete_precopy().
3. Added comments explaining the purpose of ERROR state usage as a recover state (three places).
4. Changed vfio_migration_set_state() to directly reset the device if ERROR is given as recover_state, instead of setting the device in ERROR state, failing and only then resetting the device.
5. Added a note in VFIO migration documentation that migration is supported only with a single device.
Changes from v8 [4]:
- Added patch that blocks migration of multiple devices. As discussed, this is necessary since VFIO migration doesn't support P2P yet.
- Removed unnecessary P2P code. This should be added when P2P support is added.
- Fixed vfio_save_block() comment to say -errno is returned on error.
- Added Reviewed-by tag to linux headers sync patch.
Changes from v7 [5]:
- Fixed compilation error on windows in patch #9 reported by Cedric.
Changes from v6 [6]:
- Fixed another compilation error in patch #9 reported by Cedric.
- Added Reviewed-by tags.
Changes from v5 [7]:
- Dropped patch #3.
- Simplified patch #5 as per Alex's suggestion.
- Changed qemu_file_get_to_fd() to return -EIO instead of -1, as suggested by Cedric.
Also changed it so now write returns -errno instead of -1 on error.
- Fixed compilation error reported by Cedric.
- Changed vfio_migration_query_flags() to print error message and return -errno in error case as suggested by Cedric.
- Added Reviewed-by tags.
Changes from v4 [8]:
- Rebased on latest master branch.
- Added linux header update to kernel v6.2-rc1.
- Merged preview patches (#13-14) into this series.
Changes from v3 [9]:
- Rebased on latest master branch.
- Dropped patch #1 "migration: Remove res_compatible parameter" as it's not mandatory to this series and needs some further discussion.
- Dropped patch #3 "migration: Block migration comment or code is wrong" as it has been merged already.
- Addressed overlooked corner case reported by Vladimir in patch #4 "migration: Simplify migration_iteration_run()".
- Dropped patch #5 "vfio/migration: Fix wrong enum usage" as it has been merged already.
- In patch #12 "vfio/migration: Implement VFIO migration protocol v2":
1. Changed vfio_save_pending() to update res_precopy_only instead of res_postcopy_only (as VFIO migration doesn’t support postcopy).
2. Moved VFIOMigration->data_buffer allocation to vfio_save_setup() and its de-allocation to vfio_save_cleanup(), so now it's allocated when actually used (during migration and only on source side).
- Addressed Alex's comments:
1. Eliminated code duplication in patch #7 "vfio/migration: Allow migration without VFIO IOMMU dirty tracking support".
2. Removed redundant initialization of vfio_region_info in patch #10 "vfio/migration: Move migration v1 logic to vfio_migration_init()".
3. Added comment about VFIO_MIG_DATA_BUFFER_SIZE heuristic (and renamed to VFIO_MIG_DEFAULT_DATA_BUFFER_SIZE).
4. Cast migration structs to their actual types instead of void *.
5. Return -errno and -EBADF instead of -1 in vfio_migration_set_state().
6. Set migration->device_state to new_state even in case of data_fd out of sync. Although migration will be aborted, setting device state succeeded so we should reflect that.
7. Renamed VFIO_MIG_PENDING_SIZE to VFIO_MIG_STOP_COPY_SIZE, set it to 100G and added a comment about the size choice.
8. Changed vfio_save_block() to return -errno on error.
9. Squashed Patch #14 to patch #12.
10. Adjusted migration data buffer size according to MIG_DATA_SIZE ioctl.
- In preview patch #17 "vfio/migration: Query device data size in vfio_save_pending()" - changed vfio_save_pending() to report VFIO_MIG_STOP_COPY_SIZE on any error.
- Added another preview patch "vfio/migration: Optimize vfio_save_pending()".
- Added ret value on some traces as suggested by David.
- Added Reviewed-By tags.
Changes from v2 [10]:
- Rebased on top of latest master branch.
- Added relevant patches from Juan's RFC [11] with minor changes:
1. Added Reviewed-by tag to patch #3 in the RFC.
2. Adjusted patch #6 to work without patch #4 in the RFC.
- Added a new patch "vfio/migration: Fix wrong enum usage" that fixes a small bug in v1 code. This patch has been sent a few weeks ago [12] but wasn't taken yet.
- Patch #2 (vfio/migration: Skip pre-copy if dirty page tracking is not supported):
1. Dropped this patch and replaced it with "vfio/migration: Allow migration without VFIO IOMMU dirty tracking support".
The new patch uses a different approach – instead of skipping pre-copy phase completely, QEMU VFIO code will mark RAM dirty (instead of kernel). This ensures that current migration behavior is not changed and SLA is taken into account.
- Patch #4 (vfio/common: Change vfio_devices_all_running_and_saving() logic to equivalent one):
1. Improved commit message to better explain the change.
- Patch #7 (vfio/migration: Implement VFIO migration protocol v2):
1. Enhanced vfio_migration_set_state() error reporting.
2. In vfio_save_complete_precopy() of v2 protocol - when changing device state to STOP, set recover state to ERROR instead of STOP as suggested by Joao.
3. Constify SaveVMHandlers of v2 protocol.
4. Modified trace_vfio_vmstate_change and trace_vfio_migration_set_state
to print device state string instead of enum.
5. Replaced qemu_put_buffer_async() with qemu_put_buffer() in vfio_save_block(), as requested by Juan.
6. Implemented v2 protocol version of vfio_save_pending() as requested by Juan. Until ioctl to get device state size is added, we just report some big hard coded value, as agreed in KVM call.
- Patch #9 (vfio/migration: Reset device if setting recover state fails):
1. Enhanced error reporting.
2. Set VFIOMigration->device_state to RUNNING after device reset.
- Patch #11 (docs/devel: Align vfio-migration docs to VFIO migration v2):
1. Adjusted vfio migration documentation to the added vfio_save_pending()
- Added the last patch (which is not for merging yet) that demonstrates how the new ioctl to get device state size will work once added.
Changes from v1 [13]:
- Split the big patch that replaced v1 with v2 into several patches as suggested by Joao, to make review easier.
- Change warn_report to warn_report_once when container doesn't support dirty tracking.
- Add Reviewed-by tag.
[1]
https://lore.kernel.org/qemu-devel/[email protected]/
[2]
https://lore.kernel.org/all/[email protected]/
[3]
https://lore.kernel.org/qemu-devel/[email protected]/
[4]
https://lore.kernel.org/qemu-devel/[email protected]/
[5]
https://lore.kernel.org/qemu-devel/[email protected]/
[6]
https://lore.kernel.org/qemu-devel/[email protected]/
[7]
https://lore.kernel.org/qemu-devel/[email protected]/
[8]
https://lore.kernel.org/qemu-devel/[email protected]/
[9]
https://lore.kernel.org/qemu-devel/[email protected]/
[10]
https://lore.kernel.org/all/[email protected]/
[11]
https://lore.kernel.org/qemu-devel/[email protected]/T/
[12]
https://lore.kernel.org/all/[email protected]/
[13]
https://lore.kernel.org/all/[email protected]/
Avihai Horon (12):
linux-headers: Update to v6.2-rc1
vfio/migration: Fix NULL pointer dereference bug vfio/migration: Allow migration without VFIO IOMMU dirty tracking
support
migration/qemu-file: Add qemu_file_get_to_fd() vfio/common: Change vfio_devices_all_running_and_saving() logic to
equivalent one
vfio/migration: Block multiple devices migration vfio/migration: Move migration v1 logic to vfio_migration_init() vfio/migration: Rename functions/structs related to v1 protocol vfio/migration: Implement VFIO migration protocol v2 vfio/migration: Remove VFIO migration protocol v1
vfio: Alphabetize migration section of VFIO trace-events file docs/devel: Align VFIO migration docs to v2 protocol
docs/devel/vfio-migration.rst | 72 +- include/hw/vfio/vfio-common.h | 10 +- include/standard-headers/drm/drm_fourcc.h | 63 +- include/standard-headers/linux/ethtool.h | 81 +- include/standard-headers/linux/fuse.h | 20 +- .../linux/input-event-codes.h | 4 + include/standard-headers/linux/pci_regs.h | 2 + include/standard-headers/linux/virtio_blk.h | 19 + include/standard-headers/linux/virtio_bt.h | 8 + include/standard-headers/linux/virtio_net.h | 4 + linux-headers/asm-arm64/kvm.h | 1 + linux-headers/asm-generic/hugetlb_encode.h | 26 +- linux-headers/asm-generic/mman-common.h | 2 + linux-headers/asm-mips/mman.h | 2 + linux-headers/asm-riscv/kvm.h | 7 + linux-headers/asm-x86/kvm.h | 11 +- linux-headers/linux/kvm.h | 32 +- linux-headers/linux/psci.h | 14 + linux-headers/linux/userfaultfd.h | 4 + linux-headers/linux/vfio.h | 278 ++++++- migration/qemu-file.h | 1 + hw/vfio/common.c | 92 ++- hw/vfio/migration.c | 741 ++++++------------ migration/qemu-file.c | 34 + hw/vfio/trace-events | 28 +- 25 files changed, 940 insertions(+), 616 deletions(-)
Signature · 1 line
2.26.3
PATCH v10 1/12 linux-headers: Update to v6.2-rc1
Update to commit 1b929c02afd3 ("Linux 6.2-rc1").
--- include/standard-headers/drm/drm_fourcc.h | 63 +++- include/standard-headers/linux/ethtool.h | 81 ++++- include/standard-headers/linux/fuse.h | 20 +- .../linux/input-event-codes.h | 4 + include/standard-headers/linux/pci_regs.h | 2 + include/standard-headers/linux/virtio_blk.h | 19 ++ include/standard-headers/linux/virtio_bt.h | 8 + include/standard-headers/linux/virtio_net.h | 4 + linux-headers/asm-arm64/kvm.h | 1 + linux-headers/asm-generic/hugetlb_encode.h | 26 +- linux-headers/asm-generic/mman-common.h | 2 + linux-headers/asm-mips/mman.h | 2 + linux-headers/asm-riscv/kvm.h | 7 + linux-headers/asm-x86/kvm.h | 11 +- linux-headers/linux/kvm.h | 32 +- linux-headers/linux/psci.h | 14 + linux-headers/linux/userfaultfd.h | 4 + linux-headers/linux/vfio.h | 278 +++++++++++++++++- 18 files changed, 522 insertions(+), 56 deletions(-)
include/standard-headers/drm/drm_fourcc.h +59 -4
@@ -98,18 +98,42 @@ extern "C" {#define DRM_FORMAT_INVALID 0/* color index */ +#define DRM_FORMAT_C1 fourcc_code('C', '1', ' ', ' ')/* [7:0] C0:C1:C2:C3:C4:C5:C6:C7 1:1:1:1:1:1:1:1 eight pixels/byte */ +#define DRM_FORMAT_C2 fourcc_code('C', '2', ' ', ' ')/* [7:0] C0:C1:C2:C3 2:2:2:2 four pixels/byte */ +#define DRM_FORMAT_C4 fourcc_code('C', '4', ' ', ' ')/* [7:0] C0:C1 4:4 two pixels/byte */ #define DRM_FORMAT_C8 fourcc_code('C', '8', ' ', ' ')/* [7:0] C */ -/* 8 bpp Red */ +/* 1 bpp Darkness (inverse relationship between channel value and brightness) */ +#define DRM_FORMAT_D1 fourcc_code('D', '1', ' ', ' ')/* [7:0] D0:D1:D2:D3:D4:D5:D6:D7 1:1:1:1:1:1:1:1 eight pixels/byte */ + +/* 2 bpp Darkness (inverse relationship between channel value and brightness) */ +#define DRM_FORMAT_D2 fourcc_code('D', '2', ' ', ' ')/* [7:0] D0:D1:D2:D3 2:2:2:2 four pixels/byte */ + +/* 4 bpp Darkness (inverse relationship between channel value and brightness) */ +#define DRM_FORMAT_D4 fourcc_code('D', '4', ' ', ' ')/* [7:0] D0:D1 4:4 two pixels/byte */ + +/* 8 bpp Darkness (inverse relationship between channel value and brightness) */ +#define DRM_FORMAT_D8 fourcc_code('D', '8', ' ', ' ')/* [7:0] D */ + +/* 1 bpp Red (direct relationship between channel value and brightness) */ +#define DRM_FORMAT_R1 fourcc_code('R', '1', ' ', ' ')/* [7:0] R0:R1:R2:R3:R4:R5:R6:R7 1:1:1:1:1:1:1:1 eight pixels/byte */ + +/* 2 bpp Red (direct relationship between channel value and brightness) */ +#define DRM_FORMAT_R2 fourcc_code('R', '2', ' ', ' ')/* [7:0] R0:R1:R2:R3 2:2:2:2 four pixels/byte */ + +/* 4 bpp Red (direct relationship between channel value and brightness) */ +#define DRM_FORMAT_R4 fourcc_code('R', '4', ' ', ' ')/* [7:0] R0:R1 4:4 two pixels/byte */ + +/* 8 bpp Red (direct relationship between channel value and brightness) */ #define DRM_FORMAT_R8 fourcc_code('R', '8', ' ', ' ')/* [7:0] R */ -/* 10 bpp Red */ +/* 10 bpp Red (direct relationship between channel value and brightness) */ #define DRM_FORMAT_R10 fourcc_code('R', '1', '0', ' ')/* [15:0] x:R 6:10 little endian */ -/* 12 bpp Red */ +/* 12 bpp Red (direct relationship between channel value and brightness) */ #define DRM_FORMAT_R12 fourcc_code('R', '1', '2', ' ')/* [15:0] x:R 4:12 little endian */ -/* 16 bpp Red */ +/* 16 bpp Red (direct relationship between channel value and brightness) */ #define DRM_FORMAT_R16 fourcc_code('R', '1', '6', ' ')/* [15:0] R little endian */ /* 16 bpp RG */
@@ -204,7 +228,9 @@ extern "C" {#define DRM_FORMAT_VYUY fourcc_code('V', 'Y', 'U', 'Y')/* [31:0] Y1:Cb0:Y0:Cr0 8:8:8:8 little endian */ #define DRM_FORMAT_AYUV fourcc_code('A', 'Y', 'U', 'V')/* [31:0] A:Y:Cb:Cr 8:8:8:8 little endian */ +#define DRM_FORMAT_AVUY8888 fourcc_code('A', 'V', 'U', 'Y')/* [31:0] A:Cr:Cb:Y 8:8:8:8 little endian */ #define DRM_FORMAT_XYUV8888 fourcc_code('X', 'Y', 'U', 'V')/* [31:0] X:Y:Cb:Cr 8:8:8:8 little endian */ +#define DRM_FORMAT_XVUY8888 fourcc_code('X', 'V', 'U', 'Y')/* [31:0] X:Cr:Cb:Y 8:8:8:8 little endian */ #define DRM_FORMAT_VUY888 fourcc_code('V', 'U', '2', '4')/* [23:0] Cr:Cb:Y 8:8:8 little endian */ #define DRM_FORMAT_VUY101010 fourcc_code('V', 'U', '3', '0')/* Y followed by U then V, 10:10:10. Non-linear modifier only */
@@ -717,6 +743,35 @@ extern "C" {*/ #define DRM_FORMAT_MOD_VIVANTE_SPLIT_SUPER_TILED fourcc_mod_code(VIVANTE, 4) +/* +* Vivante TS (tile-status) buffer modifiers. They can be combined with all of +* the color buffer tiling modifiers defined above. When TS is present it's a +* separate buffer containing the clear/compression status of each tile. The +* modifiers are defined as VIVANTE_MOD_TS_c_s, where c is the color buffer +* tile size in bytes covered by one entry in the status buffer and s is the +* number of status bits per entry. +* We reserve the top 8 bits of the Vivante modifier space for tile status +* clear/compression modifiers, as future cores might add some more TS layout +* variations. +*/ +#define VIVANTE_MOD_TS_64_4 (1ULL << 48) +#define VIVANTE_MOD_TS_64_2 (2ULL << 48) +#define VIVANTE_MOD_TS_128_4 (3ULL << 48) +#define VIVANTE_MOD_TS_256_4 (4ULL << 48) +#define VIVANTE_MOD_TS_MASK (0xfULL << 48) + +/* +* Vivante compression modifiers. Those depend on a TS modifier being present +* as the TS bits get reinterpreted as compression tags instead of simple +* clear markers when compression is enabled. +*/ +#define VIVANTE_MOD_COMP_DEC400 (1ULL << 52) +#define VIVANTE_MOD_COMP_MASK (0xfULL << 52) + +/* Masking out the extension bits will yield the base modifier. */ +#define VIVANTE_MOD_EXT_MASK (VIVANTE_MOD_TS_MASK | \ + VIVANTE_MOD_COMP_MASK) +/* NVIDIA frame buffer modifiers */ /*
include/standard-headers/linux/ethtool.h +73 -8
130 lines not on this page · raw message
include/standard-headers/linux/fuse.h +18 -2
@@ -194,6 +194,13 @@* - add FUSE_SECURITY_CTX init flag * - add security context to create, mkdir, symlink, and mknod requests * - add FUSE_HAS_INODE_DAX, FUSE_ATTR_DAX +* +* 7.37 +* - add FUSE_TMPFILE +* +* 7.38 +* - add FUSE_EXPIRE_ONLY flag to fuse_notify_inval_entry +* - add FOPEN_PARALLEL_DIRECT_WRITES */ #ifndef _LINUX_FUSE_H
@@ -225,7 +232,7 @@#define FUSE_KERNEL_VERSION 7/** Minor version number of this interface */ -#define FUSE_KERNEL_MINOR_VERSION 36 +#define FUSE_KERNEL_MINOR_VERSION 38/** The node ID of the root inode */ #define FUSE_ROOT_ID 1
@@ -297,6 +304,7 @@ struct fuse_file_lock {* FOPEN_CACHE_DIR: allow caching this directory * FOPEN_STREAM: the file is stream-like (no file position at all) * FOPEN_NOFLUSH: don't flush data cache on close (unless FUSE_WRITEBACK_CACHE) +* FOPEN_PARALLEL_DIRECT_WRITES: Allow concurrent direct writes on the same inode */ #define FOPEN_DIRECT_IO (1 << 0)#define FOPEN_KEEP_CACHE (1 << 1)
@@ -304,6 +312,7 @@ struct fuse_file_lock {#define FOPEN_CACHE_DIR (1 << 3)#define FOPEN_STREAM (1 << 4)#define FOPEN_NOFLUSH (1 << 5) +#define FOPEN_PARALLEL_DIRECT_WRITES (1 << 6)/** * INIT request/reply flags
@@ -484,6 +493,12 @@ struct fuse_file_lock {*/ #define FUSE_SETXATTR_ACL_KILL_SGID (1 << 0) +/** +* notify_inval_entry flags +* FUSE_EXPIRE_ONLY +*/ +#define FUSE_EXPIRE_ONLY (1 << 0) +enum fuse_opcode {FUSE_LOOKUP =1 ,FUSE_FORGET =2 ,/* no reply */
@@ -533,6 +548,7 @@ enum fuse_opcode {FUSE_SETUPMAPPING =48 ,FUSE_REMOVEMAPPING =49 ,FUSE_SYNCFS =50 , +FUSE_TMPFILE =51 ,/* CUSE specific operations */ CUSE_INIT = 4096,
@@ -911,7 +927,7 @@ struct fuse_notify_inval_inode_out {struct fuse_notify_inval_entry_out {uint64_t parent;uint32_t namelen; -uint32_t padding; +uint32_t flags; };struct fuse_notify_delete_out {
include/standard-headers/linux/input-event-codes.h +4 -0
@@ -614,6 +614,9 @@#define KEY_KBD_LAYOUT_NEXT 0x248/* AC Next Keyboard Layout Select */ #define KEY_EMOJI_PICKER 0x249/* Show/hide emoji picker (HUTRR101) */ #define KEY_DICTATE 0x24a/* Start or Stop Voice Dictation Session (HUTRR99) */ +#define KEY_CAMERA_ACCESS_ENABLE 0x24b/* Enables programmatic access to camera devices. (HUTRR72) */ +#define KEY_CAMERA_ACCESS_DISABLE 0x24c/* Disables programmatic access to camera devices. (HUTRR72) */ +#define KEY_CAMERA_ACCESS_TOGGLE 0x24d/* Toggles the current state of the camera access control. (HUTRR72) */ #define KEY_BRIGHTNESS_MIN 0x250/* Set Brightness to Minimum */ #define KEY_BRIGHTNESS_MAX 0x251/* Set Brightness to Maximum */
@@ -862,6 +865,7 @@#define ABS_TOOL_WIDTH 0x1c#define ABS_VOLUME 0x20 +#define ABS_PROFILE 0x21#define ABS_MISC 0x28
include/standard-headers/linux/pci_regs.h +2 -0
@@ -1058,6 +1058,7 @@/* Precision Time Measurement */ #define PCI_PTM_CAP 0x04/* PTM Capability */ #define PCI_PTM_CAP_REQ 0x00000001/* Requester capable */ +#define PCI_PTM_CAP_RES 0x00000002/* Responder capable */ #define PCI_PTM_CAP_ROOT 0x00000004/* Root capable */ #define PCI_PTM_GRANULARITY_MASK 0x0000FF00/* Clock granularity */ #define PCI_PTM_CTRL 0x08/* PTM Control */
@@ -1119,6 +1120,7 @@#define PCI_DOE_STATUS_DATA_OBJECT_READY 0x80000000/* Data Object Ready */ #define PCI_DOE_WRITE 0x10/* DOE Write Data Mailbox Register */ #define PCI_DOE_READ 0x14/* DOE Read Data Mailbox Register */ +#define PCI_DOE_CAP_SIZEOF 0x18/* Size of DOE register block */ /* DOE Data Object - note not actually registers */ #define PCI_DOE_DATA_OBJECT_HEADER_1_VID 0x0000ffff
include/standard-headers/linux/virtio_blk.h +19 -0
@@ -40,6 +40,7 @@#define VIRTIO_BLK_F_MQ 12/* support more than one vq */ #define VIRTIO_BLK_F_DISCARD 13/* DISCARD is supported */ #define VIRTIO_BLK_F_WRITE_ZEROES 14/* WRITE ZEROES is supported */ +#define VIRTIO_BLK_F_SECURE_ERASE 16/* Secure Erase is supported */ /* Legacy feature bits */ #ifndef VIRTIO_BLK_NO_LEGACY
@@ -119,6 +120,21 @@ struct virtio_blk_config {uint8_t write_zeroes_may_unmap;uint8_t unused1[3 ]; + +/* the next 3 entries are guarded by VIRTIO_BLK_F_SECURE_ERASE */ +/* +* The maximum secure erase sectors (in 512-byte sectors) for +* one segment. +*/ +__virtio32 max_secure_erase_sectors; +/* +* The maximum number of secure erase segments in a +* secure erase command. +*/ +__virtio32 max_secure_erase_seg; +/* Secure erase commands must be aligned to this number of sectors. */ +__virtio32 secure_erase_sector_alignment; + }QEMU_PACKED ;/*
@@ -153,6 +169,9 @@ struct virtio_blk_config {/* Write zeroes command */ #define VIRTIO_BLK_T_WRITE_ZEROES 13 +/* Secure erase command */ +#define VIRTIO_BLK_T_SECURE_ERASE 14 +#ifndef VIRTIO_BLK_NO_LEGACY /* Barrier before this op. */ #define VIRTIO_BLK_T_BARRIER 0x80000000
include/standard-headers/linux/virtio_bt.h +8 -0
@@ -9,6 +9,7 @@#define VIRTIO_BT_F_VND_HCI 0/* Indicates vendor command support */ #define VIRTIO_BT_F_MSFT_EXT 1/* Indicates MSFT vendor support */ #define VIRTIO_BT_F_AOSP_EXT 2/* Indicates AOSP vendor support */ +#define VIRTIO_BT_F_CONFIG_V2 3/* Use second version configuration */ enum virtio_bt_config_type {VIRTIO_BT_CONFIG_TYPE_PRIMARY =0 ,
@@ -28,4 +29,11 @@ struct virtio_bt_config { uint16_t msft_opcode; }QEMU_PACKED ; +struct virtio_bt_config_v2 { +uint8_t type; +uint8_t alignment; +uint16_t vendor; +uint16_t msft_opcode; +}; +#endif /* _LINUX_VIRTIO_BT_H */
include/standard-headers/linux/virtio_net.h +4 -0
@@ -57,6 +57,9 @@* Steering */ #define VIRTIO_NET_F_CTRL_MAC_ADDR 23/* Set MAC address */ #define VIRTIO_NET_F_NOTF_COAL 53/* Device supports notifications coalescing */ +#define VIRTIO_NET_F_GUEST_USO4 54/* Guest can handle USOv4 in. */ +#define VIRTIO_NET_F_GUEST_USO6 55/* Guest can handle USOv6 in. */ +#define VIRTIO_NET_F_HOST_USO 56/* Host can handle USO in. */ #define VIRTIO_NET_F_HASH_REPORT 57/* Supports hash report */ #define VIRTIO_NET_F_RSS 60/* Supports RSS RX steering */ #define VIRTIO_NET_F_RSC_EXT 61/* extended coalescing info */
@@ -130,6 +133,7 @@ struct virtio_net_hdr_v1 {#define VIRTIO_NET_HDR_GSO_TCPV4 1/* GSO frame, IPv4 TCP (TSO) */ #define VIRTIO_NET_HDR_GSO_UDP 3/* GSO frame, IPv4 UDP (UFO) */ #define VIRTIO_NET_HDR_GSO_TCPV6 4/* GSO frame, IPv6 TCP */ +#define VIRTIO_NET_HDR_GSO_UDP_L4 5/* GSO frame, IPv4& IPv6 UDP (USO) */ #define VIRTIO_NET_HDR_GSO_ECN 0x80/* TCP has ECN set */ uint8_t gso_type;__virtio16 hdr_len;/* Ethernet + IP + tcp/udp hdrs */
linux-headers/asm-arm64/kvm.h +1 -0
@@ -43,6 +43,7 @@#define __KVM_HAVE_VCPU_EVENTS#define KVM_COALESCED_MMIO_PAGE_OFFSET 1 +#define KVM_DIRTY_LOG_PAGE_OFFSET 64#define KVM_REG_SIZE (id) \ (1U << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT))
linux-headers/asm-generic/hugetlb_encode.h +13 -13
@@ -20,18 +20,18 @@#define HUGETLB_FLAG_ENCODE_SHIFT 26#define HUGETLB_FLAG_ENCODE_MASK 0x3f -#define HUGETLB_FLAG_ENCODE_16KB (14 << HUGETLB_FLAG_ENCODE_SHIFT) -#define HUGETLB_FLAG_ENCODE_64KB (16 << HUGETLB_FLAG_ENCODE_SHIFT) -#define HUGETLB_FLAG_ENCODE_512KB (19 << HUGETLB_FLAG_ENCODE_SHIFT) -#define HUGETLB_FLAG_ENCODE_1MB (20 << HUGETLB_FLAG_ENCODE_SHIFT) -#define HUGETLB_FLAG_ENCODE_2MB (21 << HUGETLB_FLAG_ENCODE_SHIFT) -#define HUGETLB_FLAG_ENCODE_8MB (23 << HUGETLB_FLAG_ENCODE_SHIFT) -#define HUGETLB_FLAG_ENCODE_16MB (24 << HUGETLB_FLAG_ENCODE_SHIFT) -#define HUGETLB_FLAG_ENCODE_32MB (25 << HUGETLB_FLAG_ENCODE_SHIFT) -#define HUGETLB_FLAG_ENCODE_256MB (28 << HUGETLB_FLAG_ENCODE_SHIFT) -#define HUGETLB_FLAG_ENCODE_512MB (29 << HUGETLB_FLAG_ENCODE_SHIFT) -#define HUGETLB_FLAG_ENCODE_1GB (30 << HUGETLB_FLAG_ENCODE_SHIFT) -#define HUGETLB_FLAG_ENCODE_2GB (31 << HUGETLB_FLAG_ENCODE_SHIFT) -#define HUGETLB_FLAG_ENCODE_16GB (34 << HUGETLB_FLAG_ENCODE_SHIFT) +#define HUGETLB_FLAG_ENCODE_16KB (14U << HUGETLB_FLAG_ENCODE_SHIFT) +#define HUGETLB_FLAG_ENCODE_64KB (16U << HUGETLB_FLAG_ENCODE_SHIFT) +#define HUGETLB_FLAG_ENCODE_512KB (19U << HUGETLB_FLAG_ENCODE_SHIFT) +#define HUGETLB_FLAG_ENCODE_1MB (20U << HUGETLB_FLAG_ENCODE_SHIFT) +#define HUGETLB_FLAG_ENCODE_2MB (21U << HUGETLB_FLAG_ENCODE_SHIFT) +#define HUGETLB_FLAG_ENCODE_8MB (23U << HUGETLB_FLAG_ENCODE_SHIFT) +#define HUGETLB_FLAG_ENCODE_16MB (24U << HUGETLB_FLAG_ENCODE_SHIFT) +#define HUGETLB_FLAG_ENCODE_32MB (25U << HUGETLB_FLAG_ENCODE_SHIFT) +#define HUGETLB_FLAG_ENCODE_256MB (28U << HUGETLB_FLAG_ENCODE_SHIFT) +#define HUGETLB_FLAG_ENCODE_512MB (29U << HUGETLB_FLAG_ENCODE_SHIFT) +#define HUGETLB_FLAG_ENCODE_1GB (30U << HUGETLB_FLAG_ENCODE_SHIFT) +#define HUGETLB_FLAG_ENCODE_2GB (31U << HUGETLB_FLAG_ENCODE_SHIFT) +#define HUGETLB_FLAG_ENCODE_16GB (34U << HUGETLB_FLAG_ENCODE_SHIFT)#endif /* _ASM_GENERIC_HUGETLB_ENCODE_H_ */
linux-headers/asm-generic/mman-common.h +2 -0
@@ -77,6 +77,8 @@#define MADV_DONTNEED_LOCKED 24/* like DONTNEED, but drop locked pages too */ +#define MADV_COLLAPSE 25/* Synchronous hugepage collapse */ +/* compatibility flags */ #define MAP_FILE 0
linux-headers/asm-mips/mman.h +2 -0
@@ -103,6 +103,8 @@#define MADV_DONTNEED_LOCKED 24/* like DONTNEED, but drop locked pages too */ +#define MADV_COLLAPSE 25/* Synchronous hugepage collapse */ +/* compatibility flags */ #define MAP_FILE 0
linux-headers/asm-riscv/kvm.h +7 -0
@@ -48,6 +48,10 @@ struct kvm_sregs {/* CONFIG registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */ struct kvm_riscv_config {unsigned long isa; +unsigned long zicbom_block_size; +unsigned long mvendorid; +unsigned long marchid; +unsigned long mimpid; };/* CORE registers for KVM_GET_ONE_REG and KVM_SET_ONE_REG */
@@ -98,6 +102,9 @@ enum KVM_RISCV_ISA_EXT_ID {KVM_RISCV_ISA_EXT_M ,KVM_RISCV_ISA_EXT_SVPBMT ,KVM_RISCV_ISA_EXT_SSTC , +KVM_RISCV_ISA_EXT_SVINVAL , +KVM_RISCV_ISA_EXT_ZIHINTPAUSE , +KVM_RISCV_ISA_EXT_ZICBOM , KVM_RISCV_ISA_EXT_MAX, };
linux-headers/asm-x86/kvm.h +3 -8
@@ -53,14 +53,6 @@/* Architectural interrupt line count. */ #define KVM_NR_INTERRUPTS 256 -struct kvm_memory_alias { -__u32 slot;/* this has a different namespace than memory slots */ -__u32 flags; -__u64 guest_phys_addr; -__u64 memory_size; -__u64 target_phys_addr; -}; -/* for KVM_GET_IRQCHIP and KVM_SET_IRQCHIP */ struct kvm_pic_state {__u8 last_irr;/* edge detection */
@@ -214,6 +206,8 @@ struct kvm_msr_list {struct kvm_msr_filter_range {#define KVM_MSR_FILTER_READ (1 << 0)#define KVM_MSR_FILTER_WRITE (1 << 1) +#define KVM_MSR_FILTER_RANGE_VALID_MASK (KVM_MSR_FILTER_READ | \ + KVM_MSR_FILTER_WRITE)__u32 flags;__u32 nmsrs;/* number of msrs in bitmap */ __u32 base;/* MSR index the bitmap starts at */
@@ -224,6 +218,7 @@ struct kvm_msr_filter_range {struct kvm_msr_filter {#define KVM_MSR_FILTER_DEFAULT_ALLOW (0 << 0)#define KVM_MSR_FILTER_DEFAULT_DENY (1 << 0) +#define KVM_MSR_FILTER_VALID_MASK (KVM_MSR_FILTER_DEFAULT_DENY)__u32 flags;struct kvm_msr_filter_range ranges[KVM_MSR_FILTER_MAX_RANGES ]; };
linux-headers/linux/kvm.h +15 -17
@@ -86,14 +86,6 @@ struct kvm_debug_guest {/* *** End of deprecated interfaces *** */ -/* for KVM_CREATE_MEMORY_REGION */ -struct kvm_memory_region { -__u32 slot; -__u32 flags; -__u64 guest_phys_addr; -__u64 memory_size;/* bytes */ -}; -/* for KVM_SET_USER_MEMORY_REGION */ struct kvm_userspace_memory_region {__u32 slot;
@@ -104,9 +96,9 @@ struct kvm_userspace_memory_region { };/* -* The bit 0 ~ bit 15 of kvm_memory_region::flags are visible for userspace, -* other bits are reserved for kvm internal use which are defined in -* include/linux/kvm_host.h. +* The bit 0 ~ bit 15 of kvm_userspace_memory_region::flags are visible for +* userspace, other bits are reserved for kvm internal use which are defined +* in include/linux/kvm_host.h. */ #define KVM_MEM_LOG_DIRTY_PAGES (1UL << 0)#define KVM_MEM_READONLY (1UL << 1)
@@ -483,6 +475,9 @@ struct kvm_run {#define KVM_MSR_EXIT_REASON_INVAL (1 << 0)#define KVM_MSR_EXIT_REASON_UNKNOWN (1 << 1)#define KVM_MSR_EXIT_REASON_FILTER (1 << 2) +#define KVM_MSR_EXIT_REASON_VALID_MASK (KVM_MSR_EXIT_REASON_INVAL | \ + KVM_MSR_EXIT_REASON_UNKNOWN | \ + KVM_MSR_EXIT_REASON_FILTER)__u32 reason;/* kernel -> user */ __u32 index;/* kernel -> user */ __u64 data;/* kernel <-> user */
@@ -1175,6 +1170,9 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_VM_DISABLE_NX_HUGE_PAGES 220#define KVM_CAP_S390_ZPCI_OP 221#define KVM_CAP_S390_CPU_TOPOLOGY 222 +#define KVM_CAP_DIRTY_LOG_RING_ACQ_REL 223 +#define KVM_CAP_S390_PROTECTED_ASYNC_DISABLE 224 +#define KVM_CAP_DIRTY_LOG_RING_WITH_BITMAP 225#ifdef KVM_CAP_IRQ_ROUTING
@@ -1264,6 +1262,7 @@ struct kvm_x86_mce {#define KVM_XEN_HVM_CONFIG_RUNSTATE (1 << 3)#define KVM_XEN_HVM_CONFIG_EVTCHN_2LEVEL (1 << 4)#define KVM_XEN_HVM_CONFIG_EVTCHN_SEND (1 << 5) +#define KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG (1 << 6)struct kvm_xen_hvm_config {__u32 flags;
@@ -1434,18 +1433,12 @@ struct kvm_vfio_spapr_tce {__s32 tablefd; }; -/* -* ioctls for VM fds -*/ -#define KVM_SET_MEMORY_REGION _IOW(KVMIO, 0x40, struct kvm_memory_region)/* * KVM_CREATE_VCPU receives as a parameter the vcpu slot, and returns * a vcpu fd. */ #define KVM_CREATE_VCPU _IO(KVMIO, 0x41)#define KVM_GET_DIRTY_LOG _IOW(KVMIO, 0x42, struct kvm_dirty_log) -/* KVM_SET_MEMORY_ALIAS is obsolete: */ -#define KVM_SET_MEMORY_ALIAS _IOW(KVMIO, 0x43, struct kvm_memory_alias)#define KVM_SET_NR_MMU_PAGES _IO(KVMIO, 0x44)#define KVM_GET_NR_MMU_PAGES _IO(KVMIO, 0x45)#define KVM_SET_USER_MEMORY_REGION _IOW(KVMIO, 0x46, \
@@ -1737,6 +1730,8 @@ enum pv_cmd_id {KVM_PV_UNSHARE_ALL ,KVM_PV_INFO ,KVM_PV_DUMP , +KVM_PV_ASYNC_CLEANUP_PREPARE , + KVM_PV_ASYNC_CLEANUP_PERFORM, }; struct kvm_pv_cmd {
@@ -1767,6 +1762,7 @@ struct kvm_xen_hvm_attr {union {__u8 long_mode;__u8 vector; +__u8 runstate_update_flag;struct {__u64 gfn; } shared_info;
@@ -1807,6 +1803,8 @@ struct kvm_xen_hvm_attr {/* Available with KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_EVTCHN_SEND */ #define KVM_XEN_ATTR_TYPE_EVTCHN 0x3#define KVM_XEN_ATTR_TYPE_XEN_VERSION 0x4 +/* Available with KVM_CAP_XEN_HVM / KVM_XEN_HVM_CONFIG_RUNSTATE_UPDATE_FLAG */ +#define KVM_XEN_ATTR_TYPE_RUNSTATE_UPDATE_FLAG 0x5/* Per-vCPU Xen attributes */ #define KVM_XEN_VCPU_GET_ATTR _IOWR(KVMIO, 0xca, struct kvm_xen_vcpu_attr)
linux-headers/linux/psci.h +14 -0
@@ -48,12 +48,26 @@#define PSCI_0_2_FN64_MIGRATE_INFO_UP_CPU PSCI_0_2_FN64(7)#define PSCI_1_0_FN_PSCI_FEATURES PSCI_0_2_FN(10) +#define PSCI_1_0_FN_CPU_FREEZE PSCI_0_2_FN(11) +#define PSCI_1_0_FN_CPU_DEFAULT_SUSPEND PSCI_0_2_FN(12) +#define PSCI_1_0_FN_NODE_HW_STATE PSCI_0_2_FN(13)#define PSCI_1_0_FN_SYSTEM_SUSPEND PSCI_0_2_FN(14)#define PSCI_1_0_FN_SET_SUSPEND_MODE PSCI_0_2_FN(15) +#define PSCI_1_0_FN_STAT_RESIDENCY PSCI_0_2_FN(16) +#define PSCI_1_0_FN_STAT_COUNT PSCI_0_2_FN(17) +#define PSCI_1_1_FN_SYSTEM_RESET2 PSCI_0_2_FN(18) +#define PSCI_1_1_FN_MEM_PROTECT PSCI_0_2_FN(19) +#define PSCI_1_1_FN_MEM_PROTECT_CHECK_RANGE PSCI_0_2_FN(19) +#define PSCI_1_0_FN64_CPU_DEFAULT_SUSPEND PSCI_0_2_FN64(12) +#define PSCI_1_0_FN64_NODE_HW_STATE PSCI_0_2_FN64(13)#define PSCI_1_0_FN64_SYSTEM_SUSPEND PSCI_0_2_FN64(14) +#define PSCI_1_0_FN64_STAT_RESIDENCY PSCI_0_2_FN64(16) +#define PSCI_1_0_FN64_STAT_COUNT PSCI_0_2_FN64(17) +#define PSCI_1_1_FN64_SYSTEM_RESET2 PSCI_0_2_FN64(18) +#define PSCI_1_1_FN64_MEM_PROTECT_CHECK_RANGE PSCI_0_2_FN64(19)/* PSCI v0.2 power state encoding for CPU_SUSPEND function */ #define PSCI_0_2_POWER_STATE_ID_MASK 0xffff
linux-headers/linux/userfaultfd.h +4 -0
@@ -12,6 +12,10 @@#include <linux/types.h> +/* ioctls for /dev/userfaultfd */ +#define USERFAULTFD_IOC 0xAA +#define USERFAULTFD_IOC_NEW _IO(USERFAULTFD_IOC, 0x00) +/* * If the UFFDIO_API is upgraded someday, the UFFDIO_UNREGISTER and * UFFDIO_WAKE ioctls should be defined as _IOW and not as _IOR. In
linux-headers/linux/vfio.h +274 -4
347 lines not on this page · raw message
Signature · 1 line
2.26.3
PATCH v10 2/12 vfio/migration: Fix NULL pointer dereference bug
In reply to Avihai HoronAs part of its error flow, vfio_vmstate_change() accesses MigrationState->to_dst_file without any checks. This can cause a NULL pointer dereference if the error flow is taken and MigrationState->to_dst_file is not set.
For example, this can happen if VM is started or stopped not during migration and vfio_vmstate_change() error flow is taken, as MigrationState->to_dst_file is not set at that time.
Fix it by checking that MigrationState->to_dst_file is set before using it.
--- hw/vfio/migration.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
hw/vfio/migration.c +3 -1
@@ -744,7 +744,9 @@ static void vfio_vmstate_change(void *opaque, bool running, RunState state)*/ error_report ("%s: Failed to set device state 0x%x" , vbasedev->name, (migration->device_state & mask) | value); -qemu_file_set_error (migrate_get_current ()->to_dst_file, ret); +if (migrate_get_current ()->to_dst_file) { +qemu_file_set_error (migrate_get_current ()->to_dst_file, ret); + } } vbasedev->migration->vm_running = running; trace_vfio_vmstate_change(vbasedev->name, running, RunState_str(state),
Signature · 1 line
2.26.3
PATCH v10 3/12 vfio/migration: Allow migration without VFIO IOMMU dirty tracking support
In reply to Avihai HoronCurrently, if IOMMU of a VFIO container doesn't support dirty page tracking, migration is blocked. This is because a DMA-able VFIO device can dirty RAM pages without updating QEMU about it, thus breaking the migration.
However, this doesn't mean that migration can't be done at all. In such case, allow migration and let QEMU VFIO code mark all pages dirty.
This guarantees that all pages that might have gotten dirty are reported back, and thus guarantees a valid migration even without VFIO IOMMU dirty tracking support.
The motivation for this patch is the introduction of iommufd [1]. iommufd can directly implement the /dev/vfio/vfio container IOCTLs by mapping them into its internal ops, allowing the usage of these IOCTLs over iommufd. However, VFIO IOMMU dirty tracking is not supported by this VFIO compatibility API.
This patch will allow migration by hosts that use the VFIO compatibility API and prevent migration regressions caused by the lack of VFIO IOMMU dirty tracking support.
[1]
https://lore.kernel.org/kvm/[email protected]/
--- hw/vfio/common.c | 20 ++++++++++++++++++-- hw/vfio/migration.c | 3 +-- 2 files changed, 19 insertions(+), 4 deletions(-)
hw/vfio/common.c +18 -2
@@ -488,6 +488,12 @@ static int vfio_dma_unmap(VFIOContainer *container,return -errno; } +if (iotlb &&vfio_devices_all_running_and_saving (container)) { +cpu_physical_memory_set_dirty_range (iotlb->translated_addr, size, +tcg_enabled () ?DIRTY_CLIENTS_ALL : +DIRTY_CLIENTS_NOCODE ); + } +return 0 ; }
@@ -1201,6 +1207,10 @@ static void vfio_set_dirty_page_tracking(VFIOContainer *container, bool start) .argsz = sizeof(dirty), }; +if (!container->dirty_pages_supported) { +return ; + } +if (start) { dirty.flags =VFIO_IOMMU_DIRTY_PAGES_FLAG_START ; }else {
@@ -1236,6 +1246,13 @@ static int vfio_get_dirty_bitmap(VFIOContainer *container, uint64_t iova,uint64_t pages;int ret; +if (!container->dirty_pages_supported) { +cpu_physical_memory_set_dirty_range (ram_addr, size, +tcg_enabled () ?DIRTY_CLIENTS_ALL : +DIRTY_CLIENTS_NOCODE ); +return 0 ; + } + dbitmap =g_malloc0 (sizeof (*dbitmap) +sizeof (*range)); dbitmap->argsz =sizeof (*dbitmap) +sizeof (*range);
@@ -1409,8 +1426,7 @@ static void vfio_listener_log_sync(MemoryListener *listener, {VFIOContainer *container =container_of (listener, VFIOContainer, listener); -if (vfio_listener_skipped_section (section) || - !container->dirty_pages_supported) { +if (vfio_listener_skipped_section (section)) {return ; }
hw/vfio/migration.c +1 -2
@@ -861,11 +861,10 @@ int64_t vfio_mig_bytes_transferred(void)int vfio_migration_probe (VFIODevice *vbasedev,Error **errp) { -VFIOContainer *container = vbasedev->group->container;struct vfio_region_info *info =NULL ;int ret = -ENOTSUP ; -if (!vbasedev->enable_migration || !container->dirty_pages_supported) { +if (!vbasedev->enable_migration) { goto add_blocker; }
Signature · 1 line
2.26.3
Re: [PATCH v10 03/12] vfio/migration: Allow migration without VFIO IOMMU dirty tracking support
Quoted 23 lines · Avihai Horon
Currently, if IOMMU of a VFIO container doesn't support dirty page tracking, migration is blocked. This is because a DMA-able VFIO device can dirty RAM pages without updating QEMU about it, thus breaking the migration.
However, this doesn't mean that migration can't be done at all. In such case, allow migration and let QEMU VFIO code mark all pages dirty.
This guarantees that all pages that might have gotten dirty are reported back, and thus guarantees a valid migration even without VFIO IOMMU dirty tracking support.
The motivation for this patch is the introduction of iommufd [1]. iommufd can directly implement the
/dev/vfio/vfiocontainer IOCTLs by mapping them into its internal ops, allowing the usage of these IOCTLs over iommufd. However, VFIO IOMMU dirty tracking is not supported by this VFIO compatibility API.This patch will allow migration by hosts that use the VFIO compatibility API and prevent migration regressions caused by the lack of VFIO IOMMU dirty tracking support.
Quoted 5 lines
[1]
https://lore.kernel.org/kvm/[email protected]/Signed-off-by Avihai Horon <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>
I know why you are doing this.
But I think this should print a warning, error, somewhere.
You are just dirtying all pages each time we arrive here.
Even calling the featura "experimental" is an understatement.
Later, Juan.
Re: [PATCH v10 03/12] vfio/migration: Allow migration without VFIO IOMMU dirty tracking support
Quoted 30 lines · Juan Quintela
External email: Use caution opening links or attachments
Quoted 26 lines · Avihai Horon
Currently, if IOMMU of a VFIO container doesn't support dirty page tracking, migration is blocked. This is because a DMA-able VFIO device can dirty RAM pages without updating QEMU about it, thus breaking the migration.
However, this doesn't mean that migration can't be done at all. In such case, allow migration and let QEMU VFIO code mark all pages dirty.
This guarantees that all pages that might have gotten dirty are reported back, and thus guarantees a valid migration even without VFIO IOMMU dirty tracking support.
The motivation for this patch is the introduction of iommufd [1]. iommufd can directly implement the
/dev/vfio/vfiocontainer IOCTLs by mapping them into its internal ops, allowing the usage of these IOCTLs over iommufd. However, VFIO IOMMU dirty tracking is not supported by this VFIO compatibility API.This patch will allow migration by hosts that use the VFIO compatibility API and prevent migration regressions caused by the lack of VFIO IOMMU dirty tracking support.
Quoted 7 lines
Quoted 2 lines
Signed-off-by Avihai Horon <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>Reviewed-by Juan Quintela <[email protected]>I know why you are doing this.
But I think this should print a warning, error, somewhere.
IMHO, I'm not sure it's really necessary.
To enable VFIO migration the user must explicitly set x-enable-migration=on.
I guess in this case the user is well aware of the dirty tracking capabilities the VFIO device has or doesn't have. So I don't think adding this error/warning will help much.
Thanks.
Quoted 7 lines
You are just dirtying all pages each time we arrive here.
Even calling the featura "experimental" is an understatement.
Later, Juan.
Re: [PATCH v10 03/12] vfio/migration: Allow migration without VFIO IOMMU dirty tracking support
Quoted 37 lines · Avihai Horon
Quoted 36 lines · Juan Quintela
External email: Use caution opening links or attachments
Quoted 23 lines · Avihai Horon
Currently, if IOMMU of a VFIO container doesn't support dirty page tracking, migration is blocked. This is because a DMA-able VFIO device can dirty RAM pages without updating QEMU about it, thus breaking the migration.
However, this doesn't mean that migration can't be done at all. In such case, allow migration and let QEMU VFIO code mark all pages dirty.
This guarantees that all pages that might have gotten dirty are reported back, and thus guarantees a valid migration even without VFIO IOMMU dirty tracking support.
The motivation for this patch is the introduction of iommufd [1]. iommufd can directly implement the
/dev/vfio/vfiocontainer IOCTLs by mapping them into its internal ops, allowing the usage of these IOCTLs over iommufd. However, VFIO IOMMU dirty tracking is not supported by this VFIO compatibility API.This patch will allow migration by hosts that use the VFIO compatibility API and prevent migration regressions caused by the lack of VFIO IOMMU dirty tracking support.
Quoted 5 lines
[1]
https://lore.kernel.org/kvm/[email protected]/Signed-off-by Avihai Horon <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>Reviewed-by Juan Quintela <[email protected]>I know why you are doing this.
Quoted 8 lines
Quoted 1 line
But I think this should print a warning, error, somewhere.
IMHO, I'm not sure it's really necessary.
To enable VFIO migration the user must explicitly set x-enable-migration=on. I guess in this case the user is well aware of the dirty tracking capabilities the VFIO device has or doesn't have.
So I don't think adding this error/warning will help much.
Oops. I missed that bit.
I retire my objection.
Sorry, Juan.
Quoted 9 lines
Thanks.
Quoted 7 lines
You are just dirtying all pages each time we arrive here.
Even calling the featura "experimental" is an understatement.
Later, Juan.
Re: [PATCH v10 03/12] vfio/migration: Allow migration without VFIO IOMMU dirty tracking support
Quoted 42 lines · On Wed, 15 Feb 2023 19:04:33 +0100 Juan Quintela <[email protected]> wrote:
Quoted 41 lines · Avihai Horon
Quoted 30 lines · Juan Quintela
External email: Use caution opening links or attachments
Quoted 26 lines · Avihai Horon
Currently, if IOMMU of a VFIO container doesn't support dirty page tracking, migration is blocked. This is because a DMA-able VFIO device can dirty RAM pages without updating QEMU about it, thus breaking the migration.
However, this doesn't mean that migration can't be done at all. In such case, allow migration and let QEMU VFIO code mark all pages dirty.
This guarantees that all pages that might have gotten dirty are reported back, and thus guarantees a valid migration even without VFIO IOMMU dirty tracking support.
The motivation for this patch is the introduction of iommufd [1]. iommufd can directly implement the
/dev/vfio/vfiocontainer IOCTLs by mapping them into its internal ops, allowing the usage of these IOCTLs over iommufd. However, VFIO IOMMU dirty tracking is not supported by this VFIO compatibility API.This patch will allow migration by hosts that use the VFIO compatibility API and prevent migration regressions caused by the lack of VFIO IOMMU dirty tracking support.
Quoted 7 lines
Quoted 2 lines
Signed-off-by Avihai Horon <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>Reviewed-by Juan Quintela <[email protected]>I know why you are doing this.
But I think this should print a warning, error, somewhere.
IMHO, I'm not sure it's really necessary.
Quoted 7 lines
Quoted 4 lines
To enable VFIO migration the user must explicitly set x-enable-migration=on. I guess in this case the user is well aware of the dirty tracking capabilities the VFIO device has or doesn't have.
So I don't think adding this error/warning will help much.Oops. I missed that bit.
I retire my objection.
Keep it in mind though as hopefully we'll be making vfio migration non-experimental soon and enabled by default where devices support it. We'll need to consider whether we want to keep "dumb" dirty tracking, or even any form of dirty tracking in the type1 uAPI, under an experimental opt-in. Thanks,
Alex
Re: [PATCH v10 03/12] vfio/migration: Allow migration without VFIO IOMMU dirty tracking support
Quoted 3 lines · Alex Williamson
We'll need to consider whether we want to keep "dumb" dirty tracking, or even any form of dirty tracking in the type1 uAPI, under an experimental opt-in. Thanks,
I was expecting we'd delete the kernel code for type 1 dirty tracking once the v2 parts are merged to qemu since we don't and won't have any kernel implementation of it..
The big point of this to allow qmeu to continue on with a future kernel that no longer reports it supports this.
Jason
Re: [PATCH v10 03/12] vfio/migration: Allow migration without VFIO IOMMU dirty tracking support
Quoted 6 lines · On Wed, 15 Feb 2023 16:38:10 -0400 Jason Gunthorpe <[email protected]> wrote:
Quoted 3 lines · Alex Williamson
We'll need to consider whether we want to keep "dumb" dirty tracking, or even any form of dirty tracking in the type1 uAPI, under an experimental opt-in. Thanks,
Quoted 6 lines
I was expecting we'd delete the kernel code for type 1 dirty tracking once the v2 parts are merged to qemu since we don't and won't have any kernel implementation of it..
The big point of this to allow qmeu to continue on with a future kernel that no longer reports it supports this.
Right, in the part-1 series adding v2 support, we have no other dirty tracking, so it serves a purpose until we have device-level dirty tracking in the part-2 series. After that, we can certainly at least remove the type1 dirty tracking since there never were, and likely never will be, any in-kernel implementations. I could go either way if we want to keep the in-QEMU dirty-everything tracking around as an experimental option to aid migration driver development/debug (ie. maybe enabling it preempts device dirty tracking as a comparison for debug). Thanks,
Alex
PATCH v10 4/12 migration/qemu-file: Add qemu_file_get_to_fd()
In reply to Avihai HoronAdd new function qemu_file_get_to_fd() that allows reading data from QEMUFile and writing it straight into a given fd.
This will be used later in VFIO migration code.
--- migration/qemu-file.h | 1 + migration/qemu-file.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+)
migration/qemu-file.h +1 -0
@@ -148,6 +148,7 @@ int qemu_file_shutdown(QEMUFile *f);QEMUFile *qemu_file_get_return_path (QEMUFile *f);void qemu_fflush (QEMUFile *f);void qemu_file_set_blocking (QEMUFile *f,bool block); +int qemu_file_get_to_fd (QEMUFile *f,int fd,size_t size);void ram_control_before_iterate (QEMUFile *f,uint64_t flags);void ram_control_after_iterate (QEMUFile *f,uint64_t flags);
migration/qemu-file.c +34 -0
@@ -940,3 +940,37 @@ QIOChannel *qemu_file_get_ioc(QEMUFile *file) {return file->ioc; } + +/* +* Read size bytes from QEMUFile f and write them to fd. +*/ +int qemu_file_get_to_fd (QEMUFile *f,int fd,size_t size) +{ +while (size) { +size_t pending = f->buf_size - f->buf_index; +ssize_t rc; + +if (!pending) { + rc =qemu_fill_buffer (f); +if (rc <0 ) { +return rc; + } +if (rc ==0 ) { +return -EIO ; + } +continue ; + } + + rc =write (fd, f->buf + f->buf_index,MIN (pending, size)); +if (rc <0 ) { +return -errno; + } +if (rc ==0 ) { +return -EIO ; + } + f->buf_index += rc; + size -= rc; + } + +return 0 ; +}
Signature · 1 line
2.26.3
Re: [PATCH v10 04/12] migration/qemu-file: Add qemu_file_get_to_fd()
Hey Juan,
I think we're close, please ack this if it looks ok. Thanks,
Alex
Quoted 67 lines · On Thu, 9 Feb 2023 21:20:35 +0200 Avihai Horon <[email protected]> wrote:
Add new function
qemu_file_get_to_fd()that allows reading data from QEMUFile and writing it straight into a given fd.This will be used later in VFIO migration code.
Signed-off-by Avihai Horon <[email protected]>Reviewed-by Vladimir Sementsov-Ogievskiy <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>--- migration/qemu-file.h | 1 + migration/qemu-file.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+)migration/qemu-file.h +1
-0@@ -148,6 +148,7 @@ int qemu_file_shutdown(QEMUFile *f);QEMUFile *qemu_file_get_return_path (QEMUFile *f);void qemu_fflush (QEMUFile *f);void qemu_file_set_blocking (QEMUFile *f,bool block); +int qemu_file_get_to_fd (QEMUFile *f,int fd,size_t size);void ram_control_before_iterate (QEMUFile *f,uint64_t flags);void ram_control_after_iterate (QEMUFile *f,uint64_t flags);migration/qemu-file.c +34
-0@@ -940,3 +940,37 @@ QIOChannel *qemu_file_get_ioc(QEMUFile *file) {return file->ioc; } + +/* +* Read size bytes from QEMUFile f and write them to fd. +*/ +int qemu_file_get_to_fd (QEMUFile *f,int fd,size_t size) +{ +while (size) { +size_t pending = f->buf_size - f->buf_index; +ssize_t rc; + +if (!pending) { + rc =qemu_fill_buffer (f); +if (rc <0 ) { +return rc; + } +if (rc ==0 ) { +return -EIO ; + } +continue ; + } + + rc =write (fd, f->buf + f->buf_index,MIN (pending, size)); +if (rc <0 ) { +return -errno; + } +if (rc ==0 ) { +return -EIO ; + } + f->buf_index += rc; + size -= rc; + } + +return 0 ; +}
Re: [PATCH v10 04/12] migration/qemu-file: Add qemu_file_get_to_fd()
In reply to Avihai HoronQuoted 8 lines · Avihai Horon
Add new function
qemu_file_get_to_fd()that allows reading data from QEMUFile and writing it straight into a given fd.This will be used later in VFIO migration code.
Signed-off-by Avihai Horon <[email protected]>Reviewed-by Vladimir Sementsov-Ogievskiy <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>
PATCH v10 5/12 vfio/common: Change vfio_devices_all_running_and_saving() logic to equivalent one
In reply to Avihai Horonvfio_devices_all_running_and_saving() is used to check if migration is in pre-copy phase. This is done by checking if migration is in setup or active states and if all VFIO devices are in pre-copy state, i.e. _SAVING | _RUNNING.
In VFIO migration protocol v2 pre-copy support is made optional. Hence, a matching v2 protocol pre-copy state can't be used here.
As preparation for adding v2 protocol, change vfio_devices_all_running_and_saving() logic such that it doesn't use the VFIO pre-copy state.
The new equivalent logic checks if migration is in active state and if all VFIO devices are in running state [1]. No functional changes intended.
[1] Note that checking if migration is in setup or active states and if all VFIO devices are in running state doesn't guarantee that we are in pre-copy phase, thus we check if migration is only in active state.
--- hw/vfio/common.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
hw/vfio/common.c +10 -7
@@ -40,6 +40,7 @@#include "trace.h" #include "qapi/error.h" #include "migration/migration.h" +#include "migration/misc.h" #include "sysemu/tpm.h" VFIOGroupList vfio_group_list =
@@ -363,13 +364,16 @@ static bool vfio_devices_all_dirty_tracking(VFIOContainer *container)return true; } -static bool vfio_devices_all_running_and_saving (VFIOContainer *container) +/* +* Check if all VFIO devices are running and migration is active, which is +* essentially equivalent to the migration being in pre-copy phase. +*/ +static bool vfio_devices_all_running_and_mig_active (VFIOContainer *container) {VFIOGroup *group;VFIODevice *vbasedev; -MigrationState *ms =migrate_get_current (); -if (!migration_is_setup_or_active (ms->state)) { +if (!migration_is_active (migrate_get_current ())) {return false; }
@@ -381,8 +385,7 @@ static bool vfio_devices_all_running_and_saving(VFIOContainer *container)return false; } -if ((migration->device_state &VFIO_DEVICE_STATE_V1_SAVING ) && - (migration->device_state &VFIO_DEVICE_STATE_V1_RUNNING )) { +if (migration->device_state &VFIO_DEVICE_STATE_V1_RUNNING ) {continue ; }else {return false;
@@ -461,7 +464,7 @@ static int vfio_dma_unmap(VFIOContainer *container, };if (iotlb && container->dirty_pages_supported && -vfio_devices_all_running_and_saving (container)) { +vfio_devices_all_running_and_mig_active (container)) {return vfio_dma_unmap_bitmap (container, iova, size, iotlb); }
@@ -488,7 +491,7 @@ static int vfio_dma_unmap(VFIOContainer *container,return -errno; } -if (iotlb &&vfio_devices_all_running_and_saving (container)) { +if (iotlb &&vfio_devices_all_running_and_mig_active (container)) {cpu_physical_memory_set_dirty_range (iotlb->translated_addr, size,tcg_enabled () ?DIRTY_CLIENTS_ALL :DIRTY_CLIENTS_NOCODE );
Signature · 1 line
2.26.3
PATCH v10 6/12 vfio/migration: Block multiple devices migration
In reply to Avihai HoronCurrently VFIO migration doesn't implement some kind of intermediate quiescent state in which P2P DMAs are quiesced before stopping or running the device. This can cause problems in multi-device migration where the devices are doing P2P DMAs, since the devices are not stopped together at the same time.
Until such support is added, block migration of multiple devices.
--- include/hw/vfio/vfio-common.h | 2 ++ hw/vfio/common.c | 53 +++++++++++++++++++++++++++++++++++ hw/vfio/migration.c | 6 ++++ 3 files changed, 61 insertions(+)
include/hw/vfio/vfio-common.h +2 -0
@@ -218,6 +218,8 @@ typedef QLIST_HEAD(VFIOGroupList, VFIOGroup) VFIOGroupList;extern VFIOGroupList vfio_group_list;bool vfio_mig_active (void ); +int vfio_block_multiple_devices_migration (Error **errp); +void vfio_unblock_multiple_devices_migration (void );int64_t vfio_mig_bytes_transferred (void );#ifdef CONFIG_LINUX
hw/vfio/common.c +53 -0
65 lines not on this page · raw message
hw/vfio/migration.c +6 -0
@@ -881,6 +881,11 @@ int vfio_migration_probe(VFIODevice *vbasedev, Error **errp) goto add_blocker; } + ret =vfio_block_multiple_devices_migration (errp); +if (ret) { +return ret; + } +trace_vfio_migration_probe (vbasedev->name, info->index);g_free (info);return 0 ;
@@ -907,6 +912,7 @@ void vfio_migration_finalize(VFIODevice *vbasedev)qemu_del_vm_change_state_handler (migration->vm_state);unregister_savevm (VMSTATE_IF (vbasedev->dev),"vfio" , vbasedev);vfio_migration_exit (vbasedev); +vfio_unblock_multiple_devices_migration (); }if (vbasedev->migration_blocker) {
Signature · 1 line
2.26.3
Re: [PATCH v10 06/12] vfio/migration: Block multiple devices migration
Quoted 9 lines · Avihai Horon
Currently VFIO migration doesn't implement some kind of intermediate quiescent state in which P2P DMAs are quiesced before stopping or running the device. This can cause problems in multi-device migration where the devices are doing P2P DMAs, since the devices are not stopped together at the same time.
Until such support is added, block migration of multiple devices.
Signed-off-by Avihai Horon <[email protected]>
Thanks,
C.
Quoted 114 lines
--- include/hw/vfio/vfio-common.h | 2 ++ hw/vfio/common.c | 53 +++++++++++++++++++++++++++++++++++ hw/vfio/migration.c | 6 ++++ 3 files changed, 61 insertions(+)include/hw/vfio/vfio-common.h +2
-0@@ -218,6 +218,8 @@ typedef QLIST_HEAD(VFIOGroupList, VFIOGroup) VFIOGroupList;extern VFIOGroupList vfio_group_list;bool vfio_mig_active (void ); +int vfio_block_multiple_devices_migration (Error **errp); +void vfio_unblock_multiple_devices_migration (void );int64_t vfio_mig_bytes_transferred (void );#ifdef CONFIG_LINUX hw/vfio/common.c +53
-0@@ -41,6 +41,7 @@#include "qapi/error.h" #include "migration/migration.h" #include "migration/misc.h" +#include "migration/blocker.h" #include "sysemu/tpm.h" VFIOGroupList vfio_group_list =@@ -337,6 +338,58 @@ bool vfio_mig_active(void)return true; } +static Error *multiple_devices_migration_blocker; + +static unsigned int vfio_migratable_device_num (void ) +{ +VFIOGroup *group; +VFIODevice *vbasedev; +unsigned int device_num =0 ; + + QLIST_FOREACH(group, &vfio_group_list, next) { + QLIST_FOREACH(vbasedev, &group->device_list, next) { +if (vbasedev->migration) { + device_num++; + } + } + } + +return device_num; +} + +int vfio_block_multiple_devices_migration (Error **errp) +{ +int ret; + +if (multiple_devices_migration_blocker || +vfio_migratable_device_num () <=1 ) { +return 0 ; + } + +error_setg (&multiple_devices_migration_blocker, +"Migration is currently not supported with multiple " +"VFIO devices" ); + ret =migrate_add_blocker (multiple_devices_migration_blocker, errp); +if (ret <0 ) { +error_free (multiple_devices_migration_blocker); + multiple_devices_migration_blocker =NULL ; + } + +return ret; +} + +void vfio_unblock_multiple_devices_migration (void ) +{ +if (!multiple_devices_migration_blocker || +vfio_migratable_device_num () >1 ) { +return ; + } + +migrate_del_blocker (multiple_devices_migration_blocker); +error_free (multiple_devices_migration_blocker); + multiple_devices_migration_blocker =NULL ; +} +static bool vfio_devices_all_dirty_tracking (VFIOContainer *container) {VFIOGroup *group;hw/vfio/migration.c +6
-0@@ -881,6 +881,11 @@ int vfio_migration_probe(VFIODevice *vbasedev, Error **errp) goto add_blocker; } + ret =vfio_block_multiple_devices_migration (errp); +if (ret) { +return ret; + } +trace_vfio_migration_probe (vbasedev->name, info->index);g_free (info);return 0 ;@@ -907,6 +912,7 @@ void vfio_migration_finalize(VFIODevice *vbasedev)qemu_del_vm_change_state_handler (migration->vm_state);unregister_savevm (VMSTATE_IF (vbasedev->dev),"vfio" , vbasedev);vfio_migration_exit (vbasedev); +vfio_unblock_multiple_devices_migration (); }if (vbasedev->migration_blocker) {
Re: [PATCH v10 06/12] vfio/migration: Block multiple devices migration
In reply to Avihai HoronQuoted 9 lines · Avihai Horon
Currently VFIO migration doesn't implement some kind of intermediate quiescent state in which P2P DMAs are quiesced before stopping or running the device. This can cause problems in multi-device migration where the devices are doing P2P DMAs, since the devices are not stopped together at the same time.
Until such support is added, block migration of multiple devices.
Signed-off-by Avihai Horon <[email protected]>
With respect to how it intercat with migration.
PATCH v10 7/12 vfio/migration: Move migration v1 logic to vfio_migration_init()
In reply to Avihai HoronMove vfio_dev_get_region_info() logic from vfio_migration_probe() to vfio_migration_init(). This logic is specific to v1 protocol and moving it will make it easier to add the v2 protocol implementation later. No functional changes intended.
--- hw/vfio/migration.c | 30 +++++++++++++++--------------- hw/vfio/trace-events | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-)
hw/vfio/migration.c +15 -15
@@ -789,14 +789,14 @@ static void vfio_migration_exit(VFIODevice *vbasedev) vbasedev->migration =NULL ; } -static int vfio_migration_init (VFIODevice *vbasedev, -struct vfio_region_info *info) +static int vfio_migration_init (VFIODevice *vbasedev) {int ret;Object *obj;VFIOMigration *migration;char id[256 ] ="" ; g_autofree char *path = NULL, *oid = NULL; +struct vfio_region_info *info;if (!vbasedev->ops->vfio_get_object) {return -EINVAL ;
@@ -807,6 +807,14 @@ static int vfio_migration_init(VFIODevice *vbasedev,return -EINVAL ; } + ret =vfio_get_dev_region_info (vbasedev, +VFIO_REGION_TYPE_MIGRATION_DEPRECATED , +VFIO_REGION_SUBTYPE_MIGRATION_DEPRECATED , + &info); +if (ret) { +return ret; + } + vbasedev->migration =g_new0 (VFIOMigration,1 ); vbasedev->migration->device_state =VFIO_DEVICE_STATE_V1_RUNNING ; vbasedev->migration->vm_running =runstate_is_running ();
@@ -826,6 +834,8 @@ static int vfio_migration_init(VFIODevice *vbasedev, goto err; } +g_free (info); + migration = vbasedev->migration; migration->vbasedev = vbasedev;
@@ -848,6 +858,7 @@ static int vfio_migration_init(VFIODevice *vbasedev,return 0 ; err: +g_free (info);vfio_migration_exit (vbasedev);return ret; }
@@ -861,22 +872,13 @@ int64_t vfio_mig_bytes_transferred(void)int vfio_migration_probe (VFIODevice *vbasedev,Error **errp) { -struct vfio_region_info *info =NULL ;int ret = -ENOTSUP ;if (!vbasedev->enable_migration) { goto add_blocker; } - ret =vfio_get_dev_region_info (vbasedev, -VFIO_REGION_TYPE_MIGRATION_DEPRECATED , -VFIO_REGION_SUBTYPE_MIGRATION_DEPRECATED , - &info); -if (ret) { - goto add_blocker; - } - - ret =vfio_migration_init (vbasedev, info); + ret =vfio_migration_init (vbasedev);if (ret) { goto add_blocker; }
@@ -886,14 +888,12 @@ int vfio_migration_probe(VFIODevice *vbasedev, Error **errp)return ret; } -trace_vfio_migration_probe (vbasedev->name, info->index); -g_free (info); +trace_vfio_migration_probe (vbasedev->name);return 0 ; add_blocker:error_setg (&vbasedev->migration_blocker,"VFIO device doesn't support migration" ); -g_free (info); ret =migrate_add_blocker (vbasedev->migration_blocker, errp);if (ret <0 ) {
hw/vfio/trace-events +1 -1
@@ -148,7 +148,7 @@ vfio_display_edid_update(uint32_t prefx, uint32_t prefy) "%ux%u" vfio_display_edid_write_error(void) "" # migration.c -vfio_migration_probe(const char *name, uint32_t index) " (%s) Region %d" +vfio_migration_probe(const char *name) " (%s)" vfio_migration_set_state(const char *name, uint32_t state) " (%s) state %d" vfio_vmstate_change(const char *name, int running, const char *reason, uint32_t dev_state) " (%s) running %d reason %s device state %d" vfio_migration_state_notifier(const char *name, const char *state) " (%s) state %s"
Signature · 1 line
2.26.3
PATCH v10 8/12 vfio/migration: Rename functions/structs related to v1 protocol
In reply to Avihai HoronTo avoid name collisions, rename functions and structs related to VFIO migration protocol v1. This will allow the two protocols to co-exist when v2 protocol is added, until v1 is removed. No functional changes intended.
--- include/hw/vfio/vfio-common.h | 2 +- hw/vfio/common.c | 6 +- hw/vfio/migration.c | 107 +++++++++++++++++----------------- hw/vfio/trace-events | 12 ++-- 4 files changed, 63 insertions(+), 64 deletions(-)
include/hw/vfio/vfio-common.h +1 -1
@@ -62,7 +62,7 @@ typedef struct VFIOMigration {struct VFIODevice *vbasedev;VMChangeStateEntry *vm_state;VFIORegion region; -uint32_t device_state; +uint32_t device_state_v1;int vm_running;Notifier migration_state;uint64_t pending_bytes;
hw/vfio/common.c +3 -3
@@ -408,8 +408,8 @@ static bool vfio_devices_all_dirty_tracking(VFIOContainer *container)return false; } -if ((vbasedev->pre_copy_dirty_page_tracking ==ON_OFF_AUTO_OFF ) - && (migration->device_state &VFIO_DEVICE_STATE_V1_RUNNING )) { +if ((vbasedev->pre_copy_dirty_page_tracking ==ON_OFF_AUTO_OFF ) && + (migration->device_state_v1 &VFIO_DEVICE_STATE_V1_RUNNING )) {return false; } }
@@ -438,7 +438,7 @@ static bool vfio_devices_all_running_and_mig_active(VFIOContainer *container)return false; } -if (migration->device_state &VFIO_DEVICE_STATE_V1_RUNNING ) { +if (migration->device_state_v1 &VFIO_DEVICE_STATE_V1_RUNNING ) {continue ; }else {return false;
hw/vfio/migration.c +53 -54
271 lines not on this page · raw message
hw/vfio/trace-events +6 -6
@@ -149,20 +149,20 @@ vfio_display_edid_write_error(void) "" # migration.c vfio_migration_probe(const char *name) " (%s)" -vfio_migration_set_state(const char *name, uint32_t state) " (%s) state %d" -vfio_vmstate_change(const char *name, int running, const char *reason, uint32_t dev_state) " (%s) running %d reason %s device state %d" +vfio_migration_v1_set_state(const char *name, uint32_t state) " (%s) state %d" +vfio_v1_vmstate_change(const char *name, int running, const char *reason, uint32_t dev_state) " (%s) running %d reason %s device state %d" vfio_migration_state_notifier(const char *name, const char *state) " (%s) state %s" -vfio_save_setup(const char *name) " (%s)" +vfio_v1_save_setup(const char *name) " (%s)" vfio_save_cleanup(const char *name) " (%s)" vfio_save_buffer(const char *name, uint64_t data_offset, uint64_t data_size, uint64_t pending) " (%s) Offset 0x%"PRIx64" size 0x%"PRIx64" pending 0x%"PRIx64 vfio_update_pending(const char *name, uint64_t pending) " (%s) pending 0x%"PRIx64 vfio_save_device_config_state(const char *name) " (%s)" -vfio_state_pending(const char *name, uint64_t precopy, uint64_t postcopy, uint64_t compatible) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64" compatible 0x%"PRIx64 +vfio_v1_state_pending(const char *name, uint64_t precopy, uint64_t postcopy, uint64_t compatible) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64" compatible 0x%"PRIx64 vfio_save_iterate(const char *name, int data_size) " (%s) data_size %d" -vfio_save_complete_precopy(const char *name) " (%s)" +vfio_v1_save_complete_precopy(const char *name) " (%s)" vfio_load_device_config_state(const char *name) " (%s)" vfio_load_state(const char *name, uint64_t data) " (%s) data 0x%"PRIx64 -vfio_load_state_device_data(const char *name, uint64_t data_offset, uint64_t data_size) " (%s) Offset 0x%"PRIx64" size 0x%"PRIx64 +vfio_v1_load_state_device_data(const char *name, uint64_t data_offset, uint64_t data_size) " (%s) Offset 0x%"PRIx64" size 0x%"PRIx64 vfio_load_cleanup(const char *name) " (%s)" vfio_get_dirty_bitmap(int fd, uint64_t iova, uint64_t size, uint64_t bitmap_size, uint64_t start) "container fd=%d, iova=0x%"PRIx64" size= 0x%"PRIx64" bitmap_size=0x%"PRIx64" start=0x%"PRIx64 vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu dirty @ 0x%"PRIx64" - 0x%"PRIx64
Signature · 1 line
2.26.3
PATCH v10 9/12 vfio/migration: Implement VFIO migration protocol v2
In reply to Avihai HoronImplement the basic mandatory part of VFIO migration protocol v2. This includes all functionality that is necessary to support VFIO_MIGRATION_STOP_COPY part of the v2 protocol.
The two protocols, v1 and v2, will co-exist and in the following patches v1 protocol code will be removed.
There are several main differences between v1 and v2 protocols:
- VFIO device state is now represented as a finite state machine instead of a bitmap.
- Migration interface with kernel is now done using VFIO_DEVICE_FEATURE ioctl and normal read() and write() instead of the migration region.
- Pre-copy is made optional in v2 protocol. Support for pre-copy will be added later on.
Detailed information about VFIO migration protocol v2 and its difference compared to v1 protocol can be found here [1].
[1]
https://lore.kernel.org/all/[email protected]/
--- include/hw/vfio/vfio-common.h | 5 + hw/vfio/common.c | 17 +- hw/vfio/migration.c | 481 +++++++++++++++++++++++++++++++--- hw/vfio/trace-events | 7 + 4 files changed, 471 insertions(+), 39 deletions(-)
include/hw/vfio/vfio-common.h +5 -0
@@ -66,6 +66,11 @@ typedef struct VFIOMigration {int vm_running;Notifier migration_state;uint64_t pending_bytes; +uint32_t device_state; +int data_fd; +void *data_buffer; +size_t data_buffer_size; +bool v2; } VFIOMigration; typedef struct VFIOAddressSpace {
hw/vfio/common.c +15 -2
@@ -408,10 +408,17 @@ static bool vfio_devices_all_dirty_tracking(VFIOContainer *container)return false; } -if ((vbasedev->pre_copy_dirty_page_tracking ==ON_OFF_AUTO_OFF ) && +if (!migration->v2 && + (vbasedev->pre_copy_dirty_page_tracking ==ON_OFF_AUTO_OFF ) && (migration->device_state_v1 &VFIO_DEVICE_STATE_V1_RUNNING )) {return false; } + +if (migration->v2 && + vbasedev->pre_copy_dirty_page_tracking ==ON_OFF_AUTO_OFF && + migration->device_state ==VFIO_DEVICE_STATE_RUNNING ) { +return false; + } } }return true;
@@ -438,7 +445,13 @@ static bool vfio_devices_all_running_and_mig_active(VFIOContainer *container)return false; } -if (migration->device_state_v1 &VFIO_DEVICE_STATE_V1_RUNNING ) { +if (!migration->v2 && + migration->device_state_v1 &VFIO_DEVICE_STATE_V1_RUNNING ) { +continue ; + } + +if (migration->v2 && + migration->device_state ==VFIO_DEVICE_STATE_RUNNING ) {continue ; }else {return false;
hw/vfio/migration.c +444 -37
602 lines not on this page · raw message
hw/vfio/trace-events +7 -0
@@ -149,20 +149,27 @@ vfio_display_edid_write_error(void) "" # migration.c vfio_migration_probe(const char *name) " (%s)" +vfio_migration_set_state(const char *name, const char *state) " (%s) state %s" vfio_migration_v1_set_state(const char *name, uint32_t state) " (%s) state %d" +vfio_vmstate_change(const char *name, int running, const char *reason, const char *dev_state) " (%s) running %d reason %s device state %s" vfio_v1_vmstate_change(const char *name, int running, const char *reason, uint32_t dev_state) " (%s) running %d reason %s device state %d" vfio_migration_state_notifier(const char *name, const char *state) " (%s) state %s" +vfio_save_setup(const char *name, uint64_t data_buffer_size) " (%s) data buffer size 0x%"PRIx64 vfio_v1_save_setup(const char *name) " (%s)" vfio_save_cleanup(const char *name) " (%s)" vfio_save_buffer(const char *name, uint64_t data_offset, uint64_t data_size, uint64_t pending) " (%s) Offset 0x%"PRIx64" size 0x%"PRIx64" pending 0x%"PRIx64 vfio_update_pending(const char *name, uint64_t pending) " (%s) pending 0x%"PRIx64 vfio_save_device_config_state(const char *name) " (%s)" +vfio_state_pending_exact(const char *name, uint64_t precopy, uint64_t postcopy, uint64_t compatible, uint64_t stopcopy_size) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64" compatible 0x%"PRIx64" stopcopy size 0x%"PRIx64 vfio_v1_state_pending(const char *name, uint64_t precopy, uint64_t postcopy, uint64_t compatible) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64" compatible 0x%"PRIx64 vfio_save_iterate(const char *name, int data_size) " (%s) data_size %d" +vfio_save_complete_precopy(const char *name, int ret) " (%s) ret %d" vfio_v1_save_complete_precopy(const char *name) " (%s)" vfio_load_device_config_state(const char *name) " (%s)" vfio_load_state(const char *name, uint64_t data) " (%s) data 0x%"PRIx64 vfio_v1_load_state_device_data(const char *name, uint64_t data_offset, uint64_t data_size) " (%s) Offset 0x%"PRIx64" size 0x%"PRIx64 +vfio_load_state_device_data(const char *name, uint64_t data_size, int ret) " (%s) size 0x%"PRIx64" ret %d" vfio_load_cleanup(const char *name) " (%s)" vfio_get_dirty_bitmap(int fd, uint64_t iova, uint64_t size, uint64_t bitmap_size, uint64_t start) "container fd=%d, iova=0x%"PRIx64" size= 0x%"PRIx64" bitmap_size=0x%"PRIx64" start=0x%"PRIx64 vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu dirty @ 0x%"PRIx64" - 0x%"PRIx64 +vfio_save_block(const char *name, int data_size) " (%s) data_size %d"
Signature · 1 line
2.26.3
Quoted 24 lines · Avihai Horon
Implement the basic mandatory part of VFIO migration protocol v2. This includes all functionality that is necessary to support
VFIO_MIGRATION_STOP_COPYpart of the v2 protocol.The two protocols, v1 and v2, will co-exist and in the following patches v1 protocol code will be removed.
There are several main differences between v1 and v2 protocols:
- VFIO device state is now represented as a finite state machine instead of a bitmap.- Migration interface with kernel is now done using
VFIO_DEVICE_FEATUREioctl and normalread()andwrite()instead of the migration region.- Pre-copy is made optional in v2 protocol. Support for pre-copy will be added later on.
Detailed information about VFIO migration protocol v2 and its difference compared to v1 protocol can be found here [1].
[1]
https://lore.kernel.org/all/[email protected]/Signed-off-by Avihai Horon <[email protected]>
hw/vfio/migration.c static void vfio_v1_save_cleanup(void *opaque) · line 673
Quoted 5 lines
hw/vfio/migration.c +5
-0+/* +* Migration size of VFIO devices can be as little as a few KBs or as big as +* many GBs. This value should be big enough to cover the worst case. +*/ +#define VFIO_MIG_STOP_COPY_SIZE (100 * GiB)
Wow O:-)
hw/vfio/migration.c static void vfio_v1_save_cleanup(void *opaque) · line 680
Quoted 7 lines
hw/vfio/migration.c +7
-0+ +/* +* Only exact function is implemented and not estimate function. The reason is +* that during pre-copy phase of migration the estimate function is called +* repeatedly while pending RAM size is over the threshold, thus migration +* can't converge and querying the VFIO device pending data size is useless. +*/
You can do it after this is merge, but I think you can do better than this. Something in the lines of:
// I put it in a global variable, but it really needs to be in VFIODevice to be // able to support several devices. You get the idea O:-)
static uint64_t cached_size = -1;
static void vfio_state_pending_exact(void *opaque, uint64_t *res_precopy_only,
uint64_t *res_compatible, uint64_t *res_postcopy_only)
{
VFIODevice *vbasedev = opaque;
uint64_t stop_copy_size = VFIO_MIG_STOP_COPY_SIZE;
/*
* If getting pending migration size fails, VFIO_MIG_STOP_COPY_SIZE is
* reported so downtime limit won't be violated.
*/
vfio_query_stop_copy_size(vbasedev, &stop_copy_size);
*res_precopy_only += stop_copy_size;
cached_size = stop_copy_size;
trace_vfio_state_pending_exact(vbasedev->name, *res_precopy_only,
*res_postcopy_only, *res_compatible,
stop_copy_size);
}static void vfio_state_pending_estimate(void *opaque, uint64_t *res_precopy_only,
uint64_t *res_compatible, uint64_t *res_postcopy_only)
{
VFIODevice *vbasedev = opaque;
uint64_t stop_copy_size = VFIO_MIG_STOP_COPY_SIZE;
if (cached_size == -1) {
uint64_t res_precopy;
uint64_t res_compatible;
uint64_t res_postcopy;
vfio_state_pending_exact(opaque, &res_precopy, &res_compatible, &res_postcopy);
}
*res_precopy_only += cached_size;
}Quoted 76 lines · Juan Quintela
External email: Use caution opening links or attachments
Quoted 24 lines · Avihai Horon
Implement the basic mandatory part of VFIO migration protocol v2. This includes all functionality that is necessary to support
VFIO_MIGRATION_STOP_COPYpart of the v2 protocol.The two protocols, v1 and v2, will co-exist and in the following patches v1 protocol code will be removed.
There are several main differences between v1 and v2 protocols:
- VFIO device state is now represented as a finite state machine instead of a bitmap.- Migration interface with kernel is now done using
VFIO_DEVICE_FEATUREioctl and normalread()andwrite()instead of the migration region.- Pre-copy is made optional in v2 protocol. Support for pre-copy will be added later on.
Detailed information about VFIO migration protocol v2 and its difference compared to v1 protocol can be found here [1].
[1]
https://lore.kernel.org/all/[email protected]/Signed-off-by Avihai Horon <[email protected]>hw/vfio/migration.c static void vfio_v1_save_cleanup(void *opaque) · line 673
Quoted 5 lines
hw/vfio/migration.c +5
-0+/* +* Migration size of VFIO devices can be as little as a few KBs or as big as +* many GBs. This value should be big enough to cover the worst case. +*/ +#define VFIO_MIG_STOP_COPY_SIZE (100 * GiB)Wow O:-)
hw/vfio/migration.c static void vfio_v1_save_cleanup(void *opaque) · line 680
Quoted 7 lines
hw/vfio/migration.c +7
-0+ +/* +* Only exact function is implemented and not estimate function. The reason is +* that during pre-copy phase of migration the estimate function is called +* repeatedly while pending RAM size is over the threshold, thus migration +* can't converge and querying the VFIO device pending data size is useless. +*/ You can do it after this is merge, but I think you can do better than this. Something in the lines of:
// I put it in a global variable, but it really needs to be in VFIODevice to be // able to support several devices. You get the idea O:-)
static
uint64_tcached_size= -1;static void vfio_state_pending_exact(void *opaque,
uint64_t*res_precopy_only,
uint64_t*res_compatible,uint64_t*res_postcopy_only){ VFIODevice *vbasedev = opaque; uint64_t stop_copy_size = VFIO_MIG_STOP_COPY_SIZE; /* * If getting pending migration size fails, VFIO_MIG_STOP_COPY_SIZE is * reported so downtime limit won't be violated. */ vfio_query_stop_copy_size(vbasedev, &stop_copy_size); *res_precopy_only += stop_copy_size; cached_size = stop_copy_size; trace_vfio_state_pending_exact(vbasedev->name, *res_precopy_only, *res_postcopy_only, *res_compatible, stop_copy_size); }static void vfio_state_pending_estimate(void *opaque,
uint64_t*res_precopy_only,
uint64_t*res_compatible,uint64_t*res_postcopy_only)
Quoted 12 lines
{
VFIODevice *vbasedev = opaque;
uint64_t stop_copy_size = VFIO_MIG_STOP_COPY_SIZE;
if (cached_size == -1) {
uint64_t res_precopy;
uint64_t res_compatible;
uint64_t res_postcopy;
vfio_state_pending_exact(opaque, &res_precopy, &res_compatible, &res_postcopy);
}
*res_precopy_only += cached_size;
}In the next series, which will add pre-copy support to VFIO migration (v1 was sent [1] but isn't rebased on your pull reqs yet), I am going to do something similar to what you suggested. It will be like you did here but with pre-copy data size (data which can be transferred during pre-copy phase) instead of the stop_copy_size.
Plus, I don't think caching the stop_copy_size and reporting the cached value in the estimate handler fits the best here, because stop_copy_size doesn't decrease by pre-copy iterations as opposed to RAM pre-copy data, for example.
So I would rather keep things as they are and add something similar to your suggestion in the pre-copy series.
Thanks!
Quoted 96 lines · On Wed, 15 Feb 2023 20:23:12 +0200 Avihai Horon <[email protected]> wrote:
Quoted 76 lines · Juan Quintela
External email: Use caution opening links or attachments
Quoted 24 lines · Avihai Horon
Implement the basic mandatory part of VFIO migration protocol v2. This includes all functionality that is necessary to support
VFIO_MIGRATION_STOP_COPYpart of the v2 protocol.The two protocols, v1 and v2, will co-exist and in the following patches v1 protocol code will be removed.
There are several main differences between v1 and v2 protocols:
- VFIO device state is now represented as a finite state machine instead of a bitmap.- Migration interface with kernel is now done using
VFIO_DEVICE_FEATUREioctl and normalread()andwrite()instead of the migration region.- Pre-copy is made optional in v2 protocol. Support for pre-copy will be added later on.
Detailed information about VFIO migration protocol v2 and its difference compared to v1 protocol can be found here [1].
[1]
https://lore.kernel.org/all/[email protected]/Signed-off-by Avihai Horon <[email protected]>hw/vfio/migration.c static void vfio_v1_save_cleanup(void *opaque) · line 673
Quoted 5 lines
hw/vfio/migration.c +5
-0+/* +* Migration size of VFIO devices can be as little as a few KBs or as big as +* many GBs. This value should be big enough to cover the worst case. +*/ +#define VFIO_MIG_STOP_COPY_SIZE (100 * GiB)Wow O:-)
hw/vfio/migration.c static void vfio_v1_save_cleanup(void *opaque) · line 680
Quoted 7 lines
hw/vfio/migration.c +7
-0+ +/* +* Only exact function is implemented and not estimate function. The reason is +* that during pre-copy phase of migration the estimate function is called +* repeatedly while pending RAM size is over the threshold, thus migration +* can't converge and querying the VFIO device pending data size is useless. +*/ You can do it after this is merge, but I think you can do better than this. Something in the lines of:
// I put it in a global variable, but it really needs to be in VFIODevice to be // able to support several devices. You get the idea O:-)
static
uint64_tcached_size= -1;static void vfio_state_pending_exact(void *opaque,
uint64_t*res_precopy_only,
uint64_t*res_compatible,uint64_t*res_postcopy_only){ VFIODevice *vbasedev = opaque; uint64_t stop_copy_size = VFIO_MIG_STOP_COPY_SIZE; /* * If getting pending migration size fails, VFIO_MIG_STOP_COPY_SIZE is * reported so downtime limit won't be violated. */ vfio_query_stop_copy_size(vbasedev, &stop_copy_size); *res_precopy_only += stop_copy_size; cached_size = stop_copy_size; trace_vfio_state_pending_exact(vbasedev->name, *res_precopy_only, *res_postcopy_only, *res_compatible, stop_copy_size); }static void vfio_state_pending_estimate(void *opaque,
uint64_t*res_precopy_only,
uint64_t*res_compatible,uint64_t*res_postcopy_only)Quoted 12 lines
{ VFIODevice *vbasedev = opaque; uint64_t stop_copy_size = VFIO_MIG_STOP_COPY_SIZE; if (cached_size == -1) { uint64_t res_precopy; uint64_t res_compatible; uint64_t res_postcopy; vfio_state_pending_exact(opaque, &res_precopy, &res_compatible, &res_postcopy); } *res_precopy_only += cached_size; }In the next series, which will add pre-copy support to VFIO migration (v1 was sent [1] but isn't rebased on your pull reqs yet), I am going to do something similar to what you suggested.
It will be like you did here but with pre-copy data size (data which can be transferred during pre-copy phase) instead of thestop_copy_size.
Quoted 7 lines
Plus, I don't think caching the
stop_copy_sizeand reporting the cached value in the estimate handler fits the best here,
becausestop_copy_sizedoesn't decrease by pre-copy iterations as opposed to RAM pre-copy data, for example.So I would rather keep things as they are and add something similar to your suggestion in the pre-copy series.
Assuming Juan is on board with this, please re-base your series on Juan's latest pull request. At the time of writing, this is:
https://lore.kernel.org/all/[email protected]/
The kernel headers need an update (you might as well pick up v6.2-rc8 at this point to be as close as possible to what lands in v6.2), Juan's pull request includes qemu_file_get_to_fd(), so we can drop it here, and there are some conflicts that need to be ironed out relative to 24beea4efe6e ("migration: Rename res_{postcopy,precopy}_only"). Thanks,
Alex
Quoted 111 lines · Alex Williamson
External email: Use caution opening links or attachments
Quoted 95 lines · On Wed, 15 Feb 2023 20:23:12 +0200 Avihai Horon <[email protected]> wrote:
Quoted 76 lines · Juan Quintela
External email: Use caution opening links or attachments
Quoted 24 lines · Avihai Horon
Implement the basic mandatory part of VFIO migration protocol v2. This includes all functionality that is necessary to support
VFIO_MIGRATION_STOP_COPYpart of the v2 protocol.The two protocols, v1 and v2, will co-exist and in the following patches v1 protocol code will be removed.
There are several main differences between v1 and v2 protocols:
- VFIO device state is now represented as a finite state machine instead of a bitmap.- Migration interface with kernel is now done using
VFIO_DEVICE_FEATUREioctl and normalread()andwrite()instead of the migration region.- Pre-copy is made optional in v2 protocol. Support for pre-copy will be added later on.
Detailed information about VFIO migration protocol v2 and its difference compared to v1 protocol can be found here [1].
[1]
https://lore.kernel.org/all/[email protected]/Signed-off-by Avihai Horon <[email protected]>hw/vfio/migration.c static void vfio_v1_save_cleanup(void *opaque) · line 673
Quoted 5 lines
hw/vfio/migration.c +5
-0+/* +* Migration size of VFIO devices can be as little as a few KBs or as big as +* many GBs. This value should be big enough to cover the worst case. +*/ +#define VFIO_MIG_STOP_COPY_SIZE (100 * GiB)Wow O:-)
hw/vfio/migration.c static void vfio_v1_save_cleanup(void *opaque) · line 680
Quoted 7 lines
hw/vfio/migration.c +7
-0+ +/* +* Only exact function is implemented and not estimate function. The reason is +* that during pre-copy phase of migration the estimate function is called +* repeatedly while pending RAM size is over the threshold, thus migration +* can't converge and querying the VFIO device pending data size is useless. +*/ You can do it after this is merge, but I think you can do better than this. Something in the lines of:
// I put it in a global variable, but it really needs to be in VFIODevice to be // able to support several devices. You get the idea O:-)
static
uint64_tcached_size= -1;static void vfio_state_pending_exact(void *opaque,
uint64_t*res_precopy_only,
uint64_t*res_compatible,uint64_t*res_postcopy_only){ VFIODevice *vbasedev = opaque; uint64_t stop_copy_size = VFIO_MIG_STOP_COPY_SIZE; /* * If getting pending migration size fails, VFIO_MIG_STOP_COPY_SIZE is * reported so downtime limit won't be violated. */ vfio_query_stop_copy_size(vbasedev, &stop_copy_size); *res_precopy_only += stop_copy_size; cached_size = stop_copy_size; trace_vfio_state_pending_exact(vbasedev->name, *res_precopy_only, *res_postcopy_only, *res_compatible, stop_copy_size); }static void vfio_state_pending_estimate(void *opaque,
uint64_t*res_precopy_only,
uint64_t*res_compatible,uint64_t*res_postcopy_only)Quoted 12 lines
{ VFIODevice *vbasedev = opaque; uint64_t stop_copy_size = VFIO_MIG_STOP_COPY_SIZE; if (cached_size == -1) { uint64_t res_precopy; uint64_t res_compatible; uint64_t res_postcopy; vfio_state_pending_exact(opaque, &res_precopy, &res_compatible, &res_postcopy); } *res_precopy_only += cached_size; }In the next series, which will add pre-copy support to VFIO migration (v1 was sent [1] but isn't rebased on your pull reqs yet), I am going to do something similar to what you suggested.
It will be like you did here but with pre-copy data size (data which can be transferred during pre-copy phase) instead of thestop_copy_size.Quoted 7 lines
Plus, I don't think caching the
stop_copy_sizeand reporting the cached value in the estimate handler fits the best here,
becausestop_copy_sizedoesn't decrease by pre-copy iterations as opposed to RAM pre-copy data, for example.So I would rather keep things as they are and add something similar to your suggestion in the pre-copy series.
Assuming Juan is on board with this, please re-base your series on Juan's latest pull request. At the time of writing, this is:
Quoted 7 lines
https://lore.kernel.org/all/[email protected]/
The kernel headers need an update (you might as well pick up v6.2-rc8 at this point to be as close as possible to what lands in v6.2), Juan's pull request includes
qemu_file_get_to_fd(), so we can drop it here, and there are some conflicts that need to be ironed out relative to24beea4efe6e("migration: Rename res_{postcopy,precopy}_only").
Sure, I will do it and post v11.
Thanks.
PATCH v10 10/12 vfio/migration: Remove VFIO migration protocol v1
In reply to Avihai HoronNow that v2 protocol implementation has been added, remove the deprecated v1 implementation.
--- include/hw/vfio/vfio-common.h | 5 - hw/vfio/common.c | 17 +- hw/vfio/migration.c | 702 ++-------------------------------- hw/vfio/trace-events | 9 - 4 files changed, 24 insertions(+), 709 deletions(-)
include/hw/vfio/vfio-common.h +0 -5
@@ -61,16 +61,11 @@ typedef struct VFIORegion {typedef struct VFIOMigration {struct VFIODevice *vbasedev;VMChangeStateEntry *vm_state; -VFIORegion region; -uint32_t device_state_v1; -int vm_running;Notifier migration_state; -uint64_t pending_bytes;uint32_t device_state;int data_fd;void *data_buffer;size_t data_buffer_size; -bool v2; }VFIOMigration ; typedef struct VFIOAddressSpace {
hw/vfio/common.c +2 -15
@@ -408,14 +408,7 @@ static bool vfio_devices_all_dirty_tracking(VFIOContainer *container)return false; } -if (!migration->v2 && - (vbasedev->pre_copy_dirty_page_tracking ==ON_OFF_AUTO_OFF ) && - (migration->device_state_v1 &VFIO_DEVICE_STATE_V1_RUNNING )) { -return false; - } - -if (migration->v2 && - vbasedev->pre_copy_dirty_page_tracking ==ON_OFF_AUTO_OFF && +if (vbasedev->pre_copy_dirty_page_tracking ==ON_OFF_AUTO_OFF && migration->device_state ==VFIO_DEVICE_STATE_RUNNING ) {return false; }
@@ -445,13 +438,7 @@ static bool vfio_devices_all_running_and_mig_active(VFIOContainer *container)return false; } -if (!migration->v2 && - migration->device_state_v1 &VFIO_DEVICE_STATE_V1_RUNNING ) { -continue ; - } - -if (migration->v2 && - migration->device_state ==VFIO_DEVICE_STATE_RUNNING ) { +if (migration->device_state ==VFIO_DEVICE_STATE_RUNNING ) {continue ; }else {return false;
hw/vfio/migration.c +22 -680
818 lines not on this page · raw message
hw/vfio/trace-events +0 -9
@@ -150,24 +150,15 @@ vfio_display_edid_write_error(void) "" # migration.c vfio_migration_probe(const char *name) " (%s)" vfio_migration_set_state(const char *name, const char *state) " (%s) state %s" -vfio_migration_v1_set_state(const char *name, uint32_t state) " (%s) state %d" vfio_vmstate_change(const char *name, int running, const char *reason, const char *dev_state) " (%s) running %d reason %s device state %s" -vfio_v1_vmstate_change(const char *name, int running, const char *reason, uint32_t dev_state) " (%s) running %d reason %s device state %d" vfio_migration_state_notifier(const char *name, const char *state) " (%s) state %s" vfio_save_setup(const char *name, uint64_t data_buffer_size) " (%s) data buffer size 0x%"PRIx64 -vfio_v1_save_setup(const char *name) " (%s)" vfio_save_cleanup(const char *name) " (%s)" -vfio_save_buffer(const char *name, uint64_t data_offset, uint64_t data_size, uint64_t pending) " (%s) Offset 0x%"PRIx64" size 0x%"PRIx64" pending 0x%"PRIx64 -vfio_update_pending(const char *name, uint64_t pending) " (%s) pending 0x%"PRIx64 vfio_save_device_config_state(const char *name) " (%s)" vfio_state_pending_exact(const char *name, uint64_t precopy, uint64_t postcopy, uint64_t compatible, uint64_t stopcopy_size) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64" compatible 0x%"PRIx64" stopcopy size 0x%"PRIx64 -vfio_v1_state_pending(const char *name, uint64_t precopy, uint64_t postcopy, uint64_t compatible) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64" compatible 0x%"PRIx64 -vfio_save_iterate(const char *name, int data_size) " (%s) data_size %d" vfio_save_complete_precopy(const char *name, int ret) " (%s) ret %d" -vfio_v1_save_complete_precopy(const char *name) " (%s)" vfio_load_device_config_state(const char *name) " (%s)" vfio_load_state(const char *name, uint64_t data) " (%s) data 0x%"PRIx64 -vfio_v1_load_state_device_data(const char *name, uint64_t data_offset, uint64_t data_size) " (%s) Offset 0x%"PRIx64" size 0x%"PRIx64 vfio_load_state_device_data(const char *name, uint64_t data_size, int ret) " (%s) size 0x%"PRIx64" ret %d" vfio_load_cleanup(const char *name) " (%s)" vfio_get_dirty_bitmap(int fd, uint64_t iova, uint64_t size, uint64_t bitmap_size, uint64_t start) "container fd=%d, iova=0x%"PRIx64" size= 0x%"PRIx64" bitmap_size=0x%"PRIx64" start=0x%"PRIx64
Signature · 1 line
2.26.3
Re: [PATCH v10 10/12] vfio/migration: Remove VFIO migration protocol v1
Quoted 5 lines · Avihai Horon
Now that v2 protocol implementation has been added, remove the deprecated v1 implementation.
Signed-off-by Avihai Horon <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>
Yes, yes, yes O:-)
PATCH v10 11/12 vfio: Alphabetize migration section of VFIO trace-events file
In reply to Avihai HoronSort the migration section of VFIO trace events file alphabetically and move two misplaced traces to common.c section.
--- hw/vfio/trace-events | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
hw/vfio/trace-events +10 -10
@@ -119,6 +119,8 @@ vfio_region_sparse_mmap_header(const char *name, int index, int nr_areas) "Devic vfio_region_sparse_mmap_entry(int i, unsigned long start, unsigned long end) "sparse entry %d [0x%lx - 0x%lx]" vfio_get_dev_region(const char *name, int index, uint32_t type, uint32_t subtype) "%s index %d, %08x/%0x8" vfio_dma_unmap_overflow_workaround(void) "" +vfio_get_dirty_bitmap(int fd, uint64_t iova, uint64_t size, uint64_t bitmap_size, uint64_t start) "container fd=%d, iova=0x%"PRIx64" size= 0x%"PRIx64" bitmap_size=0x%"PRIx64" start=0x%"PRIx64 +vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu dirty @ 0x%"PRIx64" - 0x%"PRIx64 # platform.c vfio_platform_base_device_init(char *name, int groupid) "%s belongs to group #%d"
@@ -148,19 +150,17 @@ vfio_display_edid_update(uint32_t prefx, uint32_t prefy) "%ux%u" vfio_display_edid_write_error(void) "" # migration.c +vfio_load_cleanup(const char *name) " (%s)" +vfio_load_device_config_state(const char *name) " (%s)" +vfio_load_state(const char *name, uint64_t data) " (%s) data 0x%"PRIx64 +vfio_load_state_device_data(const char *name, uint64_t data_size, int ret) " (%s) size 0x%"PRIx64" ret %d" vfio_migration_probe(const char *name) " (%s)" vfio_migration_set_state(const char *name, const char *state) " (%s) state %s" -vfio_vmstate_change(const char *name, int running, const char *reason, const char *dev_state) " (%s) running %d reason %s device state %s" vfio_migration_state_notifier(const char *name, const char *state) " (%s) state %s" -vfio_save_setup(const char *name, uint64_t data_buffer_size) " (%s) data buffer size 0x%"PRIx64 +vfio_save_block(const char *name, int data_size) " (%s) data_size %d" vfio_save_cleanup(const char *name) " (%s)" +vfio_save_complete_precopy(const char *name, int ret) " (%s) ret %d" vfio_save_device_config_state(const char *name) " (%s)" +vfio_save_setup(const char *name, uint64_t data_buffer_size) " (%s) data buffer size 0x%"PRIx64 vfio_state_pending_exact(const char *name, uint64_t precopy, uint64_t postcopy, uint64_t compatible, uint64_t stopcopy_size) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64" compatible 0x%"PRIx64" stopcopy size 0x%"PRIx64 -vfio_save_complete_precopy(const char *name, int ret) " (%s) ret %d" -vfio_load_device_config_state(const char *name) " (%s)" -vfio_load_state(const char *name, uint64_t data) " (%s) data 0x%"PRIx64 -vfio_load_state_device_data(const char *name, uint64_t data_size, int ret) " (%s) size 0x%"PRIx64" ret %d" -vfio_load_cleanup(const char *name) " (%s)" -vfio_get_dirty_bitmap(int fd, uint64_t iova, uint64_t size, uint64_t bitmap_size, uint64_t start) "container fd=%d, iova=0x%"PRIx64" size= 0x%"PRIx64" bitmap_size=0x%"PRIx64" start=0x%"PRIx64 -vfio_iommu_map_dirty_notify(uint64_t iova_start, uint64_t iova_end) "iommu dirty @ 0x%"PRIx64" - 0x%"PRIx64 -vfio_save_block(const char *name, int data_size) " (%s) data_size %d" +vfio_vmstate_change(const char *name, int running, const char *reason, const char *dev_state) " (%s) running %d reason %s device state %s"
Signature · 1 line
2.26.3
Re: [PATCH v10 11/12] vfio: Alphabetize migration section of VFIO trace-events file
Quoted 5 lines · Avihai Horon
Sort the migration section of VFIO trace events file alphabetically and move two misplaced traces to
common.csection.Signed-off-by Avihai Horon <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>
PATCH v10 12/12 docs/devel: Align VFIO migration docs to v2 protocol
In reply to Avihai HoronNow that VFIO migration protocol v2 has been implemented and v1 protocol has been removed, update the documentation according to v2 protocol.
--- docs/devel/vfio-migration.rst | 72 +++++++++++++++++------------------ 1 file changed, 34 insertions(+), 38 deletions(-)
docs/devel/vfio-migration.rst +34 -38
@@ -7,46 +7,43 @@ the guest is running on source host and restoring this saved state on the destination host. This document details how saving and restoring of VFIO devices is done in QEMU. -Migration of VFIO devices consists of two phases: the optional pre-copy phase, -and the stop-and-copy phase. The pre-copy phase is iterative and allows to -accommodate VFIO devices that have a large amount of data that needs to be -transferred. The iterative pre-copy phase of migration allows for the guest to -continue whilst the VFIO device state is transferred to the destination, this -helps to reduce the total downtime of the VM. VFIO devices can choose to skip -the pre-copy phase of migration by returning pending_bytes as zero during the -pre-copy phase. +Migration of VFIO devices currently consists of a single stop-and-copy phase. +During the stop-and-copy phase the guest is stopped and the entire VFIO device +data is transferred to the destination. + +The pre-copy phase of migration is currently not supported for VFIO devices. +Support for VFIO pre-copy will be added later on. + +Note that currently VFIO migration is supported only for a single device. This +is due to VFIO migration's lack of P2P support. However, P2P support is planned +to be added later on. A detailed description of the UAPI for VFIO device migration can be found in -the comment for the ``vfio_device_migration_info`` structure in the header -file linux-headers/linux/vfio.h. +the comment for the ``vfio_device_mig_state`` structure in the header file +linux-headers/linux/vfio.h. VFIO implements the device hooks for the iterative approach as follows: -* A ``save_setup`` function that sets up the migration region and sets _SAVING - flag in the VFIO device state. +* A ``save_setup`` function that sets up migration on the source. -* A ``load_setup`` function that sets up the migration region on the - destination and sets _RESUMING flag in the VFIO device state. +* A ``load_setup`` function that sets the VFIO device on the destination in + _RESUMING state. * A ``state_pending_exact`` function that reads pending_bytes from the vendor driver, which indicates the amount of data that the vendor driver has yet to save for the VFIO device. -* A ``save_live_iterate`` function that reads the VFIO device's data from the - vendor driver through the migration region during iterative phase. - * A ``save_state`` function to save the device config space if it is present. -* A ``save_live_complete_precopy`` function that resets _RUNNING flag from the - VFIO device state and iteratively copies the remaining data for the VFIO - device until the vendor driver indicates that no data remains (pending bytes - is zero). +* A ``save_live_complete_precopy`` function that sets the VFIO device in + _STOP_COPY state and iteratively copies the data for the VFIO device until + the vendor driver indicates that no data remains. * A ``load_state`` function that loads the config section and the data - sections that are generated by the save functions above + sections that are generated by the save functions above. * ``cleanup`` functions for both save and load that perform any migration - related cleanup, including unmapping the migration region + related cleanup. The VFIO migration code uses a VM state change handler to change the VFIO
@@ -71,13 +68,13 @@ tracking can identify dirtied pages, but any page pinned by the vendor driver can also be written by the device. There is currently no device or IOMMU support for dirty page tracking in hardware. -By default, dirty pages are tracked when the device is in pre-copy as well as -stop-and-copy phase. So, a page pinned by the vendor driver will be copied to -the destination in both phases. Copying dirty pages in pre-copy phase helps -QEMU to predict if it can achieve its downtime tolerances. If QEMU during -pre-copy phase keeps finding dirty pages continuously, then it understands -that even in stop-and-copy phase, it is likely to find dirty pages and can -predict the downtime accordingly. +By default, dirty pages are tracked during pre-copy as well as stop-and-copy +phase. So, a page pinned by the vendor driver will be copied to the destination +in both phases. Copying dirty pages in pre-copy phase helps QEMU to predict if +it can achieve its downtime tolerances. If QEMU during pre-copy phase keeps +finding dirty pages continuously, then it understands that even in stop-and-copy +phase, it is likely to find dirty pages and can predict the downtime +accordingly. QEMU also provides a per device opt-out option ``pre-copy-dirty-page-tracking`` which disables querying the dirty bitmap during pre-copy phase. If it is set to
@@ -111,23 +108,22 @@ Live migration save path | migrate_init spawns migration_thread Migration thread then calls each device's .save_setup() - (RUNNING, _SETUP, _RUNNING|_SAVING) + (RUNNING, _SETUP, _RUNNING) | - (RUNNING, _ACTIVE, _RUNNING|_SAVING) + (RUNNING, _ACTIVE, _RUNNING) If device is active, get pending_bytes by .state_pending_exact() If total pending_bytes >= threshold_size, call .save_live_iterate() - Data of VFIO device for pre-copy phase is copied Iterate till total pending bytes converge and are less than threshold | On migration completion, vCPU stops and calls .save_live_complete_precopy for - each active device. The VFIO device is then transitioned into _SAVING state - (FINISH_MIGRATE, _DEVICE, _SAVING) + each active device. The VFIO device is then transitioned into _STOP_COPY state + (FINISH_MIGRATE, _DEVICE, _STOP_COPY) | For the VFIO device, iterate in .save_live_complete_precopy until pending data is 0 - (FINISH_MIGRATE, _DEVICE, _STOPPED) + (FINISH_MIGRATE, _DEVICE, _STOP) | - (FINISH_MIGRATE, _COMPLETED, _STOPPED) + (FINISH_MIGRATE, _COMPLETED, _STOP) Migraton thread schedules cleanup bottom half and exits Live migration resume path
@@ -136,7 +132,7 @@ Live migration resume path :: Incoming migration calls .load_setup for each device - (RESTORE_VM, _ACTIVE, _STOPPED) + (RESTORE_VM, _ACTIVE, _STOP) | For each device, .load_state is called for that device section data (RESTORE_VM, _ACTIVE, _RESUMING)
Signature · 1 line
2.26.3