Make switchover-ack re-usable and add VFIO precopy REINIT feature
cover Make switchover-ack re-usable and add VFIO precopy REINIT feature
Hello,
This series adds support for the kernel VFIO_PRECOPY_INFO_REINIT feature [1], which can reduce migration downtime in some VFIO precopy scenarios (see the Tests section below). Supporting it requires refactoring switchover-ack and making it re-usable; that work comes first.
The series is based on Peter's VFIO fixes series [2].
Based-on: [email protected]
=== Background ===
Switchover-ack is a mechanism to synchronize between source and destination QEMU during migration to prevent the source from switching over prematurely.
VFIO uses switchover-ack to ensure switchover happens only after destination side has loaded the precopy initial bytes. This is important for VFIO, as otherwise downtime could be impacted and be higher.
In its current state, switchover-ack is a one-time mechanism, meaning that switchover is acked only once and past that another ACK cannot be requested again. This was sufficient until now, as VFIO precopy initial bytes was defined to be monotonically decreasing. Thus, when precopy initial bytes reached zero for all VFIO devices, a single ACK would be sent and its validity would hold.
=== Problem ===
Now the new VFIO_PRECOPY_INFO_REINIT feature allows precopy initial bytes to be re-initialized during precopy. Specifically, it means that initial bytes can grow after reaching zero, which would invalidate a previously sent switchover ACK.
=== Solution ===
To support VFIO_PRECOPY_INFO_REINIT, this series makes switchover-ack re-usable and allows devices to request another switchover ACK when needed.
In the new mechansim, switchover ACK can be requested for a specific device and in different times, so switchover ACK is changed to be per-device (instead of a single ACK for all devices) and source side is the one who does the pending ACKs accounting (instead of destination side).
The old (legacy) switchover-ack mechanism is kept for backward compatibility and is turned on by a compatibility property for older machines.
With that infrastructure in place, VFIO uses the new switchover-ack path and implements VFIO_PRECOPY_INFO_REINIT.
=== Tests ===
Functional and performance tests were run.
Performance tests were done by migrating a single VM with:
* 8 GB RAM
* 4 mlx5 VFIO devices:
- One device with 1GB of device data (stopcopy data) that runs workload during precopy so VFIO_PRECOPY_INFO_REINIT is exercised (generate new initial_bytes chunks during precopy).
- The other 3 devices are idle.
In this setup, VFIO_PRECOPY_INFO_REINIT reduced total migration downtime by about 43%, and downtime attributed to the busy VFIO device by about 67%:
With VFIO_PRECOPY_INFO_REINIT:
1335ms total (~520ms from the VFIO device running the workload).
Without VFIO_PRECOPY_INFO_REINIT:
2352ms total (~1600ms from the VFIO device running the workload).
Functional tests covered the main code paths and combinations, including legacy and new switchover-ack across versions, for example:
* Migration between QEMU 11.0 (old binary) and 11.1 (new binary).
* Migration between two 11.1 binaries with different machine versions.
* Migration when the VFIO device has no VFIO_PRECOPY_INFO_REINIT.
* Migration when the VFIO device has no VFIO precopy support.
=== Patch Breakdown ===
* Patches 1-2: Update Linux headers
* Patches 3-8,14: Migration cleanups and the new switchover-ack mechanism
* Patches 9-13: VFIO cleanups and VFIO_PRECOPY_INFO_REINIT
Thanks.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/qemu-devel/[email protected]/
Avihai Horon (14):
scripts/update-linux-headers: Add typelimits.h
linux-headers: Update to Linux v7.1-rc1
migration: Propagate errors in migration_completion_precopy()
migration: Log the approver in qemu_loadvm_approve_switchover()
migration: Replace switchover_ack_needed SaveVMHandler
migration: Rename switchover-ack code to legacy
migration: Make switchover-ack re-usable
migration: Check switchover-ack during switchover phase vfio/migration: Re-query precopy size before sending
VFIO_MIG_FLAG_DEV_INIT_DATA_SENT
vfio/migration: Add Error ** parameter to vfio_migration_init() vfio/migration: Add new switchover-ack mechanism vfio/migration: Implement VFIO_PRECOPY_INFO_REINIT feature vfio/migration: Check VFIO_PRECOPY_INFO_REINIT during switchover
migration: Enable new switchover-ack
docs/devel/migration/vfio.rst | 4 +- hw/vfio/vfio-migration-internal.h | 2 + include/migration/client-options.h | 1 + include/migration/misc.h | 2 + include/migration/register.h | 21 +- include/standard-headers/drm/drm_fourcc.h | 28 +- include/standard-headers/linux/const.h | 18 + include/standard-headers/linux/ethtool.h | 28 +- .../linux/input-event-codes.h | 13 + include/standard-headers/linux/pci_regs.h | 71 ++- include/standard-headers/linux/typelimits.h | 8 + include/standard-headers/linux/virtio_ring.h | 3 +- include/standard-headers/linux/virtio_rtc.h | 237 ++++++++++ include/standard-headers/linux/vmclock-abi.h | 20 + linux-headers/asm-arm64/kvm.h | 1 + linux-headers/asm-arm64/unistd_64.h | 1 + linux-headers/asm-generic/unistd.h | 5 +- linux-headers/asm-loongarch/kvm.h | 5 + linux-headers/asm-loongarch/kvm_para.h | 1 + linux-headers/asm-loongarch/unistd_64.h | 2 + linux-headers/asm-mips/unistd_n32.h | 1 + linux-headers/asm-mips/unistd_n64.h | 1 + linux-headers/asm-mips/unistd_o32.h | 1 + linux-headers/asm-powerpc/unistd_32.h | 1 + linux-headers/asm-powerpc/unistd_64.h | 1 + linux-headers/asm-riscv/kvm.h | 11 +- linux-headers/asm-riscv/ptrace.h | 37 ++ linux-headers/asm-riscv/unistd_32.h | 1 + linux-headers/asm-riscv/unistd_64.h | 1 + linux-headers/asm-s390/unistd_32.h | 446 ------------------ linux-headers/asm-s390/unistd_64.h | 1 + linux-headers/asm-x86/kvm.h | 21 +- linux-headers/asm-x86/unistd_32.h | 1 + linux-headers/asm-x86/unistd_64.h | 1 + linux-headers/asm-x86/unistd_x32.h | 1 + linux-headers/linux/const.h | 18 + linux-headers/linux/iommufd.h | 48 ++ linux-headers/linux/kvm.h | 46 +- linux-headers/linux/mshv.h | 4 +- linux-headers/linux/psp-sev.h | 2 +- linux-headers/linux/stddef.h | 4 + linux-headers/linux/vduse.h | 85 +++- linux-headers/linux/vfio.h | 30 +- migration/migration.h | 17 +- migration/savevm.h | 4 +- hw/core/machine.c | 4 +- hw/vfio/migration.c | 195 +++++++- migration/migration.c | 65 ++- migration/options.c | 9 + migration/savevm.c | 146 ++++-- hw/vfio/trace-events | 5 +- migration/trace-events | 8 +- scripts/update-linux-headers.sh | 2 + 53 files changed, 1109 insertions(+), 580 deletions(-) create mode 100644 include/standard-headers/linux/typelimits.h create mode 100644 include/standard-headers/linux/virtio_rtc.h delete mode 100644 linux-headers/asm-s390/unistd_32.h
Signature · 1 line
2.40.1
PATCH 1/14 scripts/update-linux-headers: Add typelimits.h
Upstream Linux added include/uapi/linux/typelimits.h and includes it from ethtool.h [1][2].
Teach update-linux-headers.sh to install that header into standard-headers to be able to update kernel headers to versions that include the above changes.
[1] ca9d74eb5f6a ("uapi: add INT_MAX and INT_MIN constants")
[2] a8a11e5237ae ("ethtool: uapi: Use UAPI definition of INT_MAX")
--- scripts/update-linux-headers.sh | 2 ++ 1 file changed, 2 insertions(+)
scripts/update-linux-headers.sh +2 -0
@@ -60,6 +60,7 @@ cp_portable() { -e 'drm.h' \ -e 'limits' \ -e 'linux/const' \ + -e 'linux/typelimits' \ -e 'linux/kernel' \ -e 'linux/sysinfo' \ -e 'asm/setup_data.h' \
@@ -250,6 +251,7 @@ for i in "$hdrdir"/include/linux/*virtio*.h \ "$hdrdir/include/linux/pci_regs.h" \ "$hdrdir/include/linux/ethtool.h" \ "$hdrdir/include/linux/const.h" \ + "$hdrdir/include/linux/typelimits.h" \ "$hdrdir/include/linux/kernel.h" \ "$hdrdir/include/linux/kvm_para.h" \ "$hdrdir/include/linux/vhost_types.h" \
Signature · 1 line
2.40.1
Re: [PATCH 01/14] scripts/update-linux-headers: Add typelimits.h
+ Song Gao
Quoted 28 lines · Avihai Horon
Upstream Linux added
include/uapi/linux/typelimits.hand includes it fromethtool.h[1][2].Teach
update-linux-headers.shto install that header into standard-headers to be able to update kernel headers to versions that include the above changes.[1]
ca9d74eb5f6a("uapi: addINT_MAXandINT_MINconstants")
[2]a8a11e5237ae("ethtool: uapi: Use UAPI definition ofINT_MAX")Signed-off-by Avihai Horon <[email protected]>--- scripts/update-linux-headers.sh | 2 ++ 1 file changed, 2 insertions(+)scripts/update-linux-headers.sh +1
-0@@ -60,6 +60,7 @@ cp_portable() { -e 'drm.h' \ -e 'limits' \ -e 'linux/const' \ + -e 'linux/typelimits' \ -e 'linux/kernel' \ -e 'linux/sysinfo' \ -e 'asm/setup_data.h' \
scripts/update-linux-headers.sh for i in "$hdrdir"/include/linux/*virtio*.h \ · line 257
Quoted 7 lines
scripts/update-linux-headers.sh +1
-0@@ -250,6 +251,7 @@ for i in "$hdrdir"/include/linux/*virtio*.h \ "$hdrdir/include/linux/pci_regs.h" \ "$hdrdir/include/linux/ethtool.h" \ "$hdrdir/include/linux/const.h" \ + "$hdrdir/include/linux/typelimits.h" \ "$hdrdir/include/linux/kernel.h" \ "$hdrdir/include/linux/kvm_para.h" \ "$hdrdir/include/linux/vhost_types.h" \
Thanks,
C.
gaosong
Reviewed-byRe: [PATCH 01/14] scripts/update-linux-headers: Add typelimits.h
Hi,
I take this patch for my series and update the linux-headers.
Quoted 33 lines · Cédric Le Goater
+ Song Gao
Quoted 30 lines · Avihai Horon
Upstream Linux added
include/uapi/linux/typelimits.hand includes it fromethtool.h[1][2].Teach
update-linux-headers.shto install that header into standard-headers to be able to update kernel headers to versions that include the above changes.[1]
ca9d74eb5f6a("uapi: addINT_MAXandINT_MINconstants")
[2]a8a11e5237ae("ethtool: uapi: Use UAPI definition ofINT_MAX")Signed-off-by Avihai Horon <[email protected]>---
scripts/update-linux-headers.sh| 2 ++1 file changed, 2 insertions(+)scripts/update-linux-headers.sh +1
-0@@ -60,6 +60,7 @@ cp_portable() { -e 'drm.h' \ -e 'limits' \ -e 'linux/const' \ + -e 'linux/typelimits' \ -e 'linux/kernel' \ -e 'linux/sysinfo' \ -e 'asm/setup_data.h' \@@ -250,6 +251,7 @@ for i in "$hdrdir"/include/linux/*virtio*.h \ "$hdrdir/include/linux/pci_regs.h" \ "$hdrdir/include/linux/ethtool.h" \
Quoted 9 lines
scripts/update-linux-headers.sh for i in "$hdrdir"/include/linux/*virtio*.h \ · line 257
Quoted 5 lines
scripts/update-linux-headers.sh +1
-0"$hdrdir/include/linux/const.h" \ + "$hdrdir/include/linux/typelimits.h" \ "$hdrdir/include/linux/kernel.h" \ "$hdrdir/include/linux/kvm_para.h" \ "$hdrdir/include/linux/vhost_types.h" \Reviewed-by Cédric Le Goater <[email protected]>
Thanks.
Song Gao
Quoted 3 lines
Thanks,
C.
PATCH 2/14 linux-headers: Update to Linux v7.1-rc1
In reply to Avihai HoronUpdate Linux headers to get VFIO_PRECOPY_INFO_REINIT feature of VFIO migration uAPI.
The update was done by running update-linux-headers.sh on commit 254f49634ee1 ("Linux 7.1-rc1") in the Linux tree.
--- include/standard-headers/drm/drm_fourcc.h | 28 +- include/standard-headers/linux/const.h | 18 + include/standard-headers/linux/ethtool.h | 28 +- .../linux/input-event-codes.h | 13 + include/standard-headers/linux/pci_regs.h | 71 ++- include/standard-headers/linux/typelimits.h | 8 + include/standard-headers/linux/virtio_ring.h | 3 +- include/standard-headers/linux/virtio_rtc.h | 237 ++++++++++ include/standard-headers/linux/vmclock-abi.h | 20 + linux-headers/asm-arm64/kvm.h | 1 + linux-headers/asm-arm64/unistd_64.h | 1 + linux-headers/asm-generic/unistd.h | 5 +- linux-headers/asm-loongarch/kvm.h | 5 + linux-headers/asm-loongarch/kvm_para.h | 1 + linux-headers/asm-loongarch/unistd_64.h | 2 + linux-headers/asm-mips/unistd_n32.h | 1 + linux-headers/asm-mips/unistd_n64.h | 1 + linux-headers/asm-mips/unistd_o32.h | 1 + linux-headers/asm-powerpc/unistd_32.h | 1 + linux-headers/asm-powerpc/unistd_64.h | 1 + linux-headers/asm-riscv/kvm.h | 11 +- linux-headers/asm-riscv/ptrace.h | 37 ++ linux-headers/asm-riscv/unistd_32.h | 1 + linux-headers/asm-riscv/unistd_64.h | 1 + linux-headers/asm-s390/unistd_32.h | 446 ------------------ linux-headers/asm-s390/unistd_64.h | 1 + linux-headers/asm-x86/kvm.h | 21 +- linux-headers/asm-x86/unistd_32.h | 1 + linux-headers/asm-x86/unistd_64.h | 1 + linux-headers/asm-x86/unistd_x32.h | 1 + linux-headers/linux/const.h | 18 + linux-headers/linux/iommufd.h | 48 ++ linux-headers/linux/kvm.h | 46 +- linux-headers/linux/mshv.h | 4 +- linux-headers/linux/psp-sev.h | 2 +- linux-headers/linux/stddef.h | 4 + linux-headers/linux/vduse.h | 85 +++- linux-headers/linux/vfio.h | 30 +- 38 files changed, 711 insertions(+), 493 deletions(-) create mode 100644 include/standard-headers/linux/typelimits.h create mode 100644 include/standard-headers/linux/virtio_rtc.h delete mode 100644 linux-headers/asm-s390/unistd_32.h
include/standard-headers/drm/drm_fourcc.h +22 -6
@@ -400,8 +400,8 @@ extern "C" {* implementation can multiply the values by 2^6=64. For that reason the padding * must only contain zeros. * index 0 = Y plane, [15:0] z:Y [6:10] little endian -* index 1 = Cr plane, [15:0] z:Cr [6:10] little endian -* index 2 = Cb plane, [15:0] z:Cb [6:10] little endian +* index 1 = Cb plane, [15:0] z:Cb [6:10] little endian +* index 2 = Cr plane, [15:0] z:Cr [6:10] little endian */ #define DRM_FORMAT_S010 fourcc_code('S', '0', '1', '0')/* 2x2 subsampled Cb (1) and Cr (2) planes 10 bits per channel */ #define DRM_FORMAT_S210 fourcc_code('S', '2', '1', '0')/* 2x1 subsampled Cb (1) and Cr (2) planes 10 bits per channel */
@@ -413,8 +413,8 @@ extern "C" {* implementation can multiply the values by 2^4=16. For that reason the padding * must only contain zeros. * index 0 = Y plane, [15:0] z:Y [4:12] little endian -* index 1 = Cr plane, [15:0] z:Cr [4:12] little endian -* index 2 = Cb plane, [15:0] z:Cb [4:12] little endian +* index 1 = Cb plane, [15:0] z:Cb [4:12] little endian +* index 2 = Cr plane, [15:0] z:Cr [4:12] little endian */ #define DRM_FORMAT_S012 fourcc_code('S', '0', '1', '2')/* 2x2 subsampled Cb (1) and Cr (2) planes 12 bits per channel */ #define DRM_FORMAT_S212 fourcc_code('S', '2', '1', '2')/* 2x1 subsampled Cb (1) and Cr (2) planes 12 bits per channel */
@@ -423,8 +423,8 @@ extern "C" {/* * 3 plane YCbCr * index 0 = Y plane, [15:0] Y little endian -* index 1 = Cr plane, [15:0] Cr little endian -* index 2 = Cb plane, [15:0] Cb little endian +* index 1 = Cb plane, [15:0] Cb little endian +* index 2 = Cr plane, [15:0] Cr little endian */ #define DRM_FORMAT_S016 fourcc_code('S', '0', '1', '6')/* 2x2 subsampled Cb (1) and Cr (2) planes 16 bits per channel */ #define DRM_FORMAT_S216 fourcc_code('S', '2', '1', '6')/* 2x1 subsampled Cb (1) and Cr (2) planes 16 bits per channel */
@@ -1421,6 +1421,22 @@ drm_fourcc_canonicalize_nvidia_format_mod(uint64_t modifier)#define DRM_FORMAT_MOD_ARM_16X16_BLOCK_U_INTERLEAVED \ DRM_FORMAT_MOD_ARM_CODE(DRM_FORMAT_MOD_ARM_TYPE_MISC, 1ULL) +/* +* ARM 64k interleaved modifier +* +* This is used by ARM Mali v10+ GPUs. With this modifier, the plane is divided +* into 64k byte 1:1 or 2:1 -sided tiles. The 64k tiles are laid out linearly. +* Each 64k tile is divided into blocks of 16x16 texel blocks, which are +* themselves laid out linearly within a 64k tile. Then within each 16x16 +* block, texel blocks are laid out according to U order, similar to +* 16X16_BLOCK_U_INTERLEAVED. +* +* Note that unlike 16X16_BLOCK_U_INTERLEAVED, the layout does not change +* depending on whether a format is compressed or not. +*/ +#define DRM_FORMAT_MOD_ARM_INTERLEAVED_64K \ + DRM_FORMAT_MOD_ARM_CODE(DRM_FORMAT_MOD_ARM_TYPE_MISC, 2ULL) +/* * Allwinner tiled modifier *
include/standard-headers/linux/const.h +18 -0
@@ -50,4 +50,22 @@#define __KERNEL_DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d)) +/* +* Divide positive or negative dividend by positive or negative divisor +* and round to closest integer. Result is undefined for negative +* divisors if the dividend variable type is unsigned and for negative +* dividends if the divisor variable type is unsigned. +*/ +#define __KERNEL_DIV_ROUND_CLOSEST (x, divisor) \ +({ \ + __typeof__(x) __x = x; \ + __typeof__(divisor) __d = divisor; \ + \ + (((__typeof__(x))-1) > 0 || \ + ((__typeof__(divisor))-1) > 0 || \ + (((__x) > 0) == ((__d) > 0))) ? \ + (((__x) + ((__d) / 2)) / (__d)) : \ + (((__x) - ((__d) / 2)) / (__d)); \ +}) +#endif /* _LINUX_CONST_H */
include/standard-headers/linux/ethtool.h +22 -6
@@ -17,11 +17,10 @@#include "net/eth.h" #include "standard-headers/linux/const.h" +#include "standard-headers/linux/typelimits.h" #include "standard-headers/linux/types.h" #include "standard-headers/linux/if_ether.h" -#include <limits.h> /* for INT_MAX */ -/* All structures exposed to userland should be defined such that they * have the same layout for 32-bit and 64-bit userland. */
@@ -228,7 +227,7 @@ enum tunable_id {ETHTOOL_ID_UNSPEC ,ETHTOOL_RX_COPYBREAK ,ETHTOOL_TX_COPYBREAK , -ETHTOOL_PFC_PREVENTION_TOUT ,/* timeout in msecs */ +ETHTOOL_PFC_PREVENTION_TOUT ,/* both pause and pfc, see man ethtool */ ETHTOOL_TX_COPYBREAK_BUF_SIZE ,/* * Add your fresh new tunable attribute above and remember to update
@@ -603,6 +602,8 @@ enum ethtool_link_ext_state {ETHTOOL_LINK_EXT_STATE_POWER_BUDGET_EXCEEDED ,ETHTOOL_LINK_EXT_STATE_OVERHEAT ,ETHTOOL_LINK_EXT_STATE_MODULE , +ETHTOOL_LINK_EXT_STATE_OTP_SPEED_VIOLATION , + ETHTOOL_LINK_EXT_STATE_BMC_REQUEST_DOWN, };/* More information in addition to ETHTOOL_LINK_EXT_STATE_AUTONEG. */
@@ -1094,13 +1095,20 @@ enum ethtool_module_fw_flash_status {* struct ethtool_gstrings - string set for data tagging * @cmd: Command number = %ETHTOOL_GSTRINGS * @string_set: String set ID; one of &enum ethtool_stringset -* @len: On return, the number of strings in the string set +* @len: Number of strings in the string set * @data: Buffer for strings. Each string is null-padded to a size of * %ETH_GSTRING_LEN. * * Users must use %ETHTOOL_GSSET_INFO to find the number of strings in * the string set. They must allocate a buffer of the appropriate * size immediately following this structure. +* +* Setting @len on input is optional (though preferred), but must be zeroed +* otherwise. +* When set, @len will return the requested count if it matches the actual +* count; otherwise, it will be zero. +* This prevents issues when the number of strings is different than the +* userspace allocation. */ struct ethtool_gstrings {uint32_t cmd;
@@ -1177,13 +1185,20 @@ struct ethtool_test {/** * struct ethtool_stats - device-specific statistics * @cmd: Command number = %ETHTOOL_GSTATS -* @n_stats: On return, the number of statistics +* @n_stats: Number of statistics * @data: Array of statistics * * Users must use %ETHTOOL_GSSET_INFO or %ETHTOOL_GDRVINFO to find the * number of statistics that will be returned. They must allocate a * buffer of the appropriate size (8 * number of statistics) * immediately following this structure. +* +* Setting @n_stats on input is optional (though preferred), but must be zeroed +* otherwise. +* When set, @n_stats will return the requested count if it matches the actual +* count; otherwise, it will be zero. +* This prevents issues when the number of stats is different than the +* userspace allocation. */ struct ethtool_stats {uint32_t cmd;
@@ -2190,6 +2205,7 @@ enum ethtool_link_mode_bit_indices {#define SPEED_40000 40000#define SPEED_50000 50000#define SPEED_56000 56000 +#define SPEED_80000 80000#define SPEED_100000 100000#define SPEED_200000 200000#define SPEED_400000 400000
@@ -2200,7 +2216,7 @@ enum ethtool_link_mode_bit_indices {static inline int ethtool_validate_speed (uint32_t speed) { -return speed <=INT_MAX || speed == (uint32_t )SPEED_UNKNOWN ; +return speed <= __KERNEL_INT_MAX || speed == (uint32_t )SPEED_UNKNOWN ; }/* Duplex, half or full. */
include/standard-headers/linux/input-event-codes.h +13 -0
@@ -643,6 +643,10 @@#define KEY_EPRIVACY_SCREEN_ON 0x252#define KEY_EPRIVACY_SCREEN_OFF 0x253 +#define KEY_ACTION_ON_SELECTION 0x254/* AL Action on Selection (HUTRR119) */ +#define KEY_CONTEXTUAL_INSERT 0x255/* AL Contextual Insertion (HUTRR119) */ +#define KEY_CONTEXTUAL_QUERY 0x256/* AL Contextual Query (HUTRR119) */ +#define KEY_KBDINPUTASSIST_PREV 0x260#define KEY_KBDINPUTASSIST_NEXT 0x261#define KEY_KBDINPUTASSIST_PREVGROUP 0x262
@@ -891,6 +895,7 @@#define ABS_VOLUME 0x20#define ABS_PROFILE 0x21 +#define ABS_SND_PROFILE 0x22#define ABS_MISC 0x28
@@ -1000,4 +1005,12 @@#define SND_MAX 0x07#define SND_CNT (SND_MAX+1) +/* +* ABS_SND_PROFILE values +*/ + +#define SND_PROFILE_SILENT 0x00 +#define SND_PROFILE_VIBRATE 0x01 +#define SND_PROFILE_RING 0x02 +#endif
include/standard-headers/linux/pci_regs.h +65 -6
93 lines not on this page · raw message
include/standard-headers/linux/typelimits.h new file +8 -0
@@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _LINUX_TYPELIMITS_H +#define _LINUX_TYPELIMITS_H + +#define __KERNEL_INT_MAX ((int)(~0U >> 1)) +#define __KERNEL_INT_MIN (-__KERNEL_INT_MAX - 1) + +#endif /* _LINUX_TYPELIMITS_H */
include/standard-headers/linux/virtio_ring.h +1 -2
@@ -31,7 +31,6 @@* SUCH DAMAGE. * * Copyright Rusty Russell IBM Corporation 2007. */ -#include <stdint.h> #include "standard-headers/linux/types.h" #include "standard-headers/linux/virtio_types.h"
@@ -200,7 +199,7 @@ static inline void vring_init(struct vring *vr, unsigned int num, void *p, vr->num = num; vr->desc = p; vr->avail = (struct vring_avail *)((char *)p + num *sizeof (struct vring_desc )); - vr->used = (void *)(((uintptr_t )&vr->avail->ring[num] +sizeof (__virtio16) + vr->used = (void *)(((unsigned long )&vr->avail->ring[num] +sizeof (__virtio16) + align-1 ) & ~(align -1 )); }
include/standard-headers/linux/virtio_rtc.h new file +237 -0
237 lines not on this page · raw message
include/standard-headers/linux/vmclock-abi.h +20 -0
@@ -115,6 +115,17 @@ struct vmclock_abi {* bit again after the update, using the about-to-be-valid fields. */ #define VMCLOCK_FLAG_TIME_MONOTONIC (1 << 7) +/* +* If the VM_GEN_COUNTER_PRESENT flag is set, the hypervisor will +* bump the vm_generation_counter field every time the guest is +* loaded from some save state (restored from a snapshot). +*/ +#define VMCLOCK_FLAG_VM_GEN_COUNTER_PRESENT (1 << 8) +/* +* If the NOTIFICATION_PRESENT flag is set, the hypervisor will send +* a notification every time it updates seq_count to a new even number. +*/ +#define VMCLOCK_FLAG_NOTIFICATION_PRESENT (1 << 9)uint8_t pad[2 ];uint8_t clock_status;
@@ -177,6 +188,15 @@ struct vmclock_abi {uint64_t time_frac_sec;/* Units of 1/2^64 of a second */ uint64_t time_esterror_nanosec;uint64_t time_maxerror_nanosec; + +/* +* This field changes to another non-repeating value when the guest +* has been loaded from a snapshot. In addition to handling a +* disruption in time (which will also be signalled through the +* disruption_marker field), a guest may wish to discard UUIDs, +* reset network connections, reseed entropy, etc. +*/ + uint64_t vm_generation_counter; };#endif /* __VMCLOCK_ABI_H__ */
linux-headers/asm-arm64/kvm.h +1 -0
@@ -416,6 +416,7 @@ enum {#define KVM_DEV_ARM_ITS_RESTORE_TABLES 2#define KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES 3#define KVM_DEV_ARM_ITS_CTRL_RESET 4 +#define KVM_DEV_ARM_VGIC_USERSPACE_PPIS 5/* Device Control API on vcpu fd */ #define KVM_ARM_VCPU_PMU_V3_CTRL 0
linux-headers/asm-arm64/unistd_64.h +1 -0
@@ -327,6 +327,7 @@#define __NR_file_getattr 468#define __NR_file_setattr 469#define __NR_listns 470 +#define __NR_rseq_slice_yield 471#endif /* _ASM_UNISTD_64_H */
linux-headers/asm-generic/unistd.h +4 -1
@@ -860,8 +860,11 @@ __SYSCALL(__NR_file_setattr, sys_file_setattr)#define __NR_listns 470 __SYSCALL(__NR_listns, sys_listns) +#define __NR_rseq_slice_yield 471 +__SYSCALL(__NR_rseq_slice_yield, sys_rseq_slice_yield) +#undef __NR_syscalls -#define __NR_syscalls 471 +#define __NR_syscalls 472/* * 32 bit systems traditionally used different
linux-headers/asm-loongarch/kvm.h +5 -0
@@ -105,6 +105,7 @@ struct kvm_fpu {#define KVM_LOONGARCH_VM_FEAT_PV_STEALTIME 7#define KVM_LOONGARCH_VM_FEAT_PTW 8#define KVM_LOONGARCH_VM_FEAT_MSGINT 9 +#define KVM_LOONGARCH_VM_FEAT_PV_PREEMPT 10/* Device Control API on vcpu fd */ #define KVM_LOONGARCH_VCPU_CPUCFG 0
@@ -154,4 +155,8 @@ struct kvm_iocsr_entry {#define KVM_DEV_LOONGARCH_PCH_PIC_GRP_CTRL 0x40000006#define KVM_DEV_LOONGARCH_PCH_PIC_CTRL_INIT 0 +#define KVM_DEV_LOONGARCH_DMSINTC_GRP_CTRL 0x40000007 +#define KVM_DEV_LOONGARCH_DMSINTC_MSG_ADDR_BASE 0x0 +#define KVM_DEV_LOONGARCH_DMSINTC_MSG_ADDR_SIZE 0x1 +#endif /* __UAPI_ASM_LOONGARCH_KVM_H */
linux-headers/asm-loongarch/kvm_para.h +1 -0
@@ -15,6 +15,7 @@#define CPUCFG_KVM_FEATURE (CPUCFG_KVM_BASE + 4)#define KVM_FEATURE_IPI 1#define KVM_FEATURE_STEAL_TIME 2 +#define KVM_FEATURE_PREEMPT 3/* BIT 24 - 31 are features configurable by user space vmm */ #define KVM_FEATURE_VIRT_EXTIOI 24#define KVM_FEATURE_USER_HCALL 25
linux-headers/asm-loongarch/unistd_64.h +2 -0
@@ -300,6 +300,7 @@#define __NR_landlock_create_ruleset 444#define __NR_landlock_add_rule 445#define __NR_landlock_restrict_self 446 +#define __NR_memfd_secret 447#define __NR_process_mrelease 448#define __NR_futex_waitv 449#define __NR_set_mempolicy_home_node 450
@@ -323,6 +324,7 @@#define __NR_file_getattr 468#define __NR_file_setattr 469#define __NR_listns 470 +#define __NR_rseq_slice_yield 471#endif /* _ASM_UNISTD_64_H */
linux-headers/asm-mips/unistd_n32.h +1 -0
@@ -399,5 +399,6 @@#define __NR_file_getattr (__NR_Linux + 468)#define __NR_file_setattr (__NR_Linux + 469)#define __NR_listns (__NR_Linux + 470) +#define __NR_rseq_slice_yield (__NR_Linux + 471)#endif /* _ASM_UNISTD_N32_H */
linux-headers/asm-mips/unistd_n64.h +1 -0
@@ -375,5 +375,6 @@#define __NR_file_getattr (__NR_Linux + 468)#define __NR_file_setattr (__NR_Linux + 469)#define __NR_listns (__NR_Linux + 470) +#define __NR_rseq_slice_yield (__NR_Linux + 471)#endif /* _ASM_UNISTD_N64_H */
linux-headers/asm-mips/unistd_o32.h +1 -0
@@ -445,5 +445,6 @@#define __NR_file_getattr (__NR_Linux + 468)#define __NR_file_setattr (__NR_Linux + 469)#define __NR_listns (__NR_Linux + 470) +#define __NR_rseq_slice_yield (__NR_Linux + 471)#endif /* _ASM_UNISTD_O32_H */
linux-headers/asm-powerpc/unistd_32.h +1 -0
@@ -452,6 +452,7 @@#define __NR_file_getattr 468#define __NR_file_setattr 469#define __NR_listns 470 +#define __NR_rseq_slice_yield 471#endif /* _ASM_UNISTD_32_H */
linux-headers/asm-powerpc/unistd_64.h +1 -0
@@ -424,6 +424,7 @@#define __NR_file_getattr 468#define __NR_file_setattr 469#define __NR_listns 470 +#define __NR_rseq_slice_yield 471#endif /* _ASM_UNISTD_64_H */
linux-headers/asm-riscv/kvm.h +7 -4
@@ -110,6 +110,10 @@ struct kvm_riscv_timer {__u64 state; }; +/* Possible states for kvm_riscv_timer */ +#define KVM_RISCV_TIMER_STATE_OFF 0 +#define KVM_RISCV_TIMER_STATE_ON 1 +/* * ISA extension IDs specific to KVM. This is not the same as the host ISA * extension IDs as that is internal to the host and should not be exposed
@@ -192,6 +196,9 @@ enum KVM_RISCV_ISA_EXT_ID {KVM_RISCV_ISA_EXT_ZFBFMIN ,KVM_RISCV_ISA_EXT_ZVFBFMIN ,KVM_RISCV_ISA_EXT_ZVFBFWMA , +KVM_RISCV_ISA_EXT_ZCLSD , +KVM_RISCV_ISA_EXT_ZILSD , +KVM_RISCV_ISA_EXT_ZALASR , KVM_RISCV_ISA_EXT_MAX, };
@@ -235,10 +242,6 @@ struct kvm_riscv_sbi_fwft {struct kvm_riscv_sbi_fwft_feature pointer_masking; }; -/* Possible states for kvm_riscv_timer */ -#define KVM_RISCV_TIMER_STATE_OFF 0 -#define KVM_RISCV_TIMER_STATE_ON 1 -/* If you need to interpret the index values, here is the key: */ #define KVM_REG_RISCV_TYPE_MASK 0x00000000FF000000#define KVM_REG_RISCV_TYPE_SHIFT 24
linux-headers/asm-riscv/ptrace.h +37 -0
@@ -9,6 +9,7 @@#ifndef __ASSEMBLER__#include <linux/types.h> +#include <linux/const.h> #define PTRACE_GETFDPIC 33
@@ -127,6 +128,42 @@ struct __riscv_v_regset_state {*/ #define RISCV_MAX_VLENB (8192) +struct __sc_riscv_cfi_state { +unsigned long ss_ptr;/* shadow stack pointer */ +}; + +#define PTRACE_CFI_BRANCH_LANDING_PAD_EN_BIT 0 +#define PTRACE_CFI_BRANCH_LANDING_PAD_LOCK_BIT 1 +#define PTRACE_CFI_BRANCH_EXPECTED_LANDING_PAD_BIT 2 +#define PTRACE_CFI_SHADOW_STACK_EN_BIT 3 +#define PTRACE_CFI_SHADOW_STACK_LOCK_BIT 4 +#define PTRACE_CFI_SHADOW_STACK_PTR_BIT 5 + +#define PTRACE_CFI_BRANCH_LANDING_PAD_EN_STATE _BITUL(PTRACE_CFI_BRANCH_LANDING_PAD_EN_BIT) +#define PTRACE_CFI_BRANCH_LANDING_PAD_LOCK_STATE \ + _BITUL(PTRACE_CFI_BRANCH_LANDING_PAD_LOCK_BIT) +#define PTRACE_CFI_BRANCH_EXPECTED_LANDING_PAD_STATE \ + _BITUL(PTRACE_CFI_BRANCH_EXPECTED_LANDING_PAD_BIT) +#define PTRACE_CFI_SHADOW_STACK_EN_STATE _BITUL(PTRACE_CFI_SHADOW_STACK_EN_BIT) +#define PTRACE_CFI_SHADOW_STACK_LOCK_STATE _BITUL(PTRACE_CFI_SHADOW_STACK_LOCK_BIT) +#define PTRACE_CFI_SHADOW_STACK_PTR_STATE _BITUL(PTRACE_CFI_SHADOW_STACK_PTR_BIT) + +#define PTRACE_CFI_STATE_INVALID_MASK ~(PTRACE_CFI_BRANCH_LANDING_PAD_EN_STATE | \ + PTRACE_CFI_BRANCH_LANDING_PAD_LOCK_STATE | \ + PTRACE_CFI_BRANCH_EXPECTED_LANDING_PAD_STATE | \ + PTRACE_CFI_SHADOW_STACK_EN_STATE | \ + PTRACE_CFI_SHADOW_STACK_LOCK_STATE | \ + PTRACE_CFI_SHADOW_STACK_PTR_STATE) + +struct __cfi_status { +__u64 cfi_state; +}; + +struct user_cfi_state { +struct __cfi_status cfi_status; +__u64 shstk_ptr; +}; +#endif /* __ASSEMBLER__ */ #endif /* _ASM_RISCV_PTRACE_H */
linux-headers/asm-riscv/unistd_32.h +1 -0
@@ -318,6 +318,7 @@#define __NR_file_getattr 468#define __NR_file_setattr 469#define __NR_listns 470 +#define __NR_rseq_slice_yield 471#endif /* _ASM_UNISTD_32_H */
linux-headers/asm-riscv/unistd_64.h +1 -0
@@ -328,6 +328,7 @@#define __NR_file_getattr 468#define __NR_file_setattr 469#define __NR_listns 470 +#define __NR_rseq_slice_yield 471#endif /* _ASM_UNISTD_64_H */
linux-headers/asm-s390/unistd_32.h deleted +0 -446
446 lines not on this page · raw message
linux-headers/asm-s390/unistd_64.h +1 -0
@@ -390,6 +390,7 @@#define __NR_file_getattr 468#define __NR_file_setattr 469#define __NR_listns 470 +#define __NR_rseq_slice_yield 471#endif /* _ASM_UNISTD_64_H */
linux-headers/asm-x86/kvm.h +13 -8
@@ -197,13 +197,13 @@ struct kvm_msrs {__u32 nmsrs;/* number of msrs in entries */ __u32 pad; -struct kvm_msr_entry entries[]; + __DECLARE_FLEX_ARRAY(struct kvm_msr_entry, entries); };/* for KVM_GET_MSR_INDEX_LIST */ struct kvm_msr_list {__u32 nmsrs;/* number of msrs in entries */ -__u32 indices[]; + __DECLARE_FLEX_ARRAY(__u32, indices); };/* Maximum size of any access bitmap in bytes */
@@ -243,7 +243,7 @@ struct kvm_cpuid_entry {struct kvm_cpuid {__u32 nent;__u32 padding; -struct kvm_cpuid_entry entries[]; + __DECLARE_FLEX_ARRAY(struct kvm_cpuid_entry, entries); };struct kvm_cpuid_entry2 {
@@ -265,7 +265,7 @@ struct kvm_cpuid_entry2 {struct kvm_cpuid2 {__u32 nent;__u32 padding; -struct kvm_cpuid_entry2 entries[]; + __DECLARE_FLEX_ARRAY(struct kvm_cpuid_entry2, entries); };/* for KVM_GET_PIT and KVM_SET_PIT */
@@ -396,7 +396,7 @@ struct kvm_xsave {* the contents of CPUID leaf 0xD on the host. */ __u32 region[1024 ]; -__u32 extra[]; +__DECLARE_FLEX_ARRAY (__u32, extra); };#define KVM_MAX_XCRS 16
@@ -474,6 +474,7 @@ struct kvm_sync_regs {#define KVM_X86_QUIRK_SLOT_ZAP_ALL (1 << 7)#define KVM_X86_QUIRK_STUFF_FEATURE_MSRS (1 << 8)#define KVM_X86_QUIRK_IGNORE_GUEST_PAT (1 << 9) +#define KVM_X86_QUIRK_VMCS12_ALLOW_FREEZE_IN_SMM (1 << 10)#define KVM_STATE_NESTED_FORMAT_VMX 0#define KVM_STATE_NESTED_FORMAT_SVM 1
@@ -501,6 +502,7 @@ struct kvm_sync_regs {#define KVM_X86_GRP_SEV 1# define KVM_X86_SEV_VMSA_FEATURES 0# define KVM_X86_SNP_POLICY_BITS 1 +# define KVM_X86_SEV_SNP_REQ_CERTS 2struct kvm_vmx_nested_state_data {__u8 vmcs12[KVM_STATE_NESTED_VMX_VMCS_SIZE ];
@@ -562,7 +564,7 @@ struct kvm_pmu_event_filter {__u32 fixed_counter_bitmap;__u32 flags;__u32 pad[4 ]; -__u64 events[]; +__DECLARE_FLEX_ARRAY (__u64, events); };#define KVM_PMU_EVENT_ALLOW 0
@@ -741,6 +743,7 @@ enum sev_cmd_id {KVM_SEV_SNP_LAUNCH_START =100 ,KVM_SEV_SNP_LAUNCH_UPDATE ,KVM_SEV_SNP_LAUNCH_FINISH , +KVM_SEV_SNP_ENABLE_REQ_CERTS , KVM_SEV_NR_MAX, };
@@ -912,8 +915,10 @@ struct kvm_sev_snp_launch_finish {__u64 pad1[4 ]; }; -#define KVM_X2APIC_API_USE_32BIT_IDS (1ULL << 0) -#define KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK (1ULL << 1) +#define KVM_X2APIC_API_USE_32BIT_IDS _BITULL(0) +#define KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK _BITULL(1) +#define KVM_X2APIC_ENABLE_SUPPRESS_EOI_BROADCAST _BITULL(2) +#define KVM_X2APIC_DISABLE_SUPPRESS_EOI_BROADCAST _BITULL(3)struct kvm_hyperv_eventfd {__u32 conn_id;
linux-headers/asm-x86/unistd_32.h +1 -0
@@ -461,6 +461,7 @@#define __NR_file_getattr 468#define __NR_file_setattr 469#define __NR_listns 470 +#define __NR_rseq_slice_yield 471#endif /* _ASM_UNISTD_32_H */
linux-headers/asm-x86/unistd_64.h +1 -0
@@ -385,6 +385,7 @@#define __NR_file_getattr 468#define __NR_file_setattr 469#define __NR_listns 470 +#define __NR_rseq_slice_yield 471#endif /* _ASM_UNISTD_64_H */
linux-headers/asm-x86/unistd_x32.h +1 -0
@@ -338,6 +338,7 @@#define __NR_file_getattr (__X32_SYSCALL_BIT + 468)#define __NR_file_setattr (__X32_SYSCALL_BIT + 469)#define __NR_listns (__X32_SYSCALL_BIT + 470) +#define __NR_rseq_slice_yield (__X32_SYSCALL_BIT + 471)#define __NR_rt_sigaction (__X32_SYSCALL_BIT + 512)#define __NR_rt_sigreturn (__X32_SYSCALL_BIT + 513)#define __NR_ioctl (__X32_SYSCALL_BIT + 514)
linux-headers/linux/const.h +18 -0
@@ -50,4 +50,22 @@#define __KERNEL_DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d)) +/* +* Divide positive or negative dividend by positive or negative divisor +* and round to closest integer. Result is undefined for negative +* divisors if the dividend variable type is unsigned and for negative +* dividends if the divisor variable type is unsigned. +*/ +#define __KERNEL_DIV_ROUND_CLOSEST (x, divisor) \ +({ \ + __typeof__(x) __x = x; \ + __typeof__(divisor) __d = divisor; \ + \ + (((__typeof__(x))-1) > 0 || \ + ((__typeof__(divisor))-1) > 0 || \ + (((__x) > 0) == ((__d) > 0))) ? \ + (((__x) + ((__d) / 2)) / (__d)) : \ + (((__x) - ((__d) / 2)) / (__d)); \ +}) +#endif /* _LINUX_CONST_H */
linux-headers/linux/iommufd.h +48 -0
99 lines not on this page · raw message
linux-headers/linux/kvm.h +40 -6
139 lines not on this page · raw message
linux-headers/linux/mshv.h +3 -1
@@ -27,6 +27,8 @@ enum {MSHV_PT_BIT_X2APIC ,MSHV_PT_BIT_GPA_SUPER_PAGES ,MSHV_PT_BIT_CPU_AND_XSAVE_FEATURES , +MSHV_PT_BIT_NESTED_VIRTUALIZATION , +MSHV_PT_BIT_SMT_ENABLED_GUEST , MSHV_PT_BIT_COUNT, };
@@ -355,7 +357,7 @@ struct mshv_vtl_sint_post_msg {struct mshv_vtl_ram_disposition {__u64 start_pfn; -__u64 last_pfn; +__u64 last_pfn;/* last_pfn is excluded from the range [start_pfn, last_pfn) */ };struct mshv_vtl_set_poll_file {
linux-headers/linux/psp-sev.h +1 -1
@@ -277,7 +277,7 @@ struct sev_user_data_snp_wrapped_vlek_hashstick {* struct sev_issue_cmd - SEV ioctl parameters * * @cmd: SEV commands to execute -* @opaque: pointer to the command structure +* @data: pointer to the command structure * @error: SEV FW return code on failure */ struct sev_issue_cmd {
linux-headers/linux/stddef.h +4 -0
@@ -69,6 +69,10 @@#define __counted_by_be (m)#endif +#ifndef __counted_by_ptr +#define __counted_by_ptr (m) +#endif +#define __kernel_nonstring#endif /* _LINUX_STDDEF_H */
linux-headers/linux/vduse.h +80 -5
180 lines not on this page · raw message
linux-headers/linux/vfio.h +29 -1
@@ -141,7 +141,7 @@ struct vfio_info_cap_header {* * Retrieve information about the group. Fills in provided * struct vfio_group_info. Caller sets argsz. -* Return: 0 on succes, -errno on failure. +* Return: 0 on success, -errno on failure. * Availability: Always */ struct vfio_group_status {
@@ -964,6 +964,10 @@ struct vfio_device_bind_iommufd {* hwpt corresponding to the given pt_id. * * Return: 0 on success, -errno on failure. +* +* When a device is resetting, -EBUSY will be returned to reject any concurrent +* attachment to the resetting device itself or any sibling device in the IOMMU +* group having the resetting device. */ struct vfio_device_attach_iommufd_pt {__u32 argsz;
@@ -1262,6 +1266,19 @@ enum vfio_device_mig_state {* The initial_bytes field indicates the amount of initial precopy * data available from the device. This field should have a non-zero initial * value and decrease as migration data is read from the device. +* The presence of the VFIO_PRECOPY_INFO_REINIT output flag indicates +* that new initial data is present on the stream. +* The new initial data may result, for example, from device reconfiguration +* during migration that requires additional initialization data. +* In that case initial_bytes may report a non-zero value irrespective of +* any previously reported values, which progresses towards zero as precopy +* data is read from the data stream. dirty_bytes is also reset +* to zero and represents the state change of the device relative to the new +* initial_bytes. +* VFIO_PRECOPY_INFO_REINIT can be reported only after userspace opts in to +* VFIO_DEVICE_FEATURE_MIG_PRECOPY_INFOv2. Without this opt-in, the flags field +* of struct vfio_precopy_info is reserved for bug-compatibility reasons. +* * It is recommended to leave PRE_COPY for STOP_COPY only after this field * reaches zero. Leaving PRE_COPY earlier might make things slower. *
@@ -1297,6 +1314,7 @@ enum vfio_device_mig_state {struct vfio_precopy_info {__u32 argsz;__u32 flags; +#define VFIO_PRECOPY_INFO_REINIT (1 << 0)/* output - new initial data is present */ __aligned_u64 initial_bytes;__aligned_u64 dirty_bytes; };
@@ -1506,6 +1524,16 @@ struct vfio_device_feature_dma_buf { struct vfio_region_dma_range dma_ranges[] __counted_by(nr_ranges); }; +/* +* Enables the migration precopy_info_v2 behaviour. +* +* VFIO_DEVICE_FEATURE_MIG_PRECOPY_INFOv2. +* +* On SET, enables the v2 pre_copy_info behaviour, where the +* vfio_precopy_info.flags is a valid output field. +*/ +#define VFIO_DEVICE_FEATURE_MIG_PRECOPY_INFOv2 12 +/* -------- API for Type1 VFIO IOMMU -------- */ /**
Signature · 1 line
2.40.1
Re: [PATCH 02/14] linux-headers: Update to Linux v7.1-rc1
+ Song Gao
Quoted 47 lines · Avihai Horon
Update Linux headers to get
VFIO_PRECOPY_INFO_REINITfeature of VFIO migration uAPI.The update was done by running
update-linux-headers.shon commit254f49634ee1("Linux 7.1-rc1") in the Linux tree.Signed-off-by Avihai Horon<[email protected]>--- include/standard-headers/drm/drm_fourcc.h | 28 +- include/standard-headers/linux/const.h | 18 + include/standard-headers/linux/ethtool.h | 28 +- .../linux/input-event-codes.h | 13 + include/standard-headers/linux/pci_regs.h | 71 ++- include/standard-headers/linux/typelimits.h | 8 + include/standard-headers/linux/virtio_ring.h | 3 +- include/standard-headers/linux/virtio_rtc.h | 237 ++++++++++ include/standard-headers/linux/vmclock-abi.h | 20 + linux-headers/asm-arm64/kvm.h | 1 + linux-headers/asm-arm64/unistd_64.h | 1 + linux-headers/asm-generic/unistd.h | 5 +- linux-headers/asm-loongarch/kvm.h | 5 + linux-headers/asm-loongarch/kvm_para.h | 1 + linux-headers/asm-loongarch/unistd_64.h | 2 + linux-headers/asm-mips/unistd_n32.h | 1 + linux-headers/asm-mips/unistd_n64.h | 1 + linux-headers/asm-mips/unistd_o32.h | 1 + linux-headers/asm-powerpc/unistd_32.h | 1 + linux-headers/asm-powerpc/unistd_64.h | 1 + linux-headers/asm-riscv/kvm.h | 11 +- linux-headers/asm-riscv/ptrace.h | 37 ++ linux-headers/asm-riscv/unistd_32.h | 1 + linux-headers/asm-riscv/unistd_64.h | 1 + linux-headers/asm-s390/unistd_32.h | 446 ------------------ linux-headers/asm-s390/unistd_64.h | 1 + linux-headers/asm-x86/kvm.h | 21 +- linux-headers/asm-x86/unistd_32.h | 1 + linux-headers/asm-x86/unistd_64.h | 1 + linux-headers/asm-x86/unistd_x32.h | 1 + linux-headers/linux/const.h | 18 + linux-headers/linux/iommufd.h | 48 ++ linux-headers/linux/kvm.h | 46 +- linux-headers/linux/mshv.h | 4 +- linux-headers/linux/psp-sev.h | 2 +- linux-headers/linux/stddef.h | 4 + linux-headers/linux/vduse.h | 85 +++- linux-headers/linux/vfio.h | 30 +- 38 files changed, 711 insertions(+), 493 deletions(-)
Quoted 3 lines
create mode 100644
include/standard-headers/linux/typelimits.hcreate mode 100644include/standard-headers/linux/virtio_rtc.hdelete mode 100644linux-headers/asm-s390/unistd_32.h
Thanks,
C.
PATCH 3/14 migration: Propagate errors in migration_completion_precopy()
In reply to Avihai Horonmigration_completion_precopy() doesn't propagate errors to migration core which leads to error information loss. Fix that.
This prepares for a follow-up where migration_switchover_start() can fail on switchover-ack and still report a useful error. Errors from qemu_savevm_state_complete_precopy() are not propagated yet as it requires more plumbing.
--- migration/migration.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
migration/migration.c +6 -1
@@ -2780,23 +2780,28 @@ static bool migration_switchover_start(MigrationState *s, Error **errp)static int migration_completion_precopy (MigrationState *s) {int ret; +Error *local_err =NULL ;bql_lock ();if (!migrate_mode_is_cpr ()) { ret =migration_stop_vm (s,RUN_STATE_FINISH_MIGRATE );if (ret <0 ) { +error_setg_errno (&local_err, -ret,"Failed to stop the VM" ); goto out_unlock; } } -if (!migration_switchover_start (s,NULL )) { +if (!migration_switchover_start (s, &local_err)) { ret = -EFAULT ; goto out_unlock; } ret =qemu_savevm_state_complete_precopy (s); out_unlock: +if (local_err) { +migrate_error_propagate (s, local_err); + }bql_unlock ();return ret; }
Signature · 1 line
2.40.1
Re: [PATCH 03/14] migration: Propagate errors in migration_completion_precopy()
Quoted 37 lines · Avihai Horon
migration_completion_precopy()doesn't propagate errors to migration core which leads to error information loss. Fix that.This prepares for a follow-up where
migration_switchover_start()can fail on switchover-ack and still report a useful error. Errors fromqemu_savevm_state_complete_precopy()are not propagated yet as it requires more plumbing.Signed-off-by Avihai Horon <[email protected]>--- migration/migration.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)migration/migration.c +3
-1@@ -2780,23 +2780,28 @@ static bool migration_switchover_start(MigrationState *s, Error **errp)static int migration_completion_precopy (MigrationState *s) {int ret; +Error *local_err =NULL ;bql_lock ();if (!migrate_mode_is_cpr ()) { ret =migration_stop_vm (s,RUN_STATE_FINISH_MIGRATE );if (ret <0 ) { +error_setg_errno (&local_err, -ret,"Failed to stop the VM" ); goto out_unlock; } } -if (!migration_switchover_start (s,NULL )) { +if (!migration_switchover_start (s, &local_err)) { ret = -EFAULT ; goto out_unlock;
migration/migration.c static bool migration_switchover_start(MigrationState *s, Error **errp) · line 2807
Quoted 10 lines
migration/migration.c +3
-0} ret =qemu_savevm_state_complete_precopy (s); out_unlock: +if (local_err) { +migrate_error_propagate (s, local_err); + }bql_unlock ();return ret; }
Instead, I would modify migration_completion_precopy() to use the Error variable in migration_completion() :
static void migration_completion(MigrationState *s)
{
int ret = 0;
Error *local_err = NULL; if (s->state == MIGRATION_STATUS_ACTIVE) {
ret = migration_completion_precopy(s);
...Thanks,
C.
Re: [PATCH 03/14] migration: Propagate errors in migration_completion_precopy()
Quoted 62 lines · Cédric Le Goater
External email: Use caution opening links or attachments
Quoted 42 lines · Avihai Horon
migration_completion_precopy()doesn't propagate errors to migration core which leads to error information loss. Fix that.This prepares for a follow-up where
migration_switchover_start()can fail on switchover-ack and still report a useful error. Errors fromqemu_savevm_state_complete_precopy()are not propagated yet as it requires more plumbing.Signed-off-by Avihai Horon <[email protected]>---
migration/migration.c| 7 ++++++-1 file changed, 6 insertions(+), 1 deletion(-)migration/migration.c +3
-1@@ -2780,23 +2780,28 @@ static bool migration_switchover_start(MigrationState *s, Error **errp) static int migration_completion_precopy(MigrationState *s) { int ret; + Error *local_err = NULL; bql_lock(); if (!migrate_mode_is_cpr()) { ret = migration_stop_vm(s, RUN_STATE_FINISH_MIGRATE); if (ret < 0) { + error_setg_errno(&local_err, -ret, "Failed to stop the VM"); goto out_unlock; } } - if (!migration_switchover_start(s, NULL)) { + if (!migration_switchover_start(s, &local_err)) { ret = -EFAULT; goto out_unlock; } ret = qemu_savevm_state_complete_precopy(s);Quoted 7 lines
out_unlock:
+ if (local_err) {
+migrate_error_propagate(s, local_err);
+ }
bql_unlock();
return ret;
}Instead, I would modify
migration_completion_precopy()to use the Error variable inmigration_completion():static void
migration_completion(MigrationState *s){
int ret = 0;
Error*local_err= NULL;
Quoted 5 lines
if (
s->state==MIGRATION_STATUS_ACTIVE) {
ret =migration_completion_precopy(s);...
I'd rather keep this change limited and not involve migration_completion().
The error reporting in this path is a bit convoluted (mixing error reporting via qemu_file) and I think it deserves a separate series cleaning things up there.
Unless I am missing something here and the above should be easy?
Thanks.
Re: [PATCH 03/14] migration: Propagate errors in migration_completion_precopy()
Quoted 67 lines · Avihai Horon
Quoted 65 lines · Cédric Le Goater
External email: Use caution opening links or attachments
Quoted 42 lines · Avihai Horon
migration_completion_precopy()doesn't propagate errors to migration core which leads to error information loss. Fix that.This prepares for a follow-up where
migration_switchover_start()can fail on switchover-ack and still report a useful error. Errors fromqemu_savevm_state_complete_precopy()are not propagated yet as it requires more plumbing.Signed-off-by Avihai Horon <[email protected]>---
migration/migration.c| 7 ++++++-1 file changed, 6 insertions(+), 1 deletion(-)migration/migration.c +3
-1@@ -2780,23 +2780,28 @@ static bool migration_switchover_start(MigrationState *s, Error **errp) static int migration_completion_precopy(MigrationState *s) { int ret; + Error *local_err = NULL; bql_lock(); if (!migrate_mode_is_cpr()) { ret = migration_stop_vm(s, RUN_STATE_FINISH_MIGRATE); if (ret < 0) { + error_setg_errno(&local_err, -ret, "Failed to stop the VM"); goto out_unlock; } } - if (!migration_switchover_start(s, NULL)) { + if (!migration_switchover_start(s, &local_err)) { ret = -EFAULT; goto out_unlock; } ret = qemu_savevm_state_complete_precopy(s);Quoted 7 lines
out_unlock:
+ if (local_err) {
+migrate_error_propagate(s, local_err);
+ }
bql_unlock();
return ret;
}Instead, I would modify
migration_completion_precopy()to use the Error variable inmigration_completion():static void
migration_completion(MigrationState *s){
int ret = 0;
Error*local_err= NULL;if (
s->state==MIGRATION_STATUS_ACTIVE) {
ret =migration_completion_precopy(s);
Quoted 8 lines
Quoted 2 lines
...
I'd rather keep this change limited and not involve
migration_completion(). The error reporting in this path is a bit convoluted (mixing error reporting viaqemu_file) and I think it deserves a separate series cleaning things up there.Unless I am missing something here and the above should be easy?
Not easy to keep everything as before, but I tend to agree with Cedric.
The hard part is to maintain the same error when something failed in migration_completion(), but IMHO that's a legacy problem we'll need to tackle with, sooner or later. We can do it now, facing risk that some error message might change: I think it's worthwhile to try.
So it also avoids introducing yet another migrate_error_propagate() call deep in the stack.. Ideally we move it upper and upper so the invokation should be less as time goes.
The old priority to handle errors in migration_completion() is:
1. if qemu_file_get_error_obj() succeeded, use it first, otherwise,
2. if ret!=0, generate an error for retval
Side note: (1) is currently slightly off when qemu_file_get_error_obj() returns non-zero but without an Error attached.. but let's ignore it for now.
After this patch, we could prioritize Error* whenever set, hence:
1. if error non-null, use it directly,
2. if qemu_file_get_error_obj() succeeded, use it first, otherwise,
3. if ret!=0, generate an error for retval
I think this order makes sense because neither qemufile error nor retcode is better than a literal error passed over.
Thanks,
Signature · 1 line
Peter Xu
Re: [PATCH 03/14] migration: Propagate errors in migration_completion_precopy()
Quoted 97 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 65 lines · Avihai Horon
Quoted 64 lines · Cédric Le Goater
External email: Use caution opening links or attachments
Quoted 48 lines · Avihai Horon
migration_completion_precopy()doesn't propagate errors to migration core which leads to error information loss. Fix that.This prepares for a follow-up where
migration_switchover_start()can fail on switchover-ack and still report a useful error. Errors fromqemu_savevm_state_complete_precopy()are not propagated yet as it requires more plumbing.Signed-off-by Avihai Horon <[email protected]>--- migration/migration.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)migration/migration.c +6
-1@@ -2780,23 +2780,28 @@ static bool migration_switchover_start(MigrationState *s, Error **errp)static int migration_completion_precopy (MigrationState *s) {int ret; +Error *local_err =NULL ;bql_lock ();if (!migrate_mode_is_cpr ()) { ret =migration_stop_vm (s,RUN_STATE_FINISH_MIGRATE );if (ret <0 ) { +error_setg_errno (&local_err, -ret,"Failed to stop the VM"); goto out_unlock; } } -if (!migration_switchover_start (s,NULL )) { +if (!migration_switchover_start (s, &local_err)) { ret = -EFAULT ; goto out_unlock; } ret =qemu_savevm_state_complete_precopy (s); out_unlock: +if (local_err) { +migrate_error_propagate (s, local_err); + }bql_unlock ();return ret;Quoted 1 line
}
Instead, I would modify
migration_completion_precopy()to use the Error variable inmigration_completion():static void migration_completion(MigrationState *s) { int ret = 0; Error *local_err = NULL;if (s->state == MIGRATION_STATUS_ACTIVE) { ret = migration_completion_precopy(s);Quoted 8 lines
Quoted 2 lines
...I'd rather keep this change limited and not involve
migration_completion(). The error reporting in this path is a bit convoluted (mixing error reporting viaqemu_file) and I think it deserves a separate series cleaning things up there.Unless I am missing something here and the above should be easy?
Not easy to keep everything as before, but I tend to agree with Cedric.
The hard part is to maintain the same error when something failed in
migration_completion(), but IMHO that's a legacy problem we'll need to tackle with, sooner or later. We can do it now, facing risk that some error message might change: I think it's worthwhile to try.So it also avoids introducing yet another
migrate_error_propagate()call deep in the stack.. Ideally we move it upper and upper so the invokation should be less as time goes.The old priority to handle errors in
migration_completion()is:1. if
qemu_file_get_error_obj()succeeded, use it first, otherwise,
2. if ret!=0, generate an error for retvalSide note: (1) is currently slightly off when
qemu_file_get_error_obj()returns non-zero but without an Error attached.. but let's ignore it for now.
Quoted 8 lines
After this patch, we could prioritize Error* whenever set, hence:
1. if error non-null, use it directly,
2. ifqemu_file_get_error_obj()succeeded, use it first, otherwise,
3. if ret!=0, generate an error for retvalI think this order makes sense because neither qemufile error nor retcode is better than a literal error passed over.
Sounds reasonable, I will change it.
Thanks.
PATCH 4/14 migration: Log the approver in qemu_loadvm_approve_switchover()
In reply to Avihai HoronPass the device name that approved switchover to qemu_loadvm_approve_switchover() and log it in the trace for debugging purposes.
--- migration/savevm.h | 2 +- hw/vfio/migration.c | 2 +- migration/savevm.c | 4 ++-- migration/trace-events | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-)
migration/savevm.h +1 -1
@@ -70,7 +70,7 @@ void qemu_loadvm_state_cleanup(MigrationIncomingState *mis);int qemu_loadvm_state_main (QEMUFile *f,MigrationIncomingState *mis,Error **errp);int qemu_load_device_state (QEMUFile *f,Error **errp); -int qemu_loadvm_approve_switchover (void ); +int qemu_loadvm_approve_switchover (const char *approver);int qemu_savevm_state_non_iterable (QEMUFile *f,Error **errp); int qemu_savevm_state_non_iterable_early(QEMUFile *f, JSONWriter *vmdesc,
hw/vfio/migration.c +1 -1
@@ -818,7 +818,7 @@ static int vfio_load_state(QEMUFile *f, void *opaque, int version_id)return -EINVAL ; } - ret =qemu_loadvm_approve_switchover (); + ret =qemu_loadvm_approve_switchover (vbasedev->name);if (ret) { error_report( "%s: qemu_loadvm_approve_switchover failed, err=%d (%s)",
migration/savevm.c +2 -2
@@ -3158,7 +3158,7 @@ int qemu_load_device_state(QEMUFile *f, Error **errp)return 0 ; } -int qemu_loadvm_approve_switchover (void ) +int qemu_loadvm_approve_switchover (const char *approver) {MigrationIncomingState *mis =migration_incoming_get_current ();
@@ -3167,7 +3167,7 @@ int qemu_loadvm_approve_switchover(void) } mis->switchover_ack_pending_num--; -trace_loadvm_approve_switchover (mis->switchover_ack_pending_num); +trace_loadvm_approve_switchover (approver, mis->switchover_ack_pending_num);if (mis->switchover_ack_pending_num) {return 0 ;
migration/trace-events +1 -1
@@ -24,7 +24,7 @@ loadvm_postcopy_ram_handle_discard_end(void) "" loadvm_postcopy_ram_handle_discard_header(const char *ramid, uint16_t len) "%s: %ud" loadvm_process_command(const char *s, uint16_t len) "com=%s len=%d" loadvm_process_command_ping(uint32_t val) "0x%x" -loadvm_approve_switchover(unsigned int switchover_ack_pending_num) "Switchover ack pending num=%u" +loadvm_approve_switchover(const char *approver, unsigned int switchover_ack_pending_num) "Approver %s, switchover_ack_pending_num %u" postcopy_ram_listen_thread_exit(void) "" postcopy_ram_listen_thread_start(void) "" qemu_savevm_send_postcopy_advise(void) ""
Signature · 1 line
2.40.1
Re: [PATCH 04/14] migration: Log the approver in qemu_loadvm_approve_switchover()
Quoted 3 lines · Avihai Horon
Pass the device name that approved switchover to
qemu_loadvm_approve_switchover()and log it in the trace for debugging purposes.
hmm, isn't the trace event in vfio_load_state() enough :
trace_vfio_load_state(vbasedev->name, data);
May be we can improve it instead ?
Anyhow, I won't object to the change.
Thanks,
C.
Quoted 69 lines
Signed-off-by Avihai Horon <[email protected]>--- migration/savevm.h | 2 +- hw/vfio/migration.c | 2 +- migration/savevm.c | 4 ++-- migration/trace-events | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-)migration/savevm.h +1
-1@@ -70,7 +70,7 @@ void qemu_loadvm_state_cleanup(MigrationIncomingState *mis);int qemu_loadvm_state_main (QEMUFile *f,MigrationIncomingState *mis,Error **errp);int qemu_load_device_state (QEMUFile *f,Error **errp); -int qemu_loadvm_approve_switchover (void ); +int qemu_loadvm_approve_switchover (const char *approver);int qemu_savevm_state_non_iterable (QEMUFile *f,Error **errp); int qemu_savevm_state_non_iterable_early(QEMUFile *f, JSONWriter *vmdesc,hw/vfio/migration.c +1
-1@@ -818,7 +818,7 @@ static int vfio_load_state(QEMUFile *f, void *opaque, int version_id)return -EINVAL ; } - ret =qemu_loadvm_approve_switchover (); + ret =qemu_loadvm_approve_switchover (vbasedev->name);if (ret) { error_report( "%s: qemu_loadvm_approve_switchover failed, err=%d (%s)",migration/savevm.c +2
-2@@ -3158,7 +3158,7 @@ int qemu_load_device_state(QEMUFile *f, Error **errp)return 0 ; } -int qemu_loadvm_approve_switchover (void ) +int qemu_loadvm_approve_switchover (const char *approver) {MigrationIncomingState *mis =migration_incoming_get_current ();@@ -3167,7 +3167,7 @@ int qemu_loadvm_approve_switchover(void) } mis->switchover_ack_pending_num--; -trace_loadvm_approve_switchover (mis->switchover_ack_pending_num); +trace_loadvm_approve_switchover (approver, mis->switchover_ack_pending_num);if (mis->switchover_ack_pending_num) {return 0 ;migration/trace-events +1
-1@@ -24,7 +24,7 @@ loadvm_postcopy_ram_handle_discard_end(void) "" loadvm_postcopy_ram_handle_discard_header(const char *ramid, uint16_t len) "%s: %ud" loadvm_process_command(const char *s, uint16_t len) "com=%s len=%d" loadvm_process_command_ping(uint32_t val) "0x%x" -loadvm_approve_switchover(unsigned int switchover_ack_pending_num) "Switchover ack pending num=%u" +loadvm_approve_switchover(const char *approver, unsigned int switchover_ack_pending_num) "Approver %s, switchover_ack_pending_num %u" postcopy_ram_listen_thread_exit(void) "" postcopy_ram_listen_thread_start(void) "" qemu_savevm_send_postcopy_advise(void) ""
Re: [PATCH 04/14] migration: Log the approver in qemu_loadvm_approve_switchover()
Quoted 7 lines · Cédric Le Goater
External email: Use caution opening links or attachments
Quoted 3 lines · Avihai Horon
Pass the device name that approved switchover to
qemu_loadvm_approve_switchover()and log it in the trace for debugging purposes.
Quoted 7 lines
hmm, isn't the trace event in
vfio_load_state()enough :
trace_vfio_load_state(vbasedev->name, data);May be we can improve it instead ?
Anyhow, I won't object to the change.
We could print "data" more nicely, but the main benefit from having a separate trace is that we can enable only switchover-ack related traces without getting noise from traces of the other VFIO_MIG_FLAG_*. Plus, future switchover-ack users won't need to add a trace of their own and we can also log switchover_ack_pending_num.
I found it very convenient when debugging/testing this feature.
Thanks.
Quoted 78 lines
Quoted 77 lines
Signed-off-by Avihai Horon <[email protected]>---
migration/savevm.h | 2 +-
hw/vfio/migration.c | 2 +-
migration/savevm.c | 4 ++--
migration/trace-events | 2 +-4 files changed, 5 insertions(+), 5 deletions(-)migration/savevm.h +1
-1@@ -70,7 +70,7 @@ voidqemu_loadvm_state_cleanup (MigrationIncomingState *mis); int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis, Error **errp); int qemu_load_device_state(QEMUFile *f, Error **errp); -int qemu_loadvm_approve_switchover (void ); +int qemu_loadvm_approve_switchover (const char *approver); int qemu_savevm_state_non_iterable(QEMUFile *f, Error **errp); int qemu_savevm_state_non_iterable_early(QEMUFile *f,JSONWriter *vmdesc,
hw/vfio/migration.c +1
-1@@ -818,7 +818,7 @@ static int vfio_load_state(QEMUFile *f, void *opaque, int version_id) return -EINVAL; } - ret = qemu_loadvm_approve_switchover(); + ret = qemu_loadvm_approve_switchover(vbasedev->name); if (ret) {error_report(
"%s:qemu_loadvm_approve_switchoverfailed, err=%d (%s)",migration/savevm.c +2
-2@@ -3158,7 +3158,7 @@ int qemu_load_device_state(QEMUFile *f, Error **errp) return 0; } -int qemu_loadvm_approve_switchover (void ) +int qemu_loadvm_approve_switchover (const char *approver) { MigrationIncomingState *mis = migration_incoming_get_current();@@ -3167,7 +3167,7 @@ int qemu_loadvm_approve_switchover(void) } mis->switchover_ack_pending_num--; -trace_loadvm_approve_switchover (mis->switchover_ack_pending_num); + trace_loadvm_approve_switchover(approver, mis->switchover_ack_pending_num); if (mis->switchover_ack_pending_num) {return 0;
migration/trace-events +0
-0@@ -24,7 +24,7 @@ loadvm_postcopy_ram_handle_discard_end(void) ""
loadvm_postcopy_ram_handle_discard_header(const char *ramid, uint16_t len)"%s: %ud"loadvm_process_command(const char *s, uint16_t len)"com=%s len=%d"loadvm_process_command_ping(uint32_t val)"0x%x" -loadvm_approve_switchover(unsigned intswitchover_ack_pending_num) "Switchover ack pending num=%u"
+loadvm_approve_switchover(const char *approver, unsigned intswitchover_ack_pending_num) "Approver %s,switchover_ack_pending_num%u"postcopy_ram_listen_thread_exit(void)""postcopy_ram_listen_thread_start(void)""qemu_savevm_send_postcopy_advise(void)""
Re: [PATCH 04/14] migration: Log the approver in qemu_loadvm_approve_switchover()
In reply to Avihai HoronQuoted 5 lines · Avihai Horon
Pass the device name that approved switchover to
qemu_loadvm_approve_switchover()and log it in the trace for debugging purposes.Signed-off-by Avihai Horon <[email protected]>
Signature · 1 line
Peter Xu
PATCH 5/14 migration: Replace switchover_ack_needed SaveVMHandler
In reply to Avihai HoronA new switchover-ack mechanism that will replace the existing one will be added in the following patches. The new mechanism will have a new SaveVMHandler and will not use switchover_ack_needed. However, the old mechanism must still be kept for backward compatibility.
To keep things clear and decrease API surface of old code, replace switchover_ack_needed SaveVMHandler with a regular function migration_request_switchover_ack().
No functional changes intended.
--- docs/devel/migration/vfio.rst | 3 --- include/migration/misc.h | 2 ++ include/migration/register.h | 13 ------------- hw/vfio/migration.c | 18 ++++++++++-------- migration/migration.c | 15 +++++++++++++++ migration/savevm.c | 21 --------------------- migration/trace-events | 2 +- 7 files changed, 28 insertions(+), 46 deletions(-)
docs/devel/migration/vfio.rst +0 -3
@@ -59,9 +59,6 @@ VFIO implements the device hooks for the iterative approach as follows: * A ``save_live_iterate`` function that reads the VFIO device's data from the vendor driver during iterative pre-copy phase. -* A ``switchover_ack_needed`` function that checks if the VFIO device uses - "switchover-ack" migration capability when this capability is enabled. - * A ``switchover_start`` function that in the multifd mode starts a thread that reassembles the multifd received data and loads it in-order into the device. In the non-multifd mode this function is a NOP.
include/migration/misc.h +2 -0
@@ -156,4 +156,6 @@ bool multifd_device_state_save_thread_should_exit(void);void multifd_abort_device_state_save_threads (void );bool multifd_join_device_state_save_threads (void ); +void migration_request_switchover_ack (const char *requester); +#endif
include/migration/register.h +0 -13
@@ -299,19 +299,6 @@ typedef struct SaveVMHandlers {*/ int (*resume_prepare)(MigrationState *s,void *opaque); -/** -* @switchover_ack_needed -* -* Checks if switchover ack should be used. Called only on -* destination. -* -* @opaque: data pointer passed to register_savevm_live() -* -* Returns true if switchover ack should be used and false -* otherwise -*/ -bool (*switchover_ack_needed)(void *opaque); -/** * @switchover_start *
hw/vfio/migration.c +10 -8
@@ -463,6 +463,14 @@ static bool vfio_precopy_supported(VFIODevice *vbasedev)return migration->mig_flags &VFIO_MIGRATION_PRE_COPY ; } +static void vfio_request_switchover_ack (VFIODevice *vbasedev) +{ +if (vfio_precopy_supported (vbasedev)) { +/* Precopy support implies switchover-ack is needed */ +migration_request_switchover_ack (vbasedev->name); + } +} +/* ---------------------------------------------------------------------- */ static int vfio_save_prepare (void *opaque,Error **errp)
@@ -747,6 +755,8 @@ static int vfio_load_setup(QEMUFile *f, void *opaque, Error **errp)return ret; } +vfio_request_switchover_ack (vbasedev); +return 0 ; }
@@ -845,13 +855,6 @@ static int vfio_load_state(QEMUFile *f, void *opaque, int version_id)return ret; } -static bool vfio_switchover_ack_needed (void *opaque) -{ -VFIODevice *vbasedev = opaque; - -return vfio_precopy_supported (vbasedev); -} -static int vfio_switchover_start (void *opaque) {VFIODevice *vbasedev = opaque;
@@ -875,7 +878,6 @@ static const SaveVMHandlers savevm_vfio_handlers = { .load_setup = vfio_load_setup, .load_cleanup = vfio_load_cleanup, .load_state = vfio_load_state, - .switchover_ack_needed = vfio_switchover_ack_needed,/* * Multifd support */
migration/migration.c +15 -0
@@ -2164,6 +2164,21 @@ void migration_rp_kick(MigrationState *s)qemu_sem_post (&s->rp_state.rp_sem); } +/* This is called only on destination side */ +void migration_request_switchover_ack (const char *requester) +{ +MigrationIncomingState *mis =migration_incoming_get_current (); + +if (!migrate_switchover_ack ()) { +return ; + } + + mis->switchover_ack_pending_num++; + +trace_migration_request_switchover_ack (requester, + mis->switchover_ack_pending_num); +} + static struct rp_cmd_args { ssize_t len; /* -1 = variable */ const char *name;
migration/savevm.c +0 -21
@@ -2784,23 +2784,6 @@ static int qemu_loadvm_state_header(QEMUFile *f, Error **errp)return 0 ; } -static void qemu_loadvm_state_switchover_ack_needed (MigrationIncomingState *mis) -{ -SaveStateEntry *se; - - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { -if (!se->ops || !se->ops->switchover_ack_needed) { -continue ; - } - -if (se->ops->switchover_ack_needed (se->opaque)) { - mis->switchover_ack_pending_num++; - } - } - -trace_loadvm_state_switchover_ack_needed (mis->switchover_ack_pending_num); -} -static int qemu_loadvm_state_setup (QEMUFile *f,Error **errp) {ERRP_GUARD ();
@@ -3062,10 +3045,6 @@ int qemu_loadvm_state(QEMUFile *f, Error **errp)return -EINVAL ; } -if (migrate_switchover_ack ()) { -qemu_loadvm_state_switchover_ack_needed (mis); - } -cpu_synchronize_all_pre_loadvm (); ret =qemu_loadvm_state_main (f, mis, errp);
migration/trace-events +1 -1
@@ -8,7 +8,6 @@ qemu_loadvm_state_post_main(int ret) "%d" qemu_loadvm_state_section_startfull(uint32_t section_id, const char *idstr, uint32_t instance_id, uint32_t version_id) "%u(%s) %u %u" qemu_savevm_send_packaged(void) "" qemu_savevm_query_pending(bool exact, uint64_t precopy, uint64_t stopcopy, uint64_t postcopy, uint64_t total) "exact=%d, precopy=%"PRIu64", stopcopy=%"PRIu64", postcopy=%"PRIu64", total=%"PRIu64 -loadvm_state_switchover_ack_needed(unsigned int switchover_ack_pending_num) "Switchover ack pending num=%u" loadvm_state_setup(void) "" loadvm_state_cleanup(void) "" loadvm_handle_cmd_packaged(unsigned int length) "%u"
@@ -199,6 +198,7 @@ process_incoming_migration_co_postcopy_end_main(void) "" postcopy_preempt_enabled(bool value) "%d" migration_precopy_complete(void) "" migration_call_notifiers(int type) "type=%d" +migration_request_switchover_ack(const char *requester, unsigned int switchover_ack_pending_num) "Requester %s, switchover_ack_pending_num %u" # migration-stats migration_transferred_bytes(uint64_t qemu_file, uint64_t multifd, uint64_t rdma) "qemu_file %" PRIu64 " multifd %" PRIu64 " RDMA %" PRIu64
Signature · 1 line
2.40.1
Re: [PATCH 05/14] migration: Replace switchover_ack_needed SaveVMHandler
Quoted 5 lines · Avihai Horon
A new switchover-ack mechanism that will replace the existing one will be added in the following patches. The new mechanism will have a new SaveVMHandler and will not use
switchover_ack_needed. However, the old mechanism must still be kept for backward compatibility.
Quoted 7 lines
To keep things clear and decrease API surface of old code, replace
switchover_ack_neededSaveVMHandler with a regular functionmigration_request_switchover_ack().No functional changes intended.
Signed-off-by Avihai Horon <[email protected]>
Signature · 1 line
Peter Xu
PATCH 6/14 migration: Rename switchover-ack code to legacy
In reply to Avihai HoronA new switchover-ack mechanism will be added in the following patches. However, the old mechanism must still be kept for backward compatibility.
Rename existing code that will be used only for old switchover-ack mechanism as legacy. This will help to distinguish legacy code from new code and make it more readable and easier for removal later when no longer needed.
No functional change intended.
--- include/migration/misc.h | 2 +- migration/migration.h | 2 +- migration/savevm.h | 2 +- hw/vfio/migration.c | 14 +++++------ migration/migration.c | 8 +++---- migration/savevm.c | 51 ++++++++++++++++++++++++++-------------- migration/trace-events | 4 ++-- 7 files changed, 50 insertions(+), 33 deletions(-)
include/migration/misc.h +1 -1
@@ -156,6 +156,6 @@ bool multifd_device_state_save_thread_should_exit(void);void multifd_abort_device_state_save_threads (void );bool multifd_join_device_state_save_threads (void ); -void migration_request_switchover_ack (const char *requester); +void migration_request_switchover_ack_legacy (const char *requester);#endif
migration/migration.h +1 -1
@@ -246,7 +246,7 @@ struct MigrationIncomingState {* zero an ACK that it's OK to do switchover is sent to the source. No lock * is needed as this field is updated serially. */ -unsigned int switchover_ack_pending_num; +unsigned int switchover_ack_pending_num_legacy;/* Do exit on incoming migration failure */ bool exit_on_error;
migration/savevm.h +1 -1
@@ -70,7 +70,7 @@ void qemu_loadvm_state_cleanup(MigrationIncomingState *mis);int qemu_loadvm_state_main (QEMUFile *f,MigrationIncomingState *mis,Error **errp);int qemu_load_device_state (QEMUFile *f,Error **errp); -int qemu_loadvm_approve_switchover (const char *approver); +int qemu_loadvm_approve_switchover_legacy (const char *approver);int qemu_savevm_state_non_iterable (QEMUFile *f,Error **errp); int qemu_savevm_state_non_iterable_early(QEMUFile *f, JSONWriter *vmdesc,
hw/vfio/migration.c +7 -7
@@ -463,11 +463,11 @@ static bool vfio_precopy_supported(VFIODevice *vbasedev)return migration->mig_flags &VFIO_MIGRATION_PRE_COPY ; } -static void vfio_request_switchover_ack (VFIODevice *vbasedev) +static void vfio_request_switchover_ack_legacy (VFIODevice *vbasedev) {if (vfio_precopy_supported (vbasedev)) {/* Precopy support implies switchover-ack is needed */ -migration_request_switchover_ack (vbasedev->name); +migration_request_switchover_ack_legacy (vbasedev->name); } }
@@ -755,7 +755,7 @@ static int vfio_load_setup(QEMUFile *f, void *opaque, Error **errp)return ret; } -vfio_request_switchover_ack (vbasedev); +vfio_request_switchover_ack_legacy (vbasedev);return 0 ; }
@@ -828,11 +828,11 @@ static int vfio_load_state(QEMUFile *f, void *opaque, int version_id)return -EINVAL ; } - ret =qemu_loadvm_approve_switchover (vbasedev->name); + ret =qemu_loadvm_approve_switchover_legacy (vbasedev->name);if (ret) { -error_report ( -"%s: qemu_loadvm_approve_switchover failed, err=%d (%s)" , - vbasedev->name, ret,strerror (-ret)); +error_report ("%s: qemu_loadvm_approve_switchover_legacy " +"failed, err=%d (%s)" , + vbasedev->name, ret,strerror (-ret)); }return ret;
migration/migration.c +4 -4
@@ -2165,7 +2165,7 @@ void migration_rp_kick(MigrationState *s) }/* This is called only on destination side */ -void migration_request_switchover_ack (const char *requester) +void migration_request_switchover_ack_legacy (const char *requester) {MigrationIncomingState *mis =migration_incoming_get_current ();
@@ -2173,10 +2173,10 @@ void migration_request_switchover_ack(const char *requester)return ; } - mis->switchover_ack_pending_num++; + mis->switchover_ack_pending_num_legacy++; -trace_migration_request_switchover_ack (requester, - mis->switchover_ack_pending_num); +trace_migration_request_switchover_ack_legacy ( + requester, mis->switchover_ack_pending_num_legacy); } static struct rp_cmd_args {
migration/savevm.c +34 -17
76 lines not on this page · raw message
migration/trace-events +2 -2
@@ -23,7 +23,7 @@ loadvm_postcopy_ram_handle_discard_end(void) "" loadvm_postcopy_ram_handle_discard_header(const char *ramid, uint16_t len) "%s: %ud" loadvm_process_command(const char *s, uint16_t len) "com=%s len=%d" loadvm_process_command_ping(uint32_t val) "0x%x" -loadvm_approve_switchover(const char *approver, unsigned int switchover_ack_pending_num) "Approver %s, switchover_ack_pending_num %u" +loadvm_approve_switchover_legacy(const char *approver, unsigned int switchover_ack_pending_num_legacy) "Approver %s, switchover_ack_pending_num_legacy %u" postcopy_ram_listen_thread_exit(void) "" postcopy_ram_listen_thread_start(void) "" qemu_savevm_send_postcopy_advise(void) ""
@@ -198,7 +198,7 @@ process_incoming_migration_co_postcopy_end_main(void) "" postcopy_preempt_enabled(bool value) "%d" migration_precopy_complete(void) "" migration_call_notifiers(int type) "type=%d" -migration_request_switchover_ack(const char *requester, unsigned int switchover_ack_pending_num) "Requester %s, switchover_ack_pending_num %u" +migration_request_switchover_ack_legacy(const char *requester, unsigned int switchover_ack_pending_num_legacy) "Requester %s, switchover_ack_pending_num_legacy %u" # migration-stats migration_transferred_bytes(uint64_t qemu_file, uint64_t multifd, uint64_t rdma) "qemu_file %" PRIu64 " multifd %" PRIu64 " RDMA %" PRIu64
Signature · 1 line
2.40.1
PATCH 7/14 migration: Make switchover-ack re-usable
In reply to Avihai HoronSwitchover-ack is a mechanism to synchronize between source and destination QEMU during migration to prevent the source from switching over prematurely.
VFIO uses switchover-ack to ensure switchover happens only after destination side has loaded the precopy initial bytes. This is important for VFIO, as otherwise downtime could be impacted and be higher.
In its current state, switchover-ack is a one-time mechanism, meaning that switchover is acked only once and past that another ACK cannot be requested again. This was sufficient until now, as VFIO precopy initial bytes was defined to be monotonically decreasing. Thus, when precopy initial bytes reached zero for all VFIO devices, a single ACK would be sent and its validity would hold.
However, now the new VFIO_PRECOPY_INFO_REINIT feature allows precopy initial bytes to be re-initialized during precopy. Specifically, it means that initial bytes can grow after reaching zero, which would invalidate a previously sent switchover ACK.
To solve this, make switchover-ack reusable and allow devices to request another switchover ACK when needed.
To avoid scattering them all over, switchover ACKs are requested through a new request_switchover_ack handler which is called in specific places.
Since now switchover ACK can be requested for a specific device and in different times, make switchover ACK per-device (instead of a single ACK for all devices) and let source side do the pending ACKs accounting.
Keep the legacy switchover-ack mechanism for backward compatibility and turn it on by a compatibility property for older machines. Enable the property until VFIO implements the new switchover-ack.
--- include/migration/client-options.h | 1 + include/migration/register.h | 21 +++++++++ migration/migration.h | 15 +++++-- migration/savevm.h | 4 +- hw/core/machine.c | 4 +- hw/vfio/migration.c | 8 ++-- migration/migration.c | 38 +++++++++++++--- migration/options.c | 10 +++++ migration/savevm.c | 69 +++++++++++++++++++++++++++++- migration/trace-events | 4 +- 10 files changed, 156 insertions(+), 18 deletions(-)
include/migration/client-options.h +1 -0
@@ -13,6 +13,7 @@/* properties */ bool migrate_send_switchover_start (void ); +bool migrate_switchover_ack_legacy (void );/* capabilities */
include/migration/register.h +21 -0
@@ -30,6 +30,11 @@ typedef struct MigPendingData {uint64_t total_bytes; } MigPendingData; +enum MigSwitchoverAckRequestStage { +MIG_SWITCHOVER_ACK_REQUEST_STAGE_SETUP , +MIG_SWITCHOVER_ACK_REQUEST_STAGE_PENDING_EXACT , +}; +/** * struct SaveVMHandlers: handler structure to finely control * migration of complex subsystems and devices, such as RAM, block and
@@ -299,6 +304,22 @@ typedef struct SaveVMHandlers {*/ int (*resume_prepare)(MigrationState *s,void *opaque); +/** +* @request_switchover_ack +* +* Checks if a new switchover ACK is requested. Called only on source side +* in the stages specified in enum MigSwitchoverAckRequestStage. +* +* @stage: the stage in which the handler was called +* @opaque: data pointer passed to register_savevm_live() +* @requester: output pointer to be set to the name of the requester of the +* switchover ACK (for logging purposes). If not set, idstr will be used. +* +* Returns true to request switchover ACK and false otherwise +*/ +bool (*request_switchover_ack)(enum MigSwitchoverAckRequestStage stage, +void *opaque,const char **requester); +/** * @switchover_start *
migration/migration.h +12 -3
@@ -494,6 +494,12 @@ struct MigrationState {*/ uint8_t clear_bitmap_shift; +/* +* This decides whether to use legacy switchover ack (send ACK once for all +* devices) or new switchover ack (send ACK for each device). +*/ +bool switchover_ack_legacy; +/* * This save hostname when out-going migration starts */
@@ -503,10 +509,13 @@ struct MigrationState {JSONWriter *vmdesc;/* -* Indicates whether an ACK from the destination that it's OK to do -* switchover has been received. +* Indicates the number of pending ACKs from the destination. The value may +* increase or decrease during precopy as new ACKs are requested or +* received. When zero is reached, it's OK to switchover. In legacy +* switchover-ack, it's initialized to 1 and decreased to zero upon ACK. */ -bool switchover_acked; +uint32_t switchover_ack_pending_num; +/* Is this a rdma migration */ bool rdma_migration;
migration/savevm.h +3 -1
@@ -37,6 +37,8 @@ bool qemu_savevm_state_blocked(Error **errp);void qemu_savevm_non_migratable_list (strList **reasons);int qemu_savevm_state_prepare (Error **errp);int qemu_savevm_state_do_setup (QEMUFile *f,Error **errp); +int qemu_savevm_request_switchover_ack (enum MigSwitchoverAckRequestStage stage, +Error **errp);bool qemu_savevm_state_guest_unplug_pending (void );int qemu_savevm_state_resume_prepare (MigrationState *s);void qemu_savevm_send_header (QEMUFile *f);
@@ -70,7 +72,7 @@ void qemu_loadvm_state_cleanup(MigrationIncomingState *mis);int qemu_loadvm_state_main (QEMUFile *f,MigrationIncomingState *mis,Error **errp);int qemu_load_device_state (QEMUFile *f,Error **errp); -int qemu_loadvm_approve_switchover_legacy (const char *approver); +int qemu_loadvm_approve_switchover (const char *approver);int qemu_savevm_state_non_iterable (QEMUFile *f,Error **errp); int qemu_savevm_state_non_iterable_early(QEMUFile *f, JSONWriter *vmdesc,
hw/core/machine.c +3 -1
@@ -39,7 +39,9 @@#include "hw/acpi/generic_event_device.h" #include "qemu/audio.h" -GlobalProperty hw_compat_11_0[] = {}; +GlobalProperty hw_compat_11_0[] = { + {"migration" ,"switchover-ack-legacy" ,"on" }, +};const size_t hw_compat_11_0_len =G_N_ELEMENTS (hw_compat_11_0);GlobalProperty hw_compat_10_2[] = {
hw/vfio/migration.c +4 -4
@@ -828,11 +828,11 @@ static int vfio_load_state(QEMUFile *f, void *opaque, int version_id)return -EINVAL ; } - ret =qemu_loadvm_approve_switchover_legacy (vbasedev->name); + ret =qemu_loadvm_approve_switchover (vbasedev->name);if (ret) { -error_report ("%s: qemu_loadvm_approve_switchover_legacy " -"failed, err=%d (%s)" , - vbasedev->name, ret,strerror (-ret)); +error_report ( +"%s: qemu_loadvm_approve_switchover failed, err=%d (%s)" , + vbasedev->name, ret,strerror (-ret)); }return ret;
migration/migration.c +32 -6
@@ -1684,7 +1684,9 @@ int migrate_init(MigrationState *s, Error **errp) s->vm_old_state =-1 ; s->iteration_initial_bytes =0 ; s->threshold_size =0 ; - s->switchover_acked = false; +/* Legacy switchover-ack sends a single ACK for all devices */ +qatomic_set (&s->switchover_ack_pending_num, +migrate_switchover_ack_legacy () ?1 :0 ); s->rdma_migration = false;/*
@@ -2169,7 +2171,7 @@ void migration_request_switchover_ack_legacy(const char *requester) {MigrationIncomingState *mis =migration_incoming_get_current (); -if (!migrate_switchover_ack ()) { +if (!migrate_switchover_ack () || !migrate_switchover_ack_legacy ()) {return ; }
@@ -2425,9 +2427,18 @@ static void *source_return_path_thread(void *opaque)break ;case MIG_RP_MSG_SWITCHOVER_ACK : - ms->switchover_acked = true; -trace_source_return_path_thread_switchover_acked (); + { +uint32_t pending_num; + + pending_num =qatomic_dec_fetch (&ms->switchover_ack_pending_num); +trace_source_return_path_thread_switchover_acked (pending_num); +if (pending_num ==UINT32_MAX ) { +error_setg (&err,"Switchover ack pending num underflowed" ); + goto out; + } +break ; + }default :break ;
@@ -3221,7 +3232,7 @@ static bool migration_can_switchover(MigrationState *s)return true; } -return s->switchover_acked; +return qatomic_read (&s->switchover_ack_pending_num) ==0 ; }/* Migration thread iteration status */
@@ -3311,9 +3322,10 @@ static MigIterateState migration_iteration_run(MigrationState *s)Error *local_err =NULL ;bool in_postcopy = (s->state ==MIGRATION_STATUS_POSTCOPY_DEVICE || s->state ==MIGRATION_STATUS_POSTCOPY_ACTIVE ); -bool can_switchover =migration_can_switchover (s); +bool can_switchover;MigPendingData pending = { };bool complete_ready; +int ret;/* Fast path - get the estimated amount of pending data */ qemu_savevm_query_pending (&pending, false);
@@ -3346,8 +3358,18 @@ static MigIterateState migration_iteration_run(MigrationState *s)*/ if (migration_iteration_next_ready (s, &pending)) {migration_iteration_go_next (&pending); + ret =qemu_savevm_request_switchover_ack ( +MIG_SWITCHOVER_ACK_REQUEST_STAGE_PENDING_EXACT , &local_err); +if (ret <0 ) { +migrate_error_propagate (s, local_err); +qemu_file_set_error (s->to_dst_file, ret); +return MIG_ITERATE_RESUME ; + } } +/* Check can switchover after qemu_savevm_request_switchover_ack() */ + can_switchover =migration_can_switchover (s); +/* Should we switch to postcopy now? */ if (can_switchover &&postcopy_should_start (s, &pending)) {if (postcopy_start (s, &local_err)) {
@@ -3638,6 +3660,10 @@ static void *migration_thread(void *opaque)bql_lock (); ret =qemu_savevm_state_do_setup (s->to_dst_file, &local_err);bql_unlock (); +if (!ret) { + ret =qemu_savevm_request_switchover_ack ( +MIG_SWITCHOVER_ACK_REQUEST_STAGE_SETUP , &local_err); + }qemu_savevm_wait_unplug (s,MIGRATION_STATUS_SETUP ,MIGRATION_STATUS_ACTIVE );
migration/options.c +10 -0
@@ -108,6 +108,9 @@ const Property migration_properties[] = { preempt_pre_7_2, false),DEFINE_PROP_BOOL ("multifd-clean-tls-termination" , MigrationState, multifd_clean_tls_termination, true), +/* Use legacy until VFIO implements new switchover-ack */ +DEFINE_PROP_BOOL ("switchover-ack-legacy" , MigrationState, + switchover_ack_legacy, true),/* Migration parameters */ DEFINE_PROP_UINT8("x-throttle-trigger-threshold", MigrationState,
@@ -462,6 +465,13 @@ bool migrate_rdma(void)return s->rdma_migration; } +bool migrate_switchover_ack_legacy (void ) +{ +MigrationState *s =migrate_get_current (); + +return s->switchover_ack_legacy; +} + typedef enum WriteTrackingSupport { WT_SUPPORT_UNKNOWN = 0, WT_SUPPORT_ABSENT,
migration/savevm.c +67 -2
93 lines not on this page · raw message
migration/trace-events +3 -1
@@ -24,6 +24,7 @@ loadvm_postcopy_ram_handle_discard_header(const char *ramid, uint16_t len) "%s: loadvm_process_command(const char *s, uint16_t len) "com=%s len=%d" loadvm_process_command_ping(uint32_t val) "0x%x" loadvm_approve_switchover_legacy(const char *approver, unsigned int switchover_ack_pending_num_legacy) "Approver %s, switchover_ack_pending_num_legacy %u" +loadvm_approve_switchover(const char *approver) "Approver %s" postcopy_ram_listen_thread_exit(void) "" postcopy_ram_listen_thread_start(void) "" qemu_savevm_send_postcopy_advise(void) ""
@@ -40,6 +41,7 @@ savevm_send_postcopy_resume(void) "" savevm_send_recv_bitmap(char *name) "%s" savevm_send_switchover_start(void) "" savevm_state_setup(void) "" +savevm_request_switchover_ack(const char *stage, const char *requester, uint32_t pending_num) "Stage %s, requester %s, switchover_ack_pending_num %" PRIu32 savevm_state_resume_prepare(void) "" savevm_state_header(void) "" savevm_state_iterate(void) ""
@@ -189,7 +191,7 @@ source_return_path_thread_loop_top(void) "" source_return_path_thread_pong(uint32_t val) "0x%x" source_return_path_thread_shut(uint32_t val) "0x%x" source_return_path_thread_resume_ack(uint32_t v) "%"PRIu32 -source_return_path_thread_switchover_acked(void) "" +source_return_path_thread_switchover_acked(uint32_t pending_num) "switchover_ack_pending_num %" PRIu32 source_return_path_thread_postcopy_package_loaded(void) "" migration_thread_low_pending(uint64_t pending) "%" PRIu64 migrate_transferred(uint64_t transferred, uint64_t time_spent, uint64_t bandwidth, uint64_t avail_bw, uint64_t size) "transferred %" PRIu64 " time_spent %" PRIu64 " bandwidth %" PRIu64 " switchover_bw %" PRIu64 " max_size %" PRId64
Signature · 1 line
2.40.1
Re: [PATCH 07/14] migration: Make switchover-ack re-usable
Quoted 30 lines · Avihai Horon
Switchover-ack is a mechanism to synchronize between source and destination QEMU during migration to prevent the source from switching over prematurely.
VFIO uses switchover-ack to ensure switchover happens only after destination side has loaded the precopy initial bytes. This is important for VFIO, as otherwise downtime could be impacted and be higher.
In its current state, switchover-ack is a one-time mechanism, meaning that switchover is acked only once and past that another ACK cannot be requested again. This was sufficient until now, as VFIO precopy initial bytes was defined to be monotonically decreasing. Thus, when precopy initial bytes reached zero for all VFIO devices, a single ACK would be sent and its validity would hold.
However, now the new
VFIO_PRECOPY_INFO_REINITfeature allows precopy initial bytes to be re-initialized during precopy. Specifically, it means that initial bytes can grow after reaching zero, which would invalidate a previously sent switchover ACK.To solve this, make switchover-ack reusable and allow devices to request another switchover ACK when needed.
To avoid scattering them all over, switchover ACKs are requested through a new
request_switchover_ackhandler which is called in specific places.Since now switchover ACK can be requested for a specific device and in different times, make switchover ACK per-device (instead of a single ACK for all devices) and let source side do the pending ACKs accounting.
Quoted 5 lines
Keep the legacy switchover-ack mechanism for backward compatibility and turn it on by a compatibility property for older machines. Enable the property until VFIO implements the new switchover-ack.
Signed-off-by Avihai Horon <[email protected]>
Re: [PATCH 07/14] migration: Make switchover-ack re-usable
In reply to Avihai HoronQuoted 35 lines · Avihai Horon
Switchover-ack is a mechanism to synchronize between source and destination QEMU during migration to prevent the source from switching over prematurely.
VFIO uses switchover-ack to ensure switchover happens only after destination side has loaded the precopy initial bytes. This is important for VFIO, as otherwise downtime could be impacted and be higher.
In its current state, switchover-ack is a one-time mechanism, meaning that switchover is acked only once and past that another ACK cannot be requested again. This was sufficient until now, as VFIO precopy initial bytes was defined to be monotonically decreasing. Thus, when precopy initial bytes reached zero for all VFIO devices, a single ACK would be sent and its validity would hold.
However, now the new
VFIO_PRECOPY_INFO_REINITfeature allows precopy initial bytes to be re-initialized during precopy. Specifically, it means that initial bytes can grow after reaching zero, which would invalidate a previously sent switchover ACK.To solve this, make switchover-ack reusable and allow devices to request another switchover ACK when needed.
To avoid scattering them all over, switchover ACKs are requested through a new
request_switchover_ackhandler which is called in specific places.Since now switchover ACK can be requested for a specific device and in different times, make switchover ACK per-device (instead of a single ACK for all devices) and let source side do the pending ACKs accounting.
Keep the legacy switchover-ack mechanism for backward compatibility and turn it on by a compatibility property for older machines. Enable the property until VFIO implements the new switchover-ack.
Signed-off-by Avihai Horon <[email protected]>
Quoted 12 lines
--- include/migration/client-options.h | 1 + include/migration/register.h | 21 +++++++++ migration/migration.h | 15 +++++-- migration/savevm.h | 4 +- hw/core/machine.c | 4 +- hw/vfio/migration.c | 8 ++-- migration/migration.c | 38 +++++++++++++--- migration/options.c | 10 +++++ migration/savevm.c | 69 +++++++++++++++++++++++++++++- migration/trace-events | 4 +- 10 files changed, 156 insertions(+), 18 deletions(-)
We may need to also update qapi/migration.json for its behavior change.
One option is to simplify that rather than mentioning too much details on legacy / modern behaviors: the QAPI documentatation can describe the general concept of this feature, leaving impl details to QEMU internals.
IIUC, the generic concept of this feature is allowing destination QEMU to acknowledge a switchover decision that source makes, rather than fully relying on the source QEMU. The doc can avoid mentioning how many ACKs it needs, and whether the ACK message is global, or per-device.
Quoted 128 lines
include/migration/client-options.h +1
-0@@ -13,6 +13,7 @@/* properties */ bool migrate_send_switchover_start (void ); +bool migrate_switchover_ack_legacy (void );/* capabilities */ include/migration/register.h +21
-0@@ -30,6 +30,11 @@ typedef struct MigPendingData {uint64_t total_bytes; } MigPendingData; +enum MigSwitchoverAckRequestStage { +MIG_SWITCHOVER_ACK_REQUEST_STAGE_SETUP , +MIG_SWITCHOVER_ACK_REQUEST_STAGE_PENDING_EXACT , +}; +/** * struct SaveVMHandlers: handler structure to finely control * migration of complex subsystems and devices, such as RAM, block and @@ -299,6 +304,22 @@ typedef struct SaveVMHandlers {*/ int (*resume_prepare)(MigrationState *s,void *opaque); +/** +* @request_switchover_ack +* +* Checks if a new switchover ACK is requested. Called only on source side +* in the stages specified in enum MigSwitchoverAckRequestStage. +* +* @stage: the stage in which the handler was called +* @opaque: data pointer passed to register_savevm_live() +* @requester: output pointer to be set to the name of the requester of the +* switchover ACK (for logging purposes). If not set, idstr will be used. +* +* Returns true to request switchover ACK and false otherwise +*/ +bool (*request_switchover_ack)(enum MigSwitchoverAckRequestStage stage, +void *opaque,const char **requester); +/** * @switchover_start * migration/migration.h +12
-3@@ -494,6 +494,12 @@ struct MigrationState {*/ uint8_t clear_bitmap_shift; +/* +* This decides whether to use legacy switchover ack (send ACK once for all +* devices) or new switchover ack (send ACK for each device). +*/ +bool switchover_ack_legacy; +/* * This save hostname when out-going migration starts */ @@ -503,10 +509,13 @@ struct MigrationState {JSONWriter *vmdesc;/* -* Indicates whether an ACK from the destination that it's OK to do -* switchover has been received. +* Indicates the number of pending ACKs from the destination. The value may +* increase or decrease during precopy as new ACKs are requested or +* received. When zero is reached, it's OK to switchover. In legacy +* switchover-ack, it's initialized to 1 and decreased to zero upon ACK. */ -bool switchover_acked; +uint32_t switchover_ack_pending_num; +/* Is this a rdma migration */ bool rdma_migration;migration/savevm.h +3
-1@@ -37,6 +37,8 @@ bool qemu_savevm_state_blocked(Error **errp);void qemu_savevm_non_migratable_list (strList **reasons);int qemu_savevm_state_prepare (Error **errp);int qemu_savevm_state_do_setup (QEMUFile *f,Error **errp); +int qemu_savevm_request_switchover_ack (enum MigSwitchoverAckRequestStage stage, +Error **errp);bool qemu_savevm_state_guest_unplug_pending (void );int qemu_savevm_state_resume_prepare (MigrationState *s);void qemu_savevm_send_header (QEMUFile *f);@@ -70,7 +72,7 @@ void qemu_loadvm_state_cleanup(MigrationIncomingState *mis);int qemu_loadvm_state_main (QEMUFile *f,MigrationIncomingState *mis,Error **errp);int qemu_load_device_state (QEMUFile *f,Error **errp); -int qemu_loadvm_approve_switchover_legacy (const char *approver); +int qemu_loadvm_approve_switchover (const char *approver);int qemu_savevm_state_non_iterable (QEMUFile *f,Error **errp); int qemu_savevm_state_non_iterable_early(QEMUFile *f, JSONWriter *vmdesc,hw/core/machine.c +3
-1@@ -39,7 +39,9 @@#include "hw/acpi/generic_event_device.h" #include "qemu/audio.h" -GlobalProperty hw_compat_11_0[] = {}; +GlobalProperty hw_compat_11_0[] = { + {"migration" ,"switchover-ack-legacy" ,"on" }, +};const size_t hw_compat_11_0_len =G_N_ELEMENTS (hw_compat_11_0);GlobalProperty hw_compat_10_2[] = {hw/vfio/migration.c +0
-0
hw/vfio/migration.c static int vfio_load_state(QEMUFile *f, void *opaque, int version_id) · line 831
Quoted 5 lines
hw/vfio/migration.c +1
-1@@ -828,11 +828,11 @@ static int vfio_load_state(QEMUFile *f, void *opaque, int version_id)return -EINVAL ; } - ret =qemu_loadvm_approve_switchover_legacy (vbasedev->name); + ret =qemu_loadvm_approve_switchover (vbasedev->name);
This switches the just-renamed legacy function back. Looks a bit weird.
Quoted 77 lines
hw/vfio/migration.c +3
-3if (ret) { -error_report ("%s: qemu_loadvm_approve_switchover_legacy " -"failed, err=%d (%s)" , - vbasedev->name, ret,strerror (-ret)); +error_report ( +"%s: qemu_loadvm_approve_switchover failed, err=%d (%s)" , + vbasedev->name, ret,strerror (-ret)); }return ret;migration/migration.c +18
-6@@ -1684,7 +1684,9 @@ int migrate_init(MigrationState *s, Error **errp) s->vm_old_state =-1 ; s->iteration_initial_bytes =0 ; s->threshold_size =0 ; - s->switchover_acked = false; +/* Legacy switchover-ack sends a single ACK for all devices */ +qatomic_set (&s->switchover_ack_pending_num, +migrate_switchover_ack_legacy () ?1 :0 ); s->rdma_migration = false;/* @@ -2169,7 +2171,7 @@ void migration_request_switchover_ack_legacy(const char *requester) {MigrationIncomingState *mis =migration_incoming_get_current (); -if (!migrate_switchover_ack ()) { +if (!migrate_switchover_ack () || !migrate_switchover_ack_legacy ()) {return ; }@@ -2425,9 +2427,18 @@ static void *source_return_path_thread(void *opaque)break ;case MIG_RP_MSG_SWITCHOVER_ACK : - ms->switchover_acked = true; -trace_source_return_path_thread_switchover_acked (); + { +uint32_t pending_num; + + pending_num =qatomic_dec_fetch (&ms->switchover_ack_pending_num); +trace_source_return_path_thread_switchover_acked (pending_num); +if (pending_num ==UINT32_MAX ) { +error_setg (&err,"Switchover ack pending num underflowed" ); + goto out; + } +break ; + }default :break ;@@ -3221,7 +3232,7 @@ static bool migration_can_switchover(MigrationState *s)return true; } -return s->switchover_acked; +return qatomic_read (&s->switchover_ack_pending_num) ==0 ; }/* Migration thread iteration status */ @@ -3311,9 +3322,10 @@ static MigIterateState migration_iteration_run(MigrationState *s)Error *local_err =NULL ;bool in_postcopy = (s->state ==MIGRATION_STATUS_POSTCOPY_DEVICE || s->state ==MIGRATION_STATUS_POSTCOPY_ACTIVE ); -bool can_switchover =migration_can_switchover (s); +bool can_switchover;MigPendingData pending = { };bool complete_ready; +int ret;/* Fast path - get the estimated amount of pending data */ qemu_savevm_query_pending (&pending, false);
migration/migration.c static MigIterateState migration_iteration_run(MigrationState *s) · line 3362
Quoted 5 lines
migration/migration.c +2
-0@@ -3346,8 +3358,18 @@ static MigIterateState migration_iteration_run(MigrationState *s)*/ if (migration_iteration_next_ready (s, &pending)) {migration_iteration_go_next (&pending); + ret =qemu_savevm_request_switchover_ack ( +MIG_SWITCHOVER_ACK_REQUEST_STAGE_PENDING_EXACT , &local_err);
I agree this is a good spot to report when a new ack will be needed, but this PENDING_EXACT stage is confusing to me. Actually, I think it's the whole concept of this extra "stage" is not easy to understand, and I don't yet understand why it is needed.
To me, the module should be able to raise a switch-ack request anytime, and it doesn't need to have a "stage" passed in.
The only difference here, IIUC, is for COMPLETE stage the current version modified qemu_savevm_request_switchover_ack() to fail explicitly.
It's fine, but we can also move that logic out, say, we can make sure all modules reported the last time of "whether a new switchover ack needed" after stopping VM, then read once more switchover_ack_pending_num making sure it's zero before switching over. IIUC that removes the last piece of dependency of this whole "stage" concept.
IOW, I wonder if we can provide such reporting facility of "we need a switch-ack" in the save_query_pending() API. For example, we can extend existing MigPendingData:
include/migration/register.h +2 -0
@@ -23,6 +23,8 @@ typedef struct MigPendingData {uint64_t postcopy_bytes;/* Amount of pending bytes can be transferred only in stopcopy */ uint64_t stopcopy_bytes; +/* Report if a new switchover-ack will be needed */ +uint64_t switchover_ack_pending;/* * Total pending data, modules do not need to update this field, it * will be automatically calculated by migration core API.
migration/savevm.c +12 -0
@@ -1879,6 +1879,18 @@ void qemu_savevm_query_pending(MigPendingData *pending, bool exact)*/ mig_stats.dirty_bytes_total = pending->total_bytes; + +if (pending->switchover_ack_pending) { +qatomic_add (&s->switchover_ack_pending_num, + pending->switchover_ack_pending); +/* +* NOTE: If we rely on migration core to request that on dest, we +* need a new type of message sent to dest QEMU to request for +* that. Otherwise we can also rely on per-module protocol to +* request it. +*/ + } +
With that, module can report anytime, where query's @exact can be either true / false, it doesn't matter. The one reported in SETUP can be done in the first query which is guaranteed to happen before switchover.
So I also left a "NOTE" above, currently IIUC VFIO is responsible for telling dest QEMU that it needs to emit one more switchover-ack (likely by VFIO_MIG_FLAG_DEV_INIT_DATA_SENT, which is vfio specific protocol), another way to do this is requesting that from migration core, then we can send a new REQUEST_SWITCHOVER_ACK message to dest, routing it to the device.
Logically relying on migration core should be better: consider in the future all these things can be reusable by e.g. vDPA or other similar cases. But so far I don't have a strong feeling.
Quoted 14 lines
migration/migration.c +8
-0+if (ret <0 ) { +migrate_error_propagate (s, local_err); +qemu_file_set_error (s->to_dst_file, ret); +return MIG_ITERATE_RESUME ; + } } +/* Check can switchover after qemu_savevm_request_switchover_ack() */ + can_switchover =migration_can_switchover (s); +/* Should we switch to postcopy now? */ if (can_switchover &&postcopy_should_start (s, &pending)) {if (postcopy_start (s, &local_err)) {
migration/migration.c static void *migration_thread(void *opaque) · line 3666
Quoted 7 lines
migration/migration.c +4
-0@@ -3638,6 +3660,10 @@ static void *migration_thread(void *opaque)bql_lock (); ret =qemu_savevm_state_do_setup (s->to_dst_file, &local_err);bql_unlock (); +if (!ret) { + ret =qemu_savevm_request_switchover_ack ( +MIG_SWITCHOVER_ACK_REQUEST_STAGE_SETUP , &local_err); + }
Let's always avoid doing things like this with "if (!ret)"? We can put it after the whole unplug event and after the ret check, fail immediately if ret != 0.
Quoted 164 lines
migration/migration.c +0
-0qemu_savevm_wait_unplug (s,MIGRATION_STATUS_SETUP ,MIGRATION_STATUS_ACTIVE );migration/options.c +10
-0@@ -108,6 +108,9 @@ const Property migration_properties[] = { preempt_pre_7_2, false),DEFINE_PROP_BOOL ("multifd-clean-tls-termination" , MigrationState, multifd_clean_tls_termination, true), +/* Use legacy until VFIO implements new switchover-ack */ +DEFINE_PROP_BOOL ("switchover-ack-legacy" , MigrationState, + switchover_ack_legacy, true),/* Migration parameters */ DEFINE_PROP_UINT8("x-throttle-trigger-threshold", MigrationState,@@ -462,6 +465,13 @@ bool migrate_rdma(void)return s->rdma_migration; } +bool migrate_switchover_ack_legacy (void ) +{ +MigrationState *s =migrate_get_current (); + +return s->switchover_ack_legacy; +} + typedef enum WriteTrackingSupport { WT_SUPPORT_UNKNOWN = 0, WT_SUPPORT_ABSENT,migration/savevm.c +67
-2@@ -1472,6 +1472,54 @@ int qemu_savevm_state_do_setup(QEMUFile *f, Error **errp)return precopy_notify (PRECOPY_NOTIFY_SETUP , errp); } +static const char * +switchover_ack_stage_to_str (enum MigSwitchoverAckRequestStage stage) +{ +switch (stage) { +case MIG_SWITCHOVER_ACK_REQUEST_STAGE_SETUP : +return "SETUP" ; +case MIG_SWITCHOVER_ACK_REQUEST_STAGE_PENDING_EXACT : +return "PENDING_EXACT" ; +default : +return "UNKNOWN" ; + } +} + +int qemu_savevm_request_switchover_ack (enum MigSwitchoverAckRequestStage stage, +Error **errp) +{ +MigrationState *s =migrate_get_current (); +uint32_t pending_num; +SaveStateEntry *se; +const char *requester; + +if (!migrate_switchover_ack () ||migrate_switchover_ack_legacy ()) { +return 0 ; + } + + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { +if (!se->ops || !se->ops->request_switchover_ack) { +continue ; + } + + requester =NULL ; +if (se->ops->request_switchover_ack (stage, se->opaque, &requester)) { + requester = requester ?: se->idstr; + pending_num =qatomic_inc_fetch (&s->switchover_ack_pending_num); +if (pending_num ==0 ) { +error_setg (errp,"Switchover ack pending num overflowed by %s" , + requester); +return -EOVERFLOW ; + } + +trace_savevm_request_switchover_ack ( +switchover_ack_stage_to_str (stage), requester, pending_num); + } + } + +return 0 ; +} +int qemu_savevm_state_resume_prepare (MigrationState *s) {SaveStateEntry *se;@@ -2471,7 +2519,7 @@ static int loadvm_switchover_ack_no_users_legacy(MigrationIncomingState *mis, {int ret; -if (!migrate_switchover_ack ()) { +if (!migrate_switchover_ack () || !migrate_switchover_ack_legacy ()) {return 0 ; }@@ -3153,7 +3201,7 @@ int qemu_load_device_state(QEMUFile *f, Error **errp)return 0 ; } -int qemu_loadvm_approve_switchover_legacy (const char *approver) +static int qemu_loadvm_approve_switchover_legacy (const char *approver) {MigrationIncomingState *mis =migration_incoming_get_current ();@@ -3172,6 +3220,23 @@ int qemu_loadvm_approve_switchover_legacy(const char *approver)return migrate_send_rp_switchover_ack (mis); } +int qemu_loadvm_approve_switchover (const char *approver) +{ +MigrationIncomingState *mis =migration_incoming_get_current (); + +if (!migrate_switchover_ack ()) { +return 0 ; + } + +if (migrate_switchover_ack_legacy ()) { +return qemu_loadvm_approve_switchover_legacy (approver); + } + +trace_loadvm_approve_switchover (approver); + +return migrate_send_rp_switchover_ack (mis); +} +bool qemu_loadvm_load_state_buffer (const char *idstr,uint32_t instance_id,char *buf,size_t len,Error **errp) {migration/trace-events +3
-1@@ -24,6 +24,7 @@ loadvm_postcopy_ram_handle_discard_header(const char *ramid, uint16_t len) "%s: loadvm_process_command(const char *s, uint16_t len) "com=%s len=%d" loadvm_process_command_ping(uint32_t val) "0x%x" loadvm_approve_switchover_legacy(const char *approver, unsigned int switchover_ack_pending_num_legacy) "Approver %s, switchover_ack_pending_num_legacy %u" +loadvm_approve_switchover(const char *approver) "Approver %s" postcopy_ram_listen_thread_exit(void) "" postcopy_ram_listen_thread_start(void) "" qemu_savevm_send_postcopy_advise(void) ""@@ -40,6 +41,7 @@ savevm_send_postcopy_resume(void) "" savevm_send_recv_bitmap(char *name) "%s" savevm_send_switchover_start(void) "" savevm_state_setup(void) "" +savevm_request_switchover_ack(const char *stage, const char *requester, uint32_t pending_num) "Stage %s, requester %s, switchover_ack_pending_num %" PRIu32 savevm_state_resume_prepare(void) "" savevm_state_header(void) "" savevm_state_iterate(void) ""@@ -189,7 +191,7 @@ source_return_path_thread_loop_top(void) "" source_return_path_thread_pong(uint32_t val) "0x%x" source_return_path_thread_shut(uint32_t val) "0x%x" source_return_path_thread_resume_ack(uint32_t v) "%"PRIu32 -source_return_path_thread_switchover_acked(void) "" +source_return_path_thread_switchover_acked(uint32_t pending_num) "switchover_ack_pending_num %" PRIu32 source_return_path_thread_postcopy_package_loaded(void) "" migration_thread_low_pending(uint64_t pending) "%" PRIu64 migrate_transferred(uint64_t transferred, uint64_t time_spent, uint64_t bandwidth, uint64_t avail_bw, uint64_t size) "transferred %" PRIu64 " time_spent %" PRIu64 " bandwidth %" PRIu64 " switchover_bw %" PRIu64 " max_size %" PRId64Signature · 1 line
2.40.1
Signature · 1 line
Peter Xu
Re: [PATCH 07/14] migration: Make switchover-ack re-usable
Quoted 53 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 35 lines · Avihai Horon
Switchover-ack is a mechanism to synchronize between source and destination QEMU during migration to prevent the source from switching over prematurely.
VFIO uses switchover-ack to ensure switchover happens only after destination side has loaded the precopy initial bytes. This is important for VFIO, as otherwise downtime could be impacted and be higher.
In its current state, switchover-ack is a one-time mechanism, meaning that switchover is acked only once and past that another ACK cannot be requested again. This was sufficient until now, as VFIO precopy initial bytes was defined to be monotonically decreasing. Thus, when precopy initial bytes reached zero for all VFIO devices, a single ACK would be sent and its validity would hold.
However, now the new
VFIO_PRECOPY_INFO_REINITfeature allows precopy initial bytes to be re-initialized during precopy. Specifically, it means that initial bytes can grow after reaching zero, which would invalidate a previously sent switchover ACK.To solve this, make switchover-ack reusable and allow devices to request another switchover ACK when needed.
To avoid scattering them all over, switchover ACKs are requested through a new
request_switchover_ackhandler which is called in specific places.Since now switchover ACK can be requested for a specific device and in different times, make switchover ACK per-device (instead of a single ACK for all devices) and let source side do the pending ACKs accounting.
Keep the legacy switchover-ack mechanism for backward compatibility and turn it on by a compatibility property for older machines. Enable the property until VFIO implements the new switchover-ack.
Signed-off-by Avihai Horon <[email protected]>Quoted 12 lines
--- include/migration/client-options.h | 1 + include/migration/register.h | 21 +++++++++ migration/migration.h | 15 +++++-- migration/savevm.h | 4 +- hw/core/machine.c | 4 +- hw/vfio/migration.c | 8 ++-- migration/migration.c | 38 +++++++++++++--- migration/options.c | 10 +++++ migration/savevm.c | 69 +++++++++++++++++++++++++++++- migration/trace-events | 4 +- 10 files changed, 156 insertions(+), 18 deletions(-)We may need to also update
qapi/migration.jsonfor its behavior change.
Quoted 8 lines
One option is to simplify that rather than mentioning too much details on legacy / modern behaviors: the QAPI documentatation can describe the general concept of this feature, leaving impl details to QEMU internals.
IIUC, the generic concept of this feature is allowing destination QEMU to acknowledge a switchover decision that source makes, rather than fully relying on the source QEMU. The doc can avoid mentioning how many ACKs it needs, and whether the ACK message is global, or per-device.
Sure, I will reword it.
Quoted 131 lines
Quoted 131 lines
include/migration/client-options.h +1
-0@@ -13,6 +13,7 @@/* properties */ bool migrate_send_switchover_start (void ); +bool migrate_switchover_ack_legacy (void );/* capabilities */ include/migration/register.h +21
-0@@ -30,6 +30,11 @@ typedef struct MigPendingData {uint64_t total_bytes; } MigPendingData; +enum MigSwitchoverAckRequestStage { +MIG_SWITCHOVER_ACK_REQUEST_STAGE_SETUP , +MIG_SWITCHOVER_ACK_REQUEST_STAGE_PENDING_EXACT , +}; +/** * struct SaveVMHandlers: handler structure to finely control * migration of complex subsystems and devices, such as RAM, block and @@ -299,6 +304,22 @@ typedef struct SaveVMHandlers {*/ int (*resume_prepare)(MigrationState *s,void *opaque); +/** +* @request_switchover_ack +* +* Checks if a new switchover ACK is requested. Called only on source side +* in the stages specified in enum MigSwitchoverAckRequestStage. +* +* @stage: the stage in which the handler was called +* @opaque: data pointer passed to register_savevm_live() +* @requester: output pointer to be set to the name of the requester of the +* switchover ACK (for logging purposes). If not set, idstr will be used. +* +* Returns true to request switchover ACK and false otherwise +*/ +bool (*request_switchover_ack)(enum MigSwitchoverAckRequestStage stage, +void *opaque,const char **requester); +/** * @switchover_start * migration/migration.h +12
-3@@ -494,6 +494,12 @@ struct MigrationState {*/ uint8_t clear_bitmap_shift; +/* +* This decides whether to use legacy switchover ack (send ACK once for all +* devices) or new switchover ack (send ACK for each device). +*/ +bool switchover_ack_legacy; +/* * This save hostname when out-going migration starts */ @@ -503,10 +509,13 @@ struct MigrationState {JSONWriter *vmdesc;/* -* Indicates whether an ACK from the destination that it's OK to do -* switchover has been received. +* Indicates the number of pending ACKs from the destination. The value may +* increase or decrease during precopy as new ACKs are requested or +* received. When zero is reached, it's OK to switchover. In legacy +* switchover-ack, it's initialized to 1 and decreased to zero upon ACK. */ -bool switchover_acked; +uint32_t switchover_ack_pending_num; +/* Is this a rdma migration */ bool rdma_migration;migration/savevm.h +3
-1@@ -37,6 +37,8 @@ bool qemu_savevm_state_blocked(Error **errp);void qemu_savevm_non_migratable_list (strList **reasons);int qemu_savevm_state_prepare (Error **errp);int qemu_savevm_state_do_setup (QEMUFile *f,Error **errp); +int qemu_savevm_request_switchover_ack (enum MigSwitchoverAckRequestStage stage, +Error **errp);bool qemu_savevm_state_guest_unplug_pending (void );int qemu_savevm_state_resume_prepare (MigrationState *s);void qemu_savevm_send_header (QEMUFile *f);@@ -70,7 +72,7 @@ void qemu_loadvm_state_cleanup(MigrationIncomingState *mis);int qemu_loadvm_state_main (QEMUFile *f,MigrationIncomingState *mis,Error **errp);int qemu_load_device_state (QEMUFile *f,Error **errp); -int qemu_loadvm_approve_switchover_legacy (const char *approver); +int qemu_loadvm_approve_switchover (const char *approver);int qemu_savevm_state_non_iterable (QEMUFile *f,Error **errp); int qemu_savevm_state_non_iterable_early(QEMUFile *f, JSONWriter *vmdesc,hw/core/machine.c +3
-1@@ -39,7 +39,9 @@#include "hw/acpi/generic_event_device.h" #include "qemu/audio.h" -GlobalProperty hw_compat_11_0[] = {}; +GlobalProperty hw_compat_11_0[] = { + {"migration" ,"switchover-ack-legacy" ,"on" }, +};const size_t hw_compat_11_0_len =G_N_ELEMENTS (hw_compat_11_0);GlobalProperty hw_compat_10_2[] = {hw/vfio/migration.c +0
-0@@ -828,11 +828,11 @@ static int vfio_load_state(QEMUFile *f, void *opaque, int version_id)return -EINVAL ; }
Quoted 3 lines
hw/vfio/migration.c static int vfio_load_state(QEMUFile *f, void *opaque, int version_id) · line 831
Quoted 2 lines
hw/vfio/migration.c +1
-1- ret =qemu_loadvm_approve_switchover_legacy (vbasedev->name); + ret =qemu_loadvm_approve_switchover (vbasedev->name);This switches the just-renamed legacy function back. Looks a bit weird.
I can drop renaming qemu_loadvm_approve_switchover() to legacy in previous patch.
Or I can keep qemu_loadvm_approve_switchover_legacy() exported and have VFIO check migrate_switchover_ack_legacy() and call the right function.
Would one of the above be less awkward?
Quoted 138 lines
Quoted 78 lines
hw/vfio/migration.c +3
-3if (ret) { -error_report ("%s: qemu_loadvm_approve_switchover_legacy " -"failed, err=%d (%s)" , - vbasedev->name, ret,strerror (-ret)); +error_report ( +"%s: qemu_loadvm_approve_switchover failed, err=%d (%s)" , + vbasedev->name, ret,strerror (-ret)); }return ret;migration/migration.c +18
-6@@ -1684,7 +1684,9 @@ int migrate_init(MigrationState *s, Error **errp) s->vm_old_state =-1 ; s->iteration_initial_bytes =0 ; s->threshold_size =0 ; - s->switchover_acked = false; +/* Legacy switchover-ack sends a single ACK for all devices */ +qatomic_set (&s->switchover_ack_pending_num, +migrate_switchover_ack_legacy () ?1 :0 ); s->rdma_migration = false;/* @@ -2169,7 +2171,7 @@ void migration_request_switchover_ack_legacy(const char *requester) {MigrationIncomingState *mis =migration_incoming_get_current (); -if (!migrate_switchover_ack ()) { +if (!migrate_switchover_ack () || !migrate_switchover_ack_legacy ()) {return ; }@@ -2425,9 +2427,18 @@ static void *source_return_path_thread(void *opaque)break ;case MIG_RP_MSG_SWITCHOVER_ACK : - ms->switchover_acked = true; -trace_source_return_path_thread_switchover_acked (); + { +uint32_t pending_num; + + pending_num =qatomic_dec_fetch (&ms->switchover_ack_pending_num); +trace_source_return_path_thread_switchover_acked (pending_num); +if (pending_num ==UINT32_MAX ) { +error_setg (&err,"Switchover ack pending num underflowed" ); + goto out; + } +break ; + }default :break ;@@ -3221,7 +3232,7 @@ static bool migration_can_switchover(MigrationState *s)return true; } -return s->switchover_acked; +return qatomic_read (&s->switchover_ack_pending_num) ==0 ; }/* Migration thread iteration status */ @@ -3311,9 +3322,10 @@ static MigIterateState migration_iteration_run(MigrationState *s)Error *local_err =NULL ;bool in_postcopy = (s->state ==MIGRATION_STATUS_POSTCOPY_DEVICE || s->state ==MIGRATION_STATUS_POSTCOPY_ACTIVE ); -bool can_switchover =migration_can_switchover (s); +bool can_switchover;MigPendingData pending = { };bool complete_ready; +int ret;/* Fast path - get the estimated amount of pending data */ qemu_savevm_query_pending (&pending, false);migration/migration.c static MigIterateState migration_iteration_run(MigrationState *s) · line 3362
Quoted 5 lines
migration/migration.c +2
-0@@ -3346,8 +3358,18 @@ static MigIterateState migration_iteration_run(MigrationState *s)*/ if (migration_iteration_next_ready (s, &pending)) {migration_iteration_go_next (&pending); + ret =qemu_savevm_request_switchover_ack ( +MIG_SWITCHOVER_ACK_REQUEST_STAGE_PENDING_EXACT , &local_err);I agree this is a good spot to report when a new ack will be needed, but this
PENDING_EXACTstage is confusing to me. Actually, I think it's the whole concept of this extra "stage" is not easy to understand, and I don't yet understand why it is needed.To me, the module should be able to raise a switch-ack request anytime, and it doesn't need to have a "stage" passed in.
The only difference here, IIUC, is for COMPLETE stage the current version modified
qemu_savevm_request_switchover_ack()to fail explicitly.It's fine, but we can also move that logic out, say, we can make sure all modules reported the last time of "whether a new switchover ack needed" after stopping VM, then read once more
switchover_ack_pending_nummaking sure it's zero before switching over. IIUC that removes the last piece of dependency of this whole "stage" concept.IOW, I wonder if we can provide such reporting facility of "we need a switch-ack" in the
save_query_pending()API. For example, we can extend existing MigPendingData:include/migration/register.h +2
-0@@ -23,6 +23,8 @@ typedef struct MigPendingData {uint64_t postcopy_bytes;/* Amount of pending bytes can be transferred only in stopcopy */ uint64_t stopcopy_bytes; +/* Report if a new switchover-ack will be needed */ +uint64_t switchover_ack_pending;/* * Total pending data, modules do not need to update this field, it * will be automatically calculated by migration core API. migration/savevm.c +12
-0@@ -1879,6 +1879,18 @@ void qemu_savevm_query_pending(MigPendingData *pending, bool exact)*/ mig_stats.dirty_bytes_total = pending->total_bytes; + +if (pending->switchover_ack_pending) { +qatomic_add (&s->switchover_ack_pending_num, + pending->switchover_ack_pending); +/* +* NOTE: If we rely on migration core to request that on dest, we +* need a new type of message sent to dest QEMU to request for +* that. Otherwise we can also rely on per-module protocol to +* request it. +*/ + } +
Quoted 3 lines
With that, module can report anytime, where query's @exact can be either true / false, it doesn't matter. The one reported in SETUP can be done in the first query which is guaranteed to happen before switchover.
So basically your approach reduced the stages into a single one - during query pending (either exact or estimate) - which allows us to drop the stage param.
I agree SETUP can be dropped now that switchover-ack can be requested also in query pending estimate. But how can modules request another switchover-ack past the last query pending (after which we switchover)?
IIUC, we would need to issue another query pending after VM stop, but VFIO will fail a query pending exact at that stage (when VM stopped), so we can only issue query estimate pending.
This seems a bit weird, so I guess we can add another flavor for query pending which only queries switchover-ack? Or completely split it from query pending into a separate migrate_request_switchover_ack() function?
Quoted 10 lines
So I also left a "NOTE" above, currently IIUC VFIO is responsible for telling dest QEMU that it needs to emit one more switchover-ack (likely by
VFIO_MIG_FLAG_DEV_INIT_DATA_SENT, which is vfio specific protocol), another way to do this is requesting that from migration core, then we can send a newREQUEST_SWITCHOVER_ACKmessage to dest, routing it to the device.Logically relying on migration core should be better: consider in the future all these things can be reusable by e.g. vDPA or other similar cases. But so far I don't have a strong feeling.
Note that for VFIO, requesting switchover-ack from source (incrementing switchover_ack_pending_num) and requesting an ack from destination happen in different times - the former happens once we see new init_bytes > 0, and the latter happens when init_bytes = 0 again.
I need to think this through, but did you have something specific in mind?
Quoted 17 lines
Quoted 17 lines
migration/migration.c +8
-0+if (ret <0 ) { +migrate_error_propagate (s, local_err); +qemu_file_set_error (s->to_dst_file, ret); +return MIG_ITERATE_RESUME ; + } } +/* Check can switchover after qemu_savevm_request_switchover_ack() */ + can_switchover =migration_can_switchover (s); +/* Should we switch to postcopy now? */ if (can_switchover &&postcopy_should_start (s, &pending)) {if (postcopy_start (s, &local_err)) {@@ -3638,6 +3660,10 @@ static void *migration_thread(void *opaque)bql_lock (); ret =qemu_savevm_state_do_setup (s->to_dst_file, &local_err);
Quoted 8 lines
migration/migration.c static void *migration_thread(void *opaque) · line 3666
Quoted 5 lines
migration/migration.c +4
-0bql_unlock (); +if (!ret) { + ret =qemu_savevm_request_switchover_ack ( +MIG_SWITCHOVER_ACK_REQUEST_STAGE_SETUP , &local_err); + }Let's always avoid doing things like this with "if (!ret)"? We can put it after the whole unplug event and after the ret check, fail immediately if ret != 0.
Sure.
Thanks!
Quoted 167 lines
Quoted 162 lines
migration/migration.c +0
-0qemu_savevm_wait_unplug (s,MIGRATION_STATUS_SETUP ,MIGRATION_STATUS_ACTIVE );migration/options.c +10
-0@@ -108,6 +108,9 @@ const Property migration_properties[] = { preempt_pre_7_2, false),DEFINE_PROP_BOOL ("multifd-clean-tls-termination" , MigrationState, multifd_clean_tls_termination, true), +/* Use legacy until VFIO implements new switchover-ack */ +DEFINE_PROP_BOOL ("switchover-ack-legacy" , MigrationState, + switchover_ack_legacy, true),/* Migration parameters */ DEFINE_PROP_UINT8("x-throttle-trigger-threshold", MigrationState,@@ -462,6 +465,13 @@ bool migrate_rdma(void)return s->rdma_migration; } +bool migrate_switchover_ack_legacy (void ) +{ +MigrationState *s =migrate_get_current (); + +return s->switchover_ack_legacy; +} + typedef enum WriteTrackingSupport { WT_SUPPORT_UNKNOWN = 0, WT_SUPPORT_ABSENT,migration/savevm.c +67
-2@@ -1472,6 +1472,54 @@ int qemu_savevm_state_do_setup(QEMUFile *f, Error **errp)return precopy_notify (PRECOPY_NOTIFY_SETUP , errp); } +static const char * +switchover_ack_stage_to_str (enum MigSwitchoverAckRequestStage stage) +{ +switch (stage) { +case MIG_SWITCHOVER_ACK_REQUEST_STAGE_SETUP : +return "SETUP" ; +case MIG_SWITCHOVER_ACK_REQUEST_STAGE_PENDING_EXACT : +return "PENDING_EXACT" ; +default : +return "UNKNOWN" ; + } +} + +int qemu_savevm_request_switchover_ack (enum MigSwitchoverAckRequestStage stage, +Error **errp) +{ +MigrationState *s =migrate_get_current (); +uint32_t pending_num; +SaveStateEntry *se; +const char *requester; + +if (!migrate_switchover_ack () ||migrate_switchover_ack_legacy ()) { +return 0 ; + } + + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { +if (!se->ops || !se->ops->request_switchover_ack) { +continue ; + } + + requester =NULL ; +if (se->ops->request_switchover_ack (stage, se->opaque, &requester)) { + requester = requester ?: se->idstr; + pending_num =qatomic_inc_fetch (&s->switchover_ack_pending_num); +if (pending_num ==0 ) { +error_setg (errp,"Switchover ack pending num overflowed by %s" , + requester); +return -EOVERFLOW ; + } + +trace_savevm_request_switchover_ack ( +switchover_ack_stage_to_str (stage), requester, pending_num); + } + } + +return 0 ; +} +int qemu_savevm_state_resume_prepare (MigrationState *s) {SaveStateEntry *se;@@ -2471,7 +2519,7 @@ static int loadvm_switchover_ack_no_users_legacy(MigrationIncomingState *mis, {int ret; -if (!migrate_switchover_ack ()) { +if (!migrate_switchover_ack () || !migrate_switchover_ack_legacy ()) {return 0 ; }@@ -3153,7 +3201,7 @@ int qemu_load_device_state(QEMUFile *f, Error **errp)return 0 ; } -int qemu_loadvm_approve_switchover_legacy (const char *approver) +static int qemu_loadvm_approve_switchover_legacy (const char *approver) {MigrationIncomingState *mis =migration_incoming_get_current ();@@ -3172,6 +3220,23 @@ int qemu_loadvm_approve_switchover_legacy(const char *approver)return migrate_send_rp_switchover_ack (mis); } +int qemu_loadvm_approve_switchover (const char *approver) +{ +MigrationIncomingState *mis =migration_incoming_get_current (); + +if (!migrate_switchover_ack ()) { +return 0 ; + } + +if (migrate_switchover_ack_legacy ()) { +return qemu_loadvm_approve_switchover_legacy (approver); + } + +trace_loadvm_approve_switchover (approver); + +return migrate_send_rp_switchover_ack (mis); +} +bool qemu_loadvm_load_state_buffer (const char *idstr,uint32_t instance_id,char *buf,size_t len,Error **errp) {migration/trace-events +3
-2@@ -24,6 +24,7 @@ loadvm_postcopy_ram_handle_discard_header(const char *ramid, uint16_t len) "%s: loadvm_process_command(const char *s, uint16_t len) "com=%s len=%d" loadvm_process_command_ping(uint32_t val) "0x%x" loadvm_approve_switchover_legacy(const char *approver, unsigned int switchover_ack_pending_num_legacy) "Approver %s, switchover_ack_pending_num_legacy %u" +loadvm_approve_switchover(const char *approver) "Approver %s" postcopy_ram_listen_thread_exit(void) "" postcopy_ram_listen_thread_start(void) "" qemu_savevm_send_postcopy_advise(void) ""@@ -40,6 +41,7 @@ savevm_send_postcopy_resume(void) "" savevm_send_recv_bitmap(char *name) "%s" savevm_send_switchover_start(void) "" savevm_state_setup(void) "" +savevm_request_switchover_ack(const char *stage, const char *requester, uint32_t pending_num) "Stage %s, requester %s, switchover_ack_pending_num %" PRIu32 savevm_state_resume_prepare(void) "" savevm_state_header(void) "" savevm_state_iterate(void) ""@@ -189,7 +191,7 @@ source_return_path_thread_loop_top(void) "" source_return_path_thread_pong(uint32_t val) "0x%x" source_return_path_thread_shut(uint32_t val) "0x%x" source_return_path_thread_resume_ack(uint32_t v) "%"PRIu32 -source_return_path_thread_switchover_acked(void) "" +source_return_path_thread_switchover_acked(uint32_t pending_num) "switchover_ack_pending_num %" PRIu32 source_return_path_thread_postcopy_package_loaded(void) "" migration_thread_low_pending(uint64_t pending) "%" PRIu64 migrate_transferred(uint64_t transferred, uint64_t time_spent, uint64_t bandwidth, uint64_t avail_bw, uint64_t size) "transferred %" PRIu64 " time_spent %" PRIu64 " bandwidth %" PRIu64 " switchover_bw %" PRIu64 " max_size %" PRId64 --Quoted 2 lines
2.40.1
--
Peter Xu
Re: [PATCH 07/14] migration: Make switchover-ack re-usable
Quoted 201 lines · Avihai Horon
Quoted 53 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 35 lines · Avihai Horon
Switchover-ack is a mechanism to synchronize between source and destination QEMU during migration to prevent the source from switching over prematurely.
VFIO uses switchover-ack to ensure switchover happens only after destination side has loaded the precopy initial bytes. This is important for VFIO, as otherwise downtime could be impacted and be higher.
In its current state, switchover-ack is a one-time mechanism, meaning that switchover is acked only once and past that another ACK cannot be requested again. This was sufficient until now, as VFIO precopy initial bytes was defined to be monotonically decreasing. Thus, when precopy initial bytes reached zero for all VFIO devices, a single ACK would be sent and its validity would hold.
However, now the new
VFIO_PRECOPY_INFO_REINITfeature allows precopy initial bytes to be re-initialized during precopy. Specifically, it means that initial bytes can grow after reaching zero, which would invalidate a previously sent switchover ACK.To solve this, make switchover-ack reusable and allow devices to request another switchover ACK when needed.
To avoid scattering them all over, switchover ACKs are requested through a new
request_switchover_ackhandler which is called in specific places.Since now switchover ACK can be requested for a specific device and in different times, make switchover ACK per-device (instead of a single ACK for all devices) and let source side do the pending ACKs accounting.
Keep the legacy switchover-ack mechanism for backward compatibility and turn it on by a compatibility property for older machines. Enable the property until VFIO implements the new switchover-ack.
Signed-off-by Avihai Horon <[email protected]>Quoted 12 lines
--- include/migration/client-options.h | 1 + include/migration/register.h | 21 +++++++++ migration/migration.h | 15 +++++-- migration/savevm.h | 4 +- hw/core/machine.c | 4 +- hw/vfio/migration.c | 8 ++-- migration/migration.c | 38 +++++++++++++--- migration/options.c | 10 +++++ migration/savevm.c | 69 +++++++++++++++++++++++++++++- migration/trace-events | 4 +- 10 files changed, 156 insertions(+), 18 deletions(-)We may need to also update
qapi/migration.jsonfor its behavior change.Quoted 8 lines
One option is to simplify that rather than mentioning too much details on legacy / modern behaviors: the QAPI documentatation can describe the general concept of this feature, leaving impl details to QEMU internals.
IIUC, the generic concept of this feature is allowing destination QEMU to acknowledge a switchover decision that source makes, rather than fully relying on the source QEMU. The doc can avoid mentioning how many ACKs it needs, and whether the ACK message is global, or per-device.
Sure, I will reword it.
Quoted 131 lines
Quoted 131 lines
include/migration/client-options.h +1
-0@@ -13,6 +13,7 @@/* properties */ bool migrate_send_switchover_start (void ); +bool migrate_switchover_ack_legacy (void );/* capabilities */ include/migration/register.h +21
-0@@ -30,6 +30,11 @@ typedef struct MigPendingData {uint64_t total_bytes; } MigPendingData; +enum MigSwitchoverAckRequestStage { +MIG_SWITCHOVER_ACK_REQUEST_STAGE_SETUP , +MIG_SWITCHOVER_ACK_REQUEST_STAGE_PENDING_EXACT , +}; +/** * struct SaveVMHandlers: handler structure to finely control * migration of complex subsystems and devices, such as RAM, block and @@ -299,6 +304,22 @@ typedef struct SaveVMHandlers {*/ int (*resume_prepare)(MigrationState *s,void *opaque); +/** +* @request_switchover_ack +* +* Checks if a new switchover ACK is requested. Called only on source side +* in the stages specified in enum MigSwitchoverAckRequestStage. +* +* @stage: the stage in which the handler was called +* @opaque: data pointer passed to register_savevm_live() +* @requester: output pointer to be set to the name of the requester of the +* switchover ACK (for logging purposes). If not set, idstr will be used. +* +* Returns true to request switchover ACK and false otherwise +*/ +bool (*request_switchover_ack)(enum MigSwitchoverAckRequestStage stage, +void *opaque,const char **requester); +/** * @switchover_start * migration/migration.h +12
-3@@ -494,6 +494,12 @@ struct MigrationState {*/ uint8_t clear_bitmap_shift; +/* +* This decides whether to use legacy switchover ack (send ACK once for all +* devices) or new switchover ack (send ACK for each device). +*/ +bool switchover_ack_legacy; +/* * This save hostname when out-going migration starts */ @@ -503,10 +509,13 @@ struct MigrationState {JSONWriter *vmdesc;/* -* Indicates whether an ACK from the destination that it's OK to do -* switchover has been received. +* Indicates the number of pending ACKs from the destination. The value may +* increase or decrease during precopy as new ACKs are requested or +* received. When zero is reached, it's OK to switchover. In legacy +* switchover-ack, it's initialized to 1 and decreased to zero upon ACK. */ -bool switchover_acked; +uint32_t switchover_ack_pending_num; +/* Is this a rdma migration */ bool rdma_migration;migration/savevm.h +3
-1@@ -37,6 +37,8 @@ bool qemu_savevm_state_blocked(Error **errp);void qemu_savevm_non_migratable_list (strList **reasons);int qemu_savevm_state_prepare (Error **errp);int qemu_savevm_state_do_setup (QEMUFile *f,Error **errp); +int qemu_savevm_request_switchover_ack (enum MigSwitchoverAckRequestStage stage, +Error **errp);bool qemu_savevm_state_guest_unplug_pending (void );int qemu_savevm_state_resume_prepare (MigrationState *s);void qemu_savevm_send_header (QEMUFile *f);@@ -70,7 +72,7 @@ void qemu_loadvm_state_cleanup(MigrationIncomingState *mis);int qemu_loadvm_state_main (QEMUFile *f,MigrationIncomingState *mis,Error **errp);int qemu_load_device_state (QEMUFile *f,Error **errp); -int qemu_loadvm_approve_switchover_legacy (const char *approver); +int qemu_loadvm_approve_switchover (const char *approver);int qemu_savevm_state_non_iterable (QEMUFile *f,Error **errp); int qemu_savevm_state_non_iterable_early(QEMUFile *f, JSONWriter *vmdesc,hw/core/machine.c +3
-1@@ -39,7 +39,9 @@#include "hw/acpi/generic_event_device.h" #include "qemu/audio.h" -GlobalProperty hw_compat_11_0[] = {}; +GlobalProperty hw_compat_11_0[] = { + {"migration" ,"switchover-ack-legacy" ,"on" }, +};const size_t hw_compat_11_0_len =G_N_ELEMENTS (hw_compat_11_0);GlobalProperty hw_compat_10_2[] = {hw/vfio/migration.c +0
-0@@ -828,11 +828,11 @@ static int vfio_load_state(QEMUFile *f, void *opaque, int version_id)return -EINVAL ; }Quoted 3 lines
hw/vfio/migration.c static int vfio_load_state(QEMUFile *f, void *opaque, int version_id) · line 831
Quoted 2 lines
hw/vfio/migration.c +1
-1- ret =qemu_loadvm_approve_switchover_legacy (vbasedev->name); + ret =qemu_loadvm_approve_switchover (vbasedev->name);This switches the just-renamed legacy function back. Looks a bit weird.
Quoted 6 lines
I can drop renaming
qemu_loadvm_approve_switchover()to legacy in previous patch.
Or I can keepqemu_loadvm_approve_switchover_legacy()exported and have VFIO checkmigrate_switchover_ack_legacy()and call the right function.Would one of the above be less awkward?
In the final version, qemu_loadvm_approve_switchover() contains both the legacy and modern handling already:
int qemu_loadvm_approve_switchover(const char *approver)
{
MigrationIncomingState *mis = migration_incoming_get_current();
if (!migrate_switchover_ack()) {
return 0;
}
if (migrate_switchover_ack_legacy()) {
return qemu_loadvm_approve_switchover_legacy(approver);
}
trace_loadvm_approve_switchover(approver);
return migrate_send_rp_switchover_ack(mis);
}Then option 1 makes more sense to avoid renaming it to _legacy() since the start.
Quoted 152 lines
Quoted 139 lines
Quoted 79 lines
hw/vfio/migration.c +3
-3if (ret) { -error_report ("%s: qemu_loadvm_approve_switchover_legacy " -"failed, err=%d (%s)" , - vbasedev->name, ret,strerror (-ret)); +error_report ( +"%s: qemu_loadvm_approve_switchover failed, err=%d (%s)" , + vbasedev->name, ret,strerror (-ret)); }return ret;migration/migration.c +18
-6@@ -1684,7 +1684,9 @@ int migrate_init(MigrationState *s, Error **errp) s->vm_old_state =-1 ; s->iteration_initial_bytes =0 ; s->threshold_size =0 ; - s->switchover_acked = false; +/* Legacy switchover-ack sends a single ACK for all devices */ +qatomic_set (&s->switchover_ack_pending_num, +migrate_switchover_ack_legacy () ?1 :0 ); s->rdma_migration = false;/* @@ -2169,7 +2171,7 @@ void migration_request_switchover_ack_legacy(const char *requester) {MigrationIncomingState *mis =migration_incoming_get_current (); -if (!migrate_switchover_ack ()) { +if (!migrate_switchover_ack () || !migrate_switchover_ack_legacy ()) {return ; }@@ -2425,9 +2427,18 @@ static void *source_return_path_thread(void *opaque)break ;case MIG_RP_MSG_SWITCHOVER_ACK : - ms->switchover_acked = true; -trace_source_return_path_thread_switchover_acked (); + { +uint32_t pending_num; + + pending_num =qatomic_dec_fetch (&ms->switchover_ack_pending_num); +trace_source_return_path_thread_switchover_acked (pending_num); +if (pending_num ==UINT32_MAX ) { +error_setg (&err,"Switchover ack pending num underflowed" ); + goto out; + } +break ; + }default :break ;@@ -3221,7 +3232,7 @@ static bool migration_can_switchover(MigrationState *s)return true; } -return s->switchover_acked; +return qatomic_read (&s->switchover_ack_pending_num) ==0 ; }/* Migration thread iteration status */ @@ -3311,9 +3322,10 @@ static MigIterateState migration_iteration_run(MigrationState *s)Error *local_err =NULL ;bool in_postcopy = (s->state ==MIGRATION_STATUS_POSTCOPY_DEVICE || s->state ==MIGRATION_STATUS_POSTCOPY_ACTIVE ); -bool can_switchover =migration_can_switchover (s); +bool can_switchover;MigPendingData pending = { };bool complete_ready; +int ret;/* Fast path - get the estimated amount of pending data */ qemu_savevm_query_pending (&pending, false);migration/migration.c static MigIterateState migration_iteration_run(MigrationState *s) · line 3362
Quoted 5 lines
migration/migration.c +2
-0@@ -3346,8 +3358,18 @@ static MigIterateState migration_iteration_run(MigrationState *s)*/ if (migration_iteration_next_ready (s, &pending)) {migration_iteration_go_next (&pending); + ret =qemu_savevm_request_switchover_ack ( +MIG_SWITCHOVER_ACK_REQUEST_STAGE_PENDING_EXACT , &local_err);I agree this is a good spot to report when a new ack will be needed, but this
PENDING_EXACTstage is confusing to me. Actually, I think it's the whole concept of this extra "stage" is not easy to understand, and I don't yet understand why it is needed.To me, the module should be able to raise a switch-ack request anytime, and it doesn't need to have a "stage" passed in.
The only difference here, IIUC, is for COMPLETE stage the current version modified
qemu_savevm_request_switchover_ack()to fail explicitly.It's fine, but we can also move that logic out, say, we can make sure all modules reported the last time of "whether a new switchover ack needed" after stopping VM, then read once more
switchover_ack_pending_nummaking sure it's zero before switching over. IIUC that removes the last piece of dependency of this whole "stage" concept.IOW, I wonder if we can provide such reporting facility of "we need a switch-ack" in the
save_query_pending()API. For example, we can extend existing MigPendingData:include/migration/register.h +2
-0@@ -23,6 +23,8 @@ typedef struct MigPendingData {uint64_t postcopy_bytes;/* Amount of pending bytes can be transferred only in stopcopy */ uint64_t stopcopy_bytes; +/* Report if a new switchover-ack will be needed */ +uint64_t switchover_ack_pending;/* * Total pending data, modules do not need to update this field, it * will be automatically calculated by migration core API. migration/savevm.c +12
-0@@ -1879,6 +1879,18 @@ void qemu_savevm_query_pending(MigPendingData *pending, bool exact)*/ mig_stats.dirty_bytes_total = pending->total_bytes; + +if (pending->switchover_ack_pending) { +qatomic_add (&s->switchover_ack_pending_num, + pending->switchover_ack_pending); +/* +* NOTE: If we rely on migration core to request that on dest, we +* need a new type of message sent to dest QEMU to request for +* that. Otherwise we can also rely on per-module protocol to +* request it. +*/ + } +Quoted 3 lines
With that, module can report anytime, where query's @exact can be either true / false, it doesn't matter. The one reported in SETUP can be done in the first query which is guaranteed to happen before switchover.
So basically your approach reduced the stages into a single one - during query pending (either exact or estimate) - which allows us to drop the stage param.
I agree SETUP can be dropped now that switchover-ack can be requested also in query pending estimate.
But how can modules request another switchover-ack past the last query pending (after which we switchover)?
Quoted 7 lines
IIUC, we would need to issue another query pending after VM stop, but VFIO will fail a query pending exact at that stage (when VM stopped), so we can only issue query estimate pending.
This seems a bit weird, so I guess we can add another flavor for query pending which only queries switchover-ack? Or completely split it from query pending into a separate
migrate_request_switchover_ack()function?
It shouldn't be awkward, and IMHO it'll further cleanup the code base, further removing some legacy RAM hacks.
In reality / theory, we must do a sync / slow query after VM stopped, because that's the only way to collect the ultimate last set of dirty info for the whole system, and we must not miss anything or dest QEMU will crash.
For RAM (which was the only one that cares before), that was done currently in a, IMHO, "hacky" way:
ram_save_complete():
if (!migration_in_postcopy()) {
migration_bitmap_sync_precopy(true);
}That should really not hide in a complete() callback. It should be a pretty generic concept for all modules. And now with the save_query_pending() API introduced, that slow sync is that generic approach.
As a first step, I think we need to move this sync out of RAM's complete(), similarly to what I have done in the dependency patch to move some ram-specific changes out to generic migration code.
After moving out, it will become a sync query and VFIO should also properly handle it.
I'm not sure why currently VFIO mustn't do such a sync query after VM stopped, but if there's some nuance that caused it, VFIO will need to handle it in its save_query_pending(sync=on) and makes sure:
(1) VFIO won't crash on a sync query during switchover phase, aka, VM stopped,
(2) VFIO needs to guarantee sync all through the stack so that all dirty data is collected properly (I bet this was always the case, so no real concern here..)
Then, it means we'll do a sync query after VM stop, and VFIO (while synchronizing dirty info) will report the last switchover-ack request too altogether in the same query, as part of "pending data".
Then with that, when switchover_ack_pending_num!=0, we either:
- Fail the migration, as this patchset does for now, or,
- Goes back to iteration phase, which can be TBD in the future, since REINIT shouldn't be common anyway
Do you think such would work out clean?
Quoted 12 lines
Quoted 11 lines
So I also left a "NOTE" above, currently IIUC VFIO is responsible for telling dest QEMU that it needs to emit one more switchover-ack (likely by
VFIO_MIG_FLAG_DEV_INIT_DATA_SENT, which is vfio specific protocol), another way to do this is requesting that from migration core, then we can send a newREQUEST_SWITCHOVER_ACKmessage to dest, routing it to the device.Logically relying on migration core should be better: consider in the future all these things can be reusable by e.g. vDPA or other similar cases. But so far I don't have a strong feeling.
Quoted 6 lines
Note that for VFIO, requesting switchover-ack from source (incrementing
switchover_ack_pending_num) and requesting an ack from destination happen in different times - the former happens once we see newinit_bytes> 0, and the latter happens wheninit_bytes= 0 again.I need to think this through, but did you have something specific in mind?
Not really something useful, but I can share my thoughts.
Currently, VFIO does it in a way that it first push all data, then put a tag of VFIO_MIG_FLAG_DEV_INIT_DATA_SENT at the end if all data pushed flushed all INIT/REINIT data.
That'll work out, because "ACK" essentially can be emitted on dest as long as dest QEMU completely received and applied the prior vfio_save_block() dump. There's nothing special dest needs to do. IOW, dest is not making much decision, but blindly ACK after seeing VFIO_MIG_FLAG_DEV_INIT_DATA_SENT. Such sequence will make everything flow.
What I had in mind was allowing src QEMU to send a "Request ACK for device XXX instance_id YYY", then dest migration core routes it to the corresponding module. The module then will decide itself on when to ACK.
Now think about it, maybe it's an overkill. It's more flexible, it can be reused by vDPA and others, but it's more than what we need right now.
Also, since VFIO_MIG_FLAG_DEV_INIT_DATA_SENT is already the wire protocol, let's stick with it to not introduce confusions.
Thanks,
Quoted 199 lines
Quoted 18 lines
Quoted 18 lines
migration/migration.c +8
-0+if (ret <0 ) { +migrate_error_propagate (s, local_err); +qemu_file_set_error (s->to_dst_file, ret); +return MIG_ITERATE_RESUME ; + } } +/* Check can switchover after qemu_savevm_request_switchover_ack() */ + can_switchover =migration_can_switchover (s); +/* Should we switch to postcopy now? */ if (can_switchover &&postcopy_should_start (s, &pending)) {if (postcopy_start (s, &local_err)) {@@ -3638,6 +3660,10 @@ static void *migration_thread(void *opaque)bql_lock (); ret =qemu_savevm_state_do_setup (s->to_dst_file, &local_err);Quoted 8 lines
migration/migration.c static void *migration_thread(void *opaque) · line 3666
Quoted 5 lines
migration/migration.c +4
-0bql_unlock (); +if (!ret) { + ret =qemu_savevm_request_switchover_ack ( +MIG_SWITCHOVER_ACK_REQUEST_STAGE_SETUP , &local_err); + }Let's always avoid doing things like this with "if (!ret)"? We can put it after the whole unplug event and after the ret check, fail immediately if ret != 0.
Sure.
Thanks!
Quoted 167 lines
Quoted 162 lines
migration/migration.c +0
-0qemu_savevm_wait_unplug (s,MIGRATION_STATUS_SETUP ,MIGRATION_STATUS_ACTIVE );migration/options.c +10
-0@@ -108,6 +108,9 @@ const Property migration_properties[] = { preempt_pre_7_2, false),DEFINE_PROP_BOOL ("multifd-clean-tls-termination" , MigrationState, multifd_clean_tls_termination, true), +/* Use legacy until VFIO implements new switchover-ack */ +DEFINE_PROP_BOOL ("switchover-ack-legacy" , MigrationState, + switchover_ack_legacy, true),/* Migration parameters */ DEFINE_PROP_UINT8("x-throttle-trigger-threshold", MigrationState,@@ -462,6 +465,13 @@ bool migrate_rdma(void)return s->rdma_migration; } +bool migrate_switchover_ack_legacy (void ) +{ +MigrationState *s =migrate_get_current (); + +return s->switchover_ack_legacy; +} + typedef enum WriteTrackingSupport { WT_SUPPORT_UNKNOWN = 0, WT_SUPPORT_ABSENT,migration/savevm.c +67
-2@@ -1472,6 +1472,54 @@ int qemu_savevm_state_do_setup(QEMUFile *f, Error **errp)return precopy_notify (PRECOPY_NOTIFY_SETUP , errp); } +static const char * +switchover_ack_stage_to_str (enum MigSwitchoverAckRequestStage stage) +{ +switch (stage) { +case MIG_SWITCHOVER_ACK_REQUEST_STAGE_SETUP : +return "SETUP" ; +case MIG_SWITCHOVER_ACK_REQUEST_STAGE_PENDING_EXACT : +return "PENDING_EXACT" ; +default : +return "UNKNOWN" ; + } +} + +int qemu_savevm_request_switchover_ack (enum MigSwitchoverAckRequestStage stage, +Error **errp) +{ +MigrationState *s =migrate_get_current (); +uint32_t pending_num; +SaveStateEntry *se; +const char *requester; + +if (!migrate_switchover_ack () ||migrate_switchover_ack_legacy ()) { +return 0 ; + } + + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { +if (!se->ops || !se->ops->request_switchover_ack) { +continue ; + } + + requester =NULL ; +if (se->ops->request_switchover_ack (stage, se->opaque, &requester)) { + requester = requester ?: se->idstr; + pending_num =qatomic_inc_fetch (&s->switchover_ack_pending_num); +if (pending_num ==0 ) { +error_setg (errp,"Switchover ack pending num overflowed by %s" , + requester); +return -EOVERFLOW ; + } + +trace_savevm_request_switchover_ack ( +switchover_ack_stage_to_str (stage), requester, pending_num); + } + } + +return 0 ; +} +int qemu_savevm_state_resume_prepare (MigrationState *s) {SaveStateEntry *se;@@ -2471,7 +2519,7 @@ static int loadvm_switchover_ack_no_users_legacy(MigrationIncomingState *mis, {int ret; -if (!migrate_switchover_ack ()) { +if (!migrate_switchover_ack () || !migrate_switchover_ack_legacy ()) {return 0 ; }@@ -3153,7 +3201,7 @@ int qemu_load_device_state(QEMUFile *f, Error **errp)return 0 ; } -int qemu_loadvm_approve_switchover_legacy (const char *approver) +static int qemu_loadvm_approve_switchover_legacy (const char *approver) {MigrationIncomingState *mis =migration_incoming_get_current ();@@ -3172,6 +3220,23 @@ int qemu_loadvm_approve_switchover_legacy(const char *approver)return migrate_send_rp_switchover_ack (mis); } +int qemu_loadvm_approve_switchover (const char *approver) +{ +MigrationIncomingState *mis =migration_incoming_get_current (); + +if (!migrate_switchover_ack ()) { +return 0 ; + } + +if (migrate_switchover_ack_legacy ()) { +return qemu_loadvm_approve_switchover_legacy (approver); + } + +trace_loadvm_approve_switchover (approver); + +return migrate_send_rp_switchover_ack (mis); +} +bool qemu_loadvm_load_state_buffer (const char *idstr,uint32_t instance_id,char *buf,size_t len,Error **errp) {migration/trace-events +3
-2@@ -24,6 +24,7 @@ loadvm_postcopy_ram_handle_discard_header(const char *ramid, uint16_t len) "%s: loadvm_process_command(const char *s, uint16_t len) "com=%s len=%d" loadvm_process_command_ping(uint32_t val) "0x%x" loadvm_approve_switchover_legacy(const char *approver, unsigned int switchover_ack_pending_num_legacy) "Approver %s, switchover_ack_pending_num_legacy %u" +loadvm_approve_switchover(const char *approver) "Approver %s" postcopy_ram_listen_thread_exit(void) "" postcopy_ram_listen_thread_start(void) "" qemu_savevm_send_postcopy_advise(void) ""@@ -40,6 +41,7 @@ savevm_send_postcopy_resume(void) "" savevm_send_recv_bitmap(char *name) "%s" savevm_send_switchover_start(void) "" savevm_state_setup(void) "" +savevm_request_switchover_ack(const char *stage, const char *requester, uint32_t pending_num) "Stage %s, requester %s, switchover_ack_pending_num %" PRIu32 savevm_state_resume_prepare(void) "" savevm_state_header(void) "" savevm_state_iterate(void) ""@@ -189,7 +191,7 @@ source_return_path_thread_loop_top(void) "" source_return_path_thread_pong(uint32_t val) "0x%x" source_return_path_thread_shut(uint32_t val) "0x%x" source_return_path_thread_resume_ack(uint32_t v) "%"PRIu32 -source_return_path_thread_switchover_acked(void) "" +source_return_path_thread_switchover_acked(uint32_t pending_num) "switchover_ack_pending_num %" PRIu32 source_return_path_thread_postcopy_package_loaded(void) "" migration_thread_low_pending(uint64_t pending) "%" PRIu64 migrate_transferred(uint64_t transferred, uint64_t time_spent, uint64_t bandwidth, uint64_t avail_bw, uint64_t size) "transferred %" PRIu64 " time_spent %" PRIu64 " bandwidth %" PRIu64 " switchover_bw %" PRIu64 " max_size %" PRId64 --Quoted 2 lines
2.40.1
--
Peter Xu
Signature · 1 line
Peter Xu
Re: [PATCH 07/14] migration: Make switchover-ack re-usable
Quoted 227 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 197 lines · Avihai Horon
Quoted 53 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 35 lines · Avihai Horon
Switchover-ack is a mechanism to synchronize between source and destination QEMU during migration to prevent the source from switching over prematurely.
VFIO uses switchover-ack to ensure switchover happens only after destination side has loaded the precopy initial bytes. This is important for VFIO, as otherwise downtime could be impacted and be higher.
In its current state, switchover-ack is a one-time mechanism, meaning that switchover is acked only once and past that another ACK cannot be requested again. This was sufficient until now, as VFIO precopy initial bytes was defined to be monotonically decreasing. Thus, when precopy initial bytes reached zero for all VFIO devices, a single ACK would be sent and its validity would hold.
However, now the new
VFIO_PRECOPY_INFO_REINITfeature allows precopy initial bytes to be re-initialized during precopy. Specifically, it means that initial bytes can grow after reaching zero, which would invalidate a previously sent switchover ACK.To solve this, make switchover-ack reusable and allow devices to request another switchover ACK when needed.
To avoid scattering them all over, switchover ACKs are requested through a new
request_switchover_ackhandler which is called in specific places.Since now switchover ACK can be requested for a specific device and in different times, make switchover ACK per-device (instead of a single ACK for all devices) and let source side do the pending ACKs accounting.
Keep the legacy switchover-ack mechanism for backward compatibility and turn it on by a compatibility property for older machines. Enable the property until VFIO implements the new switchover-ack.
Signed-off-by Avihai Horon <[email protected]>Quoted 12 lines
--- include/migration/client-options.h | 1 + include/migration/register.h | 21 +++++++++ migration/migration.h | 15 +++++-- migration/savevm.h | 4 +- hw/core/machine.c | 4 +- hw/vfio/migration.c | 8 ++-- migration/migration.c | 38 +++++++++++++--- migration/options.c | 10 +++++ migration/savevm.c | 69 +++++++++++++++++++++++++++++- migration/trace-events | 4 +- 10 files changed, 156 insertions(+), 18 deletions(-)We may need to also update
qapi/migration.jsonfor its behavior change.Quoted 8 lines
One option is to simplify that rather than mentioning too much details on legacy / modern behaviors: the QAPI documentatation can describe the general concept of this feature, leaving impl details to QEMU internals.
IIUC, the generic concept of this feature is allowing destination QEMU to acknowledge a switchover decision that source makes, rather than fully relying on the source QEMU. The doc can avoid mentioning how many ACKs it needs, and whether the ACK message is global, or per-device.
Sure, I will reword it.
Quoted 130 lines
Quoted 130 lines
include/migration/client-options.h +1
-0@@ -13,6 +13,7 @@/* properties */ bool migrate_send_switchover_start (void ); +bool migrate_switchover_ack_legacy (void );/* capabilities */ include/migration/register.h +21
-0@@ -30,6 +30,11 @@ typedef struct MigPendingData {uint64_t total_bytes; } MigPendingData; +enum MigSwitchoverAckRequestStage { +MIG_SWITCHOVER_ACK_REQUEST_STAGE_SETUP , +MIG_SWITCHOVER_ACK_REQUEST_STAGE_PENDING_EXACT , +}; +/** * struct SaveVMHandlers: handler structure to finely control * migration of complex subsystems and devices, such as RAM, block and @@ -299,6 +304,22 @@ typedef struct SaveVMHandlers {*/ int (*resume_prepare)(MigrationState *s,void *opaque); +/** +* @request_switchover_ack +* +* Checks if a new switchover ACK is requested. Called only on source side +* in the stages specified in enum MigSwitchoverAckRequestStage. +* +* @stage: the stage in which the handler was called +* @opaque: data pointer passed to register_savevm_live() +* @requester: output pointer to be set to the name of the requester of the +* switchover ACK (for logging purposes). If not set, idstr will be used. +* +* Returns true to request switchover ACK and false otherwise +*/ +bool (*request_switchover_ack)(enum MigSwitchoverAckRequestStage stage, +void *opaque,const char **requester); +/** * @switchover_start * migration/migration.h +12
-3@@ -494,6 +494,12 @@ struct MigrationState {*/ uint8_t clear_bitmap_shift; +/* +* This decides whether to use legacy switchover ack (send ACK once for all +* devices) or new switchover ack (send ACK for each device). +*/ +bool switchover_ack_legacy; +/* * This save hostname when out-going migration starts */ @@ -503,10 +509,13 @@ struct MigrationState {JSONWriter *vmdesc;/* -* Indicates whether an ACK from the destination that it's OK to do -* switchover has been received. +* Indicates the number of pending ACKs from the destination. The value may +* increase or decrease during precopy as new ACKs are requested or +* received. When zero is reached, it's OK to switchover. In legacy +* switchover-ack, it's initialized to 1 and decreased to zero upon ACK. */ -bool switchover_acked; +uint32_t switchover_ack_pending_num; +/* Is this a rdma migration */ bool rdma_migration;migration/savevm.h +3
-1@@ -37,6 +37,8 @@ bool qemu_savevm_state_blocked(Error **errp);void qemu_savevm_non_migratable_list (strList **reasons);int qemu_savevm_state_prepare (Error **errp);int qemu_savevm_state_do_setup (QEMUFile *f,Error **errp); +int qemu_savevm_request_switchover_ack (enum MigSwitchoverAckRequestStage stage, +Error **errp);bool qemu_savevm_state_guest_unplug_pending (void );int qemu_savevm_state_resume_prepare (MigrationState *s);void qemu_savevm_send_header (QEMUFile *f);@@ -70,7 +72,7 @@ void qemu_loadvm_state_cleanup(MigrationIncomingState *mis);int qemu_loadvm_state_main (QEMUFile *f,MigrationIncomingState *mis,Error **errp);int qemu_load_device_state (QEMUFile *f,Error **errp); -int qemu_loadvm_approve_switchover_legacy (const char *approver); +int qemu_loadvm_approve_switchover (const char *approver);int qemu_savevm_state_non_iterable (QEMUFile *f,Error **errp); int qemu_savevm_state_non_iterable_early(QEMUFile *f, JSONWriter *vmdesc,hw/core/machine.c +3
-1@@ -39,7 +39,9 @@#include "hw/acpi/generic_event_device.h" #include "qemu/audio.h" -GlobalProperty hw_compat_11_0[] = {}; +GlobalProperty hw_compat_11_0[] = { + {"migration" ,"switchover-ack-legacy" ,"on" }, +};const size_t hw_compat_11_0_len =G_N_ELEMENTS (hw_compat_11_0);GlobalProperty hw_compat_10_2[] = {hw/vfio/migration.c +0
-0@@ -828,11 +828,11 @@ static int vfio_load_state(QEMUFile *f, void *opaque, int version_id)return -EINVAL ; }Quoted 3 lines
hw/vfio/migration.c static int vfio_load_state(QEMUFile *f, void *opaque, int version_id) · line 831
Quoted 2 lines
hw/vfio/migration.c +1
-1- ret =qemu_loadvm_approve_switchover_legacy (vbasedev->name); + ret =qemu_loadvm_approve_switchover (vbasedev->name);This switches the just-renamed legacy function back. Looks a bit weird.
Quoted 6 lines
I can drop renaming
qemu_loadvm_approve_switchover()to legacy in previous patch.
Or I can keepqemu_loadvm_approve_switchover_legacy()exported and have VFIO checkmigrate_switchover_ack_legacy()and call the right function.Would one of the above be less awkward?
In the final version,
qemu_loadvm_approve_switchover()contains both the legacy and modern handling already:int
qemu_loadvm_approve_switchover(const char *approver){ MigrationIncomingState *mis = migration_incoming_get_current(); if (!migrate_switchover_ack()) { return 0; } if (migrate_switchover_ack_legacy()) { return qemu_loadvm_approve_switchover_legacy(approver); } trace_loadvm_approve_switchover(approver); return migrate_send_rp_switchover_ack(mis); }
Quoted 2 lines
Then option 1 makes more sense to avoid renaming it to
_legacy()since the start.
Ack.
Quoted 169 lines
Quoted 150 lines
Quoted 138 lines
Quoted 78 lines
hw/vfio/migration.c +3
-3if (ret) { -error_report ("%s: qemu_loadvm_approve_switchover_legacy " -"failed, err=%d (%s)" , - vbasedev->name, ret,strerror (-ret)); +error_report ( +"%s: qemu_loadvm_approve_switchover failed, err=%d (%s)" , + vbasedev->name, ret,strerror (-ret)); }return ret;migration/migration.c +18
-6@@ -1684,7 +1684,9 @@ int migrate_init(MigrationState *s, Error **errp) s->vm_old_state =-1 ; s->iteration_initial_bytes =0 ; s->threshold_size =0 ; - s->switchover_acked = false; +/* Legacy switchover-ack sends a single ACK for all devices */ +qatomic_set (&s->switchover_ack_pending_num, +migrate_switchover_ack_legacy () ?1 :0 ); s->rdma_migration = false;/* @@ -2169,7 +2171,7 @@ void migration_request_switchover_ack_legacy(const char *requester) {MigrationIncomingState *mis =migration_incoming_get_current (); -if (!migrate_switchover_ack ()) { +if (!migrate_switchover_ack () || !migrate_switchover_ack_legacy ()) {return ; }@@ -2425,9 +2427,18 @@ static void *source_return_path_thread(void *opaque)break ;case MIG_RP_MSG_SWITCHOVER_ACK : - ms->switchover_acked = true; -trace_source_return_path_thread_switchover_acked (); + { +uint32_t pending_num; + + pending_num =qatomic_dec_fetch (&ms->switchover_ack_pending_num); +trace_source_return_path_thread_switchover_acked (pending_num); +if (pending_num ==UINT32_MAX ) { +error_setg (&err,"Switchover ack pending num underflowed" ); + goto out; + } +break ; + }default :break ;@@ -3221,7 +3232,7 @@ static bool migration_can_switchover(MigrationState *s)return true; } -return s->switchover_acked; +return qatomic_read (&s->switchover_ack_pending_num) ==0 ; }/* Migration thread iteration status */ @@ -3311,9 +3322,10 @@ static MigIterateState migration_iteration_run(MigrationState *s)Error *local_err =NULL ;bool in_postcopy = (s->state ==MIGRATION_STATUS_POSTCOPY_DEVICE || s->state ==MIGRATION_STATUS_POSTCOPY_ACTIVE ); -bool can_switchover =migration_can_switchover (s); +bool can_switchover;MigPendingData pending = { };bool complete_ready; +int ret;/* Fast path - get the estimated amount of pending data */ qemu_savevm_query_pending (&pending, false);migration/migration.c static MigIterateState migration_iteration_run(MigrationState *s) · line 3362
Quoted 5 lines
migration/migration.c +2
-0@@ -3346,8 +3358,18 @@ static MigIterateState migration_iteration_run(MigrationState *s)*/ if (migration_iteration_next_ready (s, &pending)) {migration_iteration_go_next (&pending); + ret =qemu_savevm_request_switchover_ack ( +MIG_SWITCHOVER_ACK_REQUEST_STAGE_PENDING_EXACT , &local_err);I agree this is a good spot to report when a new ack will be needed, but this
PENDING_EXACTstage is confusing to me. Actually, I think it's the whole concept of this extra "stage" is not easy to understand, and I don't yet understand why it is needed.To me, the module should be able to raise a switch-ack request anytime, and it doesn't need to have a "stage" passed in.
The only difference here, IIUC, is for COMPLETE stage the current version modified
qemu_savevm_request_switchover_ack()to fail explicitly.It's fine, but we can also move that logic out, say, we can make sure all modules reported the last time of "whether a new switchover ack needed" after stopping VM, then read once more
switchover_ack_pending_nummaking sure it's zero before switching over. IIUC that removes the last piece of dependency of this whole "stage" concept.IOW, I wonder if we can provide such reporting facility of "we need a switch-ack" in the
save_query_pending()API. For example, we can extend existing MigPendingData:include/migration/register.h +2
-0@@ -23,6 +23,8 @@ typedef struct MigPendingData {uint64_t postcopy_bytes;/* Amount of pending bytes can be transferred only in stopcopy */ uint64_t stopcopy_bytes; +/* Report if a new switchover-ack will be needed */ +uint64_t switchover_ack_pending;/* * Total pending data, modules do not need to update this field, it * will be automatically calculated by migration core API. migration/savevm.c +12
-0@@ -1879,6 +1879,18 @@ void qemu_savevm_query_pending(MigPendingData *pending, bool exact)*/ mig_stats.dirty_bytes_total = pending->total_bytes; + +if (pending->switchover_ack_pending) { +qatomic_add (&s->switchover_ack_pending_num, + pending->switchover_ack_pending); +/* +* NOTE: If we rely on migration core to request that on dest, we +* need a new type of message sent to dest QEMU to request for +* that. Otherwise we can also rely on per-module protocol to +* request it. +*/ + } +Quoted 3 lines
With that, module can report anytime, where query's @exact can be either true / false, it doesn't matter. The one reported in SETUP can be done in the first query which is guaranteed to happen before switchover.
So basically your approach reduced the stages into a single one - during query pending (either exact or estimate) - which allows us to drop the stage param.
I agree SETUP can be dropped now that switchover-ack can be requested also in query pending estimate.
But how can modules request another switchover-ack past the last query pending (after which we switchover)?Quoted 7 lines
IIUC, we would need to issue another query pending after VM stop, but VFIO will fail a query pending exact at that stage (when VM stopped), so we can only issue query estimate pending.
This seems a bit weird, so I guess we can add another flavor for query pending which only queries switchover-ack? Or completely split it from query pending into a separate
migrate_request_switchover_ack()function?It shouldn't be awkward, and IMHO it'll further cleanup the code base, further removing some legacy RAM hacks.
In reality / theory, we must do a sync / slow query after VM stopped, because that's the only way to collect the ultimate last set of dirty info for the whole system, and we must not miss anything or dest QEMU will crash.
For RAM (which was the only one that cares before), that was done currently in a, IMHO, "hacky" way:
ram_save_complete():
Quoted 8 lines
if (!migration_in_postcopy()) { migration_bitmap_sync_precopy(true); }That should really not hide in a
complete()callback. It should be a pretty generic concept for all modules. And now with thesave_query_pending()API introduced, that slow sync is that generic approach.
Ah, right, I totally forgot that RAM does a last query in complete phase, I was probably too focused on VFIO which doesn't need such query.
In that case, I agree with you, this should be cleaner.
Quoted 23 lines
As a first step, I think we need to move this sync out of RAM's
complete(), similarly to what I have done in the dependency patch to move some ram-specific changes out to generic migration code.After moving out, it will become a sync query and VFIO should also properly handle it.
I'm not sure why currently VFIO mustn't do such a sync query after VM stopped, but if there's some nuance that caused it, VFIO will need to handle it in its
save_query_pending(sync=on)and makes sure:(1) VFIO won't crash on a sync query during switchover phase, aka, VM stopped,
(2) VFIO needs to guarantee sync all through the stack so that all dirty data is collected properly (I bet this was always the case, so no real concern here..)
Then, it means we'll do a sync query after VM stop, and VFIO (while synchronizing dirty info) will report the last switchover-ack request too altogether in the same query, as part of "pending data".
Quoted 8 lines
Then with that, when switchover_ack_pending_num!=0, we either:
- Fail the migration, as this patchset does for now, or,
- Goes back to iteration phase, which can be TBD in the future, since REINIT shouldn't be common anyway
Do you think such would work out clean?
Yes I think so.
We just need to indicate modules that it’s the last query during switchover so they can handle it properly. Do you think it would be reasonable to add a "bool final" param to save_query_pending handler?
For RAM it will be used to indicate we are running under the BQL (since currently save_query_pending runs only outside BQL) and to pass the proper last_stage param into migration_bitmap_sync_precopy(). For VFIO it will indicate we should not do a query precopy info ioctl (which is only valid in VFIO precopy states, not while VM is stopped).
Quoted 32 lines
Quoted 10 lines
Quoted 10 lines
So I also left a "NOTE" above, currently IIUC VFIO is responsible for telling dest QEMU that it needs to emit one more switchover-ack (likely by
VFIO_MIG_FLAG_DEV_INIT_DATA_SENT, which is vfio specific protocol), another way to do this is requesting that from migration core, then we can send a newREQUEST_SWITCHOVER_ACKmessage to dest, routing it to the device.Logically relying on migration core should be better: consider in the future all these things can be reusable by e.g. vDPA or other similar cases. But so far I don't have a strong feeling.
Quoted 6 lines
Note that for VFIO, requesting switchover-ack from source (incrementing
switchover_ack_pending_num) and requesting an ack from destination happen in different times - the former happens once we see newinit_bytes> 0, and the latter happens wheninit_bytes= 0 again.I need to think this through, but did you have something specific in mind?
Not really something useful, but I can share my thoughts.
Currently, VFIO does it in a way that it first push all data, then put a tag of
VFIO_MIG_FLAG_DEV_INIT_DATA_SENTat the end if all data pushed flushed all INIT/REINIT data.That'll work out, because "ACK" essentially can be emitted on dest as long as dest QEMU completely received and applied the prior
vfio_save_block()dump. There's nothing special dest needs to do. IOW, dest is not making much decision, but blindly ACK after seeingVFIO_MIG_FLAG_DEV_INIT_DATA_SENT. Such sequence will make everything flow.What I had in mind was allowing src QEMU to send a "Request ACK for device XXX
instance_idYYY", then dest migration core routes it to the corresponding module. The module then will decide itself on when to ACK.
Quoted 5 lines
Now think about it, maybe it's an overkill. It's more flexible, it can be reused by vDPA and others, but it's more than what we need right now.
Also, since
VFIO_MIG_FLAG_DEV_INIT_DATA_SENTis already the wire protocol, let's stick with it to not introduce confusions.
I see.
Yes, we can keep VFIO_MIG_FLAG_DEV_INIT_DATA_SENT for now and if a new module wants to use switchover-ack in the future, we can think of a general solution then.
Thanks.
Quoted 197 lines
Quoted 24 lines
Quoted 16 lines
Quoted 16 lines
migration/migration.c +8
-0+if (ret <0 ) { +migrate_error_propagate (s, local_err); +qemu_file_set_error (s->to_dst_file, ret); +return MIG_ITERATE_RESUME ; + } } +/* Check can switchover after qemu_savevm_request_switchover_ack() */ + can_switchover =migration_can_switchover (s); +/* Should we switch to postcopy now? */ if (can_switchover &&postcopy_should_start (s, &pending)) {if (postcopy_start (s, &local_err)) {@@ -3638,6 +3660,10 @@ static void *migration_thread(void *opaque)bql_lock (); ret =qemu_savevm_state_do_setup (s->to_dst_file, &local_err);Quoted 8 lines
migration/migration.c static void *migration_thread(void *opaque) · line 3666
Quoted 5 lines
migration/migration.c +4
-0bql_unlock (); +if (!ret) { + ret =qemu_savevm_request_switchover_ack ( +MIG_SWITCHOVER_ACK_REQUEST_STAGE_SETUP , &local_err); + }Let's always avoid doing things like this with "if (!ret)"? We can put it after the whole unplug event and after the ret check, fail immediately if ret != 0.
Quoted 170 lines
Sure.
Thanks!
Quoted 166 lines
Quoted 161 lines
migration/migration.c +0
-0qemu_savevm_wait_unplug (s,MIGRATION_STATUS_SETUP ,MIGRATION_STATUS_ACTIVE );migration/options.c +10
-0@@ -108,6 +108,9 @@ const Property migration_properties[] = { preempt_pre_7_2, false),DEFINE_PROP_BOOL ("multifd-clean-tls-termination" , MigrationState, multifd_clean_tls_termination, true), +/* Use legacy until VFIO implements new switchover-ack */ +DEFINE_PROP_BOOL ("switchover-ack-legacy" , MigrationState, + switchover_ack_legacy, true),/* Migration parameters */ DEFINE_PROP_UINT8("x-throttle-trigger-threshold", MigrationState,@@ -462,6 +465,13 @@ bool migrate_rdma(void)return s->rdma_migration; } +bool migrate_switchover_ack_legacy (void ) +{ +MigrationState *s =migrate_get_current (); + +return s->switchover_ack_legacy; +} + typedef enum WriteTrackingSupport { WT_SUPPORT_UNKNOWN = 0, WT_SUPPORT_ABSENT,migration/savevm.c +67
-2@@ -1472,6 +1472,54 @@ int qemu_savevm_state_do_setup(QEMUFile *f, Error **errp)return precopy_notify (PRECOPY_NOTIFY_SETUP , errp); } +static const char * +switchover_ack_stage_to_str (enum MigSwitchoverAckRequestStage stage) +{ +switch (stage) { +case MIG_SWITCHOVER_ACK_REQUEST_STAGE_SETUP : +return "SETUP" ; +case MIG_SWITCHOVER_ACK_REQUEST_STAGE_PENDING_EXACT : +return "PENDING_EXACT" ; +default : +return "UNKNOWN" ; + } +} + +int qemu_savevm_request_switchover_ack (enum MigSwitchoverAckRequestStage stage, +Error **errp) +{ +MigrationState *s =migrate_get_current (); +uint32_t pending_num; +SaveStateEntry *se; +const char *requester; + +if (!migrate_switchover_ack () ||migrate_switchover_ack_legacy ()) { +return 0 ; + } + + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { +if (!se->ops || !se->ops->request_switchover_ack) { +continue ; + } + + requester =NULL ; +if (se->ops->request_switchover_ack (stage, se->opaque, &requester)) { + requester = requester ?: se->idstr; + pending_num =qatomic_inc_fetch (&s->switchover_ack_pending_num); +if (pending_num ==0 ) { +error_setg (errp,"Switchover ack pending num overflowed by %s" , + requester); +return -EOVERFLOW ; + } + +trace_savevm_request_switchover_ack ( +switchover_ack_stage_to_str (stage), requester, pending_num); + } + } + +return 0 ; +} +int qemu_savevm_state_resume_prepare (MigrationState *s) {SaveStateEntry *se;@@ -2471,7 +2519,7 @@ static int loadvm_switchover_ack_no_users_legacy(MigrationIncomingState *mis, {int ret; -if (!migrate_switchover_ack ()) { +if (!migrate_switchover_ack () || !migrate_switchover_ack_legacy ()) {return 0 ; }@@ -3153,7 +3201,7 @@ int qemu_load_device_state(QEMUFile *f, Error **errp)return 0 ; } -int qemu_loadvm_approve_switchover_legacy (const char *approver) +static int qemu_loadvm_approve_switchover_legacy (const char *approver) {MigrationIncomingState *mis =migration_incoming_get_current ();@@ -3172,6 +3220,23 @@ int qemu_loadvm_approve_switchover_legacy(const char *approver)return migrate_send_rp_switchover_ack (mis); } +int qemu_loadvm_approve_switchover (const char *approver) +{ +MigrationIncomingState *mis =migration_incoming_get_current (); + +if (!migrate_switchover_ack ()) { +return 0 ; + } + +if (migrate_switchover_ack_legacy ()) { +return qemu_loadvm_approve_switchover_legacy (approver); + } + +trace_loadvm_approve_switchover (approver); + +return migrate_send_rp_switchover_ack (mis); +} +bool qemu_loadvm_load_state_buffer (const char *idstr,uint32_t instance_id,char *buf,size_t len,Error **errp) {migration/trace-events +3
-2@@ -24,6 +24,7 @@ loadvm_postcopy_ram_handle_discard_header(const char *ramid, uint16_t len) "%s: loadvm_process_command(const char *s, uint16_t len) "com=%s len=%d" loadvm_process_command_ping(uint32_t val) "0x%x" loadvm_approve_switchover_legacy(const char *approver, unsigned int switchover_ack_pending_num_legacy) "Approver %s, switchover_ack_pending_num_legacy %u" +loadvm_approve_switchover(const char *approver) "Approver %s" postcopy_ram_listen_thread_exit(void) "" postcopy_ram_listen_thread_start(void) "" qemu_savevm_send_postcopy_advise(void) ""@@ -40,6 +41,7 @@ savevm_send_postcopy_resume(void) "" savevm_send_recv_bitmap(char *name) "%s" savevm_send_switchover_start(void) "" savevm_state_setup(void) "" +savevm_request_switchover_ack(const char *stage, const char *requester, uint32_t pending_num) "Stage %s, requester %s, switchover_ack_pending_num %" PRIu32 savevm_state_resume_prepare(void) "" savevm_state_header(void) "" savevm_state_iterate(void) ""@@ -189,7 +191,7 @@ source_return_path_thread_loop_top(void) "" source_return_path_thread_pong(uint32_t val) "0x%x" source_return_path_thread_shut(uint32_t val) "0x%x" source_return_path_thread_resume_ack(uint32_t v) "%"PRIu32 -source_return_path_thread_switchover_acked(void) "" +source_return_path_thread_switchover_acked(uint32_t pending_num) "switchover_ack_pending_num %" PRIu32 source_return_path_thread_postcopy_package_loaded(void) "" migration_thread_low_pending(uint64_t pending) "%" PRIu64 migrate_transferred(uint64_t transferred, uint64_t time_spent, uint64_t bandwidth, uint64_t avail_bw, uint64_t size) "transferred %" PRIu64 " time_spent %" PRIu64 " bandwidth %" PRIu64 " switchover_bw %" PRIu64 " max_size %" PRId64 --Quoted 2 lines
2.40.1
--
Peter Xu--
Peter Xu
Re: [PATCH 07/14] migration: Make switchover-ack re-usable
Quoted 7 lines · Avihai Horon
Yes I think so.
We just need to indicate modules that it’s the last query during switchover so they can handle it properly.
Do you think it would be reasonable to add a "bool final" param tosave_query_pendinghandler?
Quoted 5 lines
For RAM it will be used to indicate we are running under the BQL (since currently
save_query_pendingruns only outside BQL) and to pass the properlast_stageparam intomigration_bitmap_sync_precopy().
For VFIO it will indicate we should not do a query precopy info ioctl (which is only valid in VFIO precopy states, not while VM is stopped).
Yes, a final boolean sounds reasonable, implying both (1) last sync before switchover, VM stopped, (2) BQL held.
For VFIO, I double checked the complete() that does not depend on the precopy_bytes fetched, then it should be fine indeed,
vfio_save_complete_precopy():
do {
data_size = vfio_save_block(f, vbasedev->migration);
if (data_size < 0) {
return data_size;
}
} while (data_size);It's just werid to see that it doesn't depend on either precopy_bytes or initial_bytes, even if logically it should.. this will be confusing to whoever start reading this code.. but I understand not much we can do with the current kernel API.
Side note: should we still better update these fields to make sure they'll be zero after migration? That means vfio_update_estimated_pending_data() in vfio_save_complete_precopy() too, with/without further sanity checks. That seems to be missing right now. I'm not sure if it's intentional.
Thanks,
Signature · 1 line
Peter Xu
Re: [PATCH 07/14] migration: Make switchover-ack re-usable
Quoted 35 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 7 lines · Avihai Horon
Yes I think so.
We just need to indicate modules that it’s the last query during switchover so they can handle it properly.
Do you think it would be reasonable to add a "bool final" param tosave_query_pendinghandler?Quoted 5 lines
For RAM it will be used to indicate we are running under the BQL (since currently
save_query_pendingruns only outside BQL) and to pass the properlast_stageparam intomigration_bitmap_sync_precopy().
For VFIO it will indicate we should not do a query precopy info ioctl (which is only valid in VFIO precopy states, not while VM is stopped).Yes, a final boolean sounds reasonable, implying both (1) last sync before switchover, VM stopped, (2) BQL held.
For VFIO, I double checked the
complete()that does not depend on theprecopy_bytesfetched, then it should be fine indeed,
vfio_save_complete_precopy():do { data_size = vfio_save_block(f, vbasedev->migration); if (data_size < 0) { return data_size; } } while (data_size);It's just werid to see that it doesn't depend on either
precopy_bytesorinitial_bytes, even if logically it should.. this will be confusing to whoever start reading this code.. but I understand not much we can do with the current kernel API.
Quoted 4 lines
Side note: should we still better update these fields to make sure they'll be zero after migration? That means
vfio_update_estimated_pending_data()invfio_save_complete_precopy()too, with/without further sanity checks. That seems to be missing right now. I'm not sure if it's intentional.
Yes, it's intentional, since we don't use these values after calling vfio_save_complete_precopy() -- they are only used for downtime estimation prior switchover. Precopy_init/dirty sizes are zeroed in vfio_save_cleanup() though, but not stopcopy_size (however, that's benign, since upon new migration it will be reset before used).
So calling vfio_update_estimated_pending_data() here seems redundant to me.
Thanks.
Re: [PATCH 07/14] migration: Make switchover-ack re-usable
Quoted 42 lines · Avihai Horon
Quoted 35 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 7 lines · Avihai Horon
Yes I think so.
We just need to indicate modules that it’s the last query during switchover so they can handle it properly.
Do you think it would be reasonable to add a "bool final" param tosave_query_pendinghandler?Quoted 5 lines
For RAM it will be used to indicate we are running under the BQL (since currently
save_query_pendingruns only outside BQL) and to pass the properlast_stageparam intomigration_bitmap_sync_precopy().
For VFIO it will indicate we should not do a query precopy info ioctl (which is only valid in VFIO precopy states, not while VM is stopped).Yes, a final boolean sounds reasonable, implying both (1) last sync before switchover, VM stopped, (2) BQL held.
For VFIO, I double checked the
complete()that does not depend on theprecopy_bytesfetched, then it should be fine indeed,
vfio_save_complete_precopy():do { data_size = vfio_save_block(f, vbasedev->migration); if (data_size < 0) { return data_size; } } while (data_size);It's just werid to see that it doesn't depend on either
precopy_bytesorinitial_bytes, even if logically it should.. this will be confusing to whoever start reading this code.. but I understand not much we can do with the current kernel API.Quoted 4 lines
Side note: should we still better update these fields to make sure they'll be zero after migration? That means
vfio_update_estimated_pending_data()invfio_save_complete_precopy()too, with/without further sanity checks. That seems to be missing right now. I'm not sure if it's intentional.
Quoted 8 lines
Yes, it's intentional, since we don't use these values after calling
vfio_save_complete_precopy()-- they are only used for downtime estimation prior switchover.
Precopy_init/dirty sizes are zeroed invfio_save_cleanup()though, but notstopcopy_size(however, that's benign, since upon new migration it will be reset before used).So calling
vfio_update_estimated_pending_data()here seems redundant to me.
Logically migration can still fail during complete():
qemu_savevm_state_complete_precopy():
ret = qemu_savevm_state_complete_precopy_iterable(f, false);
if (ret) {
return ret;
}If vfio_update_estimated_pending_data() has the safe guard for any form of overflow, then IMHO we should try to maintain those counters if possible.
Thanks,
Signature · 1 line
Peter Xu
Re: [PATCH 07/14] migration: Make switchover-ack re-usable
Quoted 54 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 40 lines · Avihai Horon
Quoted 35 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 7 lines · Avihai Horon
Yes I think so.
We just need to indicate modules that it’s the last query during switchover so they can handle it properly.
Do you think it would be reasonable to add a "bool final" param tosave_query_pendinghandler?Quoted 5 lines
For RAM it will be used to indicate we are running under the BQL (since currently
save_query_pendingruns only outside BQL) and to pass the properlast_stageparam intomigration_bitmap_sync_precopy().
For VFIO it will indicate we should not do a query precopy info ioctl (which is only valid in VFIO precopy states, not while VM is stopped).Yes, a final boolean sounds reasonable, implying both (1) last sync before switchover, VM stopped, (2) BQL held.
For VFIO, I double checked the
complete()that does not depend on theprecopy_bytesfetched, then it should be fine indeed,
vfio_save_complete_precopy():do { data_size = vfio_save_block(f, vbasedev->migration); if (data_size < 0) { return data_size; } } while (data_size);It's just werid to see that it doesn't depend on either
precopy_bytesorinitial_bytes, even if logically it should.. this will be confusing to whoever start reading this code.. but I understand not much we can do with the current kernel API.Quoted 4 lines
Side note: should we still better update these fields to make sure they'll be zero after migration? That means
vfio_update_estimated_pending_data()invfio_save_complete_precopy()too, with/without further sanity checks. That seems to be missing right now. I'm not sure if it's intentional.Quoted 8 lines
Yes, it's intentional, since we don't use these values after calling
vfio_save_complete_precopy()-- they are only used for downtime estimation prior switchover.
Precopy_init/dirty sizes are zeroed invfio_save_cleanup()though, but notstopcopy_size(however, that's benign, since upon new migration it will be reset before used).So calling
vfio_update_estimated_pending_data()here seems redundant to me.Logically migration can still fail during
complete():
Quoted 8 lines
qemu_savevm_state_complete_precopy():ret = qemu_savevm_state_complete_precopy_iterable(f, false); if (ret) { return ret; }If
vfio_update_estimated_pending_data()has the safe guard for any form of overflow, then IMHO we should try to maintain those counters if possible.
Yes, we can call vfio_update_estimated_pending_data() in vfio_save_complete_precopy(), but I am not sure I see what's the benefit of it?
If it's to ensure these counters are zero post of migration, then even if migration fails the .save_cleanup handler will be called and zero them (I can add a patch that zeroes stopcopy_size as well).
Thanks.
Re: [PATCH 07/14] migration: Make switchover-ack re-usable
Quoted 65 lines · Avihai Horon
Quoted 54 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 40 lines · Avihai Horon
Quoted 35 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 7 lines · Avihai Horon
Yes I think so.
We just need to indicate modules that it’s the last query during switchover so they can handle it properly.
Do you think it would be reasonable to add a "bool final" param tosave_query_pendinghandler?Quoted 5 lines
For RAM it will be used to indicate we are running under the BQL (since currently
save_query_pendingruns only outside BQL) and to pass the properlast_stageparam intomigration_bitmap_sync_precopy().
For VFIO it will indicate we should not do a query precopy info ioctl (which is only valid in VFIO precopy states, not while VM is stopped).Yes, a final boolean sounds reasonable, implying both (1) last sync before switchover, VM stopped, (2) BQL held.
For VFIO, I double checked the
complete()that does not depend on theprecopy_bytesfetched, then it should be fine indeed,
vfio_save_complete_precopy():do { data_size = vfio_save_block(f, vbasedev->migration); if (data_size < 0) { return data_size; } } while (data_size);It's just werid to see that it doesn't depend on either
precopy_bytesorinitial_bytes, even if logically it should.. this will be confusing to whoever start reading this code.. but I understand not much we can do with the current kernel API.Quoted 4 lines
Side note: should we still better update these fields to make sure they'll be zero after migration? That means
vfio_update_estimated_pending_data()invfio_save_complete_precopy()too, with/without further sanity checks. That seems to be missing right now. I'm not sure if it's intentional.Quoted 8 lines
Yes, it's intentional, since we don't use these values after calling
vfio_save_complete_precopy()-- they are only used for downtime estimation prior switchover.
Precopy_init/dirty sizes are zeroed invfio_save_cleanup()though, but notstopcopy_size(however, that's benign, since upon new migration it will be reset before used).So calling
vfio_update_estimated_pending_data()here seems redundant to me.Logically migration can still fail during
complete():Quoted 8 lines
qemu_savevm_state_complete_precopy():ret = qemu_savevm_state_complete_precopy_iterable(f, false); if (ret) { return ret; }If
vfio_update_estimated_pending_data()has the safe guard for any form of overflow, then IMHO we should try to maintain those counters if possible.
Quoted 7 lines
Yes, we can call
vfio_update_estimated_pending_data()invfio_save_complete_precopy(), but I am not sure I see what's the benefit of it?If it's to ensure these counters are zero post of migration, then even if migration fails the .save_cleanup handler will be called and zero them (I can add a patch that zeroes
stopcopy_sizeas well).
Nothing critical indeed.
I only wished save_complete() should look almost what save_live_iterate() looks like. Because they should really do similar things dumping iterable data.. with some nuances only.
Ideally, if we can add vfio_update_estimated_pending_data() into vfio's complete() it reduces that gap.
That, including the other thing you plan to do by moving the slow sync out of RAM's complete(): both of them try to also make complete() look more like save_live_iterate().
If one day we want to remove save_complete(), it'll also be easier. And IMO we should consider removing it at some point, passing another "bool final" to save_live_iterate().
If we see some other save_complete() hooks: htab_save_complete() is almost a dup of htab_save_iterate() with trivial diff, cmma_save_complete() is literally cmma_save_iterate() with passing "final" to cmma_save(), etc.
So that's only about making VFIO less special in complete() only. If you think that's a good future approach we can do that in this series together, but we can also leave it for later. No strong feelings.
Thanks,
Signature · 1 line
Peter Xu
Re: [PATCH 07/14] migration: Make switchover-ack re-usable
Quoted 91 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 63 lines · Avihai Horon
Quoted 54 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 40 lines · Avihai Horon
Quoted 35 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 7 lines · Avihai Horon
Yes I think so.
We just need to indicate modules that it’s the last query during switchover so they can handle it properly.
Do you think it would be reasonable to add a "bool final" param tosave_query_pendinghandler?Quoted 5 lines
For RAM it will be used to indicate we are running under the BQL (since currently
save_query_pendingruns only outside BQL) and to pass the properlast_stageparam intomigration_bitmap_sync_precopy().
For VFIO it will indicate we should not do a query precopy info ioctl (which is only valid in VFIO precopy states, not while VM is stopped).Yes, a final boolean sounds reasonable, implying both (1) last sync before switchover, VM stopped, (2) BQL held.
For VFIO, I double checked the
complete()that does not depend on theprecopy_bytesfetched, then it should be fine indeed,
vfio_save_complete_precopy():do { data_size = vfio_save_block(f, vbasedev->migration); if (data_size < 0) { return data_size; } } while (data_size);It's just werid to see that it doesn't depend on either
precopy_bytesorinitial_bytes, even if logically it should.. this will be confusing to whoever start reading this code.. but I understand not much we can do with the current kernel API.Quoted 4 lines
Side note: should we still better update these fields to make sure they'll be zero after migration? That means
vfio_update_estimated_pending_data()invfio_save_complete_precopy()too, with/without further sanity checks. That seems to be missing right now. I'm not sure if it's intentional.Quoted 8 lines
Yes, it's intentional, since we don't use these values after calling
vfio_save_complete_precopy()-- they are only used for downtime estimation prior switchover.
Precopy_init/dirty sizes are zeroed invfio_save_cleanup()though, but notstopcopy_size(however, that's benign, since upon new migration it will be reset before used).So calling
vfio_update_estimated_pending_data()here seems redundant to me.Logically migration can still fail during
complete():Quoted 8 lines
qemu_savevm_state_complete_precopy():ret = qemu_savevm_state_complete_precopy_iterable(f, false); if (ret) { return ret; }If
vfio_update_estimated_pending_data()has the safe guard for any form of overflow, then IMHO we should try to maintain those counters if possible.Quoted 7 lines
Yes, we can call
vfio_update_estimated_pending_data()invfio_save_complete_precopy(), but I am not sure I see what's the benefit of it?If it's to ensure these counters are zero post of migration, then even if migration fails the .save_cleanup handler will be called and zero them (I can add a patch that zeroes
stopcopy_sizeas well).Nothing critical indeed.
I only wished
save_complete()should look almost whatsave_live_iterate()looks like. Because they should really do similar things dumping iterable data.. with some nuances only.Ideally, if we can add
vfio_update_estimated_pending_data()into vfio'scomplete()it reduces that gap.That, including the other thing you plan to do by moving the slow sync out of RAM's
complete(): both of them try to also makecomplete()look more likesave_live_iterate().If one day we want to remove
save_complete(), it'll also be easier. And IMO we should consider removing it at some point, passing another "bool final" tosave_live_iterate().
Quoted 7 lines
If we see some other
save_complete()hooks:htab_save_complete()is almost a dup ofhtab_save_iterate()with trivial diff,cmma_save_complete()is literallycmma_save_iterate()with passing "final" tocmma_save(), etc.So that's only about making VFIO less special in
complete()only. If you think that's a good future approach we can do that in this series together, but we can also leave it for later. No strong feelings.
I understand.
This could be a good direction, however, I'd still prefer to leave this for later to not mix things up, if that's fine.
Thanks.
Re: [PATCH 07/14] migration: Make switchover-ack re-usable
Quoted 3 lines · Avihai Horon
I understand.
This could be a good direction, however, I'd still prefer to leave this for later to not mix things up, if that's fine.
Sure.
Signature · 1 line
Peter Xu
PATCH 8/14 migration: Check switchover-ack during switchover phase
In reply to Avihai HoronSwitchover ACK is checked only during precopy while the guest is still running. The last migration_can_switchover() decision and guest stop are not atomic, so a device may want to request another switchover ACK in the gap after switchover decision has been made but before the guest is stopped. Migration would then miss that request, which can increase downtime.
Cover this case by checking switchover ACK again during the switchover phase, after the guest has been stopped. If a new ACK is required at that point, fail migration so the condition is not ignored.
Ideally, precopy iterations should be resumed in this case, however, VFIO doesn't support going back to precopy after being stopped, so implementing such logic would require non-trivial changes to the guest start/stop flow. Given the above and that this case should be rare, failing the migration seems reasonable.
--- include/migration/register.h | 1 + migration/migration.c | 7 +++++++ migration/savevm.c | 9 +++++++++ 3 files changed, 17 insertions(+)
include/migration/register.h +1 -0
@@ -33,6 +33,7 @@ typedef struct MigPendingData {enum MigSwitchoverAckRequestStage {MIG_SWITCHOVER_ACK_REQUEST_STAGE_SETUP ,MIG_SWITCHOVER_ACK_REQUEST_STAGE_PENDING_EXACT , +MIG_SWITCHOVER_ACK_REQUEST_STAGE_COMPLETE , };/**
migration/migration.c +7 -0
@@ -2776,6 +2776,13 @@ static bool migration_switchover_prepare(MigrationState *s)static bool migration_switchover_start (MigrationState *s,Error **errp) {ERRP_GUARD (); +int ret; + + ret =qemu_savevm_request_switchover_ack ( +MIG_SWITCHOVER_ACK_REQUEST_STAGE_COMPLETE , errp); +if (ret <0 ) { +return false; + }if (!migration_switchover_prepare (s)) {error_setg (errp,"Switchover is interrupted" );
migration/savevm.c +9 -0
@@ -1480,6 +1480,8 @@ switchover_ack_stage_to_str(enum MigSwitchoverAckRequestStage stage)return "SETUP" ;case MIG_SWITCHOVER_ACK_REQUEST_STAGE_PENDING_EXACT :return "PENDING_EXACT" ; +case MIG_SWITCHOVER_ACK_REQUEST_STAGE_COMPLETE : +return "COMPLETE" ;default :return "UNKNOWN" ; }
@@ -1505,6 +1507,13 @@ int qemu_savevm_request_switchover_ack(enum MigSwitchoverAckRequestStage stage, requester =NULL ;if (se->ops->request_switchover_ack (stage, se->opaque, &requester)) { requester = requester ?: se->idstr; +if (stage ==MIG_SWITCHOVER_ACK_REQUEST_STAGE_COMPLETE ) { +error_setg (errp, +"Switchover ACK requested by %s during switchover" , + requester); +return -EPERM ; + } + pending_num =qatomic_inc_fetch (&s->switchover_ack_pending_num);if (pending_num ==0 ) { error_setg(errp, "Switchover ack pending num overflowed by %s",
Signature · 1 line
2.40.1
PATCH 9/14 vfio/migration: Re-query precopy size before sending VFIO_MIG_FLAG_DEV_INIT_DATA_SENT
In reply to Avihai HoronWhen precopy initial_bytes reaches zero VFIO_MIG_FLAG_DEV_INIT_DATA_SENT flag is sent to the destination to indicate that initial data has been sent, so destination can indicate back to source when it finished loading it.
To get a more accurate estimation of initial_bytes, re-query precopy size before sending the flag. Extract the flag sending logic from vfio_save_iterate() to a new helper for clarity.
This may prevent premature sending of VFIO_MIG_FLAG_DEV_INIT_DATA_SENT flag if, for example, the previously queried initial_bytes was lower than actually is. Additionally, it prevents sending the flag if vfio_query_precopy_size() failed.
--- hw/vfio/migration.c | 37 ++++++++++++++++++++++++++++++++----- hw/vfio/trace-events | 1 + 2 files changed, 33 insertions(+), 5 deletions(-)
hw/vfio/migration.c +32 -5
@@ -456,6 +456,37 @@ static void vfio_update_estimated_pending_data(VFIOMigration *migration, data_size); } +/* Returns true if the init data flag was sent, false otherwise */ +static bool vfio_send_init_data_flag (QEMUFile *f,VFIOMigration *migration) +{ +VFIODevice *vbasedev = migration->vbasedev; +int ret; + +if (!migrate_switchover_ack ()) { +return false; + } + +if (migration->precopy_init_size || migration->initial_data_sent) { +return false; + } + +/* +* precopy_init_size holds an estimation of the initial data size, re-query +* precopy size to ensure it's really zero before sending init data flag. +* Don't send the flag if query fails. +*/ + ret =vfio_query_precopy_size (migration); +if (ret || migration->precopy_init_size) { +return false; + } + +qemu_put_be64 (f,VFIO_MIG_FLAG_DEV_INIT_DATA_SENT ); + migration->initial_data_sent = true; +trace_vfio_send_init_data_flag (vbasedev->name); + +return true; +} +static bool vfio_precopy_supported (VFIODevice *vbasedev) {VFIOMigration *migration = vbasedev->migration;
@@ -664,11 +695,7 @@ static int vfio_save_iterate(QEMUFile *f, void *opaque)vfio_update_estimated_pending_data (migration, data_size); -if (migrate_switchover_ack () && !migration->precopy_init_size && - !migration->initial_data_sent) { -qemu_put_be64 (f,VFIO_MIG_FLAG_DEV_INIT_DATA_SENT ); - migration->initial_data_sent = true; - }else { +if (!vfio_send_init_data_flag (f, migration)) {qemu_put_be64 (f,VFIO_MIG_FLAG_END_OF_STATE ); }
hw/vfio/trace-events +1 -0
@@ -176,6 +176,7 @@ vfio_save_iterate(const char *name, uint64_t precopy_init_size, uint64_t precopy vfio_save_iterate_start(const char *name) " (%s)" vfio_save_setup(const char *name, uint64_t data_buffer_size) " (%s) data buffer size %"PRIu64 vfio_state_pending(const char *name, uint64_t stopcopy_size, uint64_t precopy_init_size, uint64_t precopy_dirty_size, bool exact) " (%s) stopcopy size %"PRIu64" precopy initial size %"PRIu64" precopy dirty size %"PRIu64 " exact %d" +vfio_send_init_data_flag(const char *name) " (%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_vmstate_change_prepare(const char *name, int running, const char *reason, const char *dev_state) " (%s) running %d reason %s device state %s"
Signature · 1 line
2.40.1
Re: [PATCH 09/14] vfio/migration: Re-query precopy size before sending VFIO_MIG_FLAG_DEV_INIT_DATA_SENT
Hello Avihai
Quoted 8 lines · Avihai Horon
When precopy
initial_bytesreaches zeroVFIO_MIG_FLAG_DEV_INIT_DATA_SENTflag is sent to the destination to indicate that initial data has been sent, so destination can indicate back to source when it finished loading it.To get a more accurate estimation of
initial_bytes, re-query precopy size before sending the flag. Extract the flag sending logic fromvfio_save_iterate()to a new helper for clarity.
I would prefer to separate the changes, so a patch for this new routine, and then :
Quoted 5 lines
This may prevent premature sending of
VFIO_MIG_FLAG_DEV_INIT_DATA_SENTflag if, for example, the previously queriedinitial_byteswas lower than actually is. Additionally, it prevents sending the flag ifvfio_query_precopy_size()failed.
Thanks,
C.
Quoted 74 lines
Signed-off-by Avihai Horon <[email protected]>--- hw/vfio/migration.c | 37 ++++++++++++++++++++++++++++++++----- hw/vfio/trace-events | 1 + 2 files changed, 33 insertions(+), 5 deletions(-)hw/vfio/migration.c +32
-5@@ -456,6 +456,37 @@ static void vfio_update_estimated_pending_data(VFIOMigration *migration, data_size); } +/* Returns true if the init data flag was sent, false otherwise */ +static bool vfio_send_init_data_flag (QEMUFile *f,VFIOMigration *migration) +{ +VFIODevice *vbasedev = migration->vbasedev; +int ret; + +if (!migrate_switchover_ack ()) { +return false; + } + +if (migration->precopy_init_size || migration->initial_data_sent) { +return false; + } + +/* +* precopy_init_size holds an estimation of the initial data size, re-query +* precopy size to ensure it's really zero before sending init data flag. +* Don't send the flag if query fails. +*/ + ret =vfio_query_precopy_size (migration); +if (ret || migration->precopy_init_size) { +return false; + } + +qemu_put_be64 (f,VFIO_MIG_FLAG_DEV_INIT_DATA_SENT ); + migration->initial_data_sent = true; +trace_vfio_send_init_data_flag (vbasedev->name); + +return true; +} +static bool vfio_precopy_supported (VFIODevice *vbasedev) {VFIOMigration *migration = vbasedev->migration;@@ -664,11 +695,7 @@ static int vfio_save_iterate(QEMUFile *f, void *opaque)vfio_update_estimated_pending_data (migration, data_size); -if (migrate_switchover_ack () && !migration->precopy_init_size && - !migration->initial_data_sent) { -qemu_put_be64 (f,VFIO_MIG_FLAG_DEV_INIT_DATA_SENT ); - migration->initial_data_sent = true; - }else { +if (!vfio_send_init_data_flag (f, migration)) {qemu_put_be64 (f,VFIO_MIG_FLAG_END_OF_STATE ); }hw/vfio/trace-events +1
-0@@ -176,6 +176,7 @@ vfio_save_iterate(const char *name, uint64_t precopy_init_size, uint64_t precopy vfio_save_iterate_start(const char *name) " (%s)" vfio_save_setup(const char *name, uint64_t data_buffer_size) " (%s) data buffer size %"PRIu64 vfio_state_pending(const char *name, uint64_t stopcopy_size, uint64_t precopy_init_size, uint64_t precopy_dirty_size, bool exact) " (%s) stopcopy size %"PRIu64" precopy initial size %"PRIu64" precopy dirty size %"PRIu64 " exact %d" +vfio_send_init_data_flag(const char *name) " (%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_vmstate_change_prepare(const char *name, int running, const char *reason, const char *dev_state) " (%s) running %d reason %s device state %s"
Re: [PATCH 09/14] vfio/migration: Re-query precopy size before sending VFIO_MIG_FLAG_DEV_INIT_DATA_SENT
Quoted 11 lines · Cédric Le Goater
External email: Use caution opening links or attachments
Hello Avihai
Quoted 5 lines · Avihai Horon
When precopy
initial_bytesreaches zeroVFIO_MIG_FLAG_DEV_INIT_DATA_SENTflag is sent to the destination to indicate that initial data has been sent, so destination can indicate back to source when it finished loading it.
Quoted 13 lines
Quoted 3 lines
To get a more accurate estimation of
initial_bytes, re-query precopy size before sending the flag. Extract the flag sending logic fromvfio_save_iterate()to a new helper for clarity.I would prefer to separate the changes, so a patch for this new routine, and then :
Quoted 5 lines
This may prevent premature sending of
VFIO_MIG_FLAG_DEV_INIT_DATA_SENTflag if, for example, the previously queriedinitial_byteswas lower than actually is. Additionally, it prevents sending the flag ifvfio_query_precopy_size()failed.
Of course, will do.
Thanks.
Quoted 83 lines
Quoted 82 lines
Signed-off-by Avihai Horon <[email protected]>---
hw/vfio/migration.c | 37 ++++++++++++++++++++++++++++++++----- hw/vfio/trace-events | 1 +2 files changed, 33 insertions(+), 5 deletions(-)hw/vfio/migration.c +16
-0@@ -456,6 +456,37 @@ static voidvfio_update_estimated_pending_data (VFIOMigration *migration, data_size); } +/* Returns true if the init data flag was sent, false otherwise */ +static bool vfio_send_init_data_flag (QEMUFile *f,VFIOMigration *migration) +{ + VFIODevice *vbasedev = migration->vbasedev; + int ret; + + if (!migrate_switchover_ack()) { + return false; + } + + if (migration->precopy_init_size || migration->initial_data_sent) { + return false; + } + + /* +* precopy_init_size holds an estimation of the initial data size, re-query
+ * precopy size to ensure it's really zero before sending init data flag.
+ * Don't send the flag if query fails.
+ */
+ ret =vfio_query_precopy_size(migration);
+ if (ret ||migration->precopy_init_size) {
+ return false;
+ }hw/vfio/migration.c +8
-0+ + qemu_put_be64(f, VFIO_MIG_FLAG_DEV_INIT_DATA_SENT); + migration->initial_data_sent = true; + trace_vfio_send_init_data_flag(vbasedev->name); + + return true; +} +static bool
vfio_precopy_supported(VFIODevice *vbasedev){
VFIOMigration *migration =vbasedev->migration;hw/vfio/migration.c +1
-5@@ -664,11 +695,7 @@ static int vfio_save_iterate(QEMUFile *f, void *opaque) vfio_update_estimated_pending_data(migration, data_size); - if (migrate_switchover_ack() && !migration->precopy_init_size && - !migration->initial_data_sent) { - qemu_put_be64(f, VFIO_MIG_FLAG_DEV_INIT_DATA_SENT); - migration->initial_data_sent = true; - } else { + if (!vfio_send_init_data_flag(f, migration)) { qemu_put_be64(f, VFIO_MIG_FLAG_END_OF_STATE); }hw/vfio/trace-events +0
-0@@ -176,6 +176,7 @@ vfio_save_iterate(const char *name, uint64_t
precopy_init_size,uint64_tprecopy
vfio_save_iterate_start(const char *name)" (%s)"
vfio_save_setup(const char *name, uint64_t data_buffer_size)" (%s) data buffer size %"PRIu64
vfio_state_pending(const char *name,uint64_tstopcopy_size,uint64_tprecopy_init_size,uint64_tprecopy_dirty_size, bool exact) " (%s) stopcopy size %"PRIu64" precopy initial size %"PRIu64" precopy dirty size %"PRIu64 " exact %d" +vfio_send_init_data_flag(const char *name) " (%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_vmstate_change_prepare(const char *name, int running, const char *reason, const char *dev_state)" (%s) running %d reason %s device state %s"
Re: [PATCH 09/14] vfio/migration: Re-query precopy size before sending VFIO_MIG_FLAG_DEV_INIT_DATA_SENT
In reply to Avihai HoronQuoted 41 lines · Avihai Horon
When precopy
initial_bytesreaches zeroVFIO_MIG_FLAG_DEV_INIT_DATA_SENTflag is sent to the destination to indicate that initial data has been sent, so destination can indicate back to source when it finished loading it.To get a more accurate estimation of
initial_bytes, re-query precopy size before sending the flag. Extract the flag sending logic fromvfio_save_iterate()to a new helper for clarity.This may prevent premature sending of
VFIO_MIG_FLAG_DEV_INIT_DATA_SENTflag if, for example, the previously queriedinitial_byteswas lower than actually is. Additionally, it prevents sending the flag ifvfio_query_precopy_size()failed.Signed-off-by Avihai Horon <[email protected]>--- hw/vfio/migration.c | 37 ++++++++++++++++++++++++++++++++----- hw/vfio/trace-events | 1 + 2 files changed, 33 insertions(+), 5 deletions(-)hw/vfio/migration.c +13
-0@@ -456,6 +456,37 @@ static void vfio_update_estimated_pending_data(VFIOMigration *migration, data_size); } +/* Returns true if the init data flag was sent, false otherwise */ +static bool vfio_send_init_data_flag (QEMUFile *f,VFIOMigration *migration) +{ +VFIODevice *vbasedev = migration->vbasedev; +int ret; + +if (!migrate_switchover_ack ()) { +return false; + } + +if (migration->precopy_init_size || migration->initial_data_sent) { +return false; + }
hw/vfio/migration.c static void vfio_update_estimated_pending_data(VFIOMigration *migration, · line 481
Quoted 10 lines
hw/vfio/migration.c +10
-0+ +/* +* precopy_init_size holds an estimation of the initial data size, re-query +* precopy size to ensure it's really zero before sending init data flag. +* Don't send the flag if query fails. +*/ + ret =vfio_query_precopy_size (migration); +if (ret || migration->precopy_init_size) { +return false; + }
IIUC this chunk isn't necessary? If we don't expect REINIT to happen that much (when NIC reconfigures?), then we can still rely on the window where the "new switchover ack" will be requested later on during the exact sync.
Relying on that seems slightly cleaner.
Quoted 39 lines
hw/vfio/migration.c +9
-5+ +qemu_put_be64 (f,VFIO_MIG_FLAG_DEV_INIT_DATA_SENT ); + migration->initial_data_sent = true; +trace_vfio_send_init_data_flag (vbasedev->name); + +return true; +} +static bool vfio_precopy_supported (VFIODevice *vbasedev) {VFIOMigration *migration = vbasedev->migration;@@ -664,11 +695,7 @@ static int vfio_save_iterate(QEMUFile *f, void *opaque)vfio_update_estimated_pending_data (migration, data_size); -if (migrate_switchover_ack () && !migration->precopy_init_size && - !migration->initial_data_sent) { -qemu_put_be64 (f,VFIO_MIG_FLAG_DEV_INIT_DATA_SENT ); - migration->initial_data_sent = true; - }else { +if (!vfio_send_init_data_flag (f, migration)) {qemu_put_be64 (f,VFIO_MIG_FLAG_END_OF_STATE ); }hw/vfio/trace-events +1
-0@@ -176,6 +176,7 @@ vfio_save_iterate(const char *name, uint64_t precopy_init_size, uint64_t precopy vfio_save_iterate_start(const char *name) " (%s)" vfio_save_setup(const char *name, uint64_t data_buffer_size) " (%s) data buffer size %"PRIu64 vfio_state_pending(const char *name, uint64_t stopcopy_size, uint64_t precopy_init_size, uint64_t precopy_dirty_size, bool exact) " (%s) stopcopy size %"PRIu64" precopy initial size %"PRIu64" precopy dirty size %"PRIu64 " exact %d" +vfio_send_init_data_flag(const char *name) " (%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_vmstate_change_prepare(const char *name, int running, const char *reason, const char *dev_state) " (%s) running %d reason %s device state %s"Signature · 1 line
2.40.1
Signature · 1 line
Peter Xu
Re: [PATCH 09/14] vfio/migration: Re-query precopy size before sending VFIO_MIG_FLAG_DEV_INIT_DATA_SENT
Quoted 59 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 41 lines · Avihai Horon
When precopy
initial_bytesreaches zeroVFIO_MIG_FLAG_DEV_INIT_DATA_SENTflag is sent to the destination to indicate that initial data has been sent, so destination can indicate back to source when it finished loading it.To get a more accurate estimation of
initial_bytes, re-query precopy size before sending the flag. Extract the flag sending logic fromvfio_save_iterate()to a new helper for clarity.This may prevent premature sending of
VFIO_MIG_FLAG_DEV_INIT_DATA_SENTflag if, for example, the previously queriedinitial_byteswas lower than actually is. Additionally, it prevents sending the flag ifvfio_query_precopy_size()failed.Signed-off-by Avihai Horon <[email protected]>--- hw/vfio/migration.c | 37 ++++++++++++++++++++++++++++++++----- hw/vfio/trace-events | 1 + 2 files changed, 33 insertions(+), 5 deletions(-)hw/vfio/migration.c +13
-0@@ -456,6 +456,37 @@ static void vfio_update_estimated_pending_data(VFIOMigration *migration, data_size); } +/* Returns true if the init data flag was sent, false otherwise */ +static bool vfio_send_init_data_flag (QEMUFile *f,VFIOMigration *migration) +{ +VFIODevice *vbasedev = migration->vbasedev; +int ret; + +if (!migrate_switchover_ack ()) { +return false; + } + +if (migration->precopy_init_size || migration->initial_data_sent) { +return false; + }hw/vfio/migration.c static void vfio_update_estimated_pending_data(VFIOMigration *migration, · line 481
Quoted 10 lines
hw/vfio/migration.c +10
-0+ +/* +* precopy_init_size holds an estimation of the initial data size, re-query +* precopy size to ensure it's really zero before sending init data flag. +* Don't send the flag if query fails. +*/ + ret =vfio_query_precopy_size (migration); +if (ret || migration->precopy_init_size) { +return false; + }IIUC this chunk isn't necessary? If we don't expect REINIT to happen that much (when NIC reconfigures?), then we can still rely on the window where the "new switchover ack" will be requested later on during the exact sync.
Quoted 1 line
Relying on that seems slightly cleaner.
Not sure I follow.
New switchover ack is requested in exact sync if we see new init_bytes > 0 (REINIT flag). This flow happens only after the new switchover ack is requested in exact sync, when init_bytes = 0 again.
So this chunk just makes sure we send the VFIO_MIG_FLAG_DEV_INIT_DATA_SENT flag at the right time.
Thanks.
Quoted 43 lines
Quoted 38 lines
hw/vfio/migration.c +9
-5+ +qemu_put_be64 (f,VFIO_MIG_FLAG_DEV_INIT_DATA_SENT ); + migration->initial_data_sent = true; +trace_vfio_send_init_data_flag (vbasedev->name); + +return true; +} +static bool vfio_precopy_supported (VFIODevice *vbasedev) {VFIOMigration *migration = vbasedev->migration;@@ -664,11 +695,7 @@ static int vfio_save_iterate(QEMUFile *f, void *opaque)vfio_update_estimated_pending_data (migration, data_size); -if (migrate_switchover_ack () && !migration->precopy_init_size && - !migration->initial_data_sent) { -qemu_put_be64 (f,VFIO_MIG_FLAG_DEV_INIT_DATA_SENT ); - migration->initial_data_sent = true; - }else { +if (!vfio_send_init_data_flag (f, migration)) {qemu_put_be64 (f,VFIO_MIG_FLAG_END_OF_STATE ); }hw/vfio/trace-events +1
-1@@ -176,6 +176,7 @@ vfio_save_iterate(const char *name, uint64_t precopy_init_size, uint64_t precopy vfio_save_iterate_start(const char *name) " (%s)" vfio_save_setup(const char *name, uint64_t data_buffer_size) " (%s) data buffer size %"PRIu64 vfio_state_pending(const char *name, uint64_t stopcopy_size, uint64_t precopy_init_size, uint64_t precopy_dirty_size, bool exact) " (%s) stopcopy size %"PRIu64" precopy initial size %"PRIu64" precopy dirty size %"PRIu64 " exact %d" +vfio_send_init_data_flag(const char *name) " (%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_vmstate_change_prepare(const char *name, int running, const char *reason, const char *dev_state) " (%s) running %d reason %s device state %s" --Quoted 2 lines
2.40.1
--
Peter Xu
Re: [PATCH 09/14] vfio/migration: Re-query precopy size before sending VFIO_MIG_FLAG_DEV_INIT_DATA_SENT
Quoted 34 lines · Avihai Horon
Quoted 32 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 28 lines · Avihai Horon
When precopy
initial_bytesreaches zeroVFIO_MIG_FLAG_DEV_INIT_DATA_SENTflag is sent to the destination to indicate that initial data has been sent, so destination can indicate back to source when it finished loading it.To get a more accurate estimation of
initial_bytes, re-query precopy size before sending the flag. Extract the flag sending logic fromvfio_save_iterate()to a new helper for clarity.This may prevent premature sending of
VFIO_MIG_FLAG_DEV_INIT_DATA_SENTflag if, for example, the previously queriedinitial_byteswas lower than actually is. Additionally, it prevents sending the flag ifvfio_query_precopy_size()failed.Signed-off-by Avihai Horon <[email protected]>--- hw/vfio/migration.c | 37 ++++++++++++++++++++++++++++++++----- hw/vfio/trace-events | 1 + 2 files changed, 33 insertions(+), 5 deletions(-)hw/vfio/migration.c +0
-0@@ -456,6 +456,37 @@ static void vfio_update_estimated_pending_data(VFIOMigration *migration, data_size); }
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
hw/vfio/migration.c +5
-0+/* Returns true if the init data flag was sent, false otherwise */ +static bool vfio_send_init_data_flag (QEMUFile *f,VFIOMigration *migration) +{ +VFIODevice *vbasedev = migration->vbasedev; +int ret;Quoted 8 lines
hw/vfio/migration.c static void vfio_update_estimated_pending_data(VFIOMigration *migration, · line 471
Quoted 8 lines
hw/vfio/migration.c +8
-0+ +if (!migrate_switchover_ack ()) { +return false; + } + +if (migration->precopy_init_size || migration->initial_data_sent) { +return false; + }
[1]
Quoted 18 lines
Quoted 10 lines
hw/vfio/migration.c static void vfio_update_estimated_pending_data(VFIOMigration *migration, · line 481
Quoted 10 lines
hw/vfio/migration.c +10
-0+ +/* +* precopy_init_size holds an estimation of the initial data size, re-query +* precopy size to ensure it's really zero before sending init data flag. +* Don't send the flag if query fails. +*/ + ret =vfio_query_precopy_size (migration); +if (ret || migration->precopy_init_size) { +return false; + }Quoted 5 lines
IIUC this chunk isn't necessary? If we don't expect REINIT to happen that much (when NIC reconfigures?), then we can still rely on the window where the "new switchover ack" will be requested later on during the exact sync.
Relying on that seems slightly cleaner.
Not sure I follow.
Quoted 7 lines
New switchover ack is requested in exact sync if we see new
init_bytes> 0 (REINIT flag).
This flow happens only after the new switchover ack is requested in exact sync, wheninit_bytes= 0 again.So this chunk just makes sure we send the
VFIO_MIG_FLAG_DEV_INIT_DATA_SENTflag at the right time.
AFAIU, what this chunk does is, we may save one switchover-ack if REINIT got here. It doesn't provide much functional difference in reality.
With this code there, when it happens to see REINIT, instead of sending an immediate VFIO_MIG_FLAG_DEV_INIT_DATA_SENT message, it falls back to send init data in the next iteration loop, saving that flag, and saving a "request switchover-ack" on src QEMU too.
If above code removed, IIUC VFIO will send VFIO_MIG_FLAG_DEV_INIT_DATA_SENT immediately causing dest sends ACK. vfio_query_precopy_size() will be postponed until the next sync query (which must happen at some point before final switchover), then it will be collected there, VFIO src will request for switchover-ack, then another VFIO_MIG_FLAG_DEV_INIT_DATA_SENT is expected.
Both should work, but what I meant is, I think we don't need this random check, because it's optimistic, it's not functionally necessary, IIUC.
IOW, see the current code and how it can still race with a REINIT anyway:
migration thread some vfio driver thread
ret = vfio_query_precopy_size(migration);
if (ret || migration->precopy_init_size) {
return false;
}
got reconfigured,
set REINIT
qemu_put_be64(f, VFIO_MIG_FLAG_DEV_INIT_DATA_SENT);
migration->initial_data_sent = true;
trace_vfio_send_init_data_flag(vbasedev->name);It's the same to me if e.g. we try to vfio_query_precopy_size() in VFIO's iterative loops from time to time, it'll also work, it'll make sync more frequent, but it's not needed.
Thanks,
Signature · 1 line
Peter Xu
Re: [PATCH 09/14] vfio/migration: Re-query precopy size before sending VFIO_MIG_FLAG_DEV_INIT_DATA_SENT
Quoted 109 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 33 lines · Avihai Horon
Quoted 32 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 28 lines · Avihai Horon
When precopy
initial_bytesreaches zeroVFIO_MIG_FLAG_DEV_INIT_DATA_SENTflag is sent to the destination to indicate that initial data has been sent, so destination can indicate back to source when it finished loading it.To get a more accurate estimation of
initial_bytes, re-query precopy size before sending the flag. Extract the flag sending logic fromvfio_save_iterate()to a new helper for clarity.This may prevent premature sending of
VFIO_MIG_FLAG_DEV_INIT_DATA_SENTflag if, for example, the previously queriedinitial_byteswas lower than actually is. Additionally, it prevents sending the flag ifvfio_query_precopy_size()failed.Signed-off-by Avihai Horon <[email protected]>--- hw/vfio/migration.c | 37 ++++++++++++++++++++++++++++++++----- hw/vfio/trace-events | 1 + 2 files changed, 33 insertions(+), 5 deletions(-)hw/vfio/migration.c +0
-0@@ -456,6 +456,37 @@ static void vfio_update_estimated_pending_data(VFIOMigration *migration, data_size); }Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
hw/vfio/migration.c +5
-0+/* Returns true if the init data flag was sent, false otherwise */ +static bool vfio_send_init_data_flag (QEMUFile *f,VFIOMigration *migration) +{ +VFIODevice *vbasedev = migration->vbasedev; +int ret;Quoted 8 lines
hw/vfio/migration.c static void vfio_update_estimated_pending_data(VFIOMigration *migration, · line 471
Quoted 8 lines
hw/vfio/migration.c +8
-0+ +if (!migrate_switchover_ack ()) { +return false; + } + +if (migration->precopy_init_size || migration->initial_data_sent) { +return false; + }[1]
Quoted 17 lines
Quoted 10 lines
hw/vfio/migration.c static void vfio_update_estimated_pending_data(VFIOMigration *migration, · line 481
Quoted 10 lines
hw/vfio/migration.c +10
-0+ +/* +* precopy_init_size holds an estimation of the initial data size, re-query +* precopy size to ensure it's really zero before sending init data flag. +* Don't send the flag if query fails. +*/ + ret =vfio_query_precopy_size (migration); +if (ret || migration->precopy_init_size) { +return false; + }Quoted 5 lines
IIUC this chunk isn't necessary? If we don't expect REINIT to happen that much (when NIC reconfigures?), then we can still rely on the window where the "new switchover ack" will be requested later on during the exact sync.
Relying on that seems slightly cleaner.
Not sure I follow.
Quoted 7 lines
New switchover ack is requested in exact sync if we see new
init_bytes> 0 (REINIT flag).
This flow happens only after the new switchover ack is requested in exact sync, wheninit_bytes= 0 again.So this chunk just makes sure we send the
VFIO_MIG_FLAG_DEV_INIT_DATA_SENTflag at the right time.AFAIU, what this chunk does is, we may save one switchover-ack if REINIT got here. It doesn't provide much functional difference in reality.
With this code there, when it happens to see REINIT, instead of sending an immediate
VFIO_MIG_FLAG_DEV_INIT_DATA_SENTmessage, it falls back to send init data in the next iteration loop, saving that flag, and saving a "request switchover-ack" on src QEMU too.If above code removed, IIUC VFIO will send
VFIO_MIG_FLAG_DEV_INIT_DATA_SENTimmediately causing dest sends ACK.vfio_query_precopy_size()will be postponed until the next sync query (which must happen at some point before final switchover), then it will be collected there, VFIO src will request for switchover-ack, then anotherVFIO_MIG_FLAG_DEV_INIT_DATA_SENTis expected.Both should work, but what I meant is, I think we don't need this random check, because it's optimistic, it's not functionally necessary, IIUC.
IOW, see the current code and how it can still race with a REINIT anyway:
migration thread some vfio driver thread ret = vfio_query_precopy_size(migration); if (ret || migration->precopy_init_size) { return false; } got reconfigured, set REINIT qemu_put_be64(f, VFIO_MIG_FLAG_DEV_INIT_DATA_SENT); migration->initial_data_sent = true; trace_vfio_send_init_data_flag(vbasedev->name);
Quoted 3 lines
It's the same to me if e.g. we try to
vfio_query_precopy_size()in VFIO's iterative loops from time to time, it'll also work, it'll make sync more frequent, but it's not needed.
I see what you mean now.
However, the purpose of this chunk is not to check for another REINIT, but rather to ensure VFIO_MIG_FLAG_DEV_INIT_DATA_SENT is sent at the right time -- when init_bytes is truly 0.
If the flag is sent before init_bytes = 0 then dest may ack too early, before it did the time-consuming load and we risk having that load during downtime (see my next response to the cover letter).
At first I thought mlx5 may report init_bytes estimate which is a bit lower than the actual value but then I realized it can't happen. However, I chose to keep this patch because it's aligned with the uapi that defines init_bytes as an estimate, and because it covers the case where precopy info ioctl fails.
Granted, if initial_bytes is so important I'd expect drivers to report a pretty accurate value, but still, it's aligned with the uapi definition and doesn't hurt.
Thanks.
Re: [PATCH 09/14] vfio/migration: Re-query precopy size before sending VFIO_MIG_FLAG_DEV_INIT_DATA_SENT
Quoted 111 lines · Avihai Horon
Quoted 109 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 33 lines · Avihai Horon
Quoted 32 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 28 lines · Avihai Horon
When precopy
initial_bytesreaches zeroVFIO_MIG_FLAG_DEV_INIT_DATA_SENTflag is sent to the destination to indicate that initial data has been sent, so destination can indicate back to source when it finished loading it.To get a more accurate estimation of
initial_bytes, re-query precopy size before sending the flag. Extract the flag sending logic fromvfio_save_iterate()to a new helper for clarity.This may prevent premature sending of
VFIO_MIG_FLAG_DEV_INIT_DATA_SENTflag if, for example, the previously queriedinitial_byteswas lower than actually is. Additionally, it prevents sending the flag ifvfio_query_precopy_size()failed.Signed-off-by Avihai Horon <[email protected]>--- hw/vfio/migration.c | 37 ++++++++++++++++++++++++++++++++----- hw/vfio/trace-events | 1 + 2 files changed, 33 insertions(+), 5 deletions(-)hw/vfio/migration.c +0
-0@@ -456,6 +456,37 @@ static void vfio_update_estimated_pending_data(VFIOMigration *migration, data_size); }Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
hw/vfio/migration.c +5
-0+/* Returns true if the init data flag was sent, false otherwise */ +static bool vfio_send_init_data_flag (QEMUFile *f,VFIOMigration *migration) +{ +VFIODevice *vbasedev = migration->vbasedev; +int ret;Quoted 8 lines
hw/vfio/migration.c static void vfio_update_estimated_pending_data(VFIOMigration *migration, · line 471
Quoted 8 lines
hw/vfio/migration.c +8
-0+ +if (!migrate_switchover_ack ()) { +return false; + } + +if (migration->precopy_init_size || migration->initial_data_sent) { +return false; + }[1]
Quoted 17 lines
Quoted 10 lines
hw/vfio/migration.c static void vfio_update_estimated_pending_data(VFIOMigration *migration, · line 481
Quoted 10 lines
hw/vfio/migration.c +10
-0+ +/* +* precopy_init_size holds an estimation of the initial data size, re-query +* precopy size to ensure it's really zero before sending init data flag. +* Don't send the flag if query fails. +*/ + ret =vfio_query_precopy_size (migration); +if (ret || migration->precopy_init_size) { +return false; + }Quoted 5 lines
IIUC this chunk isn't necessary? If we don't expect REINIT to happen that much (when NIC reconfigures?), then we can still rely on the window where the "new switchover ack" will be requested later on during the exact sync.
Relying on that seems slightly cleaner.
Not sure I follow.
Quoted 7 lines
New switchover ack is requested in exact sync if we see new
init_bytes> 0 (REINIT flag).
This flow happens only after the new switchover ack is requested in exact sync, wheninit_bytes= 0 again.So this chunk just makes sure we send the
VFIO_MIG_FLAG_DEV_INIT_DATA_SENTflag at the right time.AFAIU, what this chunk does is, we may save one switchover-ack if REINIT got here. It doesn't provide much functional difference in reality.
With this code there, when it happens to see REINIT, instead of sending an immediate
VFIO_MIG_FLAG_DEV_INIT_DATA_SENTmessage, it falls back to send init data in the next iteration loop, saving that flag, and saving a "request switchover-ack" on src QEMU too.If above code removed, IIUC VFIO will send
VFIO_MIG_FLAG_DEV_INIT_DATA_SENTimmediately causing dest sends ACK.vfio_query_precopy_size()will be postponed until the next sync query (which must happen at some point before final switchover), then it will be collected there, VFIO src will request for switchover-ack, then anotherVFIO_MIG_FLAG_DEV_INIT_DATA_SENTis expected.Both should work, but what I meant is, I think we don't need this random check, because it's optimistic, it's not functionally necessary, IIUC.
IOW, see the current code and how it can still race with a REINIT anyway:
migration thread some vfio driver thread ret = vfio_query_precopy_size(migration); if (ret || migration->precopy_init_size) { return false; } got reconfigured, set REINIT qemu_put_be64(f, VFIO_MIG_FLAG_DEV_INIT_DATA_SENT); migration->initial_data_sent = true; trace_vfio_send_init_data_flag(vbasedev->name);
Quoted 8 lines
Quoted 3 lines
It's the same to me if e.g. we try to
vfio_query_precopy_size()in VFIO's iterative loops from time to time, it'll also work, it'll make sync more frequent, but it's not needed.I see what you mean now.
However, the purpose of this chunk is not to check for another REINIT, but rather to ensureVFIO_MIG_FLAG_DEV_INIT_DATA_SENTis sent at the right time -- wheninit_bytesis truly 0.
IIUC, that part should normally be guaranteed by this line you added prior to it:
+ if (migration->precopy_init_size || migration->initial_data_sent) {
+ return false;
+ }
Hence when reaching vfio_query_precopy_size(), precopy_init_size==0.
IOW, I think sending INIT_DATA_SENT is fine once it's guarateed the next vfio_query_precopy_size() will revoke it by the newly populated REINIT data. Essentially, the race window is pretty small here.
If you still want to keep it there, I'm still fine; having this extra check isn't making this incorrect. I just want to make sure we're on the same page.
Thanks,
Quoted 17 lines
If the flag is sent before
init_bytes= 0 then dest may ack too early, before it did the time-consuming load and we risk having that load during downtime (see my next response to the cover letter).At first I thought mlx5 may report
init_bytesestimate which is a bit lower than the actual value but then I realized it can't happen. However, I chose to keep this patch because it's aligned with the uapi that definesinit_bytesas an estimate, and because it covers the case where precopy info ioctl fails.Granted, if
initial_bytesis so important I'd expect drivers to report a pretty accurate value, but still, it's aligned with the uapi definition and doesn't hurt.Thanks.
Signature · 1 line
Peter Xu
Re: [PATCH 09/14] vfio/migration: Re-query precopy size before sending VFIO_MIG_FLAG_DEV_INIT_DATA_SENT
Quoted 128 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 110 lines · Avihai Horon
Quoted 109 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 33 lines · Avihai Horon
Quoted 32 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 28 lines · Avihai Horon
When precopy
initial_bytesreaches zeroVFIO_MIG_FLAG_DEV_INIT_DATA_SENTflag is sent to the destination to indicate that initial data has been sent, so destination can indicate back to source when it finished loading it.To get a more accurate estimation of
initial_bytes, re-query precopy size before sending the flag. Extract the flag sending logic fromvfio_save_iterate()to a new helper for clarity.This may prevent premature sending of
VFIO_MIG_FLAG_DEV_INIT_DATA_SENTflag if, for example, the previously queriedinitial_byteswas lower than actually is. Additionally, it prevents sending the flag ifvfio_query_precopy_size()failed.Signed-off-by Avihai Horon <[email protected]>--- hw/vfio/migration.c | 37 ++++++++++++++++++++++++++++++++----- hw/vfio/trace-events | 1 + 2 files changed, 33 insertions(+), 5 deletions(-)hw/vfio/migration.c +0
-0@@ -456,6 +456,37 @@ static void vfio_update_estimated_pending_data(VFIOMigration *migration, data_size); }Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
hw/vfio/migration.c +5
-0+/* Returns true if the init data flag was sent, false otherwise */ +static bool vfio_send_init_data_flag (QEMUFile *f,VFIOMigration *migration) +{ +VFIODevice *vbasedev = migration->vbasedev; +int ret;Quoted 8 lines
hw/vfio/migration.c static void vfio_update_estimated_pending_data(VFIOMigration *migration, · line 471
Quoted 8 lines
hw/vfio/migration.c +8
-0+ +if (!migrate_switchover_ack ()) { +return false; + } + +if (migration->precopy_init_size || migration->initial_data_sent) { +return false; + }[1]
Quoted 17 lines
Quoted 10 lines
hw/vfio/migration.c static void vfio_update_estimated_pending_data(VFIOMigration *migration, · line 481
Quoted 10 lines
hw/vfio/migration.c +10
-0+ +/* +* precopy_init_size holds an estimation of the initial data size, re-query +* precopy size to ensure it's really zero before sending init data flag. +* Don't send the flag if query fails. +*/ + ret =vfio_query_precopy_size (migration); +if (ret || migration->precopy_init_size) { +return false; + }Quoted 5 lines
IIUC this chunk isn't necessary? If we don't expect REINIT to happen that much (when NIC reconfigures?), then we can still rely on the window where the "new switchover ack" will be requested later on during the exact sync.
Relying on that seems slightly cleaner.
Not sure I follow.
Quoted 7 lines
New switchover ack is requested in exact sync if we see new
init_bytes> 0 (REINIT flag).
This flow happens only after the new switchover ack is requested in exact sync, wheninit_bytes= 0 again.So this chunk just makes sure we send the
VFIO_MIG_FLAG_DEV_INIT_DATA_SENTflag at the right time.AFAIU, what this chunk does is, we may save one switchover-ack if REINIT got here. It doesn't provide much functional difference in reality.
With this code there, when it happens to see REINIT, instead of sending an immediate
VFIO_MIG_FLAG_DEV_INIT_DATA_SENTmessage, it falls back to send init data in the next iteration loop, saving that flag, and saving a "request switchover-ack" on src QEMU too.If above code removed, IIUC VFIO will send
VFIO_MIG_FLAG_DEV_INIT_DATA_SENTimmediately causing dest sends ACK.vfio_query_precopy_size()will be postponed until the next sync query (which must happen at some point before final switchover), then it will be collected there, VFIO src will request for switchover-ack, then anotherVFIO_MIG_FLAG_DEV_INIT_DATA_SENTis expected.Both should work, but what I meant is, I think we don't need this random check, because it's optimistic, it's not functionally necessary, IIUC.
IOW, see the current code and how it can still race with a REINIT anyway:
migration thread some vfio driver thread ret = vfio_query_precopy_size(migration); if (ret || migration->precopy_init_size) { return false; } got reconfigured, set REINIT qemu_put_be64(f, VFIO_MIG_FLAG_DEV_INIT_DATA_SENT); migration->initial_data_sent = true; trace_vfio_send_init_data_flag(vbasedev->name);Quoted 7 lines
Quoted 3 lines
It's the same to me if e.g. we try to
vfio_query_precopy_size()in VFIO's iterative loops from time to time, it'll also work, it'll make sync more frequent, but it's not needed.I see what you mean now.
However, the purpose of this chunk is not to check for another REINIT, but rather to ensureVFIO_MIG_FLAG_DEV_INIT_DATA_SENTis sent at the right time -- wheninit_bytesis truly 0.IIUC, that part should normally be guaranteed by this line you added prior to it:
hw/vfio/migration.c +3
-0+if (migration->precopy_init_size || migration->initial_data_sent) { +return false; + }
Quoted 1 line
Hence when reaching
vfio_query_precopy_size(), precopy_init_size==0.
Yes, but here we only know that the estimation of init_bytes that we queried previously is 0.
Because it's an estimation, it may be lower than reality and then we end up sending the INIT_DATA_SENT flag before all init_bytes were actually sent.
For example:
Precopy info ioctl reports 10MB init_bytes estimate, but in reality there is 12MB init_bytes.
We send the 10MB init_bytes thinking we are done with it, but if we query again we see the extra 2MB (no REINIT in this case, because the 2MB belongs to the same previous init_bytes chunk). So the INIT_DATA_SENT is sent too soon.
That's why we try harder and do another query just to make sure the previous estimate was accurate.
But as I wrote below, I first thought such case could happen for mlx5, but then realized it couldn't happen. Though I still chose to keep it for the general case, not only mlx5.
However, thinking about it again now, such scenario as the above can't happen as it violates the uapi, because init_bytes can't suddenly grow without a new REINIT (and if there is a new REINIT, as you mentioned, we are fine since next query pending will catch it). So yes, I guess this extra query is redundant. I will remove it, unless you think otherwise.
Thanks.
Quoted 30 lines
IOW, I think sending
INIT_DATA_SENTis fine once it's guarateed the nextvfio_query_precopy_size()will revoke it by the newly populated REINIT data. Essentially, the race window is pretty small here.If you still want to keep it there, I'm still fine; having this extra check isn't making this incorrect. I just want to make sure we're on the same page.
Thanks,
Quoted 10 lines
If the flag is sent before
init_bytes= 0 then dest may ack too early, before it did the time-consuming load and we risk having that load during downtime (see my next response to the cover letter).At first I thought mlx5 may report
init_bytesestimate which is a bit lower than the actual value but then I realized it can't happen. However, I chose to keep this patch because it's aligned with the uapi that definesinit_bytesas an estimate, and because it covers the case where precopy info ioctl fails.Quoted 6 lines
Granted, if
initial_bytesis so important I'd expect drivers to report a pretty accurate value, but still, it's aligned with the uapi definition and doesn't hurt.Thanks.
--
Peter Xu
Re: [PATCH 09/14] vfio/migration: Re-query precopy size before sending VFIO_MIG_FLAG_DEV_INIT_DATA_SENT
Quoted 151 lines · Avihai Horon
Quoted 128 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 110 lines · Avihai Horon
Quoted 109 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 33 lines · Avihai Horon
Quoted 32 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 28 lines · Avihai Horon
When precopy
initial_bytesreaches zeroVFIO_MIG_FLAG_DEV_INIT_DATA_SENTflag is sent to the destination to indicate that initial data has been sent, so destination can indicate back to source when it finished loading it.To get a more accurate estimation of
initial_bytes, re-query precopy size before sending the flag. Extract the flag sending logic fromvfio_save_iterate()to a new helper for clarity.This may prevent premature sending of
VFIO_MIG_FLAG_DEV_INIT_DATA_SENTflag if, for example, the previously queriedinitial_byteswas lower than actually is. Additionally, it prevents sending the flag ifvfio_query_precopy_size()failed.Signed-off-by Avihai Horon <[email protected]>--- hw/vfio/migration.c | 37 ++++++++++++++++++++++++++++++++----- hw/vfio/trace-events | 1 + 2 files changed, 33 insertions(+), 5 deletions(-)hw/vfio/migration.c +0
-0@@ -456,6 +456,37 @@ static void vfio_update_estimated_pending_data(VFIOMigration *migration, data_size); }Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
hw/vfio/migration.c +5
-0+/* Returns true if the init data flag was sent, false otherwise */ +static bool vfio_send_init_data_flag (QEMUFile *f,VFIOMigration *migration) +{ +VFIODevice *vbasedev = migration->vbasedev; +int ret;Quoted 8 lines
hw/vfio/migration.c static void vfio_update_estimated_pending_data(VFIOMigration *migration, · line 471
Quoted 8 lines
hw/vfio/migration.c +8
-0+ +if (!migrate_switchover_ack ()) { +return false; + } + +if (migration->precopy_init_size || migration->initial_data_sent) { +return false; + }[1]
Quoted 17 lines
Quoted 10 lines
hw/vfio/migration.c static void vfio_update_estimated_pending_data(VFIOMigration *migration, · line 481
Quoted 10 lines
hw/vfio/migration.c +10
-0+ +/* +* precopy_init_size holds an estimation of the initial data size, re-query +* precopy size to ensure it's really zero before sending init data flag. +* Don't send the flag if query fails. +*/ + ret =vfio_query_precopy_size (migration); +if (ret || migration->precopy_init_size) { +return false; + }Quoted 5 lines
IIUC this chunk isn't necessary? If we don't expect REINIT to happen that much (when NIC reconfigures?), then we can still rely on the window where the "new switchover ack" will be requested later on during the exact sync.
Relying on that seems slightly cleaner.
Not sure I follow.
Quoted 7 lines
New switchover ack is requested in exact sync if we see new
init_bytes> 0 (REINIT flag).
This flow happens only after the new switchover ack is requested in exact sync, wheninit_bytes= 0 again.So this chunk just makes sure we send the
VFIO_MIG_FLAG_DEV_INIT_DATA_SENTflag at the right time.AFAIU, what this chunk does is, we may save one switchover-ack if REINIT got here. It doesn't provide much functional difference in reality.
With this code there, when it happens to see REINIT, instead of sending an immediate
VFIO_MIG_FLAG_DEV_INIT_DATA_SENTmessage, it falls back to send init data in the next iteration loop, saving that flag, and saving a "request switchover-ack" on src QEMU too.If above code removed, IIUC VFIO will send
VFIO_MIG_FLAG_DEV_INIT_DATA_SENTimmediately causing dest sends ACK.vfio_query_precopy_size()will be postponed until the next sync query (which must happen at some point before final switchover), then it will be collected there, VFIO src will request for switchover-ack, then anotherVFIO_MIG_FLAG_DEV_INIT_DATA_SENTis expected.Both should work, but what I meant is, I think we don't need this random check, because it's optimistic, it's not functionally necessary, IIUC.
IOW, see the current code and how it can still race with a REINIT anyway:
migration thread some vfio driver thread ret = vfio_query_precopy_size(migration); if (ret || migration->precopy_init_size) { return false; } got reconfigured, set REINIT qemu_put_be64(f, VFIO_MIG_FLAG_DEV_INIT_DATA_SENT); migration->initial_data_sent = true; trace_vfio_send_init_data_flag(vbasedev->name);Quoted 7 lines
Quoted 3 lines
It's the same to me if e.g. we try to
vfio_query_precopy_size()in VFIO's iterative loops from time to time, it'll also work, it'll make sync more frequent, but it's not needed.I see what you mean now.
However, the purpose of this chunk is not to check for another REINIT, but rather to ensureVFIO_MIG_FLAG_DEV_INIT_DATA_SENTis sent at the right time -- wheninit_bytesis truly 0.IIUC, that part should normally be guaranteed by this line you added prior to it:
(quoted diff) +3
-0+ if (migration->precopy_init_size || migration->initial_data_sent) { + return false; + }Quoted 1 line
Hence when reaching
vfio_query_precopy_size(), precopy_init_size==0.Yes, but here we only know that the estimation of
init_bytesthat we queried previously is 0.
Because it's an estimation, it may be lower than reality and then we end up sending theINIT_DATA_SENTflag before allinit_byteswere actually sent.For example:
Precopy info ioctl reports 10MBinit_bytesestimate, but in reality there is 12MBinit_bytes.
We send the 10MBinit_bytesthinking we are done with it, but if we query again we see the extra 2MB (no REINIT in this case, because the 2MB belongs to the same previousinit_byteschunk). So theINIT_DATA_SENTis sent too soon.That's why we try harder and do another query just to make sure the previous estimate was accurate.
But as I wrote below, I first thought such case could happen for mlx5, but then realized it couldn't happen. Though I still chose to keep it for the general case, not only mlx5.
Quoted 6 lines
However, thinking about it again now, such scenario as the above can't happen as it violates the uapi, because
init_bytescan't suddenly grow without a new REINIT (and if there is a new REINIT, as you mentioned, we are fine since next query pending will catch it).
So yes, I guess this extra query is redundant. I will remove it, unless you think otherwise.
I prefer removal in this case.
Thanks,
Signature · 1 line
Peter Xu
PATCH 10/14 vfio/migration: Add Error ** parameter to vfio_migration_init()
In reply to Avihai Horonvfio_migration_init() already has many failure points and a new one will be added in next patch.
Add Error ** parameter to vfio_migration_init() to report a detailed error message through it.
--- hw/vfio/migration.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-)
hw/vfio/migration.c +17 -12
@@ -1038,7 +1038,7 @@ static bool vfio_dma_logging_supported(VFIODevice *vbasedev)return !ioctl (vbasedev->fd,VFIO_DEVICE_FEATURE , feature); } -static int vfio_migration_init (VFIODevice *vbasedev) +static int vfio_migration_init (VFIODevice *vbasedev,Error **errp) {int ret;Object *obj;
@@ -1047,23 +1047,38 @@ static int vfio_migration_init(VFIODevice *vbasedev) g_autofree char *path = NULL, *oid = NULL;uint64_t mig_flags =0 ;VMChangeStateHandler *prepare_cb; + g_autofree char *error_prefix = +g_strdup_printf ("%s: VFIO migration init failed:" , vbasedev->name);if (!vbasedev->ops->vfio_get_object) { +error_setg (errp,"%s no vfio_get_object handler" , error_prefix);return -EINVAL ; } obj = vbasedev->ops->vfio_get_object (vbasedev);if (!obj) { +error_setg (errp,"%s failed to get object" , error_prefix);return -EINVAL ; } ret =vfio_migration_query_flags (vbasedev, &mig_flags);if (ret) { +if (ret == -ENOTTY ) { +error_setg_errno (errp, -ret, +"%s migration is not supported in kernel" , + error_prefix); + }else { +error_setg_errno (errp, -ret,"%s failed to query migration flags" , + error_prefix); + } +return ret; }/* Basic migration functionality must be supported */ if (!(mig_flags &VFIO_MIGRATION_STOP_COPY )) { +error_setg (errp,"%s VFIO_MIGRATION_STOP_COPY is not supported" , + error_prefix);return -EOPNOTSUPP ; }
@@ -1261,18 +1276,8 @@ bool vfio_migration_realize(VFIODevice *vbasedev, Error **errp)return !vfio_block_migration (vbasedev, err, errp); } - ret =vfio_migration_init (vbasedev); + ret =vfio_migration_init (vbasedev, &err);if (ret) { -if (ret == -ENOTTY ) { -error_setg (&err,"%s: VFIO migration is not supported in kernel" , - vbasedev->name); - }else { -error_setg (&err, -"%s: Migration couldn't be initialized for VFIO device, " -"err: %d (%s)" , - vbasedev->name, ret,strerror (-ret)); - } -return !vfio_block_migration (vbasedev, err, errp); }
Signature · 1 line
2.40.1
Re: [PATCH 10/14] vfio/migration: Add Error ** parameter to vfio_migration_init()
Hello Avihai,
Quoted 25 lines · Avihai Horon
vfio_migration_init()already has many failure points and a new one will be added in next patch.Add Error ** parameter to
vfio_migration_init()to report a detailed error message through it.Signed-off-by Avihai Horon <[email protected]>--- hw/vfio/migration.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-)hw/vfio/migration.c +1
-1@@ -1038,7 +1038,7 @@ static bool vfio_dma_logging_supported(VFIODevice *vbasedev)return !ioctl (vbasedev->fd,VFIO_DEVICE_FEATURE , feature); } -static int vfio_migration_init (VFIODevice *vbasedev) +static int vfio_migration_init (VFIODevice *vbasedev,Error **errp) {int ret;Object *obj;
hw/vfio/migration.c static int vfio_migration_init(VFIODevice *vbasedev) · line 1051
Quoted 5 lines
hw/vfio/migration.c +2
-0@@ -1047,23 +1047,38 @@ static int vfio_migration_init(VFIODevice *vbasedev) g_autofree char *path = NULL, *oid = NULL;uint64_t mig_flags =0 ;VMChangeStateHandler *prepare_cb; + g_autofree char *error_prefix = +g_strdup_printf ("%s: VFIO migration init failed:" , vbasedev->name);
We have error_prepend() for this purpose.
Thanks,
C.
Quoted 53 lines
hw/vfio/migration.c +14
-11if (!vbasedev->ops->vfio_get_object) { +error_setg (errp,"%s no vfio_get_object handler" , error_prefix);return -EINVAL ; } obj = vbasedev->ops->vfio_get_object (vbasedev);if (!obj) { +error_setg (errp,"%s failed to get object" , error_prefix);return -EINVAL ; } ret =vfio_migration_query_flags (vbasedev, &mig_flags);if (ret) { +if (ret == -ENOTTY ) { +error_setg_errno (errp, -ret, +"%s migration is not supported in kernel" , + error_prefix); + }else { +error_setg_errno (errp, -ret,"%s failed to query migration flags" , + error_prefix); + } +return ret; }/* Basic migration functionality must be supported */ if (!(mig_flags &VFIO_MIGRATION_STOP_COPY )) { +error_setg (errp,"%s VFIO_MIGRATION_STOP_COPY is not supported" , + error_prefix);return -EOPNOTSUPP ; }@@ -1261,18 +1276,8 @@ bool vfio_migration_realize(VFIODevice *vbasedev, Error **errp)return !vfio_block_migration (vbasedev, err, errp); } - ret =vfio_migration_init (vbasedev); + ret =vfio_migration_init (vbasedev, &err);if (ret) { -if (ret == -ENOTTY ) { -error_setg (&err,"%s: VFIO migration is not supported in kernel" , - vbasedev->name); - }else { -error_setg (&err, -"%s: Migration couldn't be initialized for VFIO device, " -"err: %d (%s)" , - vbasedev->name, ret,strerror (-ret)); - } -return !vfio_block_migration (vbasedev, err, errp); }
Re: [PATCH 10/14] vfio/migration: Add Error ** parameter to vfio_migration_init()
Quoted 26 lines · Cédric Le Goater
External email: Use caution opening links or attachments
Hello Avihai,
Quoted 20 lines · Avihai Horon
vfio_migration_init()already has many failure points and a new one will be added in next patch.Add Error ** parameter to
vfio_migration_init()to report a detailed error message through it.Signed-off-by Avihai Horon <[email protected]>---
hw/vfio/migration.c| 29 +++++++++++++++++------------1 file changed, 17 insertions(+), 12 deletions(-)hw/vfio/migration.c +0
-0@@ -1038,7 +1038,7 @@ static bool vfio_dma_logging_supported(VFIODevice *vbasedev) return !ioctl(vbasedev->fd, VFIO_DEVICE_FEATURE, feature); }
Quoted 15 lines
hw/vfio/migration.c static int vfio_migration_init(VFIODevice · line 1053
Quoted 13 lines
hw/vfio/migration.c +1
-1-static int vfio_migration_init (VFIODevice *vbasedev) +static int vfio_migration_init (VFIODevice *vbasedev,Error **errp) { int ret;Object *obj;
hw/vfio/migration.c +2
-0@@ -1047,23 +1047,38 @@ static int vfio_migration_init(VFIODevice *vbasedev) g_autofree char *path = NULL, *oid = NULL; uint64_t mig_flags = 0; VMChangeStateHandler *prepare_cb; + g_autofree char *error_prefix = + g_strdup_printf("%s: VFIO migration init failed:", vbasedev->name);We have
error_prepend()for this purpose.
Right.
I was trying to avoid duplicating the prefix on each fail branch.
Do you suggest to add a common "err:" goto label at the bottom and put there a single:
error_prepend(errp, "%s: VFIO migration init failed:", vbasedev->name);
?
Thanks.
Quoted 62 lines
Quoted 61 lines
hw/vfio/migration.c +12
-0if (!vbasedev->ops->vfio_get_object) { + error_setg(errp, "%s no vfio_get_object handler", error_prefix); return -EINVAL; } obj = vbasedev->ops->vfio_get_object(vbasedev); if (!obj) { + error_setg(errp, "%s failed to get object", error_prefix); return -EINVAL; } ret = vfio_migration_query_flags(vbasedev, &mig_flags); if (ret) { + if (ret == -ENOTTY) { + error_setg_errno(errp, -ret, + "%s migration is not supported in kernel", + error_prefix); + } else { + error_setg_errno(errp, -ret, "%s failed to query migration flags", + error_prefix); + } + return ret; } /* Basic migration functionality must be supported */ if (!(mig_flags & VFIO_MIGRATION_STOP_COPY)) { + error_setg(errp, "%s VFIO_MIGRATION_STOP_COPY is notsupported",
+error_prefix);
return-EOPNOTSUPP;
}hw/vfio/migration.c +1
-7@@ -1261,18 +1276,8 @@ bool vfio_migration_realize(VFIODevice *vbasedev, Error **errp) return !vfio_block_migration(vbasedev, err, errp); } - ret = vfio_migration_init(vbasedev); + ret = vfio_migration_init(vbasedev, &err); if (ret) { - if (ret == -ENOTTY) { - error_setg(&err, "%s: VFIO migration is not supported in kernel", - vbasedev->name); - } else { - error_setg(&err, - "%s: Migration couldn't be initialized forVFIO device, "
- "err: %d (%s)",
-vbasedev->name, ret, strerror(-ret)); - }
-
return !vfio_block_migration(vbasedev, err, errp); }
Re: [PATCH 10/14] vfio/migration: Add Error ** parameter to vfio_migration_init()
Quoted 44 lines · Avihai Horon
Quoted 26 lines · Cédric Le Goater
External email: Use caution opening links or attachments
Hello Avihai,
Quoted 20 lines · Avihai Horon
vfio_migration_init()already has many failure points and a new one will be added in next patch.Add Error ** parameter to
vfio_migration_init()to report a detailed error message through it.Signed-off-by Avihai Horon <[email protected]>---
hw/vfio/migration.c| 29 +++++++++++++++++------------1 file changed, 17 insertions(+), 12 deletions(-)hw/vfio/migration.c +0
-0@@ -1038,7 +1038,7 @@ static bool vfio_dma_logging_supported(VFIODevice *vbasedev) return !ioctl(vbasedev->fd, VFIO_DEVICE_FEATURE, feature); }Quoted 15 lines
hw/vfio/migration.c static int vfio_migration_init(VFIODevice · line 1053
Quoted 13 lines
hw/vfio/migration.c +1
-1-static int vfio_migration_init (VFIODevice *vbasedev) +static int vfio_migration_init (VFIODevice *vbasedev,Error **errp) { int ret;Object *obj;
hw/vfio/migration.c +2
-0@@ -1047,23 +1047,38 @@ static int vfio_migration_init(VFIODevice *vbasedev) g_autofree char *path = NULL, *oid = NULL; uint64_t mig_flags = 0; VMChangeStateHandler *prepare_cb; + g_autofree char *error_prefix = + g_strdup_printf("%s: VFIO migration init failed:", vbasedev->name);We have
error_prepend()for this purpose.
Quoted 8 lines
Right.
I was trying to avoid duplicating the prefix on each fail branch.Do you suggest to add a common "err:" goto label at the bottom and put there a single:
error_prepend(errp, "%s: VFIO migration init failed:", vbasedev->name);?
Or alternatively, put it in vfio_migration_realize():
ret = vfio_migration_init(vbasedev, &err);
if (ret) {
error_prepend(err, "%s: VFIO migration init failed:", vbasedev->name); return !vfio_block_migration(vbasedev, err, errp);
}
?
Quoted 67 lines
Thanks.
Quoted 63 lines
Quoted 62 lines
hw/vfio/migration.c +11
-0if (!vbasedev->ops->vfio_get_object) { + error_setg(errp, "%s no vfio_get_object handler", error_prefix); return -EINVAL; } obj = vbasedev->ops->vfio_get_object(vbasedev); if (!obj) { + error_setg(errp, "%s failed to get object", error_prefix); return -EINVAL; } ret = vfio_migration_query_flags(vbasedev, &mig_flags); if (ret) { + if (ret == -ENOTTY) { + error_setg_errno(errp, -ret, + "%s migration is not supported in kernel", + error_prefix); + } else { + error_setg_errno(errp, -ret, "%s failed to query migration flags", + error_prefix); + } + return ret; } /* Basic migration functionality must be supported */if (!(mig_flags &
VFIO_MIGRATION_STOP_COPY)) { + error_setg(errp, "%sVFIO_MIGRATION_STOP_COPYis not supported",
+error_prefix);
return-EOPNOTSUPP;
}hw/vfio/migration.c +1
-7@@ -1261,18 +1276,8 @@ bool vfio_migration_realize(VFIODevice *vbasedev, Error **errp) return !vfio_block_migration(vbasedev, err, errp); } - ret = vfio_migration_init(vbasedev); + ret = vfio_migration_init(vbasedev, &err); if (ret) { - if (ret == -ENOTTY) { - error_setg(&err, "%s: VFIO migration is not supported in kernel", - vbasedev->name); - } else { - error_setg(&err, - "%s: Migration couldn't be initialized forVFIO device, "
- "err: %d (%s)",
-vbasedev->name, ret, strerror(-ret)); - }
-
return !vfio_block_migration(vbasedev, err, errp); }
PATCH 11/14 vfio/migration: Add new switchover-ack mechanism
In reply to Avihai HoronAdd support for the new switchover-ack mechanism. This includes implementing a request_switchover_ack handler that requests a switchover ACK on setup.
Keep legacy switchover-ack functionality for backward compatibility.
--- docs/devel/migration/vfio.rst | 3 +++ hw/vfio/migration.c | 16 ++++++++++++++++ 2 files changed, 19 insertions(+)
docs/devel/migration/vfio.rst +3 -0
@@ -59,6 +59,9 @@ VFIO implements the device hooks for the iterative approach as follows: * A ``save_live_iterate`` function that reads the VFIO device's data from the vendor driver during iterative pre-copy phase. +* A ``request_switchover_ack`` function that requests switchover ACKs when + needed. + * A ``switchover_start`` function that in the multifd mode starts a thread that reassembles the multifd received data and loads it in-order into the device. In the non-multifd mode this function is a NOP.
hw/vfio/migration.c +16 -0
@@ -882,6 +882,21 @@ static int vfio_load_state(QEMUFile *f, void *opaque, int version_id)return ret; } +static bool vfio_request_switchover_ack (enum MigSwitchoverAckRequestStage stage, +void *opaque,const char **requester) +{ +VFIODevice *vbasedev = opaque; + + *requester = vbasedev->name; + +if (stage ==MIG_SWITCHOVER_ACK_REQUEST_STAGE_SETUP ) { +/* Precopy support implies switchover-ack is needed */ +return vfio_precopy_supported (vbasedev); + } + +return false; +} +static int vfio_switchover_start (void *opaque) {VFIODevice *vbasedev = opaque;
@@ -905,6 +920,7 @@ static const SaveVMHandlers savevm_vfio_handlers = { .load_setup = vfio_load_setup, .load_cleanup = vfio_load_cleanup, .load_state = vfio_load_state, + .request_switchover_ack = vfio_request_switchover_ack,/* * Multifd support */
Signature · 1 line
2.40.1
PATCH 12/14 vfio/migration: Implement VFIO_PRECOPY_INFO_REINIT feature
In reply to Avihai HoronAccording to VFIO uAPI, precopy initial_bytes is considered as critical data that should be transferred and loaded prior to moving to STOP_COPY state to ensure precopy phase would be effective.
As currently defined, initial_bytes can only decrease as it's being read from the data fd. However, there are cases where a new chunk of initial_bytes should be transferred during precopy.
The new VFIO_PRECOPY_INFO_REINIT feature addresses this and allows reporting a new value for initial_bytes regardless of any previously reported values.
Implement VFIO_PRECOPY_INFO_REINIT feature:
1. Opt-in for VFIO_DEVICE_FEATURE_MIG_PRECOPY_INFOv2 to make VFIO_PRECOPY_INFO_REINIT available.
2. Request a new switchover ACK if initial_bytes increases post of a previous switchover ACK. This ensures the device is not moved to STOP_COPY before initial_bytes has reached zero again.
--- hw/vfio/vfio-migration-internal.h | 2 + hw/vfio/migration.c | 73 +++++++++++++++++++++++++++++-- hw/vfio/trace-events | 4 +- 3 files changed, 74 insertions(+), 5 deletions(-)
hw/vfio/vfio-migration-internal.h +2 -0
@@ -45,6 +45,7 @@ typedef struct VFIOMigration {void *data_buffer;size_t data_buffer_size;uint64_t mig_flags; +bool precopy_info_v2_used;/* * NOTE: all three sizes cached are reported from VFIO's uAPI, which * are defined as estimate only. QEMU should not trust these values
@@ -58,6 +59,7 @@ typedef struct VFIOMigration {bool multifd_transfer;VFIOMultifd *multifd;bool initial_data_sent; +bool request_switchover_ack;bool event_save_iterate_started;bool event_precopy_empty_hit;
hw/vfio/migration.c +69 -4
142 lines not on this page · raw message
hw/vfio/trace-events +3 -1
@@ -158,12 +158,14 @@ vfio_load_state_device_buffer_starved(const char *name, uint32_t idx) " (%s) idx vfio_load_state_device_buffer_load_start(const char *name, uint32_t idx) " (%s) idx %"PRIu32 vfio_load_state_device_buffer_load_end(const char *name, uint32_t idx) " (%s) idx %"PRIu32 vfio_load_state_device_buffer_end(const char *name) " (%s)" +vfio_migration_init(const char *name, uint64_t mig_flags, bool precopy_info_v2_used, bool dirty_pages_supported) " (%s) mig_flags 0x%"PRIx64", precopy_info_v2_used %d, dirty_pages_supported %d" vfio_migration_realize(const char *name) " (%s)" vfio_migration_set_device_state(const char *name, const char *state) " (%s) state %s" vfio_migration_set_state(const char *name, const char *new_state, const char *recover_state) " (%s) new state %s, recover state %s" vfio_migration_state_notifier(const char *name, int state) " (%s) state %d" +vfio_query_precopy_size(const char *name, uint64_t init_size, uint64_t dirty_size, bool reinit, int ret) " (%s) init %"PRIu64", dirty %"PRIu64", reinit %d, ret %d" +vfio_query_precopy_size_request_switchover_ack(const char *name) " (%s)" vfio_query_stop_copy_size(const char *name, uint64_t size, int ret) " (%s) stopcopy size %"PRIu64" ret %d" -vfio_query_precopy_size(const char *name, uint64_t init_size, uint64_t dirty_size, int ret) " (%s) init %"PRIu64" dirty %"PRIu64" ret %d" vfio_save_block(const char *name, int data_size) " (%s) data_size %d" vfio_save_block_precopy_empty_hit(const char *name) " (%s)" vfio_save_cleanup(const char *name) " (%s)"
Signature · 1 line
2.40.1
PATCH 13/14 vfio/migration: Check VFIO_PRECOPY_INFO_REINIT during switchover
In reply to Avihai HoronVFIO_REPCOPY_INFO_REINIT is checked only during precopy, while the guest is running. However, the switchover decision and guest stop are not atomic, so a VFIO device may want to set VFIO_PRECOPY_INFO_REINIT and request another switchover ACK in the gap after switchover decision has been made but before the guest is stopped. This would be missed and may increase downtime.
Solve this by checking if VFIO_PRECOPY_INFO_REINIT was set during that gap, and request a new switchover-ack in the COMPLETE stage. Query precopy info after vCPUs are stopped but before transitioning from PRE_COPY state, when its valid to call the ioctl.
--- hw/vfio/migration.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-)
hw/vfio/migration.c +31 -1
@@ -915,7 +915,8 @@ static bool vfio_request_switchover_ack(enum MigSwitchoverAckRequestStage stage,if (stage ==MIG_SWITCHOVER_ACK_REQUEST_STAGE_SETUP ) {/* Precopy support implies switchover-ack is needed */ return vfio_precopy_supported (vbasedev); - }else if (stage ==MIG_SWITCHOVER_ACK_REQUEST_STAGE_PENDING_EXACT ) { + }else if (stage ==MIG_SWITCHOVER_ACK_REQUEST_STAGE_PENDING_EXACT || + stage ==MIG_SWITCHOVER_ACK_REQUEST_STAGE_COMPLETE ) { request = migration->request_switchover_ack; migration->request_switchover_ack = false;
@@ -959,6 +960,26 @@ static const SaveVMHandlers savevm_vfio_handlers = {/* ---------------------------------------------------------------------- */ +static void vfio_final_precopy_reinit_check (VFIODevice *vbasedev) +{ +VFIOMigration *migration = vbasedev->migration; +int ret; + +if (!migration->precopy_info_v2_used || !migrate_switchover_ack () || +migrate_switchover_ack_legacy ()) { +return ; + } + + ret =vfio_query_precopy_size (migration); +if (ret) { +error_report ("%s: Final precopy reinit check failed (err: %d)" , + vbasedev->name, ret); +/* If query failed, assume reinit and request switchover-ack */ + migration->request_switchover_ack = true; + migration->initial_data_sent = false; + } +} +static void vfio_vmstate_change_prepare (void *opaque,bool running,RunState state) {
@@ -972,6 +993,15 @@ static void vfio_vmstate_change_prepare(void *opaque, bool running, VFIO_DEVICE_STATE_PRE_COPY_P2P :VFIO_DEVICE_STATE_RUNNING_P2P ; +if (migration->device_state ==VFIO_DEVICE_STATE_PRE_COPY ) { +/* +* Now that vCPUs are stopped, check if new init_bytes are available +* since switchover decision, to be reported in switchover-ack COMPLETE +* stage. +*/ +vfio_final_precopy_reinit_check (vbasedev); + } + ret =vfio_migration_set_state_or_reset (vbasedev, new_state, &local_err);if (ret) {/*
Signature · 1 line
2.40.1
PATCH 14/14 migration: Enable new switchover-ack
In reply to Avihai HoronNow that VFIO has implemented new switchover-ack, enable it.
--- migration/options.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
migration/options.c +1 -2
@@ -108,9 +108,8 @@ const Property migration_properties[] = { preempt_pre_7_2, false),DEFINE_PROP_BOOL ("multifd-clean-tls-termination" , MigrationState, multifd_clean_tls_termination, true), -/* Use legacy until VFIO implements new switchover-ack */ DEFINE_PROP_BOOL ("switchover-ack-legacy" , MigrationState, - switchover_ack_legacy, true), + switchover_ack_legacy, false),/* Migration parameters */ DEFINE_PROP_UINT8("x-throttle-trigger-threshold", MigrationState,
Signature · 1 line
2.40.1
Re: [PATCH 14/14] migration: Enable new switchover-ack
Quoted 12 lines · Avihai Horon
Now that VFIO has implemented new switchover-ack, enable it.
Signed-off-by Avihai Horon <[email protected]>--- migration/options.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)migration/options.c +0
-0
migration/options.c const Property migration_properties[] = { · line 111
Quoted 4 lines
migration/options.c +0
-1@@ -108,9 +108,8 @@ const Property migration_properties[] = { preempt_pre_7_2, false), DEFINE_PROP_BOOL("multifd-clean-tls-termination", MigrationState, multifd_clean_tls_termination, true), -/* Use legacy until VFIO implements new switchover-ack */
Removing this line is fine because it's a very temporary thing. But maybe it would be good we have some rich documentation on both the legacy and new behavior of switchover-ack. Normally it would be qapi/migration.json, but in this case the user shouldn't need to choose, so I think when keeping qapi doc simple we need to have somewhere internal that document all these.
Thanks,
Quoted 9 lines
migration/options.c +1
-1DEFINE_PROP_BOOL ("switchover-ack-legacy" , MigrationState, - switchover_ack_legacy, true), + switchover_ack_legacy, false),/* Migration parameters */ DEFINE_PROP_UINT8("x-throttle-trigger-threshold", MigrationState,Signature · 1 line
2.40.1
Signature · 1 line
Peter Xu
Re: [PATCH 14/14] migration: Enable new switchover-ack
Quoted 11 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 7 lines · Avihai Horon
Now that VFIO has implemented new switchover-ack, enable it.
Signed-off-by Avihai Horon <[email protected]>--- migration/options.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Quoted 14 lines
migration/options.c const Property migration_properties[] = { · line 111
Quoted 9 lines
migration/options.c +0
-1@@ -108,9 +108,8 @@ const Property migration_properties[] = { preempt_pre_7_2, false), DEFINE_PROP_BOOL("multifd-clean-tls-termination", MigrationState, multifd_clean_tls_termination, true), -/* Use legacy until VFIO implements new switchover-ack */ Removing this line is fine because it's a very temporary thing. But maybe it would be good we have some rich documentation on both the legacy and new behavior of switchover-ack. Normally it would be
qapi/migration.json, but in this case the user shouldn't need to choose, so I think when keeping qapi doc simple we need to have somewhere internal that document all these.
Sure, I can do that.
Would adding it as a comment above struct MigrationState->switchover_ack_legacy be fine?
Thanks.
Quoted 12 lines
Quoted 9 lines
migration/options.c +1
-2DEFINE_PROP_BOOL ("switchover-ack-legacy" , MigrationState, - switchover_ack_legacy, true), + switchover_ack_legacy, false),/* Migration parameters */ DEFINE_PROP_UINT8("x-throttle-trigger-threshold", MigrationState, --2.40.1
--
Peter Xu
Re: [PATCH 14/14] migration: Enable new switchover-ack
Quoted 28 lines · Avihai Horon
Quoted 11 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 7 lines · Avihai Horon
Now that VFIO has implemented new switchover-ack, enable it.
Signed-off-by Avihai Horon <[email protected]>--- migration/options.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)Quoted 14 lines
migration/options.c const Property migration_properties[] = { · line 111
Quoted 9 lines
migration/options.c +0
-1@@ -108,9 +108,8 @@ const Property migration_properties[] = { preempt_pre_7_2, false), DEFINE_PROP_BOOL("multifd-clean-tls-termination", MigrationState, multifd_clean_tls_termination, true), -/* Use legacy until VFIO implements new switchover-ack */ Removing this line is fine because it's a very temporary thing. But maybe it would be good we have some rich documentation on both the legacy and new behavior of switchover-ack. Normally it would be
qapi/migration.json, but in this case the user shouldn't need to choose, so I think when keeping qapi doc simple we need to have somewhere internal that document all these.
Quoted 3 lines
Sure, I can do that.
Would adding it as a comment above structMigrationState->switchover_ack_legacybe fine?
Sounds good!
Signature · 1 line
Peter Xu
Quoted 6 lines · Avihai Horon
Performance tests were done by migrating a single VM with:
* 8 GB RAM
* 4 mlx5 VFIO devices:
- One device with 1GB of device data (stopcopy data) that runs workload during precopy soVFIO_PRECOPY_INFO_REINITis exercised (generate newinitial_byteschunks during precopy).
Could you elaborate a bit more on what workload is executed, and how that will affect REINIT reportings (e.g. is only one REINIT generated, or it keeps generating)?
Can I understand it in this way: without REINIT, device is forced to put those data into stopcopy size; then with REINIT, some stopcopy size is essentially moved back to precopy phase?
Thanks,
Quoted 107 lines
- The other 3 devices are idle.
In this setup,
VFIO_PRECOPY_INFO_REINITreduced total migration downtime by about 43%, and downtime attributed to the busy VFIO device by about 67%:With
VFIO_PRECOPY_INFO_REINIT:
1335ms total (~520ms from the VFIO device running the workload).Without
VFIO_PRECOPY_INFO_REINIT:
2352ms total (~1600ms from the VFIO device running the workload).Functional tests covered the main code paths and combinations, including legacy and new switchover-ack across versions, for example:
* Migration between QEMU 11.0 (old binary) and 11.1 (new binary).
* Migration between two 11.1 binaries with different machine versions.
* Migration when the VFIO device has noVFIO_PRECOPY_INFO_REINIT.
* Migration when the VFIO device has no VFIO precopy support.=== Patch Breakdown ===
* Patches 1-2: Update Linux headers
* Patches 3-8,14: Migration cleanups and the new switchover-ack mechanism
* Patches 9-13: VFIO cleanups andVFIO_PRECOPY_INFO_REINITThanks.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/qemu-devel/[email protected]/Avihai Horon (14):
scripts/update-linux-headers: Addtypelimits.h
linux-headers: Update to Linux v7.1-rc1
migration: Propagate errors inmigration_completion_precopy()
migration: Log the approver inqemu_loadvm_approve_switchover()
migration: Replaceswitchover_ack_neededSaveVMHandler
migration: Rename switchover-ack code to legacy
migration: Make switchover-ack re-usable
migration: Check switchover-ack during switchover phase vfio/migration: Re-query precopy size before sending
VFIO_MIG_FLAG_DEV_INIT_DATA_SENT
vfio/migration: Add Error ** parameter tovfio_migration_init()vfio/migration: Add new switchover-ack mechanism vfio/migration: ImplementVFIO_PRECOPY_INFO_REINITfeature vfio/migration: CheckVFIO_PRECOPY_INFO_REINITduring switchover
migration: Enable new switchover-ackdocs/devel/migration/vfio.rst | 4 +- hw/vfio/vfio-migration-internal.h | 2 + include/migration/client-options.h | 1 + include/migration/misc.h | 2 + include/migration/register.h | 21 +- include/standard-headers/drm/drm_fourcc.h | 28 +- include/standard-headers/linux/const.h | 18 + include/standard-headers/linux/ethtool.h | 28 +- .../linux/input-event-codes.h | 13 + include/standard-headers/linux/pci_regs.h | 71 ++- include/standard-headers/linux/typelimits.h | 8 + include/standard-headers/linux/virtio_ring.h | 3 +- include/standard-headers/linux/virtio_rtc.h | 237 ++++++++++ include/standard-headers/linux/vmclock-abi.h | 20 + linux-headers/asm-arm64/kvm.h | 1 + linux-headers/asm-arm64/unistd_64.h | 1 + linux-headers/asm-generic/unistd.h | 5 +- linux-headers/asm-loongarch/kvm.h | 5 + linux-headers/asm-loongarch/kvm_para.h | 1 + linux-headers/asm-loongarch/unistd_64.h | 2 + linux-headers/asm-mips/unistd_n32.h | 1 + linux-headers/asm-mips/unistd_n64.h | 1 + linux-headers/asm-mips/unistd_o32.h | 1 + linux-headers/asm-powerpc/unistd_32.h | 1 + linux-headers/asm-powerpc/unistd_64.h | 1 + linux-headers/asm-riscv/kvm.h | 11 +- linux-headers/asm-riscv/ptrace.h | 37 ++ linux-headers/asm-riscv/unistd_32.h | 1 + linux-headers/asm-riscv/unistd_64.h | 1 + linux-headers/asm-s390/unistd_32.h | 446 ------------------ linux-headers/asm-s390/unistd_64.h | 1 + linux-headers/asm-x86/kvm.h | 21 +- linux-headers/asm-x86/unistd_32.h | 1 + linux-headers/asm-x86/unistd_64.h | 1 + linux-headers/asm-x86/unistd_x32.h | 1 + linux-headers/linux/const.h | 18 + linux-headers/linux/iommufd.h | 48 ++ linux-headers/linux/kvm.h | 46 +- linux-headers/linux/mshv.h | 4 +- linux-headers/linux/psp-sev.h | 2 +- linux-headers/linux/stddef.h | 4 + linux-headers/linux/vduse.h | 85 +++- linux-headers/linux/vfio.h | 30 +- migration/migration.h | 17 +- migration/savevm.h | 4 +- hw/core/machine.c | 4 +- hw/vfio/migration.c | 195 +++++++- migration/migration.c | 65 ++- migration/options.c | 9 + migration/savevm.c | 146 ++++-- hw/vfio/trace-events | 5 +- migration/trace-events | 8 +- scripts/update-linux-headers.sh | 2 + 53 files changed, 1109 insertions(+), 580 deletions(-) create mode 100644 include/standard-headers/linux/typelimits.h create mode 100644 include/standard-headers/linux/virtio_rtc.h delete mode 100644 linux-headers/asm-s390/unistd_32.hSignature · 1 line
2.40.1
Signature · 1 line
Peter Xu
Quoted 10 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 6 lines · Avihai Horon
Performance tests were done by migrating a single VM with:
* 8 GB RAM
* 4 mlx5 VFIO devices:
- One device with 1GB of device data (stopcopy data) that runs workload during precopy soVFIO_PRECOPY_INFO_REINITis exercised (generate newinitial_byteschunks during precopy).
Quoted 3 lines
Could you elaborate a bit more on what workload is executed, and how that will affect REINIT reportings (e.g. is only one REINIT generated, or it keeps generating)?
Basically, I create and destroy RDMA resources (MRs, QPs, CQs, etc.) on the VFIO device in a loop for several iterations. This generates several REINITs.
Quoted 4 lines
Can I understand it in this way: without REINIT, device is forced to put those data into stopcopy size; then with REINIT, some stopcopy size is essentially moved back to precopy phase?
Almost:
Without REINIT, the device is forced to put this data in precopy dirty_bytes. With REINIT, this data can be put in precopy init_bytes (and do the switchover-ack dance again).
Thanks.
Quoted 110 lines
Quoted 100 lines
- The other 3 devices are idle.
In this setup,
VFIO_PRECOPY_INFO_REINITreduced total migration downtime by about 43%, and downtime attributed to the busy VFIO device by about 67%:With
VFIO_PRECOPY_INFO_REINIT:
1335ms total (~520ms from the VFIO device running the workload).Without
VFIO_PRECOPY_INFO_REINIT:
2352ms total (~1600ms from the VFIO device running the workload).Functional tests covered the main code paths and combinations, including legacy and new switchover-ack across versions, for example:
* Migration between QEMU 11.0 (old binary) and 11.1 (new binary).
* Migration between two 11.1 binaries with different machine versions.
* Migration when the VFIO device has noVFIO_PRECOPY_INFO_REINIT.
* Migration when the VFIO device has no VFIO precopy support.=== Patch Breakdown ===
* Patches 1-2: Update Linux headers
* Patches 3-8,14: Migration cleanups and the new switchover-ack mechanism
* Patches 9-13: VFIO cleanups andVFIO_PRECOPY_INFO_REINITThanks.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/qemu-devel/[email protected]/Avihai Horon (14):
scripts/update-linux-headers: Addtypelimits.h
linux-headers: Update to Linux v7.1-rc1
migration: Propagate errors inmigration_completion_precopy()
migration: Log the approver inqemu_loadvm_approve_switchover()
migration: Replaceswitchover_ack_neededSaveVMHandler
migration: Rename switchover-ack code to legacy
migration: Make switchover-ack re-usable
migration: Check switchover-ack during switchover phase vfio/migration: Re-query precopy size before sending
VFIO_MIG_FLAG_DEV_INIT_DATA_SENT
vfio/migration: Add Error ** parameter tovfio_migration_init()vfio/migration: Add new switchover-ack mechanism vfio/migration: ImplementVFIO_PRECOPY_INFO_REINITfeature vfio/migration: CheckVFIO_PRECOPY_INFO_REINITduring switchover
migration: Enable new switchover-ackdocs/devel/migration/vfio.rst | 4 +- hw/vfio/vfio-migration-internal.h | 2 + include/migration/client-options.h | 1 + include/migration/misc.h | 2 + include/migration/register.h | 21 +- include/standard-headers/drm/drm_fourcc.h | 28 +- include/standard-headers/linux/const.h | 18 + include/standard-headers/linux/ethtool.h | 28 +- .../linux/input-event-codes.h | 13 + include/standard-headers/linux/pci_regs.h | 71 ++- include/standard-headers/linux/typelimits.h | 8 + include/standard-headers/linux/virtio_ring.h | 3 +- include/standard-headers/linux/virtio_rtc.h | 237 ++++++++++ include/standard-headers/linux/vmclock-abi.h | 20 + linux-headers/asm-arm64/kvm.h | 1 + linux-headers/asm-arm64/unistd_64.h | 1 + linux-headers/asm-generic/unistd.h | 5 +- linux-headers/asm-loongarch/kvm.h | 5 + linux-headers/asm-loongarch/kvm_para.h | 1 + linux-headers/asm-loongarch/unistd_64.h | 2 + linux-headers/asm-mips/unistd_n32.h | 1 + linux-headers/asm-mips/unistd_n64.h | 1 + linux-headers/asm-mips/unistd_o32.h | 1 + linux-headers/asm-powerpc/unistd_32.h | 1 + linux-headers/asm-powerpc/unistd_64.h | 1 + linux-headers/asm-riscv/kvm.h | 11 +- linux-headers/asm-riscv/ptrace.h | 37 ++ linux-headers/asm-riscv/unistd_32.h | 1 + linux-headers/asm-riscv/unistd_64.h | 1 + linux-headers/asm-s390/unistd_32.h | 446 ------------------ linux-headers/asm-s390/unistd_64.h | 1 + linux-headers/asm-x86/kvm.h | 21 +- linux-headers/asm-x86/unistd_32.h | 1 + linux-headers/asm-x86/unistd_64.h | 1 + linux-headers/asm-x86/unistd_x32.h | 1 + linux-headers/linux/const.h | 18 + linux-headers/linux/iommufd.h | 48 ++ linux-headers/linux/kvm.h | 46 +- linux-headers/linux/mshv.h | 4 +- linux-headers/linux/psp-sev.h | 2 +- linux-headers/linux/stddef.h | 4 + linux-headers/linux/vduse.h | 85 +++- linux-headers/linux/vfio.h | 30 +- migration/migration.h | 17 +- migration/savevm.h | 4 +- hw/core/machine.c | 4 +- hw/vfio/migration.c | 195 +++++++- migration/migration.c | 65 ++- migration/options.c | 9 + migration/savevm.c | 146 ++++-- hw/vfio/trace-events | 5 +- migration/trace-events | 8 +- scripts/update-linux-headers.sh | 2 + 53 files changed, 1109 insertions(+), 580 deletions(-)Quoted 7 lines
create mode 100644
include/standard-headers/linux/typelimits.hcreate mode 100644include/standard-headers/linux/virtio_rtc.hdelete mode 100644linux-headers/asm-s390/unistd_32.h--
2.40.1--
Peter Xu
Quoted 25 lines · Avihai Horon
Quoted 10 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 6 lines · Avihai Horon
Performance tests were done by migrating a single VM with:
* 8 GB RAM
* 4 mlx5 VFIO devices:
- One device with 1GB of device data (stopcopy data) that runs workload during precopy soVFIO_PRECOPY_INFO_REINITis exercised (generate newinitial_byteschunks during precopy).Quoted 3 lines
Could you elaborate a bit more on what workload is executed, and how that will affect REINIT reportings (e.g. is only one REINIT generated, or it keeps generating)?
Basically, I create and destroy RDMA resources (MRs, QPs, CQs, etc.) on the VFIO device in a loop for several iterations.
This generates several REINITs.Quoted 4 lines
Can I understand it in this way: without REINIT, device is forced to put those data into stopcopy size; then with REINIT, some stopcopy size is essentially moved back to precopy phase?
Quoted 5 lines
Almost:
Without REINIT, the device is forced to put this data in precopydirty_bytes.
With REINIT, this data can be put in precopyinit_bytes(and do the switchover-ack dance again).
Hmm, then I don't understand why moving some chunk of data from precopy_bytes to init_bytes helps downtime.
Essentially, QEMU makes the switchover decision based on the math of:
init+dirty+stop
--------------- <= downtime_limit
bw
The possible min of above is:
stop
---------------
bw
Here whether some data would be in init or precopy portion shouldn't matter for a min downtime, since both portions are allowed to be moved during precopy phase.
OTOH, if stop_bytes unchanged, min downtime is still the same before / after supporting REINIT, if we try harder.
Say, with below testing results:
With VFIO_PRECOPY_INFO_REINIT:
1335ms total (~520ms from the VFIO device running the workload).
Without VFIO_PRECOPY_INFO_REINIT:
2352ms total (~1600ms from the VFIO device running the workload).
What is the downtime_limit you specified for both cases? Have you tried to specify lower downtime_limit than what you specified, so that both results will become even closer (until they become, statistically, identical)?
In general, I can understand the REINIT will stop converging too early, but it'll be the same IIUC just to turn the downtime_limit smaller.. IOW, I may still miss some important piece of info that how this REINIT feature helps downtime..
Thanks,
Signature · 1 line
Peter Xu
Quoted 60 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 18 lines · Avihai Horon
Quoted 10 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 6 lines · Avihai Horon
Performance tests were done by migrating a single VM with:
* 8 GB RAM
* 4 mlx5 VFIO devices:
- One device with 1GB of device data (stopcopy data) that runs workload during precopy soVFIO_PRECOPY_INFO_REINITis exercised (generate newinitial_byteschunks during precopy).Quoted 3 lines
Could you elaborate a bit more on what workload is executed, and how that will affect REINIT reportings (e.g. is only one REINIT generated, or it keeps generating)?
Basically, I create and destroy RDMA resources (MRs, QPs, CQs, etc.) on the VFIO device in a loop for several iterations.
This generates several REINITs.Quoted 8 lines
Quoted 3 lines
Can I understand it in this way: without REINIT, device is forced to put those data into stopcopy size; then with REINIT, some stopcopy size is essentially moved back to precopy phase?
Almost:
Without REINIT, the device is forced to put this data in precopydirty_bytes.
With REINIT, this data can be put in precopyinit_bytes(and do the switchover-ack dance again).Hmm, then I don't understand why moving some chunk of data from
precopy_bytestoinit_byteshelps downtime.Essentially, QEMU makes the switchover decision based on the math of:
init+dirty+stop --------------- <= downtime_limit bwThe possible min of above is:
stop --------------- bwHere whether some data would be in init or precopy portion shouldn't matter for a min downtime, since both portions are allowed to be moved during precopy phase.
OTOH, if
stop_bytesunchanged, min downtime is still the same before / after supporting REINIT, if we try harder.Say, with below testing results:
With
VFIO_PRECOPY_INFO_REINIT:
1335ms total (~520ms from the VFIO device running the workload).Without
VFIO_PRECOPY_INFO_REINIT:
2352ms total (~1600ms from the VFIO device running the workload).
Quoted 8 lines
What is the
downtime_limityou specified for both cases? Have you tried to specify lowerdowntime_limitthan what you specified, so that both results will become even closer (until they become, statistically, identical)?In general, I can understand the REINIT will stop converging too early, but it'll be the same IIUC just to turn the
downtime_limitsmaller.. IOW, I may still miss some important piece of info that how this REINIT feature helps downtime..
The init_bytes are special in the sense that it's crucial that they are transferred before switching over. Otherwise, VFIO precopy may not have full effect which could make VFIO migration slower. Accordingly, their contribution to downtime may not be just the time it takes to transfer them.
Specifically for mlx5, init_bytes hold a small portion of metadata used for time consuming pre-allocations on destination side. So, we may have 10MB of init_bytes which would take a fraction of a second to transfer, but once reached destination, it could take even a few seconds to load them.
When moving this data from dirty_bytes to init_bytes along with switchover-ack, we guarantee that this long pre-allocation doesn't happen during downtime. This is the time difference you see in the test results.
Thanks.
Quoted 77 lines · Avihai Horon
Quoted 60 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 18 lines · Avihai Horon
Quoted 10 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 6 lines · Avihai Horon
Performance tests were done by migrating a single VM with:
* 8 GB RAM
* 4 mlx5 VFIO devices:
- One device with 1GB of device data (stopcopy data) that runs workload during precopy soVFIO_PRECOPY_INFO_REINITis exercised (generate newinitial_byteschunks during precopy).Quoted 3 lines
Could you elaborate a bit more on what workload is executed, and how that will affect REINIT reportings (e.g. is only one REINIT generated, or it keeps generating)?
Basically, I create and destroy RDMA resources (MRs, QPs, CQs, etc.) on the VFIO device in a loop for several iterations.
This generates several REINITs.Quoted 8 lines
Quoted 3 lines
Can I understand it in this way: without REINIT, device is forced to put those data into stopcopy size; then with REINIT, some stopcopy size is essentially moved back to precopy phase?
Almost:
Without REINIT, the device is forced to put this data in precopydirty_bytes.
With REINIT, this data can be put in precopyinit_bytes(and do the switchover-ack dance again).Hmm, then I don't understand why moving some chunk of data from
precopy_bytestoinit_byteshelps downtime.Essentially, QEMU makes the switchover decision based on the math of:
init+dirty+stop --------------- <= downtime_limit bwThe possible min of above is:
stop --------------- bwHere whether some data would be in init or precopy portion shouldn't matter for a min downtime, since both portions are allowed to be moved during precopy phase.
OTOH, if
stop_bytesunchanged, min downtime is still the same before / after supporting REINIT, if we try harder.Say, with below testing results:
With
VFIO_PRECOPY_INFO_REINIT:
1335ms total (~520ms from the VFIO device running the workload).Without
VFIO_PRECOPY_INFO_REINIT:
2352ms total (~1600ms from the VFIO device running the workload).Quoted 8 lines
What is the
downtime_limityou specified for both cases? Have you tried to specify lowerdowntime_limitthan what you specified, so that both results will become even closer (until they become, statistically, identical)?In general, I can understand the REINIT will stop converging too early, but it'll be the same IIUC just to turn the
downtime_limitsmaller.. IOW, I may still miss some important piece of info that how this REINIT feature helps downtime..The
init_bytesare special in the sense that it's crucial that they are transferred before switching over. Otherwise, VFIO precopy may not have full effect which could make VFIO migration slower.
Accordingly, their contribution to downtime may not be just the time it takes to transfer them.
Quoted 8 lines
Specifically for mlx5,
init_byteshold a small portion of metadata used for time consuming pre-allocations on destination side. So, we may have 10MB ofinit_byteswhich would take a fraction of a second to transfer, but once reached destination, it could take even a few seconds to load them.When moving this data from
dirty_bytestoinit_bytesalong with switchover-ack, we guarantee that this long pre-allocation doesn't happen during downtime. This is the time difference you see in the test results.
I see, yes that's what I missed and this makes a lot sense, thanks.
Could you put above example into some vfio.rst doc when repost, when describing REINIT feature?
Thanks,
Signature · 1 line
Peter Xu
Quoted 84 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 80 lines · Avihai Horon
Quoted 60 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 18 lines · Avihai Horon
Quoted 10 lines · Peter Xu
External email: Use caution opening links or attachments
Quoted 6 lines · Avihai Horon
Performance tests were done by migrating a single VM with:
* 8 GB RAM
* 4 mlx5 VFIO devices:
- One device with 1GB of device data (stopcopy data) that runs workload during precopy soVFIO_PRECOPY_INFO_REINITis exercised (generate newinitial_byteschunks during precopy).Quoted 3 lines
Could you elaborate a bit more on what workload is executed, and how that will affect REINIT reportings (e.g. is only one REINIT generated, or it keeps generating)?
Basically, I create and destroy RDMA resources (MRs, QPs, CQs, etc.) on the VFIO device in a loop for several iterations.
This generates several REINITs.Quoted 8 lines
Quoted 3 lines
Can I understand it in this way: without REINIT, device is forced to put those data into stopcopy size; then with REINIT, some stopcopy size is essentially moved back to precopy phase?
Almost:
Without REINIT, the device is forced to put this data in precopydirty_bytes.
With REINIT, this data can be put in precopyinit_bytes(and do the switchover-ack dance again).Hmm, then I don't understand why moving some chunk of data from
precopy_bytestoinit_byteshelps downtime.Essentially, QEMU makes the switchover decision based on the math of:
init+dirty+stop --------------- <= downtime_limit bwThe possible min of above is:
stop --------------- bwHere whether some data would be in init or precopy portion shouldn't matter for a min downtime, since both portions are allowed to be moved during precopy phase.
OTOH, if
stop_bytesunchanged, min downtime is still the same before / after supporting REINIT, if we try harder.Say, with below testing results:
With
VFIO_PRECOPY_INFO_REINIT:
1335ms total (~520ms from the VFIO device running the workload).Without
VFIO_PRECOPY_INFO_REINIT:
2352ms total (~1600ms from the VFIO device running the workload).Quoted 8 lines
What is the
downtime_limityou specified for both cases? Have you tried to specify lowerdowntime_limitthan what you specified, so that both results will become even closer (until they become, statistically, identical)?In general, I can understand the REINIT will stop converging too early, but it'll be the same IIUC just to turn the
downtime_limitsmaller.. IOW, I may still miss some important piece of info that how this REINIT feature helps downtime..The
init_bytesare special in the sense that it's crucial that they are transferred before switching over. Otherwise, VFIO precopy may not have full effect which could make VFIO migration slower.
Accordingly, their contribution to downtime may not be just the time it takes to transfer them.Specifically for mlx5,
init_byteshold a small portion of metadata used for time consuming pre-allocations on destination side. So, we may have 10MB ofinit_byteswhich would take a fraction of a second to transfer, but once reached destination, it could take even a few seconds to load them.
Quoted 7 lines
Quoted 3 lines
When moving this data from
dirty_bytestoinit_bytesalong with switchover-ack, we guarantee that this long pre-allocation doesn't happen during downtime. This is the time difference you see in the test results.I see, yes that's what I missed and this makes a lot sense, thanks.
Could you put above example into some
vfio.rstdoc when repost, when describing REINIT feature?
Yes, sure.
I will extend the section discussing switchover-ack in docs/devel/migration/vfio.rst.
Thanks.