From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 74BB81FF0B7 for ; Mon, 30 Nov 2026 19:34:26 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 7B0FA20AA2; Mon, 30 Nov 2026 19:34:24 +0100 (CET) From: Jonas Theisen To: pve-devel@lists.proxmox.com Subject: [PATCH docs/qemu-server v3 0/6] live migrate VMs with an invariant TSC or re-enlightenment Date: Mon, 30 Nov 2026 19:34:07 +0100 Message-ID: <20261130183418.617530-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: 1796063658599 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.060 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: OEP4MFZKT2WGAMQZJWV4VUBHHVS5UIOR X-Message-ID-Hash: OEP4MFZKT2WGAMQZJWV4VUBHHVS5UIOR 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. It notifies nested Hyper-V guests, for example Windows with WSL2 or VBS, about TSC frequency changes from live migrations. Together with 'hv-frequencies', which custom CPU models can enable, this lets them keep a stable clock source for their own guests. Without it, guests do not use the notifications. 'hv-frequencies' is not enabled by this series. The flag is added in preparation for 'hv-frequencies' to become usable. For both flags, the TSC frequency is set explicitly to the host's, which is queried via KVM_GET_TSC_KHZ on a temporary VM, as upstream Linux does not export it otherwise. 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: - 'hv-reenlightenment' or 'invtsc', target can neither scale the TSC nor match the VM's TSC frequency within 250 ppm - '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 restarted. The precondition API reports both with the new 'tsc-frequency' type in 'incompatible-cpu'. pve-manager needs no changes, as pvestatd broadcasts whatever qemu-server provides. [0] cover letter of "[PATCH docs/manager/qemu-server v3 00/18] check the target node's CPU before live migrating a VM" 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 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, so they are not blocked. - 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 restarted without 'args' 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 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 (5): cpu flags: report invtsc support of nodes helpers: add helper to query the host's TSC frequency and scaling support cpu config: add hv-reenlightenment flag and set TSC frequency for it migrate: block migration to nodes with incompatible TSC for re-enlightenment cpu config: set TSC frequency for invtsc to allow live migration src/PVE/API2/Qemu.pm | 8 +- src/PVE/QemuMigrate/Helpers.pm | 82 +++++++++- src/PVE/QemuServer.pm | 15 ++ src/PVE/QemuServer/CPUConfig.pm | 35 +++++ src/PVE/QemuServer/CPUFlags.pm | 8 + src/PVE/QemuServer/Helpers.pm | 65 ++++++++ src/test/MigrationTest/QemuMigrateMock.pm | 12 +- src/test/QemuServerTest/CommandLineMocks.pm | 7 + .../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/run_api_tests.pl | 23 ++- src/test/run_qemu_migrate_tests.pl | 144 +++++++++++++++++- 16 files changed, 488 insertions(+), 8 deletions(-) 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 docs: Jonas Theisen (1): qm: document hv-reenlightenment and invtsc qm.adoc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) Summary over all repositories: 17 files changed, 512 insertions(+), 8 deletions(-) -- Generated by murpp 0.12.1