From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 827B61FF0BC for ; Wed, 02 Dec 2026 18:45:59 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 56902217A5; Wed, 02 Dec 2026 18:45:48 +0100 (CET) From: Jonas Theisen To: pve-devel@lists.proxmox.com Subject: [PATCH docs/qemu-server v4 0/7] live migrate VMs with an invariant TSC or re-enlightenment Date: Wed, 2 Dec 2026 18:45:17 +0100 Message-ID: <20261202174530.565487-1-j.theisen@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1796233540246 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.054 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: WW3EHXL2VBP334M46IS33TIZUZ6AVX37 X-Message-ID-Hash: WW3EHXL2VBP334M46IS33TIZUZ6AVX37 X-MailFrom: j.theisen@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: This series sets an explicit TSC frequency for VMs whose guest relies on a TSC frequency that does not change, so that they can be live migrated, and checks upfront whether the target node can provide it. It builds on the series "check the target node's CPU before live migrating a VM" [0], from which it was split out in v3, and needs to be applied on top of it. The invariant TSC flag 'invtsc' can be enabled with custom CPU models. Without an explicit TSC frequency, QEMU blocks live migration, snapshots with RAM and hibernation of such VMs. Guests need the flag to rely on the TSC as clock source, for example for applications reading it directly or for nested hypervisors. In benchmarks of Windows guests with virtualization-based security (VBS) and the 'host' CPU type, it considerably reduced the performance cost of VBS, for example for context switches and thread creation. Nodes now also report whether they support invtsc. Previously, they never reported it, as QEMU omits it from the migratable 'host' CPU model, so the "Supported On" column of the flag selector of the custom CPU model editor was always empty for it. The 'hv-reenlightenment' flag is added as well. Together with 'hv-frequencies', which custom CPU models can enable, it lets nested Hyper-V guests, for example Windows with WSL2 or VBS, pass a stable clock source on to their own guests. Without 'hv-frequencies', guests do not use it. As KVM does not fully implement re-enlightenment notifications, the TSC frequency of such VMs must not change across live migrations. This series does not enable 'hv-frequencies', it only adds 'hv-reenlightenment' in preparation for it. For both flags, the TSC frequency is set explicitly to the host's, except for confidential VMs, which cannot be migrated anyway. It is queried via KVM_GET_TSC_KHZ on a temporary VM, as upstream Linux does not export it otherwise. Failed queries are retried after ten minutes, as pvestatd queries this in each cycle. The 'host-cpu-info' entry each node broadcasts additionally includes the TSC frequency and whether KVM can scale the TSC, so the migration checks block: - any explicit TSC frequency of the running VM, as set for both flags, if the target can neither scale the TSC nor match the frequency within 250 ppm of its own - 'invtsc' on a VM that was started without an explicit TSC frequency, for example before the update: QEMU blocks its migration anyway, but only after the target instance was started and local disks were copied. It is refused upfront for every target, until the VM is stopped and started again. Whether QEMU blocks the migration is taken from its 'blocked-reasons', which also covers 'host,migratable=off'. - 'host'/'max' with an explicit TSC frequency, for example due to 'hv-reenlightenment', and target lacks invtsc: QEMU then passes invtsc through if the source host has it, so the check of the flags missing for 'host' includes it if the vCPUs have it. If the target does not broadcast TSC information, which nodes report together with invtsc, this only causes a warning, as its support is unknown. A VM with a custom CPU model that already enabled 'hv-reenlightenment' before the update runs without an explicit TSC frequency. If its guest enabled the notifications, QEMU on the target refuses the migrated state at the end of the migration. As this is not known upfront, only a warning suggests to stop and start the VM. The precondition API reports these with the new 'tsc-frequency' type, the refusals in 'incompatible-cpu', and the warning in 'cpu-warnings'. pve-manager needs no changes, as pvestatd broadcasts whatever qemu-server provides. [0] https://lore.proxmox.com/pve-devel/20261202151831.414110-1-j.theisen@proxmox.com/T/#t Testing: Upgrading the packages reloads pvestatd, so that it broadcasts the TSC information and the 'cpuflags-kvm' entry including invtsc. Only when deploying the code without the packages, restart pvestatd manually. Start the test VMs only afterwards, as only VMs started with this series get an explicit TSC frequency, without which the TSC check does not apply. The TSC check can be tested on a cluster with identical CPUs by making the target node broadcast a different TSC frequency. pvestatd broadcasts 'host-cpu-info' again whenever it differs, so stop it first. The following only changes the TSC information, to a 'tsc-khz' clearly different from the real one, as the check tolerates 250 ppm: systemctl stop pvestatd perl -MPVE::Cluster -MPVE::INotify -MJSON -e ' PVE::Cluster::cfs_update(); my $node = PVE::INotify::nodename(); my $info = decode_json(PVE::Cluster::get_node_kv("host-cpu-info", $node)->{$node}); $info->{"tsc-khz"} = 1000000; $info->{"tsc-scaling"} = 0; PVE::Cluster::broadcast_node_kv("host-cpu-info", encode_json($info)); ' Restarting pvestatd broadcasts the real values again: systemctl restart pvestatd What to expect for a running VM: - 'tsc-scaling' 0 and a 'tsc-khz' more than 250 ppm off: blocked for VMs with 'flags=+hv-reenlightenment' or a custom CPU model with '+invtsc' - 'invtsc' removed from 'cpuflags-kvm' on the target for a VM with 'host,flags=+hv-reenlightenment' on a source with invtsc: blocked, with override - 'invtsc' removed from 'cpuflags-kvm' on the target for a VM with a custom CPU model with '+invtsc' and a reported model other than 'host', for example the default 'kvm64': blocked, without override. With reported model 'host', it is blocked like other flags missing for 'host', so it can be overridden. VMs with CPU type 'host' do not have invtsc unless enabled explicitly or due to an explicit TSC frequency, so they are not blocked otherwise. - a VM with a custom CPU model with '+invtsc' that was started without an explicit TSC frequency, for example with 'args: -cpu kvm64,enforce,+invtsc' on a node with an invariant TSC: blocked for every target, until it is stopped and started without 'args'. The same applies to 'args: -cpu host,migratable=off'. - a VM with a custom CPU model with '+hv-reenlightenment' started with 'args: -cpu kvm64,+hv-reenlightenment': a warning for every target The invtsc support of a node requires a host CPU with an invariant TSC, which nested nodes only have if their own CPU has 'invtsc' enabled. After the upgrade, the "Supported On" column of the flag selector of the custom CPU model editor lists such nodes for invtsc. Changes since v3: * TSC helper: keep the result of each query if the other fails, and do not treat a failed capability check as a missing capability. Only cache complete results, and retry failed queries after ten minutes, as pvestatd now queries this in each cycle and each query creates a KVM VM and logs a warning on failure. Without /dev/kvm, return nothing and log nothing. Only query it on x86_64 hosts. Add tests. * restructure the commits: a preparatory commit lets checks only need information of the target, the generic handling of the TSC frequency flags is introduced with 'hv-reenlightenment', and the invtsc support of nodes is reported after their TSC information, so that the invtsc commit only adds the flag and its migration blocker * do not set an explicit TSC frequency for confidential VMs, as they cannot be live migrated, snapshotted with RAM or hibernated anyway, and QEMU refuses to start TDX VMs with a TSC frequency that is not a multiple of 25 MHz. A TDX VM with a custom CPU model enabling invtsc would otherwise fail to start after the upgrade. * check the target's TSC for any explicit TSC frequency of a running KVM VM, not only if 'hv-reenlightenment' or 'invtsc' is enabled, as QEMU sets it regardless * include invtsc in the check of the flags missing for 'host'/'max' if the vCPUs have it due to an explicit TSC frequency, as QEMU then passes it through * warn about VMs with 'hv-reenlightenment' that were started without an explicit TSC frequency, as their migration fails at the end if the guest enabled re-enlightenment notifications * detect the invtsc migration blocker via 'blocked-reasons' of 'query-migrate' instead of the CPU arguments, which miss 'host,migratable=off'. A failed query refuses the migration with a suggestion to try again, instead of one to restart the VM, but only if the vCPUs might have invtsc, as the CPU names it or as 'host' or 'max' run with 'migratable=off'. For other VMs, including 'host' and 'max' with the default 'migratable=on', it only warns. Only query it for x86 VMs. Confidential VMs are not checked at all, as with v4 of the series this builds on. * fix the 'cpu-warnings' schema of the precondition API, which lacked the 'tsc-frequency' type of the 'hv-reenlightenment' warning * only warn if a VM with invtsc is migrated to a node that lacks invtsc, but does not broadcast TSC information either, as it runs an older version, which does not report invtsc support. This applies to CPU models with 'enforce' as well as to 'host' and 'max'. * the message about an incompatible TSC frequency no longer claims that the tolerance is relative to the VM's frequency, as it is relative to the target's, and only names the flags the frequency was set for * if only the query for invtsc support fails, still broadcast the other CPU flags * report the TSC frequencies of the VM and the target as typed details in the precondition API, like v4 of the series it builds on does for the other checks. The TSC check does not need the TSC information of the source node. * docs: document the above, that affected VMs need to be stopped and started again, that confidential VMs get no explicit TSC frequency, and that targets without TSC information only cause a warning * reword the flag description, docs and comments of 'hv-reenlightenment': the pinned frequency avoids frequency changes instead of notifying the guest about them, and omitting 'hv-frequencies' does not lift the migration restriction * docs: spell out the time stamp counter (TSC), and mention that a '-cpu' option in 'args' must set the TSC frequency itself * tests: check that the override does not apply to a missing invtsc that QEMU enforces * rebased onto v4 of the series "check the target node's CPU before live migrating a VM" Changes since v2 (as part of the series "check the target node's CPU before live migrating a VM"): * split out into this series * new: refuse the live migration of VMs with invtsc that were started without an explicit TSC frequency, for example before the update, upfront. QEMU blocks their migration anyway, but only after the target instance was started and local disks were copied. Whether the vCPUs have invtsc is queried from QEMU, as 'host' and 'max' drop it if the host lacks it. * describe in the flag description, the commit message and the docs that guests only use 'hv-reenlightenment' together with 'hv-frequencies' * tests: use the helper for the migration tests of the CPU checks, and add tests for the edge of the TSC tolerance and invtsc with TCG * new: cfg2cmd test for a disabled 'hv-reenlightenment' flag * docs: mention that VMs started without an explicit TSC frequency need a restart before they can be live migrated * fix the trailing newline of the invtsc cfg2cmd test * rebased onto current master Changes since v1 (as part of the series "check the target node's CPU before live migrating a VM"): * new: report the invtsc support of nodes * new: set the TSC frequency for invtsc, as for 'hv-reenlightenment', so that such VMs can be live migrated, and extend the TSC check of the target node to it * new: docs for 'hv-reenlightenment' and invtsc qemu-server: Jonas Theisen (6): helpers: add helper to query the host's TSC frequency and scaling support migrate: allow CPU checks that only need information of the target cpu config: add hv-reenlightenment flag and set TSC frequency for it migrate: block migration to nodes that cannot provide the TSC frequency cpu flags: report invtsc support of nodes cpu config: set TSC frequency for invtsc to allow live migration src/PVE/API2/Qemu.pm | 9 +- src/PVE/QemuMigrate/Helpers.pm | 232 ++++++++++++- src/PVE/QemuServer.pm | 19 ++ src/PVE/QemuServer/CPUConfig.pm | 32 ++ src/PVE/QemuServer/CPUFlags.pm | 8 + src/PVE/QemuServer/Helpers.pm | 106 ++++++ src/test/Makefile | 5 +- src/test/MigrationTest/QemuMigrateMock.pm | 27 +- src/test/QemuServerTest/CommandLineMocks.pm | 10 + .../cpu-custom-hv-reenlightenment.conf | 6 + .../cpu-custom-hv-reenlightenment.conf.cmd | 26 ++ .../cpu-hv-reenlightenment-disabled.conf | 6 + .../cpu-hv-reenlightenment-disabled.conf.cmd | 26 ++ src/test/cfg2cmd/cpu-hv-reenlightenment.conf | 6 + .../cfg2cmd/cpu-hv-reenlightenment.conf.cmd | 26 ++ src/test/cfg2cmd/cpu-invtsc.conf | 6 + src/test/cfg2cmd/cpu-invtsc.conf.cmd | 27 ++ src/test/cfg2cmd/tdx-cpu-invtsc.conf | 9 + src/test/cfg2cmd/tdx-cpu-invtsc.conf.cmd | 30 ++ src/test/cfg2cmd/tdx-hv-reenlightenment.conf | 9 + .../cfg2cmd/tdx-hv-reenlightenment.conf.cmd | 30 ++ src/test/run_api_tests.pl | 42 ++- src/test/run_host_tsc_tests.pl | 133 ++++++++ src/test/run_qemu_migrate_tests.pl | 315 +++++++++++++++++- 24 files changed, 1120 insertions(+), 25 deletions(-) create mode 100644 src/test/cfg2cmd/cpu-custom-hv-reenlightenment.conf create mode 100644 src/test/cfg2cmd/cpu-custom-hv-reenlightenment.conf.cmd create mode 100644 src/test/cfg2cmd/cpu-hv-reenlightenment-disabled.conf create mode 100644 src/test/cfg2cmd/cpu-hv-reenlightenment-disabled.conf.cmd create mode 100644 src/test/cfg2cmd/cpu-hv-reenlightenment.conf create mode 100644 src/test/cfg2cmd/cpu-hv-reenlightenment.conf.cmd create mode 100644 src/test/cfg2cmd/cpu-invtsc.conf create mode 100644 src/test/cfg2cmd/cpu-invtsc.conf.cmd create mode 100644 src/test/cfg2cmd/tdx-cpu-invtsc.conf create mode 100644 src/test/cfg2cmd/tdx-cpu-invtsc.conf.cmd create mode 100644 src/test/cfg2cmd/tdx-hv-reenlightenment.conf create mode 100644 src/test/cfg2cmd/tdx-hv-reenlightenment.conf.cmd create mode 100755 src/test/run_host_tsc_tests.pl docs: Jonas Theisen (1): qm: document hv-reenlightenment and invtsc qm.adoc | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) Summary over all repositories: 25 files changed, 1149 insertions(+), 25 deletions(-) -- Generated by murpp 0.12.1