all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [PATCH docs/manager/qemu-server v2 00/20] check the target node's CPU before live migrating a VM
@ 2026-11-24 16:30 Jonas Theisen
  2026-11-24 16:30 ` [PATCH qemu-server v2 01/20] test: migration: allow checking for warnings and errors in the log Jonas Theisen
                   ` (19 more replies)
  0 siblings, 20 replies; 21+ messages in thread
From: Jonas Theisen @ 2026-11-24 16:30 UTC (permalink / raw)
  To: pve-devel

Live migrations of running VMs can currently fail late, or seem to
succeed and leave the guest unstable, if the target node's CPU cannot
run the VM's virtual CPU. This series checks the target's CPU upfront,
reports the result in the migration precondition API, and refuses
migrations that cannot work.

The checks use CPU information each node broadcasts to the cluster. The
already existing 'cpuflags-kvm' node key-value entry provides the flags
KVM supports. The new 'host-cpu-info' entry, broadcast by pvestatd,
provides the CPU vendor and model name, TSC frequency and TSC scaling
support. The checks are only done for running VMs, as stopped VMs get
a virtual CPU based on the target node, and they operate on the QEMU
CPU of the running instance, so they also cover custom CPU models.

Checks that block the migration:

- 'host'/'max' CPU model, target has a different CPU vendor
- fix #2924: 'host'/'max' CPU model, target lacks KVM CPU flags of the
  source. As the source flags only approximate those of the VM, root
  can override this with the new 'allow-missing-cpu-flags' option.
  'force' is not reused, as the HA stack always sets it. Instead, the
  new option is forwarded to the HA stack like other migration options.
  The migration dialog offers it as an "Ignore CPU incompatibility"
  checkbox for root, also for HA-managed VMs. Only flags that QEMU
  recognizes are compared, as the broadcast also includes other CPU
  properties that can differ between QEMU versions.
- any CPU model other than 'host'/'max', for example 'x86-64-v3',
  'Skylake-Server' or a custom model: KVM on the target does not
  support an enabled Hyper-V enlightenment (for example the Intel-only
  'hv-evmcs' on an AMD target), or, as PVE sets 'enforce' for these
  models, any other enabled flag. This includes the flags the QEMU CPU
  model enables by default, which are queried from QEMU of the running
  VM. Abstracted CPU configurations (custom model, 'nested-virt', ...)
  keep the running QEMU CPU on the target, the others get the same
  flags from the configuration.
- new 'hv-reenlightenment' flag or 'invtsc', target can neither scale
  the TSC nor match the source's TSC frequency within 250 ppm

Checks that only warn, as a task warning and in the precondition API:

- fix #6535: live migration between CPU vendors with any other model
- 'host'/'max' CPU model, target has a different CPU model name
- the target does not broadcast the CPU information a blocking check
  needs, for example as it runs an older version. Such nodes are not
  blocked, as it is unknown whether they are compatible.

HA-managed VMs:

The checks run in the migration task, so they also apply to migrations
by the HA stack. For a migration requested via the API, the CPU of the
target is now also checked before handing it over to the HA stack, so
the API call fails with the reason directly, instead of only the LRM's
migration task failing later.

Migrations that the HA stack starts on its own, for maintenance mode,
the 'migrate' shutdown policy or automatic rebalancing, do not use the
override option and fail in the migration task. The HA stack currently
retries such failed migrations without backoff and without avoiding
the failing target, see bug #8059 [0]. Without this series, they fail
as well, but only after preparing the migration, or for 'host'/'max'
seem to succeed and leave the guest unstable.

[0] https://bugzilla.proxmox.com/show_bug.cgi?id=8059

The 'hv-reenlightenment' flag is added as part of this series. It lets
nested Hyper-V guests, for example Windows with WSL2 or VBS, keep
a stable clock source across live migrations. For it, 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 same is done for the invariant TSC flag 'invtsc', which 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.
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.

API changes of the migrate precondition endpoint:

- 'incompatible-cpu' in 'not_allowed_nodes', listing the type, message
  and possible override option of each blocking incompatibility
- 'cpu-warnings', listing the warnings per node

The migration tests are extended to check for expected warnings in the
log, and cover each of the checks.

Dependencies: pve-manager's pvestatd patch uses
PVE::QemuServer::Helpers::get_host_cpu_info(), so it needs a bumped
qemu-server. Without it, qemu-server still works and runs the checks
based on the already broadcast CPU flags, but warns about the missing
CPU information.

The 'allow-missing-cpu-flags' override option relies on the HA stack
accepting forwarded migration options, as introduced for
'with-conntrack-state' and 'skip-config-check'.

Testing:

Upgrading the packages reloads pvestatd, so that it broadcasts the new
'host-cpu-info' entry 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 checks can be tested on a cluster with identical CPUs by making the
target node broadcast different CPU information. Unless noted
otherwise, run the following on the target node.

pvestatd broadcasts 'host-cpu-info' again whenever it differs, so stop
it first. Choose a 'tsc-khz' clearly different from the real one, as
the TSC check tolerates 250 ppm:

  systemctl stop pvestatd
  perl -MPVE::Cluster -e 'PVE::Cluster::broadcast_node_kv("host-cpu-info", q({"vendor":"GenuineIntel","model-name":"Fake CPU","tsc-khz":1000000,"tsc-scaling":0}))'

The 'cpuflags-kvm' entry is only broadcast again when the QEMU version
changes, so it can be changed while pvestatd runs. The following
removes the flags listed in REMOVE and adds the ones listed in ADD:

  REMOVE='avx512f sha-ni' ADD='' perl -MPVE::Cluster -MPVE::INotify -e '
      PVE::Cluster::cfs_update();
      my $node = PVE::INotify::nodename();
      my $flags = PVE::Cluster::get_node_kv("cpuflags-kvm", $node)->{$node};
      my %remove = map { $_ => 1 } split(" ", $ENV{REMOVE});
      my @flags = grep { !$remove{$_} } split(" ", $flags);
      push @flags, split(" ", $ENV{ADD});
      PVE::Cluster::broadcast_node_kv("cpuflags-kvm", join(" ", @flags));
  '

Restarting pvestatd broadcasts the real values of both entries again:

  systemctl restart pvestatd

The results show up in the precondition API, in the migration dialog,
and in the task log of 'qm migrate <vmid> <target> --online'. Disk-less
VMs suffice for live migration tests. The source node must be able to
start the VM, so it must support the flags of the tested CPU model.

  pvesh get /nodes/<source>/qemu/<vmid>/migrate --output-format json-pretty

What to expect for a running VM:

- vendor 'GenuineIntel' on an AMD cluster (or vice versa): blocked for
  CPU type 'host'/'max', a warning for other CPU types
- a different 'model-name': a warning for CPU type 'host'/'max'
- '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'
- flags removed from 'cpuflags-kvm': blocked for CPU type 'host'/'max',
  unless '--allow-missing-cpu-flags' is set, also for HA-managed VMs
- properties that are no CPU flags added to 'cpuflags-kvm' of the
  source, for example ADD='x-test-property' run on the source node: not
  blocked
- flags removed that a VM with a CPU model other than 'host'/'max'
  uses: blocked, without override. For example 'avx2' for 'x86-64-v3',
  'avx512f' for 'Skylake-Server', which that model enables by default,
  or 'hv-stimer' for 'x86-64-v2-AES' with ostype 'win11'.
- 'invtsc' removed 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.
- an empty 'host-cpu-info' value: a 'missing-cpu-info' warning for VMs
  where a blocking check needs the information
- a stopped VM: no CPU checks, as it gets a virtual CPU based on the
  target node

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.

For an HA-managed VM, 'qm migrate <vmid> <target> --online' to a node
with an incompatible CPU fails right away with the reason, instead of
requesting the migration from the HA stack. With
'--allow-missing-cpu-flags' and only missing flags for 'host'/'max',
the HA stack migrates the VM, and the migration task logs the ignored
incompatibility.

The "Ignore CPU incompatibility" checkbox of the migration dialog is
only shown for root, and the API refuses 'allow-missing-cpu-flags' for
other users.

The bulk migration of a node ("Bulk Migrate", 'pvenode migrateall')
skips VMs whose target is blocked, and logs the reason as "Has
incompatible CPU". It does not offer the override, so it also skips
VMs that are only blocked due to missing flags for 'host'/'max'.

Changes since v1:
* fix #2924 patch: only compare flags that QEMU recognizes as CPUID
  flags. The broadcast flags also include other CPU properties, such as
  'migratable' or 'l3-cache', which can differ between QEMU versions
  and would block live migration between nodes running different QEMU
  versions.
* extend the check of the flags of the kept virtual CPU to all CPU
  models other than 'host'/'max', for example 'x86-64-v3'. These are
  generated again from the configuration on the target, but with the
  same flags, and QEMU refuses to start if one is missing, as PVE sets
  'enforce' for them. The flags the QEMU CPU model enables by default
  are now included as well. The 'kept-cpu-flags' type of the
  precondition API is renamed to 'vm-cpu-flags' accordingly.
* 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: check the CPU of the target in the migrate API before
  requesting a migration of an HA-managed VM from the HA stack, with
  a preparatory patch that factors out the check
* new: docs patch for the checks, 'hv-reenlightenment' and invtsc
* add 'Fixes:' trailers with the bug report URLs
* pvestatd patch: drop the error handling for querying the host CPU
  information, as qemu-server already handles the only query that can
  fail
* rebased onto current master


qemu-server:

Jonas Theisen (15):
  test: migration: allow checking for warnings and errors in the log
  migrate: block live migration of host CPU VMs between CPU vendors
  fix #6535: migrate: warn about live migration between CPU vendors
  cpu flags: factor out parsing the broadcast CPU flags of a node
  fix #2924: migrate: block live migration of host CPU VMs to nodes
    lacking flags
  migrate: warn about live migration of host CPU VMs between CPU models
  migrate: factor out whether the running virtual CPU is kept
  migrate: block migration if the target cannot run the virtual CPU
  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
  migrate: factor out asserting the CPU compatibility of the target
  api: migrate: check the CPU of the target before requesting HA
    migration

 src/PVE/API2/Qemu.pm                          |  114 +-
 src/PVE/QemuMigrate.pm                        |   11 +-
 src/PVE/QemuMigrate/Helpers.pm                |  437 +++++++
 src/PVE/QemuServer.pm                         |   14 +
 src/PVE/QemuServer/CPUConfig.pm               |   35 +
 src/PVE/QemuServer/CPUFlags.pm                |   29 +-
 src/PVE/QemuServer/Helpers.pm                 |   99 ++
 src/test/MigrationTest/QemuMigrateMock.pm     |   52 +
 src/test/QemuServerTest/CommandLineMocks.pm   |    7 +
 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_qemu_migrate_tests.pl            | 1033 +++++++++++++++++
 14 files changed, 1887 insertions(+), 9 deletions(-)
 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


pve-manager:

Jonas Theisen (4):
  pvestatd: broadcast host CPU information relevant for live migration
  ui: migrate: show why the CPU of the target node is incompatible
  fix #6535: ui: migrate: show CPU warnings for the target node
  api: nodes: migrateall: skip VMs whose CPU is incompatible with the
    target

 PVE/API2/Nodes.pm              |  5 +++
 PVE/Service/pvestatd.pm        | 15 ++++++++
 www/manager6/window/Migrate.js | 63 ++++++++++++++++++++++++++++++++++
 3 files changed, 83 insertions(+)


pve-docs:

Jonas Theisen (1):
  qm: document hv-reenlightenment, invtsc and CPU checks for migration

 qm.adoc | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)


Summary over all repositories:
  18 files changed, 2021 insertions(+), 9 deletions(-)

-- 
Generated by murpp 0.12.1




^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH qemu-server v2 01/20] test: migration: allow checking for warnings and errors in the log
  2026-11-24 16:30 [PATCH docs/manager/qemu-server v2 00/20] check the target node's CPU before live migrating a VM Jonas Theisen
@ 2026-11-24 16:30 ` Jonas Theisen
  2026-11-24 16:30 ` [PATCH qemu-server v2 02/20] migrate: block live migration of host CPU VMs between CPU vendors Jonas Theisen
                   ` (18 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Jonas Theisen @ 2026-11-24 16:30 UTC (permalink / raw)
  To: pve-devel

So far, the log is only checked for the error message of a migration
that is expected to fail. Allow tests to also check that a migration
logs certain warnings, as the migration continues in these cases and
the result alone does not show whether the warning was issued.

Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
 src/test/run_qemu_migrate_tests.pl | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/test/run_qemu_migrate_tests.pl b/src/test/run_qemu_migrate_tests.pl
index 1936812e..07dbf02c 100755
--- a/src/test/run_qemu_migrate_tests.pl
+++ b/src/test/run_qemu_migrate_tests.pl
@@ -534,6 +534,8 @@ my $tests = [
     #                  to be made if the migration gets far enough
     # expect_die     - expect the migration call to fail, and an error message
     #                  matching the specified text in the log
+    # expect_log     - list of texts that each must be present in a warning or
+    #                  error message in the log
     # expected       - hash consisting of:
     #                  source_volids    - hash of volids expected on the source
     #                  target_volids    - hash of volids expected on the target
@@ -1942,6 +1944,15 @@ foreach my $test (@{$tests}) {
         note("mocked migrate call failed, but it was not expected - check log");
     }
 
+    if (my $expect_log = $test->{expect_log}) {
+        my @lines = split(/\n/, file_get_contents("${run_dir}/log"));
+        for my $text ($expect_log->@*) {
+            next if grep { m/^(?:err|warn):.*\Q${text}\E/ } @lines;
+            fail($name);
+            note("expected message '$text' is not present in log");
+        }
+    }
+
     my $expected_calls = decode_json(file_get_contents("${run_dir}/expected_calls"));
     foreach my $call (keys %{$expected_calls}) {
         fail($name);
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH qemu-server v2 02/20] migrate: block live migration of host CPU VMs between CPU vendors
  2026-11-24 16:30 [PATCH docs/manager/qemu-server v2 00/20] check the target node's CPU before live migrating a VM Jonas Theisen
  2026-11-24 16:30 ` [PATCH qemu-server v2 01/20] test: migration: allow checking for warnings and errors in the log Jonas Theisen
@ 2026-11-24 16:30 ` Jonas Theisen
  2026-11-24 16:30 ` [PATCH qemu-server v2 03/20] fix #6535: migrate: warn about live migration " Jonas Theisen
                   ` (17 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Jonas Theisen @ 2026-11-24 16:30 UTC (permalink / raw)
  To: pve-devel

The 'host' and 'max' CPU models pass the features of the host CPU
through to the guest, including vendor-specific ones. A guest that was
started on an AMD CPU is likely to crash after a live migration to an
Intel CPU, or vice versa, as the CPU it detected during boot changed
underneath it.

Check this before the migration, based on CPU information that each
node broadcasts to the cluster as the 'host-cpu-info' node key-value
entry, which pvestatd needs to do. Report such nodes as not allowed in
the migration precondition API, so they can be shown as such before
the migration is started, and refuse to migrate to them. Nodes that do
not broadcast the information, for example because they run an older
version, are not blocked, as it is unknown whether they are
compatible, but a warning is logged. It counts as a task warning, so
that the task status shows it.

The checks are defined in a list, so that further combinations of VM
CPU settings and node CPUs that cannot work, or are known to be prone
to problems, can be added easily. They are only done for running VMs,
as stopped VMs are started with a virtual CPU based on the target
node, and operate on the QEMU CPU of the running instance, so they
also apply to settings from custom CPU models. With TCG, the 'max'
model is fully emulated and therefore not affected.

Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
 src/PVE/API2/Qemu.pm                      |  41 ++++++-
 src/PVE/QemuMigrate.pm                    |  19 +++
 src/PVE/QemuMigrate/Helpers.pm            | 141 ++++++++++++++++++++++
 src/PVE/QemuServer/Helpers.pm             |  31 +++++
 src/test/MigrationTest/QemuMigrateMock.pm |  32 +++++
 src/test/run_qemu_migrate_tests.pl        | 114 +++++++++++++++++
 6 files changed, 377 insertions(+), 1 deletion(-)

diff --git a/src/PVE/API2/Qemu.pm b/src/PVE/API2/Qemu.pm
index 2119e69e..f27f32c6 100644
--- a/src/PVE/API2/Qemu.pm
+++ b/src/PVE/API2/Qemu.pm
@@ -5599,6 +5599,27 @@ __PACKAGE__->register_method({
                                 description => 'The config key of a mapped resource',
                             },
                         },
+                        'incompatible-cpu' => {
+                            description =>
+                                "Reasons why the node's CPU cannot run the running VM"
+                                . " after a live migration.",
+                            type => 'array',
+                            optional => 1,
+                            items => {
+                                type => 'object',
+                                properties => {
+                                    type => {
+                                        type => 'string',
+                                        description => "The check that failed.",
+                                        enum => ['cpu-vendor'],
+                                    },
+                                    message => {
+                                        type => 'string',
+                                        description => "Why the node's CPU is incompatible.",
+                                    },
+                                },
+                            },
+                        },
                         'blocking-ha-resources' => {
                             description => "HA resources, which are blocking the"
                                 . " VM from being migrated to the node.",
@@ -5716,7 +5737,8 @@ __PACKAGE__->register_method({
         # try to detect errors early
         PVE::QemuConfig->check_lock($vmconf);
 
-        $res->{running} = PVE::QemuServer::check_running($vmid) ? 1 : 0;
+        my $pid = PVE::QemuServer::check_running($vmid);
+        $res->{running} = $pid ? 1 : 0;
 
         my ($local_resources, $mapped_resources, $missing_mappings_by_node) =
             PVE::QemuMigrate::Helpers::check_local_resources($vmconf, $res->{running}, 1);
@@ -5746,6 +5768,16 @@ __PACKAGE__->register_method({
         my $has_identity = PVE::QemuConfig->has_stored_identity($vmid);
 
         my $nodelist = PVE::Cluster::get_nodelist();
+
+        my $cpu_issues_by_node = eval {
+            my $targets = [grep { $_ ne $localnode } $nodelist->@*];
+            my ($issues) = PVE::QemuMigrate::Helpers::check_target_cpu_compatibility(
+                $vmconf, $pid, $targets,
+            );
+            return $issues;
+        } // {};
+        warn "unable to check CPU compatibility of target nodes - $@" if $@;
+
         for my $node ($nodelist->@*) {
             next if $node eq $localnode;
 
@@ -5761,6 +5793,13 @@ __PACKAGE__->register_method({
                     $missing_mappings;
             }
 
+            my @cpu_errors =
+                grep { $_->{severity} eq 'error' } ($cpu_issues_by_node->{$node} // [])->@*;
+            if (scalar(@cpu_errors)) {
+                $res->{not_allowed_nodes}->{$node}->{'incompatible-cpu'} =
+                    [map { { type => $_->{type}, message => $_->{message} } } @cpu_errors];
+            }
+
             # extracting blocking resources for current node
             if (my $blocking_ha_resources = $blocking_ha_resources_by_node->{$node}) {
                 $res->{not_allowed_nodes}->{$node}->{'blocking-ha-resources'} =
diff --git a/src/PVE/QemuMigrate.pm b/src/PVE/QemuMigrate.pm
index 67b72598..4567716c 100644
--- a/src/PVE/QemuMigrate.pm
+++ b/src/PVE/QemuMigrate.pm
@@ -18,6 +18,7 @@ use PVE::GuestHelpers qw(safe_boolean_ne safe_string_ne);
 use PVE::GuestID;
 use PVE::INotify;
 use PVE::JSONSchema;
+use PVE::RESTEnvironment qw(log_warn);
 use PVE::RPCEnvironment;
 use PVE::Replication;
 use PVE::ReplicationConfig;
@@ -323,6 +324,24 @@ sub prepare {
         }
     }
 
+    # nodes of other clusters do not broadcast their CPU information to this cluster
+    if (!$self->{opts}->{remote}) {
+        my $node = $self->{node};
+        my ($cpu_issues, $unchecked_nodes) =
+            PVE::QemuMigrate::Helpers::check_target_cpu_compatibility($conf, $running, [$node]);
+
+        my @errors = grep { $_->{severity} eq 'error' } ($cpu_issues->{$node} // [])->@*;
+        if (scalar(@errors)) {
+            die "can't migrate VM to '$node' - incompatible CPU: "
+                . join('; ', map { $_->{message} } @errors) . "\n";
+        }
+
+        if (scalar($unchecked_nodes->@*)) {
+            log_warn("unable to check CPU compatibility of node '$node' - CPU information not"
+                . " available");
+        }
+    }
+
     my $vollist = PVE::QemuServer::get_vm_volumes($conf);
 
     my $storages = {};
diff --git a/src/PVE/QemuMigrate/Helpers.pm b/src/PVE/QemuMigrate/Helpers.pm
index 466517da..f4f15b96 100644
--- a/src/PVE/QemuMigrate/Helpers.pm
+++ b/src/PVE/QemuMigrate/Helpers.pm
@@ -6,11 +6,15 @@ use warnings;
 use JSON;
 
 use PVE::Cluster;
+use PVE::INotify;
 use PVE::JSONSchema qw(parse_property_string);
 use PVE::Mapping::Dir;
 use PVE::Mapping::PCI;
 use PVE::Mapping::USB;
 
+use PVE::QemuServer::CPUConfig;
+use PVE::QemuServer::CPUFlags;
+use PVE::QemuServer::Helpers;
 use PVE::QemuServer::Monitor qw(mon_cmd);
 use PVE::QemuServer::Virtiofs;
 
@@ -113,6 +117,143 @@ sub check_local_resources {
     return wantarray ? (\@loc_res, $mapped_res, $missing_mappings_by_node) : \@loc_res;
 }
 
+# Returns the CPU information the node broadcasts, see get_host_cpu_info() in
+# PVE::QemuServer::Helpers. Information the node does not broadcast is missing.
+my sub get_node_cpu_info {
+    my ($node) = @_;
+
+    my $raw = PVE::Cluster::get_node_kv('host-cpu-info', $node)->{$node};
+    my $info = defined($raw) ? eval { decode_json($raw) } : undef;
+
+    return ref($info) eq 'HASH' ? $info : {};
+}
+
+# Parses a QEMU '-cpu' argument into the CPU model and its properties. Flags given without a value
+# are stored as 'on' or 'off'.
+my sub parse_qemu_cpu_string {
+    my ($cpu_str) = @_;
+
+    my ($model, @options) = split(/,/, $cpu_str);
+
+    my $props = {};
+    for my $option (@options) {
+        my ($op, $name, $value) = $option =~ m/^([+-]?)([^=]+)(?:=(.*))?$/ or next;
+        # QEMU accepts both underscores and dashes in property names, and some aliases
+        $name =~ s/_/-/g;
+        $name = PVE::QemuServer::CPUFlags::normalize_cpu_flag($name);
+        $value = $op eq '-' ? 'off' : 'on' if !defined($value);
+        $props->{$name} = $value;
+    }
+
+    return { model => $model, props => $props };
+}
+
+my sub is_host_cpu_model {
+    my ($cpu) = @_;
+    # with TCG, 'max' is fully emulated instead of passing through the host CPU
+    return $cpu->{model} eq 'host' || ($cpu->{model} eq 'max' && $cpu->{kvm});
+}
+
+my sub vendors_differ {
+    my ($source, $target) = @_;
+
+    my ($source_vendor, $target_vendor) = ($source->{vendor}, $target->{vendor});
+    return defined($source_vendor) && defined($target_vendor) && $source_vendor ne $target_vendor;
+}
+
+# Checks whether the CPU of a target node can run a running VM after a live migration.
+#
+# 'applies' returns true if the check is relevant for the VM's CPU, as parsed by
+# parse_qemu_cpu_string(), with 'kvm' set if the VM uses KVM. 'needs' lists the CPU information
+# of the target node the check requires, nodes lacking any of it are skipped. 'check' returns why
+# the target node is incompatible, if it is. With the 'error' severity, an incompatibility
+# prevents the migration, with 'warning' it is only reported.
+my $target_cpu_checks = [
+    {
+        type => 'cpu-vendor',
+        severity => 'error',
+        needs => ['vendor'],
+        applies => sub {
+            my ($cpu) = @_;
+            # these models pass through the host CPU, including vendor-specific features
+            return is_host_cpu_model($cpu);
+        },
+        check => sub {
+            my ($cpu, $source, $target) = @_;
+
+            return if !vendors_differ($source, $target);
+
+            return "CPU model '$cpu->{model}' requires the same CPU vendor as on the source"
+                . " node ($source->{vendor}), but the node has $target->{vendor}";
+        },
+    },
+];
+
+# Returns the issues of the target node, and whether all checks that can prevent the migration
+# were done.
+my sub get_target_cpu_issues {
+    my ($cpu, $checks, $source_info, $target_info) = @_;
+
+    my ($issues, $complete) = ([], 1);
+    for my $check ($checks->@*) {
+        if (grep { !defined($target_info->{$_}) } $check->{needs}->@*) {
+            $complete = 0 if $check->{severity} eq 'error';
+            next;
+        }
+
+        my $message = $check->{check}->($cpu, $source_info, $target_info) or next;
+        push $issues->@*,
+            { type => $check->{type}, severity => $check->{severity}, message => $message };
+    }
+
+    return ($issues, $complete);
+}
+
+=head3 check_target_cpu_compatibility
+
+    my ($issues_by_node, $unchecked_nodes) = check_target_cpu_compatibility($conf, $pid, $nodes);
+
+Checks whether the VM with the configuration C<$conf>, running with the process ID C<$pid>, can
+run with its current virtual CPU on each node of C<$nodes>, based on the CPU information the
+nodes broadcast. Only applies to running VMs, as stopped VMs are started with a virtual CPU
+matching the target node.
+
+Returns a hash reference with the list of issues for each node that has any, and an array
+reference with the nodes that could not be checked for issues preventing the migration, because
+they lack the required CPU information, for example as they run an older version. Each issue is
+a hash with a C<type> identifying the check, a C<severity> of C<error> if the VM cannot run on
+the node or C<warning> if it might not, and a human-readable C<message>.
+
+=cut
+
+sub check_target_cpu_compatibility {
+    my ($conf, $pid, $nodes) = @_;
+
+    return ({}, []) if !$pid;
+
+    my $cpu = parse_qemu_cpu_string(PVE::QemuServer::CPUConfig::get_cpu_from_running_vm($pid));
+    $cpu->{kvm} = $conf->{kvm} // 1;
+
+    my $checks = [grep { $_->{applies}->($cpu) } $target_cpu_checks->@*];
+    return ({}, []) if !scalar($checks->@*);
+
+    # Use what this node broadcasts, as for the target nodes. The local pvestatd might not
+    # broadcast it yet, for example if it was not restarted after an upgrade.
+    my $source_info = get_node_cpu_info(PVE::INotify::nodename());
+    $source_info = PVE::QemuServer::Helpers::get_host_cpu_info() if !scalar(keys $source_info->%*);
+
+    my ($issues_by_node, $unchecked_nodes) = ({}, []);
+    for my $node ($nodes->@*) {
+        my $target_info = get_node_cpu_info($node);
+
+        my ($issues, $complete) = get_target_cpu_issues($cpu, $checks, $source_info, $target_info);
+        $issues_by_node->{$node} = $issues if scalar($issues->@*);
+        push $unchecked_nodes->@*, $node if !$complete;
+    }
+
+    return ($issues_by_node, $unchecked_nodes);
+}
+
 sub set_migration_caps {
     my ($vmid, $savevm) = @_;
 
diff --git a/src/PVE/QemuServer/Helpers.pm b/src/PVE/QemuServer/Helpers.pm
index 644287bc..b15599bb 100644
--- a/src/PVE/QemuServer/Helpers.pm
+++ b/src/PVE/QemuServer/Helpers.pm
@@ -364,4 +364,35 @@ sub get_host_phys_address_bits {
     return; # undef, cannot really do anything..
 }
 
+=head3 get_host_cpu_info
+
+    my $info = get_host_cpu_info();
+
+Returns the properties of this host's CPU that decide whether a running VM can be live-migrated
+to it. pvestatd broadcasts them to the cluster as the C<host-cpu-info> node key-value entry,
+encoded as JSON. The returned hash contains:
+
+=over
+
+=item C<vendor>: the CPU vendor ID, for example C<GenuineIntel> or C<AuthenticAMD>
+
+=back
+
+Properties that cannot be determined are missing. Consumers of the broadcast information must
+also handle properties that nodes running an older version do not provide yet.
+
+=cut
+
+sub get_host_cpu_info {
+    my $cpuinfo = PVE::ProcFSTools::read_cpuinfo();
+
+    # read_cpuinfo() reports values it cannot determine as 'unknown'
+    my $known = sub { $_[0] ne 'unknown' };
+
+    my $info = {};
+    $info->{vendor} = $cpuinfo->{vendor} if $known->($cpuinfo->{vendor});
+
+    return $info;
+}
+
 1;
diff --git a/src/test/MigrationTest/QemuMigrateMock.pm b/src/test/MigrationTest/QemuMigrateMock.pm
index 1d895c32..b91dc434 100644
--- a/src/test/MigrationTest/QemuMigrateMock.pm
+++ b/src/test/MigrationTest/QemuMigrateMock.pm
@@ -31,6 +31,7 @@ my $migrate_params = decode_json(file_get_contents("${RUN_DIR_PATH}/migrate_para
 my $test_vmid = $migrate_params->{vmid};
 my $test_target = $migrate_params->{target};
 my $test_opts = $migrate_params->{opts};
+my $test_cpu_info = $migrate_params->{cpu_info} // {};
 my $current_log = '';
 
 my $vm_stop_executed = 0;
@@ -116,6 +117,10 @@ $qemu_migrate_module->mock(
         my ($self, $level, $message) = @_;
         $current_log .= "$level: $message\n";
     },
+    log_warn => sub {
+        my ($message) = @_;
+        $current_log .= "warn: $message\n";
+    },
     mon_cmd => sub {
         my ($vmid, $command, %params) = @_;
 
@@ -225,8 +230,35 @@ $qemu_server_cpuconfig_module->mock(
     },
 );
 
+$MigrationTest::Shared::qemu_migrate_helpers_module->mock(
+    check_target_cpu_compatibility => sub {
+        my ($conf, $pid, $nodes) = @_;
+        # checking requires the running CPU, which most tests do not need to specify
+        return ({}, []) if $pid && !defined($vm_status->{runningcpu});
+        return $MigrationTest::Shared::qemu_migrate_helpers_module->original(
+            'check_target_cpu_compatibility')->(@_);
+    },
+);
+
+$MigrationTest::Shared::cluster_module->mock(
+    get_node_kv => sub {
+        my ($key, $node) = @_;
+        if ($key eq 'host-cpu-info') {
+            # the source node is 'pve0', without 'source' get_host_cpu_info() is used
+            my $info =
+                $node eq 'pve0' ? $test_cpu_info->{source} : $test_cpu_info->{nodes}->{$node};
+            return {} if !$info;
+            return { $node => encode_json($info) };
+        }
+        return {};
+    },
+);
+
 my $qemu_server_helpers_module = Test::MockModule->new("PVE::QemuServer::Helpers");
 $qemu_server_helpers_module->mock(
+    get_host_cpu_info => sub {
+        return { vendor => 'GenuineIntel' };
+    },
     vm_running_locally => sub {
         return $vm_status->{running} && !$vm_stop_executed;
     },
diff --git a/src/test/run_qemu_migrate_tests.pl b/src/test/run_qemu_migrate_tests.pl
index 07dbf02c..5067f0e3 100755
--- a/src/test/run_qemu_migrate_tests.pl
+++ b/src/test/run_qemu_migrate_tests.pl
@@ -530,6 +530,8 @@ my $tests = [
     # opts           - options for the migrate() call
     # target_volids  - hash of volids on the target at the beginning
     # vm_status      - hash with running, runningmachine and optionally runningcpu
+    # cpu_info       - hash with the CPU information of the 'source' node and of each
+    #                  other node in 'nodes'
     # expected_calls - hash whose keys are calls which are required
     #                  to be made if the migration gets far enough
     # expect_die     - expect the migration call to fail, and an error message
@@ -1477,6 +1479,117 @@ my $tests = [
             },
         },
     },
+    {
+        name => '1033_running_host_cpu_other_vendor',
+        target => 'pve1',
+        vmid => 1033,
+        vm_status => {
+            running => 1,
+            runningmachine => 'pc-q35-5.0+pve0',
+            runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+        },
+        cpu_info => {
+            source => { vendor => 'AuthenticAMD' },
+            nodes => {
+                pve1 => { vendor => 'GenuineIntel' },
+            },
+        },
+        opts => {
+            online => 1,
+        },
+        config_patch => {
+            cpu => 'host',
+        },
+        expected_calls => {},
+        expect_die => "can't migrate VM to 'pve1' - incompatible CPU: CPU model 'host' requires"
+            . " the same CPU vendor as on the source node (AuthenticAMD), but the node has"
+            . " GenuineIntel",
+        expected => {
+            source_volids => {},
+            target_volids => {},
+            vm_config => get_patched_config(1033, {
+                    cpu => 'host',
+            }),
+            vm_status => {
+                running => 1,
+                runningmachine => 'pc-q35-5.0+pve0',
+                runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+            },
+        },
+    },
+    {
+        name => '1033_running_host_cpu_target_without_cpu_info',
+        target => 'pve1',
+        vmid => 1033,
+        vm_status => {
+            running => 1,
+            runningmachine => 'pc-q35-5.0+pve0',
+            runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+        },
+        cpu_info => {
+            source => { vendor => 'AuthenticAMD' },
+        },
+        opts => {
+            online => 1,
+        },
+        config_patch => {
+            cpu => 'host',
+        },
+        expected_calls => $default_expected_calls_online,
+        expect_log => [
+            "unable to check CPU compatibility of node 'pve1' - CPU information not available",
+        ],
+        expected => {
+            source_volids => {},
+            target_volids => {},
+            vm_config => get_patched_config(1033, {
+                    cpu => 'host',
+            }),
+            vm_status => {
+                running => 1,
+                runningmachine => 'pc-q35-5.0+pve0',
+            },
+        },
+    },
+    {
+        name => '1033_running_max_cpu_tcg_other_vendor',
+        target => 'pve1',
+        vmid => 1033,
+        vm_status => {
+            running => 1,
+            runningmachine => 'pc-q35-5.0+pve0',
+            runningcpu => 'max',
+        },
+        cpu_info => {
+            source => { vendor => 'AuthenticAMD' },
+            nodes => {
+                pve1 => { vendor => 'GenuineIntel' },
+            },
+        },
+        opts => {
+            online => 1,
+        },
+        config_patch => {
+            cpu => 'max',
+            kvm => 0,
+        },
+        expected_calls => $default_expected_calls_online,
+        expected => {
+            source_volids => {},
+            target_volids => {},
+            vm_config => get_patched_config(
+                1033,
+                {
+                    cpu => 'max',
+                    kvm => 0,
+                },
+            ),
+            vm_status => {
+                running => 1,
+                runningmachine => 'pc-q35-5.0+pve0',
+            },
+        },
+    },
     {
         name => '105_replicated_to_non_replication_target',
         target => 'pve1',
@@ -1898,6 +2011,7 @@ foreach my $test (@{$tests}) {
         target => $test->{target},
         vmid => $test->{vmid},
         opts => $test->{opts},
+        cpu_info => $test->{cpu_info},
     };
 
     file_set_contents("${run_dir}/nbd_info", to_json({}));
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH qemu-server v2 03/20] fix #6535: migrate: warn about live migration between CPU vendors
  2026-11-24 16:30 [PATCH docs/manager/qemu-server v2 00/20] check the target node's CPU before live migrating a VM Jonas Theisen
  2026-11-24 16:30 ` [PATCH qemu-server v2 01/20] test: migration: allow checking for warnings and errors in the log Jonas Theisen
  2026-11-24 16:30 ` [PATCH qemu-server v2 02/20] migrate: block live migration of host CPU VMs between CPU vendors Jonas Theisen
@ 2026-11-24 16:30 ` Jonas Theisen
  2026-11-24 16:30 ` [PATCH qemu-server v2 04/20] cpu flags: factor out parsing the broadcast CPU flags of a node Jonas Theisen
                   ` (16 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Jonas Theisen @ 2026-11-24 16:30 UTC (permalink / raw)
  To: pve-devel

Live migrating a VM between nodes with CPUs from different vendors is
not guaranteed to work, even with generic CPU models that do not pass
through vendor-specific features, as the CPUs still behave differently
in some regards.

Warn about this in the migration task, as a task warning so that the
task status shows it, and report it for each node in the migration
precondition API, so that it can be shown before the migration is
started. As before, VMs with the 'host' or 'max' CPU model cannot be
live migrated between vendors at all.

Also report nodes that lack the CPU information needed for a check
that would block the migration as a warning in the precondition API,
as the task log only shows this once the migration is started. This
is not done for other checks, to not warn about every live migration
to nodes running an older version.

Fixes: https://bugzilla.proxmox.com/show_bug.cgi?id=6535
Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
 src/PVE/API2/Qemu.pm               | 42 +++++++++++++++++++++++++++---
 src/PVE/QemuMigrate.pm             |  9 ++++++-
 src/PVE/QemuMigrate/Helpers.pm     | 19 ++++++++++++++
 src/test/run_qemu_migrate_tests.pl | 33 +++++++++++++++++++++++
 4 files changed, 99 insertions(+), 4 deletions(-)

diff --git a/src/PVE/API2/Qemu.pm b/src/PVE/API2/Qemu.pm
index f27f32c6..eab549f5 100644
--- a/src/PVE/API2/Qemu.pm
+++ b/src/PVE/API2/Qemu.pm
@@ -5697,6 +5697,29 @@ __PACKAGE__->register_method({
                 description =>
                     "Object of mapped resources with additional information such if they're live migratable.",
             },
+            'cpu-warnings' => {
+                type => 'object',
+                optional => 1,
+                description => "For each node, reasons why the VM might not run reliably on its"
+                    . " CPU after a live migration.",
+                additionalProperties => {
+                    type => 'array',
+                    items => {
+                        type => 'object',
+                        properties => {
+                            type => {
+                                type => 'string',
+                                description => "The check that reported the warning.",
+                                enum => ['cpu-vendor', 'missing-cpu-info'],
+                            },
+                            message => {
+                                type => 'string',
+                                description => "Why the VM might not run reliably.",
+                            },
+                        },
+                    },
+                },
+            },
             'has-dbus-vmstate' => {
                 type => 'boolean',
                 description => 'Whether the VM host supports migrating additional VM state, '
@@ -5771,9 +5794,15 @@ __PACKAGE__->register_method({
 
         my $cpu_issues_by_node = eval {
             my $targets = [grep { $_ ne $localnode } $nodelist->@*];
-            my ($issues) = PVE::QemuMigrate::Helpers::check_target_cpu_compatibility(
-                $vmconf, $pid, $targets,
-            );
+            my ($issues, $unchecked_nodes) =
+                PVE::QemuMigrate::Helpers::check_target_cpu_compatibility($vmconf, $pid, $targets);
+            my $message = "the node does not provide CPU information, for example as it runs"
+                . " an older version";
+            for my $node ($unchecked_nodes->@*) {
+                my $issue =
+                    { type => 'missing-cpu-info', severity => 'warning', message => $message };
+                push $issues->{$node}->@*, $issue;
+            }
             return $issues;
         } // {};
         warn "unable to check CPU compatibility of target nodes - $@" if $@;
@@ -5800,6 +5829,13 @@ __PACKAGE__->register_method({
                     [map { { type => $_->{type}, message => $_->{message} } } @cpu_errors];
             }
 
+            my @cpu_warnings =
+                grep { $_->{severity} eq 'warning' } ($cpu_issues_by_node->{$node} // [])->@*;
+            if (scalar(@cpu_warnings)) {
+                $res->{'cpu-warnings'}->{$node} =
+                    [map { { type => $_->{type}, message => $_->{message} } } @cpu_warnings];
+            }
+
             # extracting blocking resources for current node
             if (my $blocking_ha_resources = $blocking_ha_resources_by_node->{$node}) {
                 $res->{not_allowed_nodes}->{$node}->{'blocking-ha-resources'} =
diff --git a/src/PVE/QemuMigrate.pm b/src/PVE/QemuMigrate.pm
index 4567716c..c2653473 100644
--- a/src/PVE/QemuMigrate.pm
+++ b/src/PVE/QemuMigrate.pm
@@ -330,7 +330,14 @@ sub prepare {
         my ($cpu_issues, $unchecked_nodes) =
             PVE::QemuMigrate::Helpers::check_target_cpu_compatibility($conf, $running, [$node]);
 
-        my @errors = grep { $_->{severity} eq 'error' } ($cpu_issues->{$node} // [])->@*;
+        my @errors;
+        for my $issue (($cpu_issues->{$node} // [])->@*) {
+            if ($issue->{severity} eq 'warning') {
+                log_warn("CPU of node '$node' might be incompatible: $issue->{message}");
+            } else {
+                push @errors, $issue;
+            }
+        }
         if (scalar(@errors)) {
             die "can't migrate VM to '$node' - incompatible CPU: "
                 . join('; ', map { $_->{message} } @errors) . "\n";
diff --git a/src/PVE/QemuMigrate/Helpers.pm b/src/PVE/QemuMigrate/Helpers.pm
index f4f15b96..4e4e3ae0 100644
--- a/src/PVE/QemuMigrate/Helpers.pm
+++ b/src/PVE/QemuMigrate/Helpers.pm
@@ -187,6 +187,25 @@ my $target_cpu_checks = [
                 . " node ($source->{vendor}), but the node has $target->{vendor}";
         },
     },
+    {
+        type => 'cpu-vendor',
+        severity => 'warning',
+        needs => ['vendor'],
+        applies => sub {
+            my ($cpu) = @_;
+            return $cpu->{kvm} && !is_host_cpu_model($cpu);
+        },
+        check => sub {
+            my ($cpu, $source, $target) = @_;
+
+            return if !vendors_differ($source, $target);
+
+            # even generic CPU models expose behavior that differs between vendors
+            return
+                "live migration from $source->{vendor} to $target->{vendor} is not guaranteed"
+                . " to work, as guests can become unstable, even some time after the migration";
+        },
+    },
 ];
 
 # Returns the issues of the target node, and whether all checks that can prevent the migration
diff --git a/src/test/run_qemu_migrate_tests.pl b/src/test/run_qemu_migrate_tests.pl
index 5067f0e3..a8ad8331 100755
--- a/src/test/run_qemu_migrate_tests.pl
+++ b/src/test/run_qemu_migrate_tests.pl
@@ -1590,6 +1590,39 @@ my $tests = [
             },
         },
     },
+    {
+        name => '1033_running_kvm64_cpu_other_vendor',
+        target => 'pve1',
+        vmid => 1033,
+        vm_status => {
+            running => 1,
+            runningmachine => 'pc-q35-5.0+pve0',
+            runningcpu => 'kvm64,enforce,+kvm_pv_eoi,+kvm_pv_unhalt,+lahf_lm,+sep',
+        },
+        cpu_info => {
+            source => { vendor => 'AuthenticAMD' },
+            nodes => {
+                pve1 => { vendor => 'GenuineIntel' },
+            },
+        },
+        opts => {
+            online => 1,
+        },
+        expected_calls => $default_expected_calls_online,
+        expect_log => [
+            "CPU of node 'pve1' might be incompatible: live migration from AuthenticAMD to"
+                . " GenuineIntel is not guaranteed to work",
+        ],
+        expected => {
+            source_volids => {},
+            target_volids => {},
+            vm_config => $vm_configs->{1033},
+            vm_status => {
+                running => 1,
+                runningmachine => 'pc-q35-5.0+pve0',
+            },
+        },
+    },
     {
         name => '105_replicated_to_non_replication_target',
         target => 'pve1',
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH qemu-server v2 04/20] cpu flags: factor out parsing the broadcast CPU flags of a node
  2026-11-24 16:30 [PATCH docs/manager/qemu-server v2 00/20] check the target node's CPU before live migrating a VM Jonas Theisen
                   ` (2 preceding siblings ...)
  2026-11-24 16:30 ` [PATCH qemu-server v2 03/20] fix #6535: migrate: warn about live migration " Jonas Theisen
@ 2026-11-24 16:30 ` Jonas Theisen
  2026-11-24 16:30 ` [PATCH qemu-server v2 05/20] fix #2924: migrate: block live migration of host CPU VMs to nodes lacking flags Jonas Theisen
                   ` (15 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Jonas Theisen @ 2026-11-24 16:30 UTC (permalink / raw)
  To: pve-devel

The CPU flags that pvestatd broadcasts need to be normalized, as nodes
running an older version also broadcast aliases of some flags, for
example 'sse4_2' and 'sse4-2' in addition to 'sse4.2'.

Factor this out, so that other users of the broadcast flags cannot
forget about it.

Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
 src/PVE/QemuServer/CPUFlags.pm | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/src/PVE/QemuServer/CPUFlags.pm b/src/PVE/QemuServer/CPUFlags.pm
index 0d3206b2..0ba2e115 100644
--- a/src/PVE/QemuServer/CPUFlags.pm
+++ b/src/PVE/QemuServer/CPUFlags.pm
@@ -145,6 +145,20 @@ sub normalize_cpu_flag($flag) {
     return $qemu_cpu_flag_alias_map->{$flag} // $flag;
 }
 
+=head3 parse_node_cpu_flags($raw)
+
+Parse the CPU flags of a node, as C<pvestatd> broadcasts them in the C<cpuflags-$accel> node
+key-value entries, and return them normalized with C<normalize_cpu_flag()>.
+
+The broadcast format may differ from the current one, for example if the node runs an older
+version, which also broadcast the aliases of some flags.
+
+=cut
+
+sub parse_node_cpu_flags($raw) {
+    return map { normalize_cpu_flag($_) } split(' ', $raw);
+}
+
 # Understood CPU flags are written to a file at 'pve-qemu' compile time and
 # shipped below this directory by the pve-qemu-kvm package.
 my $understood_cpu_flag_dir = "/usr/share/kvm";
@@ -295,12 +309,7 @@ sub query_available_cpu_flags($accel, $vm_specific, $arch) {
     };
 
     for my $node (keys %$flags) {
-        # This depends on `pvestatd` storing the flags in space-separated format, which
-        # is the case at the time of this commit.
-        for (split(' ', $flags->{$node})) {
-            # normalize as pvestatd's stored format may drift relative to the recognized
-            # flag list, e.g. across upgrades or between QEMU CPUID-flag aliases.
-            my $flag = normalize_cpu_flag($_);
+        for my $flag (parse_node_cpu_flags($flags->{$node})) {
             my $pve_alias = undef;
             $pve_alias = 'nested-virt' if $flag eq 'svm' || $flag eq 'vmx';
             next if $vm_specific && !flag_is_vm_specific($flag) && !$pve_alias;
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH qemu-server v2 05/20] fix #2924: migrate: block live migration of host CPU VMs to nodes lacking flags
  2026-11-24 16:30 [PATCH docs/manager/qemu-server v2 00/20] check the target node's CPU before live migrating a VM Jonas Theisen
                   ` (3 preceding siblings ...)
  2026-11-24 16:30 ` [PATCH qemu-server v2 04/20] cpu flags: factor out parsing the broadcast CPU flags of a node Jonas Theisen
@ 2026-11-24 16:30 ` Jonas Theisen
  2026-11-24 16:30 ` [PATCH qemu-server v2 06/20] migrate: warn about live migration of host CPU VMs between CPU models Jonas Theisen
                   ` (14 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Jonas Theisen @ 2026-11-24 16:30 UTC (permalink / raw)
  To: pve-devel

The 'host' and 'max' CPU models pass the flags of the host CPU through
to the guest. If the target node's CPU lacks flags that the guest might
use, the live migration often fails only near its end, with QEMU on the
target failing to set the special registers of the vCPUs, or the guest
runs into problems after the migration.

Compare the CPU flags that KVM supports on the source and the target
node, which pvestatd already broadcasts, and refuse the migration if the
target lacks any. Flags explicitly disabled for the VM and Hyper-V
enlightenments, which are not passed through, are ignored. As the flags
are broadcast independently of the other CPU information, this also
works for target nodes running an older version. The flags are
normalized, as nodes that did not query them again since an upgrade can
still broadcast aliases of some flags. Only flags that QEMU recognizes
are compared, as the broadcast also includes other CPU properties, such
as 'migratable' or 'l3-cache', which can differ between QEMU versions
without affecting the guest.

The flags of the source node are only an approximation of the flags of
the VM, as it might have been started on another node, and the flags
KVM supports also depend on the kernel version. So allow root to
override the check with the new 'allow-missing-cpu-flags' option. The
existing 'force' option is not reused for this, as the HA stack always
sets it, which would skip the check for all HA-managed VMs. Instead,
the new option is forwarded to the HA stack like other migration
options, so that it also applies to HA-managed VMs.

Fixes: https://bugzilla.proxmox.com/show_bug.cgi?id=2924
Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
 src/PVE/API2/Qemu.pm                      |  28 ++-
 src/PVE/QemuMigrate.pm                    |  13 +-
 src/PVE/QemuMigrate/Helpers.pm            |  91 +++++++-
 src/test/MigrationTest/QemuMigrateMock.pm |  11 +
 src/test/run_qemu_migrate_tests.pl        | 251 +++++++++++++++++++++-
 5 files changed, 382 insertions(+), 12 deletions(-)

diff --git a/src/PVE/API2/Qemu.pm b/src/PVE/API2/Qemu.pm
index eab549f5..3f54d8fc 100644
--- a/src/PVE/API2/Qemu.pm
+++ b/src/PVE/API2/Qemu.pm
@@ -155,6 +155,13 @@ my $migrate_json_properties = {
             . ' successfully by the target. Using this flag can lead to dropped'
             . ' configuration options if the target is too old to parse them.',
     },
+    'allow-missing-cpu-flags' => {
+        type => 'boolean',
+        optional => 1,
+        default => 0,
+        description => "Allow live migration of VMs with CPU type 'host' or 'max' to nodes"
+            . " lacking CPU flags of this node. Only root may use this option.",
+    },
 };
 
 # Properties that will be forwarded via the HA stack to the LRM, which will then use them for its
@@ -163,6 +170,7 @@ my $migrate_json_properties = {
 my $ha_migrate_props = {
     'with-conntrack-state' => 1,
     'skip-config-check' => 1,
+    'allow-missing-cpu-flags' => 1,
 };
 
 sub ha_migrate_json_properties {
@@ -5611,12 +5619,18 @@ __PACKAGE__->register_method({
                                     type => {
                                         type => 'string',
                                         description => "The check that failed.",
-                                        enum => ['cpu-vendor'],
+                                        enum => ['cpu-vendor', 'host-cpu-flags'],
                                     },
                                     message => {
                                         type => 'string',
                                         description => "Why the node's CPU is incompatible.",
                                     },
+                                    override => {
+                                        type => 'string',
+                                        optional => 1,
+                                        description => "The migration option that allows"
+                                            . " ignoring the incompatibility.",
+                                    },
                                 },
                             },
                         },
@@ -5825,8 +5839,13 @@ __PACKAGE__->register_method({
             my @cpu_errors =
                 grep { $_->{severity} eq 'error' } ($cpu_issues_by_node->{$node} // [])->@*;
             if (scalar(@cpu_errors)) {
-                $res->{not_allowed_nodes}->{$node}->{'incompatible-cpu'} =
-                    [map { { type => $_->{type}, message => $_->{message} } } @cpu_errors];
+                $res->{not_allowed_nodes}->{$node}->{'incompatible-cpu'} = [
+                    map {
+                        my $error = { type => $_->{type}, message => $_->{message} };
+                        $error->{override} = $_->{override} if defined($_->{override});
+                        $error;
+                    } @cpu_errors
+                ];
             }
 
             my @cpu_warnings =
@@ -5909,6 +5928,9 @@ __PACKAGE__->register_method({
         raise_param_exc({ force => "Only root may use this option." })
             if $param->{force} && $authuser ne 'root@pam';
 
+        raise_param_exc({ 'allow-missing-cpu-flags' => "Only root may use this option." })
+            if $param->{'allow-missing-cpu-flags'} && $authuser ne 'root@pam';
+
         raise_param_exc({ migration_type => "Only root may use this option." })
             if $param->{migration_type} && $authuser ne 'root@pam';
 
diff --git a/src/PVE/QemuMigrate.pm b/src/PVE/QemuMigrate.pm
index c2653473..c8af09fe 100644
--- a/src/PVE/QemuMigrate.pm
+++ b/src/PVE/QemuMigrate.pm
@@ -332,15 +332,26 @@ sub prepare {
 
         my @errors;
         for my $issue (($cpu_issues->{$node} // [])->@*) {
+            my $override = $issue->{override};
             if ($issue->{severity} eq 'warning') {
                 log_warn("CPU of node '$node' might be incompatible: $issue->{message}");
+            } elsif (defined($override) && $self->{opts}->{$override}) {
+                log_warn("ignoring incompatible CPU of node '$node' due to '$override':"
+                    . " $issue->{message}");
             } else {
                 push @errors, $issue;
             }
         }
         if (scalar(@errors)) {
+            my $hint = '';
+            if (!grep { !defined($_->{override}) } @errors) {
+                my %overrides = map { $_->{override} => 1 } @errors;
+                $hint =
+                    " - use " . join(' and ', map { "'$_'" } sort keys %overrides) . " to override";
+            }
             die "can't migrate VM to '$node' - incompatible CPU: "
-                . join('; ', map { $_->{message} } @errors) . "\n";
+                . join('; ', map { $_->{message} } @errors)
+                . "$hint\n";
         }
 
         if (scalar($unchecked_nodes->@*)) {
diff --git a/src/PVE/QemuMigrate/Helpers.pm b/src/PVE/QemuMigrate/Helpers.pm
index 4e4e3ae0..c65e2924 100644
--- a/src/PVE/QemuMigrate/Helpers.pm
+++ b/src/PVE/QemuMigrate/Helpers.pm
@@ -4,6 +4,7 @@ use strict;
 use warnings;
 
 use JSON;
+use List::Util qw(min);
 
 use PVE::Cluster;
 use PVE::INotify;
@@ -128,6 +129,23 @@ my sub get_node_cpu_info {
     return ref($info) eq 'HASH' ? $info : {};
 }
 
+# Returns the CPU flags KVM supports on the node, as broadcast by pvestatd, if known.
+my sub get_node_kvm_cpu_flags {
+    my ($node) = @_;
+
+    # an empty value means that pvestatd failed to detect the flags
+    my $raw = PVE::Cluster::get_node_kv('cpuflags-kvm', $node)->{$node} or return;
+
+    return { map { $_ => 1 } PVE::QemuServer::CPUFlags::parse_node_cpu_flags($raw) };
+}
+
+# Returns the CPU flags QEMU recognizes for the host architecture, if known.
+my sub get_understood_cpu_flags {
+    my $arch = PVE::QemuServer::Helpers::get_host_arch();
+    my $flags = eval { PVE::QemuServer::CPUFlags::query_understood_cpu_flags($arch) };
+    return $flags ? { map { $_ => 1 } $flags->@* } : undef;
+}
+
 # Parses a QEMU '-cpu' argument into the CPU model and its properties. Flags given without a value
 # are stored as 'on' or 'off'.
 my sub parse_qemu_cpu_string {
@@ -161,13 +179,27 @@ my sub vendors_differ {
     return defined($source_vendor) && defined($target_vendor) && $source_vendor ne $target_vendor;
 }
 
+my sub format_flag_list {
+    my ($flags) = @_;
+
+    my $max_listed = 10;
+    my $list = join(', ', $flags->@[0 .. min($max_listed, scalar($flags->@*)) - 1]);
+    $list .= " and " . (scalar($flags->@*) - $max_listed) . " more"
+        if scalar($flags->@*) > $max_listed;
+
+    return $list;
+}
+
 # Checks whether the CPU of a target node can run a running VM after a live migration.
 #
 # 'applies' returns true if the check is relevant for the VM's CPU, as parsed by
 # parse_qemu_cpu_string(), with 'kvm' set if the VM uses KVM. 'needs' lists the CPU information
-# of the target node the check requires, nodes lacking any of it are skipped. 'check' returns why
-# the target node is incompatible, if it is. With the 'error' severity, an incompatibility
-# prevents the migration, with 'warning' it is only reported.
+# of the target node the check requires, nodes lacking any of it are skipped. The CPU information
+# is in the format of get_host_cpu_info(), plus the CPU flags KVM supports as 'kvm-flags' hash.
+# The source node's information also has the CPU flags QEMU recognizes as 'understood-flags' hash,
+# if known. 'check' returns why the target node is incompatible, if it is. With the 'error'
+# severity, an incompatibility prevents the migration, with 'warning' it is only reported.
+# 'override' names the migration option that allows ignoring an error.
 my $target_cpu_checks = [
     {
         type => 'cpu-vendor',
@@ -206,6 +238,45 @@ my $target_cpu_checks = [
                 . " to work, as guests can become unstable, even some time after the migration";
         },
     },
+    {
+        type => 'host-cpu-flags',
+        severity => 'error',
+        # the flags are only known per node, the VM might have been started on another node
+        override => 'allow-missing-cpu-flags',
+        needs => ['kvm-flags'],
+        applies => sub {
+            my ($cpu) = @_;
+            return is_host_cpu_model($cpu);
+        },
+        check => sub {
+            my ($cpu, $source, $target) = @_;
+
+            # already reported by the 'cpu-vendor' check
+            return if vendors_differ($source, $target);
+
+            my ($source_flags, $target_flags) =
+                ($source->{'kvm-flags'}, $target->{'kvm-flags'});
+            return if !$source_flags;
+
+            # The broadcast also includes CPU properties that are no flags, for example
+            # 'migratable', which can differ between QEMU versions without affecting the guest.
+            my $understood = $source->{'understood-flags'};
+            my @flags = grep { !$understood || $understood->{$_} } keys $source_flags->%*;
+
+            my @missing = sort grep {
+                # Hyper-V enlightenments are not passed through, but set explicitly
+                !m/^hv-/
+                    && !$target_flags->{$_}
+                    && ($cpu->{props}->{$_} // '') ne 'off'
+            } @flags;
+            return if !scalar(@missing);
+
+            return
+                "CPU model '$cpu->{model}' passes through the flags of the host CPU, but the"
+                . " node lacks: "
+                . format_flag_list(\@missing);
+        },
+    },
 ];
 
 # Returns the issues of the target node, and whether all checks that can prevent the migration
@@ -221,8 +292,9 @@ my sub get_target_cpu_issues {
         }
 
         my $message = $check->{check}->($cpu, $source_info, $target_info) or next;
-        push $issues->@*,
-            { type => $check->{type}, severity => $check->{severity}, message => $message };
+        my $issue = { type => $check->{type}, severity => $check->{severity}, message => $message };
+        $issue->{override} = $check->{override} if defined($check->{override});
+        push $issues->@*, $issue;
     }
 
     return ($issues, $complete);
@@ -241,7 +313,8 @@ Returns a hash reference with the list of issues for each node that has any, and
 reference with the nodes that could not be checked for issues preventing the migration, because
 they lack the required CPU information, for example as they run an older version. Each issue is
 a hash with a C<type> identifying the check, a C<severity> of C<error> if the VM cannot run on
-the node or C<warning> if it might not, and a human-readable C<message>.
+the node or C<warning> if it might not, and a human-readable C<message>. If a migration option
+allows ignoring an error, C<override> names it.
 
 =cut
 
@@ -258,12 +331,16 @@ sub check_target_cpu_compatibility {
 
     # Use what this node broadcasts, as for the target nodes. The local pvestatd might not
     # broadcast it yet, for example if it was not restarted after an upgrade.
-    my $source_info = get_node_cpu_info(PVE::INotify::nodename());
+    my $local_node = PVE::INotify::nodename();
+    my $source_info = get_node_cpu_info($local_node);
     $source_info = PVE::QemuServer::Helpers::get_host_cpu_info() if !scalar(keys $source_info->%*);
+    $source_info->{'kvm-flags'} = get_node_kvm_cpu_flags($local_node);
+    $source_info->{'understood-flags'} = get_understood_cpu_flags();
 
     my ($issues_by_node, $unchecked_nodes) = ({}, []);
     for my $node ($nodes->@*) {
         my $target_info = get_node_cpu_info($node);
+        $target_info->{'kvm-flags'} = get_node_kvm_cpu_flags($node);
 
         my ($issues, $complete) = get_target_cpu_issues($cpu, $checks, $source_info, $target_info);
         $issues_by_node->{$node} = $issues if scalar($issues->@*);
diff --git a/src/test/MigrationTest/QemuMigrateMock.pm b/src/test/MigrationTest/QemuMigrateMock.pm
index b91dc434..f8d30b05 100644
--- a/src/test/MigrationTest/QemuMigrateMock.pm
+++ b/src/test/MigrationTest/QemuMigrateMock.pm
@@ -243,6 +243,10 @@ $MigrationTest::Shared::qemu_migrate_helpers_module->mock(
 $MigrationTest::Shared::cluster_module->mock(
     get_node_kv => sub {
         my ($key, $node) = @_;
+        if ($key eq 'cpuflags-kvm') {
+            my $flags = $test_cpu_info->{'kvm-flags'}->{$node} or return {};
+            return { $node => $flags };
+        }
         if ($key eq 'host-cpu-info') {
             # the source node is 'pve0', without 'source' get_host_cpu_info() is used
             my $info =
@@ -254,6 +258,13 @@ $MigrationTest::Shared::cluster_module->mock(
     },
 );
 
+my $qemu_server_cpuflags_module = Test::MockModule->new("PVE::QemuServer::CPUFlags");
+$qemu_server_cpuflags_module->mock(
+    query_understood_cpu_flags => sub {
+        return [qw(avx512f fpu hv-relaxed lahf-lm sse sse4.2)];
+    },
+);
+
 my $qemu_server_helpers_module = Test::MockModule->new("PVE::QemuServer::Helpers");
 $qemu_server_helpers_module->mock(
     get_host_cpu_info => sub {
diff --git a/src/test/run_qemu_migrate_tests.pl b/src/test/run_qemu_migrate_tests.pl
index a8ad8331..8f0015d7 100755
--- a/src/test/run_qemu_migrate_tests.pl
+++ b/src/test/run_qemu_migrate_tests.pl
@@ -531,7 +531,8 @@ my $tests = [
     # target_volids  - hash of volids on the target at the beginning
     # vm_status      - hash with running, runningmachine and optionally runningcpu
     # cpu_info       - hash with the CPU information of the 'source' node and of each
-    #                  other node in 'nodes'
+    #                  other node in 'nodes', and the KVM CPU flags of each node in
+    #                  'kvm-flags'
     # expected_calls - hash whose keys are calls which are required
     #                  to be made if the migration gets far enough
     # expect_die     - expect the migration call to fail, and an error message
@@ -1623,6 +1624,254 @@ my $tests = [
             },
         },
     },
+    {
+        # properties that are no CPU flags can differ between QEMU versions
+        name => '1033_running_host_cpu_other_properties',
+        target => 'pve1',
+        vmid => 1033,
+        vm_status => {
+            running => 1,
+            runningmachine => 'pc-q35-5.0+pve0',
+            runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+        },
+        cpu_info => {
+            source => { vendor => 'GenuineIntel' },
+            nodes => {
+                pve1 => { vendor => 'GenuineIntel' },
+            },
+            'kvm-flags' => {
+                pve0 => 'fpu l3-cache migratable sse x-vendor-cpuid-only-v2',
+                pve1 => 'fpu sse',
+            },
+        },
+        opts => {
+            online => 1,
+        },
+        config_patch => {
+            cpu => 'host',
+        },
+        expected_calls => $default_expected_calls_online,
+        expected => {
+            source_volids => {},
+            target_volids => {},
+            vm_config => get_patched_config(1033, {
+                    cpu => 'host',
+            }),
+            vm_status => {
+                running => 1,
+                runningmachine => 'pc-q35-5.0+pve0',
+            },
+        },
+    },
+    {
+        name => '1033_running_host_cpu_missing_flags',
+        target => 'pve1',
+        vmid => 1033,
+        vm_status => {
+            running => 1,
+            runningmachine => 'pc-q35-5.0+pve0',
+            runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+        },
+        cpu_info => {
+            source => { vendor => 'GenuineIntel' },
+            nodes => {
+                pve1 => { vendor => 'GenuineIntel' },
+            },
+            'kvm-flags' => {
+                pve0 => 'avx512f fpu hv-relaxed sse',
+                pve1 => 'fpu sse',
+            },
+        },
+        opts => {
+            online => 1,
+        },
+        config_patch => {
+            cpu => 'host',
+        },
+        expected_calls => {},
+        expect_die => "can't migrate VM to 'pve1' - incompatible CPU: CPU model 'host' passes"
+            . " through the flags of the host CPU, but the node lacks: avx512f - use"
+            . " 'allow-missing-cpu-flags' to override",
+        expected => {
+            source_volids => {},
+            target_volids => {},
+            vm_config => get_patched_config(1033, {
+                    cpu => 'host',
+            }),
+            vm_status => {
+                running => 1,
+                runningmachine => 'pc-q35-5.0+pve0',
+                runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+            },
+        },
+    },
+    {
+        # 'force', which the HA stack always sets, must not override the check
+        name => '1033_running_host_cpu_missing_flags_force',
+        target => 'pve1',
+        vmid => 1033,
+        vm_status => {
+            running => 1,
+            runningmachine => 'pc-q35-5.0+pve0',
+            runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+        },
+        cpu_info => {
+            source => { vendor => 'GenuineIntel' },
+            nodes => {
+                pve1 => { vendor => 'GenuineIntel' },
+            },
+            'kvm-flags' => {
+                pve0 => 'avx512f fpu hv-relaxed sse',
+                pve1 => 'fpu sse',
+            },
+        },
+        opts => {
+            online => 1,
+            force => 1,
+        },
+        config_patch => {
+            cpu => 'host',
+        },
+        expected_calls => {},
+        expect_die => "can't migrate VM to 'pve1' - incompatible CPU: CPU model 'host' passes"
+            . " through the flags of the host CPU, but the node lacks: avx512f - use"
+            . " 'allow-missing-cpu-flags' to override",
+        expected => {
+            source_volids => {},
+            target_volids => {},
+            vm_config => get_patched_config(1033, {
+                    cpu => 'host',
+            }),
+            vm_status => {
+                running => 1,
+                runningmachine => 'pc-q35-5.0+pve0',
+                runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+            },
+        },
+    },
+    {
+        name => '1033_running_host_cpu_missing_flags_allowed',
+        target => 'pve1',
+        vmid => 1033,
+        vm_status => {
+            running => 1,
+            runningmachine => 'pc-q35-5.0+pve0',
+            runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+        },
+        cpu_info => {
+            source => { vendor => 'GenuineIntel' },
+            nodes => {
+                pve1 => { vendor => 'GenuineIntel' },
+            },
+            'kvm-flags' => {
+                pve0 => 'avx512f fpu hv-relaxed sse',
+                pve1 => 'fpu sse',
+            },
+        },
+        opts => {
+            online => 1,
+            'allow-missing-cpu-flags' => 1,
+        },
+        config_patch => {
+            cpu => 'host',
+        },
+        expected_calls => $default_expected_calls_online,
+        expect_log => [
+            "ignoring incompatible CPU of node 'pve1' due to 'allow-missing-cpu-flags': CPU"
+                . " model 'host' passes through the flags of the host CPU, but the node lacks:"
+                . " avx512f",
+        ],
+        expected => {
+            source_volids => {},
+            target_volids => {},
+            vm_config => get_patched_config(1033, {
+                    cpu => 'host',
+            }),
+            vm_status => {
+                running => 1,
+                runningmachine => 'pc-q35-5.0+pve0',
+            },
+        },
+    },
+    {
+        # nodes running an older version broadcast their KVM CPU flags, but no 'host-cpu-info'
+        name => '1033_running_host_cpu_missing_flags_without_cpu_info',
+        target => 'pve1',
+        vmid => 1033,
+        vm_status => {
+            running => 1,
+            runningmachine => 'pc-q35-5.0+pve0',
+            runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+        },
+        cpu_info => {
+            source => { vendor => 'GenuineIntel' },
+            'kvm-flags' => {
+                pve0 => 'avx512f fpu hv-relaxed sse',
+                pve1 => 'fpu sse',
+            },
+        },
+        opts => {
+            online => 1,
+        },
+        config_patch => {
+            cpu => 'host',
+        },
+        expected_calls => {},
+        expect_die => "can't migrate VM to 'pve1' - incompatible CPU: CPU model 'host' passes"
+            . " through the flags of the host CPU, but the node lacks: avx512f - use"
+            . " 'allow-missing-cpu-flags' to override",
+        expected => {
+            source_volids => {},
+            target_volids => {},
+            vm_config => get_patched_config(1033, {
+                    cpu => 'host',
+            }),
+            vm_status => {
+                running => 1,
+                runningmachine => 'pc-q35-5.0+pve0',
+                runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+            },
+        },
+    },
+    {
+        # nodes that did not query their flags since an upgrade still broadcast aliases
+        name => '1033_running_host_cpu_flag_aliases',
+        target => 'pve1',
+        vmid => 1033,
+        vm_status => {
+            running => 1,
+            runningmachine => 'pc-q35-5.0+pve0',
+            runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+        },
+        cpu_info => {
+            source => { vendor => 'GenuineIntel' },
+            nodes => {
+                pve1 => { vendor => 'GenuineIntel' },
+            },
+            'kvm-flags' => {
+                pve0 => 'fpu lahf-lm lahf_lm sse sse4-2 sse4.2 sse4_2',
+                pve1 => 'fpu lahf-lm sse sse4.2',
+            },
+        },
+        opts => {
+            online => 1,
+        },
+        config_patch => {
+            cpu => 'host',
+        },
+        expected_calls => $default_expected_calls_online,
+        expected => {
+            source_volids => {},
+            target_volids => {},
+            vm_config => get_patched_config(1033, {
+                    cpu => 'host',
+            }),
+            vm_status => {
+                running => 1,
+                runningmachine => 'pc-q35-5.0+pve0',
+            },
+        },
+    },
     {
         name => '105_replicated_to_non_replication_target',
         target => 'pve1',
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH qemu-server v2 06/20] migrate: warn about live migration of host CPU VMs between CPU models
  2026-11-24 16:30 [PATCH docs/manager/qemu-server v2 00/20] check the target node's CPU before live migrating a VM Jonas Theisen
                   ` (4 preceding siblings ...)
  2026-11-24 16:30 ` [PATCH qemu-server v2 05/20] fix #2924: migrate: block live migration of host CPU VMs to nodes lacking flags Jonas Theisen
@ 2026-11-24 16:30 ` Jonas Theisen
  2026-11-24 16:30 ` [PATCH qemu-server v2 07/20] migrate: factor out whether the running virtual CPU is kept Jonas Theisen
                   ` (13 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Jonas Theisen @ 2026-11-24 16:30 UTC (permalink / raw)
  To: pve-devel

Even if the target node's CPU supports all flags of the source node's
CPU, a guest with the 'host' or 'max' CPU model can run into problems
after a live migration between different physical CPU models, as they
can still behave differently, for example regarding errata. The
documentation advises against this setup for that reason.

Broadcast the CPU model name as part of the node's CPU information and
warn if it differs between the source and the target node.

Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
 src/PVE/API2/Qemu.pm               |  2 +-
 src/PVE/QemuMigrate/Helpers.pm     | 23 ++++++++++++++
 src/PVE/QemuServer/Helpers.pm      |  3 ++
 src/test/run_qemu_migrate_tests.pl | 49 ++++++++++++++++++++++++++++++
 4 files changed, 76 insertions(+), 1 deletion(-)

diff --git a/src/PVE/API2/Qemu.pm b/src/PVE/API2/Qemu.pm
index 3f54d8fc..d51a52ce 100644
--- a/src/PVE/API2/Qemu.pm
+++ b/src/PVE/API2/Qemu.pm
@@ -5724,7 +5724,7 @@ __PACKAGE__->register_method({
                             type => {
                                 type => 'string',
                                 description => "The check that reported the warning.",
-                                enum => ['cpu-vendor', 'missing-cpu-info'],
+                                enum => ['cpu-vendor', 'missing-cpu-info', 'host-cpu-model'],
                             },
                             message => {
                                 type => 'string',
diff --git a/src/PVE/QemuMigrate/Helpers.pm b/src/PVE/QemuMigrate/Helpers.pm
index c65e2924..18cba4af 100644
--- a/src/PVE/QemuMigrate/Helpers.pm
+++ b/src/PVE/QemuMigrate/Helpers.pm
@@ -277,6 +277,29 @@ my $target_cpu_checks = [
                 . format_flag_list(\@missing);
         },
     },
+    {
+        type => 'host-cpu-model',
+        severity => 'warning',
+        needs => ['model-name'],
+        applies => sub {
+            my ($cpu) = @_;
+            return is_host_cpu_model($cpu);
+        },
+        check => sub {
+            my ($cpu, $source, $target) = @_;
+
+            # already reported by the 'cpu-vendor' check
+            return if vendors_differ($source, $target);
+
+            my ($source_model, $target_model) =
+                ($source->{'model-name'}, $target->{'model-name'});
+            return if !defined($source_model) || $source_model eq $target_model;
+
+            # same flags do not imply the same behavior, for example regarding errata
+            return "CPU model '$cpu->{model}' is only reliable for live migration between"
+                . " identical CPUs, but the node has '$target_model' instead of '$source_model'";
+        },
+    },
 ];
 
 # Returns the issues of the target node, and whether all checks that can prevent the migration
diff --git a/src/PVE/QemuServer/Helpers.pm b/src/PVE/QemuServer/Helpers.pm
index b15599bb..70f9c817 100644
--- a/src/PVE/QemuServer/Helpers.pm
+++ b/src/PVE/QemuServer/Helpers.pm
@@ -376,6 +376,8 @@ encoded as JSON. The returned hash contains:
 
 =item C<vendor>: the CPU vendor ID, for example C<GenuineIntel> or C<AuthenticAMD>
 
+=item C<model-name>: the CPU model name, for example C<AMD EPYC 7302 16-Core Processor>
+
 =back
 
 Properties that cannot be determined are missing. Consumers of the broadcast information must
@@ -391,6 +393,7 @@ sub get_host_cpu_info {
 
     my $info = {};
     $info->{vendor} = $cpuinfo->{vendor} if $known->($cpuinfo->{vendor});
+    $info->{'model-name'} = $cpuinfo->{model} if $known->($cpuinfo->{model});
 
     return $info;
 }
diff --git a/src/test/run_qemu_migrate_tests.pl b/src/test/run_qemu_migrate_tests.pl
index 8f0015d7..59b2ade2 100755
--- a/src/test/run_qemu_migrate_tests.pl
+++ b/src/test/run_qemu_migrate_tests.pl
@@ -1872,6 +1872,55 @@ my $tests = [
             },
         },
     },
+    {
+        name => '1033_running_host_cpu_other_model',
+        target => 'pve1',
+        vmid => 1033,
+        vm_status => {
+            running => 1,
+            runningmachine => 'pc-q35-5.0+pve0',
+            runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+        },
+        cpu_info => {
+            source => {
+                vendor => 'AuthenticAMD',
+                'model-name' => 'AMD EPYC 7302 16-Core Processor',
+            },
+            nodes => {
+                pve1 => {
+                    vendor => 'AuthenticAMD',
+                    'model-name' => 'AMD EPYC 7313 16-Core Processor',
+                },
+            },
+            'kvm-flags' => {
+                pve0 => 'fpu sse',
+                pve1 => 'fpu sse',
+            },
+        },
+        opts => {
+            online => 1,
+        },
+        config_patch => {
+            cpu => 'host',
+        },
+        expected_calls => $default_expected_calls_online,
+        expect_log => [
+            "CPU of node 'pve1' might be incompatible: CPU model 'host' is only reliable for"
+                . " live migration between identical CPUs, but the node has 'AMD EPYC 7313"
+                . " 16-Core Processor' instead of 'AMD EPYC 7302 16-Core Processor'",
+        ],
+        expected => {
+            source_volids => {},
+            target_volids => {},
+            vm_config => get_patched_config(1033, {
+                    cpu => 'host',
+            }),
+            vm_status => {
+                running => 1,
+                runningmachine => 'pc-q35-5.0+pve0',
+            },
+        },
+    },
     {
         name => '105_replicated_to_non_replication_target',
         target => 'pve1',
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH qemu-server v2 07/20] migrate: factor out whether the running virtual CPU is kept
  2026-11-24 16:30 [PATCH docs/manager/qemu-server v2 00/20] check the target node's CPU before live migrating a VM Jonas Theisen
                   ` (5 preceding siblings ...)
  2026-11-24 16:30 ` [PATCH qemu-server v2 06/20] migrate: warn about live migration of host CPU VMs between CPU models Jonas Theisen
@ 2026-11-24 16:30 ` Jonas Theisen
  2026-11-24 16:30 ` [PATCH qemu-server v2 08/20] migrate: block migration if the target cannot run the virtual CPU Jonas Theisen
                   ` (12 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Jonas Theisen @ 2026-11-24 16:30 UTC (permalink / raw)
  To: pve-devel

For abstracted CPU configurations, a live migration starts the target
instance with the QEMU CPU of the running instance. Factor out this
condition, so that checks whether the target can run that CPU can use
the same one as the migration itself.

Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
 src/PVE/QemuMigrate.pm         |  2 +-
 src/PVE/QemuMigrate/Helpers.pm | 16 ++++++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/PVE/QemuMigrate.pm b/src/PVE/QemuMigrate.pm
index c8af09fe..245b79d7 100644
--- a/src/PVE/QemuMigrate.pm
+++ b/src/PVE/QemuMigrate.pm
@@ -243,7 +243,7 @@ sub prepare {
         $self->{forcemachine} = PVE::QemuServer::Machine::qemu_machine_pxe($vmid, $conf);
 
         # To support abstracted CPU configurations, keep QEMU's "-cpu" parameter intact.
-        if ($conf->{cpu} && PVE::QemuServer::CPUConfig::is_abstracted($conf->{cpu})) {
+        if (PVE::QemuMigrate::Helpers::is_running_cpu_kept($conf)) {
             $self->{forcecpu} = PVE::QemuServer::CPUConfig::get_cpu_from_running_vm($pid);
         }
 
diff --git a/src/PVE/QemuMigrate/Helpers.pm b/src/PVE/QemuMigrate/Helpers.pm
index 18cba4af..844bc250 100644
--- a/src/PVE/QemuMigrate/Helpers.pm
+++ b/src/PVE/QemuMigrate/Helpers.pm
@@ -323,6 +323,22 @@ my sub get_target_cpu_issues {
     return ($issues, $complete);
 }
 
+=head3 is_running_cpu_kept
+
+    my $kept = is_running_cpu_kept($conf);
+
+Returns whether a live migration of the VM with the configuration C<$conf> starts the target
+instance with the QEMU CPU of the running instance, instead of generating it again from the
+configuration. This is the case for abstracted CPU configurations, as their QEMU CPU depends on
+more than the configuration.
+
+=cut
+
+sub is_running_cpu_kept {
+    my ($conf) = @_;
+    return $conf->{cpu} && PVE::QemuServer::CPUConfig::is_abstracted($conf->{cpu}) ? 1 : 0;
+}
+
 =head3 check_target_cpu_compatibility
 
     my ($issues_by_node, $unchecked_nodes) = check_target_cpu_compatibility($conf, $pid, $nodes);
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH qemu-server v2 08/20] migrate: block migration if the target cannot run the virtual CPU
  2026-11-24 16:30 [PATCH docs/manager/qemu-server v2 00/20] check the target node's CPU before live migrating a VM Jonas Theisen
                   ` (6 preceding siblings ...)
  2026-11-24 16:30 ` [PATCH qemu-server v2 07/20] migrate: factor out whether the running virtual CPU is kept Jonas Theisen
@ 2026-11-24 16:30 ` Jonas Theisen
  2026-11-24 16:30 ` [PATCH qemu-server v2 09/20] cpu flags: report invtsc support of nodes Jonas Theisen
                   ` (11 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Jonas Theisen @ 2026-11-24 16:30 UTC (permalink / raw)
  To: pve-devel

For VMs with an abstracted CPU configuration, for example with a custom
CPU model or the 'nested-virt' flag, the target is started with the
QEMU CPU of the running instance, instead of generating it again from
the configuration. That QEMU CPU can contain flags that KVM on the
target does not support, for example the Intel-only 'hv-evmcs'
enlightenment that is enabled for Windows 11 guests on Intel hosts.
QEMU on an AMD target then refuses to start:

  kvm: Hyper-V enlightened VMCS (hv-evmcs) is not supported by kernel

and the migration fails only after its preparation.

The same applies to all other CPU models that do not pass through the
host CPU, like 'x86-64-v3' or 'Skylake-Server'. Their QEMU CPU is
generated again from the configuration, but with the same flags, and
as 'enforce' is set for them, QEMU on the target refuses to start if
KVM lacks any flag the model enables, including those it enables by
default.

Check upfront whether KVM on the target supports all enabled Hyper-V
enlightenments of the virtual CPU, which QEMU always requires, and all
of its other enabled flags if 'enforce' is set. The flags a CPU model
enables by default are queried from QEMU of the running VM. This uses
the CPU flags that pvestatd already broadcasts for each node. Only
flags that KVM supports on the source node are considered, so that
QEMU CPU properties that are not CPU flags are not reported as missing.

Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
 src/PVE/API2/Qemu.pm                      |   7 +-
 src/PVE/QemuMigrate.pm                    |   4 +-
 src/PVE/QemuMigrate/Helpers.pm            | 100 +++++++++--
 src/test/MigrationTest/QemuMigrateMock.pm |  13 +-
 src/test/run_qemu_migrate_tests.pl        | 203 ++++++++++++++++++++++
 5 files changed, 307 insertions(+), 20 deletions(-)

diff --git a/src/PVE/API2/Qemu.pm b/src/PVE/API2/Qemu.pm
index d51a52ce..ba1ac71c 100644
--- a/src/PVE/API2/Qemu.pm
+++ b/src/PVE/API2/Qemu.pm
@@ -5619,7 +5619,8 @@ __PACKAGE__->register_method({
                                     type => {
                                         type => 'string',
                                         description => "The check that failed.",
-                                        enum => ['cpu-vendor', 'host-cpu-flags'],
+                                        enum =>
+                                            ['cpu-vendor', 'host-cpu-flags', 'vm-cpu-flags'],
                                     },
                                     message => {
                                         type => 'string',
@@ -5809,7 +5810,9 @@ __PACKAGE__->register_method({
         my $cpu_issues_by_node = eval {
             my $targets = [grep { $_ ne $localnode } $nodelist->@*];
             my ($issues, $unchecked_nodes) =
-                PVE::QemuMigrate::Helpers::check_target_cpu_compatibility($vmconf, $pid, $targets);
+                PVE::QemuMigrate::Helpers::check_target_cpu_compatibility(
+                    $vmid, $vmconf, $pid, $targets,
+                );
             my $message = "the node does not provide CPU information, for example as it runs"
                 . " an older version";
             for my $node ($unchecked_nodes->@*) {
diff --git a/src/PVE/QemuMigrate.pm b/src/PVE/QemuMigrate.pm
index 245b79d7..0b286f58 100644
--- a/src/PVE/QemuMigrate.pm
+++ b/src/PVE/QemuMigrate.pm
@@ -328,7 +328,9 @@ sub prepare {
     if (!$self->{opts}->{remote}) {
         my $node = $self->{node};
         my ($cpu_issues, $unchecked_nodes) =
-            PVE::QemuMigrate::Helpers::check_target_cpu_compatibility($conf, $running, [$node]);
+            PVE::QemuMigrate::Helpers::check_target_cpu_compatibility(
+                $vmid, $conf, $running, [$node],
+            );
 
         my @errors;
         for my $issue (($cpu_issues->{$node} // [])->@*) {
diff --git a/src/PVE/QemuMigrate/Helpers.pm b/src/PVE/QemuMigrate/Helpers.pm
index 844bc250..48e4da5e 100644
--- a/src/PVE/QemuMigrate/Helpers.pm
+++ b/src/PVE/QemuMigrate/Helpers.pm
@@ -146,6 +146,13 @@ my sub get_understood_cpu_flags {
     return $flags ? { map { $_ => 1 } $flags->@* } : undef;
 }
 
+# QEMU accepts both underscores and dashes in property names, and some aliases
+my sub normalize_cpu_property {
+    my ($name) = @_;
+    $name =~ s/_/-/g;
+    return PVE::QemuServer::CPUFlags::normalize_cpu_flag($name);
+}
+
 # Parses a QEMU '-cpu' argument into the CPU model and its properties. Flags given without a value
 # are stored as 'on' or 'off'.
 my sub parse_qemu_cpu_string {
@@ -156,9 +163,7 @@ my sub parse_qemu_cpu_string {
     my $props = {};
     for my $option (@options) {
         my ($op, $name, $value) = $option =~ m/^([+-]?)([^=]+)(?:=(.*))?$/ or next;
-        # QEMU accepts both underscores and dashes in property names, and some aliases
-        $name =~ s/_/-/g;
-        $name = PVE::QemuServer::CPUFlags::normalize_cpu_flag($name);
+        $name = normalize_cpu_property($name);
         $value = $op eq '-' ? 'off' : 'on' if !defined($value);
         $props->{$name} = $value;
     }
@@ -193,11 +198,14 @@ my sub format_flag_list {
 # Checks whether the CPU of a target node can run a running VM after a live migration.
 #
 # 'applies' returns true if the check is relevant for the VM's CPU, as parsed by
-# parse_qemu_cpu_string(), with 'kvm' set if the VM uses KVM. 'needs' lists the CPU information
-# of the target node the check requires, nodes lacking any of it are skipped. The CPU information
-# is in the format of get_host_cpu_info(), plus the CPU flags KVM supports as 'kvm-flags' hash.
-# The source node's information also has the CPU flags QEMU recognizes as 'understood-flags' hash,
-# if known. 'check' returns why the target node is incompatible, if it is. With the 'error'
+# parse_qemu_cpu_string(), with 'kvm' set if the VM uses KVM, 'kept' set if the target is
+# started with the same QEMU CPU, see is_running_cpu_kept(), 'enforce' set if QEMU refuses to
+# start without all enabled flags, and the enabled flags as 'flags' hash. If 'enforce' is set,
+# they include the flags the CPU model enables by default. 'needs' lists the CPU information of
+# the target node the check requires, nodes lacking any of it are skipped. The CPU information is
+# in the format of get_host_cpu_info(), plus the CPU flags KVM supports as 'kvm-flags' hash. The
+# source node's information also has the CPU flags QEMU recognizes as 'understood-flags' hash, if
+# known. 'check' returns why the target node is incompatible, if it is. With the 'error'
 # severity, an incompatibility prevents the migration, with 'warning' it is only reported.
 # 'override' names the migration option that allows ignoring an error.
 my $target_cpu_checks = [
@@ -300,6 +308,35 @@ my $target_cpu_checks = [
                 . " identical CPUs, but the node has '$target_model' instead of '$source_model'";
         },
     },
+    {
+        type => 'vm-cpu-flags',
+        severity => 'error',
+        needs => ['kvm-flags'],
+        applies => sub {
+            my ($cpu) = @_;
+            # other models are generated again from the configuration on the target, but with
+            # the same flags, so it must support them as well
+            return $cpu->{kept} || ($cpu->{kvm} && !is_host_cpu_model($cpu));
+        },
+        check => sub {
+            my ($cpu, $source, $target) = @_;
+
+            my ($source_flags, $target_flags) =
+                ($source->{'kvm-flags'}, $target->{'kvm-flags'});
+            return if !$source_flags;
+
+            # QEMU refuses to start with unsupported Hyper-V enlightenments, and with any other
+            # unsupported flag only if 'enforce' is set. Requiring support on the source skips
+            # properties that are no CPU flags.
+            my @missing = sort grep {
+                ($cpu->{enforce} || m/^hv-/) && $source_flags->{$_} && !$target_flags->{$_}
+            } keys $cpu->{flags}->%*;
+            return if !scalar(@missing);
+
+            return "KVM on the node does not support flags of the VM's virtual CPU: "
+                . format_flag_list(\@missing);
+        },
+    },
 ];
 
 # Returns the issues of the target node, and whether all checks that can prevent the migration
@@ -323,6 +360,22 @@ my sub get_target_cpu_issues {
     return ($issues, $complete);
 }
 
+# Returns the flags a CPU model enables by default, as QEMU of the running VM defines them.
+my sub get_cpu_model_flags {
+    my ($vmid, $model, $understood) = @_;
+
+    my $expansion =
+        mon_cmd($vmid, 'query-cpu-model-expansion', type => 'full', model => { name => $model });
+    my $props = $expansion->{model}->{props} // {};
+
+    # the expansion also includes CPU properties that are no flags
+    return [
+        grep { !$understood || $understood->{$_} }
+        map { normalize_cpu_property($_) }
+        grep { ($props->{$_} // '') eq JSON::true } keys $props->%*
+    ];
+}
+
 =head3 is_running_cpu_kept
 
     my $kept = is_running_cpu_kept($conf);
@@ -341,12 +394,13 @@ sub is_running_cpu_kept {
 
 =head3 check_target_cpu_compatibility
 
-    my ($issues_by_node, $unchecked_nodes) = check_target_cpu_compatibility($conf, $pid, $nodes);
+    my ($issues_by_node, $unchecked_nodes) =
+        check_target_cpu_compatibility($vmid, $conf, $pid, $nodes);
 
-Checks whether the VM with the configuration C<$conf>, running with the process ID C<$pid>, can
-run with its current virtual CPU on each node of C<$nodes>, based on the CPU information the
-nodes broadcast. Only applies to running VMs, as stopped VMs are started with a virtual CPU
-matching the target node.
+Checks whether the VM C<$vmid> with the configuration C<$conf>, running with the process ID
+C<$pid>, can run with its current virtual CPU on each node of C<$nodes>, based on the CPU
+information the nodes broadcast. Only applies to running VMs, as stopped VMs are started with a
+virtual CPU matching the target node.
 
 Returns a hash reference with the list of issues for each node that has any, and an array
 reference with the nodes that could not be checked for issues preventing the migration, because
@@ -358,12 +412,28 @@ allows ignoring an error, C<override> names it.
 =cut
 
 sub check_target_cpu_compatibility {
-    my ($conf, $pid, $nodes) = @_;
+    my ($vmid, $conf, $pid, $nodes) = @_;
 
     return ({}, []) if !$pid;
 
     my $cpu = parse_qemu_cpu_string(PVE::QemuServer::CPUConfig::get_cpu_from_running_vm($pid));
     $cpu->{kvm} = $conf->{kvm} // 1;
+    $cpu->{kept} = is_running_cpu_kept($conf);
+    $cpu->{enforce} = PVE::JSONSchema::parse_boolean($cpu->{props}->{enforce} // 'off');
+
+    my $understood = get_understood_cpu_flags();
+
+    $cpu->{flags} = {};
+    if ($cpu->{enforce} && $cpu->{kvm} && !is_host_cpu_model($cpu)) {
+        my $model_flags = eval { get_cpu_model_flags($vmid, $cpu->{model}, $understood) };
+        warn "unable to query the flags of CPU model '$cpu->{model}' - $@" if $@;
+        $cpu->{flags}->{$_} = 1 for ($model_flags // [])->@*;
+    }
+    for my $prop (keys $cpu->{props}->%*) {
+        my $enabled = PVE::JSONSchema::parse_boolean($cpu->{props}->{$prop});
+        next if !defined($enabled);
+        $enabled ? ($cpu->{flags}->{$prop} = 1) : delete($cpu->{flags}->{$prop});
+    }
 
     my $checks = [grep { $_->{applies}->($cpu) } $target_cpu_checks->@*];
     return ({}, []) if !scalar($checks->@*);
@@ -374,7 +444,7 @@ sub check_target_cpu_compatibility {
     my $source_info = get_node_cpu_info($local_node);
     $source_info = PVE::QemuServer::Helpers::get_host_cpu_info() if !scalar(keys $source_info->%*);
     $source_info->{'kvm-flags'} = get_node_kvm_cpu_flags($local_node);
-    $source_info->{'understood-flags'} = get_understood_cpu_flags();
+    $source_info->{'understood-flags'} = $understood;
 
     my ($issues_by_node, $unchecked_nodes) = ({}, []);
     for my $node ($nodes->@*) {
diff --git a/src/test/MigrationTest/QemuMigrateMock.pm b/src/test/MigrationTest/QemuMigrateMock.pm
index f8d30b05..6295736f 100644
--- a/src/test/MigrationTest/QemuMigrateMock.pm
+++ b/src/test/MigrationTest/QemuMigrateMock.pm
@@ -232,12 +232,21 @@ $qemu_server_cpuconfig_module->mock(
 
 $MigrationTest::Shared::qemu_migrate_helpers_module->mock(
     check_target_cpu_compatibility => sub {
-        my ($conf, $pid, $nodes) = @_;
+        my ($vmid, $conf, $pid, $nodes) = @_;
         # checking requires the running CPU, which most tests do not need to specify
         return ({}, []) if $pid && !defined($vm_status->{runningcpu});
         return $MigrationTest::Shared::qemu_migrate_helpers_module->original(
             'check_target_cpu_compatibility')->(@_);
     },
+    mon_cmd => sub {
+        my ($vmid, $command, %params) = @_;
+
+        if ($command eq 'query-cpu-model-expansion') {
+            my $flags = $test_cpu_info->{'model-flags'}->{ $params{model}->{name} } // [];
+            return { model => { props => { map { $_ => JSON::true } $flags->@* } } };
+        }
+        die "mon_cmd (mocked) - implement me: $command";
+    },
 );
 
 $MigrationTest::Shared::cluster_module->mock(
@@ -261,7 +270,7 @@ $MigrationTest::Shared::cluster_module->mock(
 my $qemu_server_cpuflags_module = Test::MockModule->new("PVE::QemuServer::CPUFlags");
 $qemu_server_cpuflags_module->mock(
     query_understood_cpu_flags => sub {
-        return [qw(avx512f fpu hv-relaxed lahf-lm sse sse4.2)];
+        return [qw(avx512f avx512vl fpu hv-relaxed lahf-lm sse sse4.2)];
     },
 );
 
diff --git a/src/test/run_qemu_migrate_tests.pl b/src/test/run_qemu_migrate_tests.pl
index 59b2ade2..9cd85990 100755
--- a/src/test/run_qemu_migrate_tests.pl
+++ b/src/test/run_qemu_migrate_tests.pl
@@ -1921,6 +1921,209 @@ my $tests = [
             },
         },
     },
+    {
+        name => '1033_running_kept_cpu_supported_flags',
+        target => 'pve1',
+        vmid => 1033,
+        vm_status => {
+            running => 1,
+            runningmachine => 'pc-q35-5.0+pve0',
+            runningcpu =>
+                'kvm64,enforce,+vmx,hv_evmcs,hv_relaxed,hv_spinlocks=0x1fff,+kvm_pv_eoi',
+        },
+        cpu_info => {
+            source => { vendor => 'GenuineIntel' },
+            nodes => {
+                pve1 => { vendor => 'GenuineIntel' },
+            },
+            'kvm-flags' => {
+                pve0 => 'fpu hv-evmcs hv-relaxed hv-spinlocks kvm-pv-eoi sse vmx',
+                pve1 => 'fpu hv-evmcs hv-relaxed kvm-pv-eoi sse vmx',
+            },
+        },
+        opts => {
+            online => 1,
+        },
+        config_patch => {
+            cpu => 'kvm64,flags=+nested-virt',
+        },
+        expected_calls => $default_expected_calls_online,
+        expected => {
+            source_volids => {},
+            target_volids => {},
+            vm_config => get_patched_config(1033, {
+                    cpu => 'kvm64,flags=+nested-virt',
+            }),
+            vm_status => {
+                running => 1,
+                runningmachine => 'pc-q35-5.0+pve0',
+                runningcpu =>
+                    'kvm64,enforce,+vmx,hv_evmcs,hv_relaxed,hv_spinlocks=0x1fff,+kvm_pv_eoi',
+            },
+        },
+    },
+    {
+        name => '1033_running_kept_cpu_unsupported_flags',
+        target => 'pve1',
+        vmid => 1033,
+        vm_status => {
+            running => 1,
+            runningmachine => 'pc-q35-5.0+pve0',
+            runningcpu =>
+                'kvm64,enforce,+vmx,hv_evmcs,hv_relaxed,hv_spinlocks=0x1fff,+kvm_pv_eoi',
+        },
+        cpu_info => {
+            source => { vendor => 'GenuineIntel' },
+            nodes => {
+                pve1 => { vendor => 'AuthenticAMD' },
+            },
+            'kvm-flags' => {
+                pve0 => 'fpu hv-evmcs hv-relaxed hv-spinlocks kvm-pv-eoi sse vmx',
+                pve1 => 'fpu hv-relaxed kvm-pv-eoi sse svm',
+            },
+        },
+        opts => {
+            online => 1,
+        },
+        config_patch => {
+            cpu => 'kvm64,flags=+nested-virt',
+        },
+        expected_calls => {},
+        expect_die =>
+            "can't migrate VM to 'pve1' - incompatible CPU: KVM on the node does not support"
+            . " flags of the VM's virtual CPU: hv-evmcs, vmx",
+        expected => {
+            source_volids => {},
+            target_volids => {},
+            vm_config => get_patched_config(1033, {
+                    cpu => 'kvm64,flags=+nested-virt',
+            }),
+            vm_status => {
+                running => 1,
+                runningmachine => 'pc-q35-5.0+pve0',
+                runningcpu =>
+                    'kvm64,enforce,+vmx,hv_evmcs,hv_relaxed,hv_spinlocks=0x1fff,+kvm_pv_eoi',
+            },
+        },
+    },
+    {
+        name => '1033_running_builtin_cpu_missing_flags',
+        target => 'pve1',
+        vmid => 1033,
+        vm_status => {
+            running => 1,
+            runningmachine => 'pc-q35-5.0+pve0',
+            runningcpu =>
+                'qemu64,enforce,+abm,+aes,+avx,+avx2,+kvm_pv_eoi,+sse4.2,vendor=GenuineIntel',
+        },
+        cpu_info => {
+            'kvm-flags' => {
+                pve0 => 'abm aes avx avx2 fpu kvm-pv-eoi sse sse4.2',
+                pve1 => 'abm aes avx fpu kvm-pv-eoi sse sse4.2',
+            },
+        },
+        opts => {
+            online => 1,
+        },
+        config_patch => {
+            cpu => 'x86-64-v3',
+        },
+        expected_calls => {},
+        expect_die =>
+            "can't migrate VM to 'pve1' - incompatible CPU: KVM on the node does not support"
+            . " flags of the VM's virtual CPU: avx2",
+        expected => {
+            source_volids => {},
+            target_volids => {},
+            vm_config => get_patched_config(1033, {
+                    cpu => 'x86-64-v3',
+            }),
+            vm_status => {
+                running => 1,
+                runningmachine => 'pc-q35-5.0+pve0',
+                runningcpu =>
+                    'qemu64,enforce,+abm,+aes,+avx,+avx2,+kvm_pv_eoi,+sse4.2,vendor=GenuineIntel',
+            },
+        },
+    },
+    {
+        name => '1033_running_named_cpu_missing_model_flags',
+        target => 'pve1',
+        vmid => 1033,
+        vm_status => {
+            running => 1,
+            runningmachine => 'pc-q35-5.0+pve0',
+            runningcpu => 'Skylake-Server,enforce,+kvm_pv_eoi,-avx512vl',
+        },
+        cpu_info => {
+            'kvm-flags' => {
+                pve0 => 'avx512f avx512vl fpu kvm-pv-eoi migratable sse sse4.2',
+                pve1 => 'fpu kvm-pv-eoi sse',
+            },
+            'model-flags' => {
+                'Skylake-Server' => [qw(avx512f avx512vl fpu migratable sse sse4_2)],
+            },
+        },
+        opts => {
+            online => 1,
+        },
+        config_patch => {
+            cpu => 'Skylake-Server',
+        },
+        expected_calls => {},
+        expect_die =>
+            "can't migrate VM to 'pve1' - incompatible CPU: KVM on the node does not support"
+            . " flags of the VM's virtual CPU: avx512f, sse4.2",
+        expected => {
+            source_volids => {},
+            target_volids => {},
+            vm_config => get_patched_config(1033, {
+                    cpu => 'Skylake-Server',
+            }),
+            vm_status => {
+                running => 1,
+                runningmachine => 'pc-q35-5.0+pve0',
+                runningcpu => 'Skylake-Server,enforce,+kvm_pv_eoi,-avx512vl',
+            },
+        },
+    },
+    {
+        name => '1033_running_named_cpu_supported_model_flags',
+        target => 'pve1',
+        vmid => 1033,
+        vm_status => {
+            running => 1,
+            runningmachine => 'pc-q35-5.0+pve0',
+            runningcpu => 'Skylake-Server,enforce,+kvm_pv_eoi,-avx512vl',
+        },
+        cpu_info => {
+            'kvm-flags' => {
+                pve0 => 'avx512f fpu kvm-pv-eoi migratable sse sse4.2',
+                pve1 => 'avx512f fpu kvm-pv-eoi sse sse4.2',
+            },
+            'model-flags' => {
+                'Skylake-Server' => [qw(avx512f avx512vl fpu migratable sse sse4_2)],
+            },
+        },
+        opts => {
+            online => 1,
+        },
+        config_patch => {
+            cpu => 'Skylake-Server',
+        },
+        expected_calls => $default_expected_calls_online,
+        expected => {
+            source_volids => {},
+            target_volids => {},
+            vm_config => get_patched_config(1033, {
+                    cpu => 'Skylake-Server',
+            }),
+            vm_status => {
+                running => 1,
+                runningmachine => 'pc-q35-5.0+pve0',
+            },
+        },
+    },
     {
         name => '105_replicated_to_non_replication_target',
         target => 'pve1',
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH qemu-server v2 09/20] cpu flags: report invtsc support of nodes
  2026-11-24 16:30 [PATCH docs/manager/qemu-server v2 00/20] check the target node's CPU before live migrating a VM Jonas Theisen
                   ` (7 preceding siblings ...)
  2026-11-24 16:30 ` [PATCH qemu-server v2 08/20] migrate: block migration if the target cannot run the virtual CPU Jonas Theisen
@ 2026-11-24 16:30 ` Jonas Theisen
  2026-11-24 16:30 ` [PATCH qemu-server v2 10/20] helpers: add helper to query the host's TSC frequency and scaling support Jonas Theisen
                   ` (10 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Jonas Theisen @ 2026-11-24 16:30 UTC (permalink / raw)
  To: pve-devel

QEMU only considers the invariant TSC flag migratable if the TSC
frequency is set explicitly. As the 'host' CPU model is migratable by
default, its expansion never includes invtsc. So no node is reported to
support it, for example in the 'Supported On' column of the CPU flag
selector.

Query the expansion once more with 'migratable' disabled and report
invtsc if the host supports it. Only invtsc is taken from it, as other
features QEMU considers unmigratable must not be reported for the
migratable 'host' model.

The live migration check for the 'host' CPU model must not require
invtsc on the target if it was not enabled explicitly, as the VM does
not have it then, and nodes with an older version do not report it.

Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
 src/PVE/QemuMigrate/Helpers.pm            |  7 +-
 src/PVE/QemuServer.pm                     | 14 ++++
 src/test/MigrationTest/QemuMigrateMock.pm |  2 +-
 src/test/run_qemu_migrate_tests.pl        | 81 +++++++++++++++++++++++
 4 files changed, 101 insertions(+), 3 deletions(-)

diff --git a/src/PVE/QemuMigrate/Helpers.pm b/src/PVE/QemuMigrate/Helpers.pm
index 48e4da5e..817bd923 100644
--- a/src/PVE/QemuMigrate/Helpers.pm
+++ b/src/PVE/QemuMigrate/Helpers.pm
@@ -271,11 +271,14 @@ my $target_cpu_checks = [
             my $understood = $source->{'understood-flags'};
             my @flags = grep { !$understood || $understood->{$_} } keys $source_flags->%*;
 
+            my $props = $cpu->{props};
             my @missing = sort grep {
-                # Hyper-V enlightenments are not passed through, but set explicitly
+                # Hyper-V enlightenments are not passed through, but set explicitly. As
+                # 'host' is migratable by default, invtsc is only enabled explicitly, too.
                 !m/^hv-/
+                    && ($_ ne 'invtsc' || $cpu->{flags}->{invtsc})
                     && !$target_flags->{$_}
-                    && ($cpu->{props}->{$_} // '') ne 'off'
+                    && ($props->{$_} // '') ne 'off'
             } @flags;
             return if !scalar(@missing);
 
diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index ecbaa27f..166b02a0 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -3045,6 +3045,20 @@ sub query_supported_cpu_flags {
 
                 $flags->{$prop} = 1;
             }
+
+            # 'host' omits invtsc while it is migratable, as QEMU only considers invtsc
+            # migratable with an explicit TSC frequency. It can still be enabled explicitly.
+            if ($kvm && $arch eq 'x86_64') {
+                $model->{props}->{migratable} = JSON::false;
+                my $unmigratable = mon_cmd(
+                    $fakevmid,
+                    'query-cpu-model-expansion',
+                    type => 'full',
+                    model => $model,
+                );
+                $flags->{invtsc} = 1
+                    if ($unmigratable->{model}->{props}->{invtsc} // '') eq JSON::true;
+            }
         };
         my $err = $@;
 
diff --git a/src/test/MigrationTest/QemuMigrateMock.pm b/src/test/MigrationTest/QemuMigrateMock.pm
index 6295736f..a27788dc 100644
--- a/src/test/MigrationTest/QemuMigrateMock.pm
+++ b/src/test/MigrationTest/QemuMigrateMock.pm
@@ -270,7 +270,7 @@ $MigrationTest::Shared::cluster_module->mock(
 my $qemu_server_cpuflags_module = Test::MockModule->new("PVE::QemuServer::CPUFlags");
 $qemu_server_cpuflags_module->mock(
     query_understood_cpu_flags => sub {
-        return [qw(avx512f avx512vl fpu hv-relaxed lahf-lm sse sse4.2)];
+        return [qw(avx512f avx512vl fpu hv-relaxed invtsc lahf-lm sse sse4.2)];
     },
 );
 
diff --git a/src/test/run_qemu_migrate_tests.pl b/src/test/run_qemu_migrate_tests.pl
index 9cd85990..90e42f2e 100755
--- a/src/test/run_qemu_migrate_tests.pl
+++ b/src/test/run_qemu_migrate_tests.pl
@@ -1872,6 +1872,87 @@ my $tests = [
             },
         },
     },
+    {
+        # 'host' only has invtsc if enabled explicitly, older nodes do not broadcast it
+        name => '1033_running_host_cpu_invtsc_not_enabled',
+        target => 'pve1',
+        vmid => 1033,
+        vm_status => {
+            running => 1,
+            runningmachine => 'pc-q35-5.0+pve0',
+            runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+        },
+        cpu_info => {
+            source => { vendor => 'GenuineIntel' },
+            nodes => {
+                pve1 => { vendor => 'GenuineIntel' },
+            },
+            'kvm-flags' => {
+                pve0 => 'fpu invtsc sse',
+                pve1 => 'fpu sse',
+            },
+        },
+        opts => {
+            online => 1,
+        },
+        config_patch => {
+            cpu => 'host',
+        },
+        expected_calls => $default_expected_calls_online,
+        expected => {
+            source_volids => {},
+            target_volids => {},
+            vm_config => get_patched_config(1033, {
+                    cpu => 'host',
+            }),
+            vm_status => {
+                running => 1,
+                runningmachine => 'pc-q35-5.0+pve0',
+            },
+        },
+    },
+    {
+        name => '1033_running_host_cpu_invtsc_enabled',
+        target => 'pve1',
+        vmid => 1033,
+        vm_status => {
+            running => 1,
+            runningmachine => 'pc-q35-5.0+pve0',
+            runningcpu => 'host,+invtsc,+kvm_pv_eoi,+kvm_pv_unhalt',
+        },
+        cpu_info => {
+            source => { vendor => 'GenuineIntel' },
+            nodes => {
+                pve1 => { vendor => 'GenuineIntel' },
+            },
+            'kvm-flags' => {
+                pve0 => 'fpu invtsc sse',
+                pve1 => 'fpu sse',
+            },
+        },
+        opts => {
+            online => 1,
+        },
+        config_patch => {
+            cpu => 'host',
+        },
+        expected_calls => {},
+        expect_die => "can't migrate VM to 'pve1' - incompatible CPU: CPU model 'host' passes"
+            . " through the flags of the host CPU, but the node lacks: invtsc - use"
+            . " 'allow-missing-cpu-flags' to override",
+        expected => {
+            source_volids => {},
+            target_volids => {},
+            vm_config => get_patched_config(1033, {
+                    cpu => 'host',
+            }),
+            vm_status => {
+                running => 1,
+                runningmachine => 'pc-q35-5.0+pve0',
+                runningcpu => 'host,+invtsc,+kvm_pv_eoi,+kvm_pv_unhalt',
+            },
+        },
+    },
     {
         name => '1033_running_host_cpu_other_model',
         target => 'pve1',
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH qemu-server v2 10/20] helpers: add helper to query the host's TSC frequency and scaling support
  2026-11-24 16:30 [PATCH docs/manager/qemu-server v2 00/20] check the target node's CPU before live migrating a VM Jonas Theisen
                   ` (8 preceding siblings ...)
  2026-11-24 16:30 ` [PATCH qemu-server v2 09/20] cpu flags: report invtsc support of nodes Jonas Theisen
@ 2026-11-24 16:30 ` Jonas Theisen
  2026-11-24 16:30 ` [PATCH qemu-server v2 11/20] cpu config: add hv-reenlightenment flag and set TSC frequency for it Jonas Theisen
                   ` (9 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Jonas Theisen @ 2026-11-24 16:30 UTC (permalink / raw)
  To: pve-devel

Guests whose time stamp counter (TSC) frequency must not change across
a live migration need to know the TSC frequency of the host they are
started on, and whether the hosts in a cluster can scale the TSC
frequency for guests.

Query both directly from KVM, as there is no other interface that
reliably exposes them: upstream Linux does not export the TSC frequency
to user space, and the TSC scaling CPU flag is shown in different
places of /proc/cpuinfo for Intel and AMD CPUs, regardless of whether
KVM uses it.

KVM_GET_TSC_KHZ is a vCPU ioctl, so a temporary VM with a single vCPU
is created. This is cheap, as no guest memory is set up, and the
result is cached, as it cannot change while the host is running.

Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
 src/PVE/QemuServer/Helpers.pm | 53 +++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/src/PVE/QemuServer/Helpers.pm b/src/PVE/QemuServer/Helpers.pm
index 70f9c817..95a3d23b 100644
--- a/src/PVE/QemuServer/Helpers.pm
+++ b/src/PVE/QemuServer/Helpers.pm
@@ -3,6 +3,7 @@ package PVE::QemuServer::Helpers;
 use strict;
 use warnings;
 
+use Fcntl qw(O_RDWR);
 use File::stat;
 use IO::File;
 
@@ -364,6 +365,58 @@ sub get_host_phys_address_bits {
     return; # undef, cannot really do anything..
 }
 
+# KVM ioctl request numbers and capabilities, see include/uapi/linux/kvm.h in Linux
+my $KVM_CREATE_VM = 0xae01;
+my $KVM_CHECK_EXTENSION = 0xae03;
+my $KVM_CREATE_VCPU = 0xae41;
+my $KVM_GET_TSC_KHZ = 0xaea3;
+my $KVM_CAP_TSC_CONTROL = 60;
+my $KVM_CAP_GET_TSC_KHZ = 61;
+
+my $_host_tsc_info;
+
+=head3 get_host_tsc_info
+
+    my $tsc_info = get_host_tsc_info();
+    my ($khz, $scaling) = $tsc_info->@{qw(khz scaling)};
+
+Returns a hash reference with information about the time stamp counter (TSC) of this host, as
+KVM reports it. C<khz> is the TSC frequency in kHz that KVM uses for new vCPUs, or undefined if
+KVM cannot report it. C<scaling> is true if KVM can run vCPUs with a different TSC frequency.
+
+The values are cached, as they cannot change while the host is running.
+
+Dies if C</dev/kvm> is not available.
+
+=cut
+
+sub get_host_tsc_info {
+    return $_host_tsc_info if defined($_host_tsc_info);
+
+    sysopen(my $kvm_fh, '/dev/kvm', O_RDWR) or die "unable to open /dev/kvm - $!\n";
+
+    my $check_extension = sub {
+        my ($cap) = @_;
+        return int(ioctl($kvm_fh, $KVM_CHECK_EXTENSION, $cap) // 0);
+    };
+
+    my $info = { scaling => $check_extension->($KVM_CAP_TSC_CONTROL) ? 1 : 0 };
+
+    # KVM_GET_TSC_KHZ is a vCPU ioctl, so it needs a temporary VM with a single vCPU
+    if ($check_extension->($KVM_CAP_GET_TSC_KHZ)) {
+        my $vm_fd = ioctl($kvm_fh, $KVM_CREATE_VM, 0) // die "unable to create KVM VM - $!\n";
+        open(my $vm_fh, '+<&=', int($vm_fd)) or die "unable to open KVM VM fd - $!\n";
+
+        my $vcpu_fd = ioctl($vm_fh, $KVM_CREATE_VCPU, 0) // die "unable to create KVM vCPU - $!\n";
+        open(my $vcpu_fh, '+<&=', int($vcpu_fd)) or die "unable to open KVM vCPU fd - $!\n";
+
+        my $khz = ioctl($vcpu_fh, $KVM_GET_TSC_KHZ, 0) // die "unable to get TSC frequency - $!\n";
+        $info->{khz} = int($khz) if int($khz) > 0;
+    }
+
+    return $_host_tsc_info = $info;
+}
+
 =head3 get_host_cpu_info
 
     my $info = get_host_cpu_info();
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH qemu-server v2 11/20] cpu config: add hv-reenlightenment flag and set TSC frequency for it
  2026-11-24 16:30 [PATCH docs/manager/qemu-server v2 00/20] check the target node's CPU before live migrating a VM Jonas Theisen
                   ` (9 preceding siblings ...)
  2026-11-24 16:30 ` [PATCH qemu-server v2 10/20] helpers: add helper to query the host's TSC frequency and scaling support Jonas Theisen
@ 2026-11-24 16:30 ` Jonas Theisen
  2026-11-24 16:30 ` [PATCH qemu-server v2 12/20] migrate: block migration to nodes with incompatible TSC for re-enlightenment Jonas Theisen
                   ` (8 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Jonas Theisen @ 2026-11-24 16:30 UTC (permalink / raw)
  To: pve-devel

Re-enlightenment notifications let nested Hyper-V guests, for example
Windows with WSL2 or VBS enabled, pass a stable clock source on to
their own guests across live migrations.

KVM does not emulate the old TSC frequency after a migration, so QEMU
refuses to load the migration stream of a guest that enabled these
notifications if no TSC frequency was set explicitly. Set it to the
host's TSC frequency, as reported by KVM, whenever the flag is enabled
for the VM or by a custom CPU model.

Treat the CPU configuration as abstracted if the flag is set, so that
the TSC frequency of the running instance is kept for live migration,
snapshots with RAM and hibernation, as the frequency of the host a VM
is resumed on can differ.

Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
 src/PVE/QemuServer/CPUConfig.pm               | 18 +++++++++++++
 src/PVE/QemuServer/CPUFlags.pm                |  8 ++++++
 src/test/QemuServerTest/CommandLineMocks.pm   |  3 +++
 src/test/cfg2cmd/cpu-hv-reenlightenment.conf  |  6 +++++
 .../cfg2cmd/cpu-hv-reenlightenment.conf.cmd   | 26 +++++++++++++++++++
 5 files changed, 61 insertions(+)
 create mode 100644 src/test/cfg2cmd/cpu-hv-reenlightenment.conf
 create mode 100644 src/test/cfg2cmd/cpu-hv-reenlightenment.conf.cmd

diff --git a/src/PVE/QemuServer/CPUConfig.pm b/src/PVE/QemuServer/CPUConfig.pm
index 414682a6..d629a2c6 100644
--- a/src/PVE/QemuServer/CPUConfig.pm
+++ b/src/PVE/QemuServer/CPUConfig.pm
@@ -718,6 +718,8 @@ determined from the configuration alone. Possible abstractions:
 
 =item abstract flag: for example, nested-virt changes with the host
 
+=item host-dependent setting: for example, hv-reenlightenment sets the TSC frequency of the host
+
 =back
 
 =cut
@@ -732,6 +734,7 @@ sub is_abstracted($cpu_property_string) {
     for my $flag (split(";", $cpu_conf->{flags})) {
         if ($flag =~ $cpu_flag_supported_re) {
             return 1 if $2 eq 'nested-virt';
+            return 1 if $2 eq 'hv-reenlightenment' && $1 eq '+';
         }
     }
     return;
@@ -965,6 +968,21 @@ sub get_cpu_options(
         $vm_flags,
         $pve_forced_flags,
     );
+
+    # Without an explicit TSC frequency, QEMU refuses to migrate a guest that enabled
+    # re-enlightenment notifications, as KVM does not emulate the old frequency afterwards.
+    my $reenlightenment = $resolved_flags->{'hv-reenlightenment'};
+    if ($kvm && $arch eq 'x86_64' && $reenlightenment && $reenlightenment->{op} ne '-') {
+        my $tsc_khz = PVE::QemuServer::Helpers::get_host_tsc_info()->{khz}
+            or die "unable to determine the host TSC frequency required for"
+            . " 'hv-reenlightenment'\n";
+        $resolved_flags->{'tsc-frequency'} = {
+            op => '',
+            value => $tsc_khz * 1000,
+            reason => "required by hv-reenlightenment",
+        };
+    }
+
     $cpu_str .= print_cpu_flags($resolved_flags);
 
     my $using_phys_bits_above_40;
diff --git a/src/PVE/QemuServer/CPUFlags.pm b/src/PVE/QemuServer/CPUFlags.pm
index 0ba2e115..bfdee207 100644
--- a/src/PVE/QemuServer/CPUFlags.pm
+++ b/src/PVE/QemuServer/CPUFlags.pm
@@ -76,6 +76,14 @@ my $supported_vm_specific_cpu_flags_by_arch = {
             description =>
                 "Improve performance for nested virtualization. Only supported on Intel" . " CPUs.",
         },
+        {
+            name => 'hv-reenlightenment',
+            description =>
+                "Allow nested Hyper-V guests, for example with WSL2 or VBS, to keep a stable"
+                . " clock source across live migrations. Sets the TSC frequency of the VM to"
+                . " the frequency of the host it is started on, so live migration only works"
+                . " to hosts with TSC scaling support or a TSC frequency within 250 ppm.",
+        },
         {
             name => 'aes',
             description => "Activate AES instruction set for HW acceleration.",
diff --git a/src/test/QemuServerTest/CommandLineMocks.pm b/src/test/QemuServerTest/CommandLineMocks.pm
index 7fd4cc23..d0cd31c2 100644
--- a/src/test/QemuServerTest/CommandLineMocks.pm
+++ b/src/test/QemuServerTest/CommandLineMocks.pm
@@ -395,6 +395,9 @@ $qemu_server_helpers->mock(
     get_host_phys_address_bits => sub {
         return 46;
     },
+    get_host_tsc_info => sub {
+        return { khz => 2999999, scaling => 1 };
+    },
     kvm_user_version => sub {
         return get_test_qemu_version();
     },
diff --git a/src/test/cfg2cmd/cpu-hv-reenlightenment.conf b/src/test/cfg2cmd/cpu-hv-reenlightenment.conf
new file mode 100644
index 00000000..7e8150df
--- /dev/null
+++ b/src/test/cfg2cmd/cpu-hv-reenlightenment.conf
@@ -0,0 +1,6 @@
+# TEST: Test that enabling hv-reenlightenment sets the TSC frequency of the host
+cpu: x86-64-v2-AES,flags=+hv-reenlightenment
+memory: 768
+numa: 0
+ostype: win11
+sockets: 1
diff --git a/src/test/cfg2cmd/cpu-hv-reenlightenment.conf.cmd b/src/test/cfg2cmd/cpu-hv-reenlightenment.conf.cmd
new file mode 100644
index 00000000..c3d8e49c
--- /dev/null
+++ b/src/test/cfg2cmd/cpu-hv-reenlightenment.conf.cmd
@@ -0,0 +1,26 @@
+/usr/bin/kvm \
+  -id 8006 \
+  -name vm8006 \
+  -no-shutdown \
+  -chardev 'socket,id=qmp,path=/var/run/qemu-server/8006.qmp,server=on,wait=off' \
+  -object 'monitor-qmp,chardev=qmp,id=monitor-qmp' \
+  -chardev 'socket,id=qmp-event,path=/var/run/qmeventd.sock,reconnect-ms=5000' \
+  -object 'monitor-qmp,chardev=qmp-event,id=monitor-qmp-event' \
+  -pidfile /var/run/qemu-server/8006.pid \
+  -daemonize \
+  -smp '1,sockets=1,cores=1,maxcpus=1' \
+  -nodefaults \
+  -boot 'menu=on,strict=on,reboot-timeout=1000,splash=/usr/share/qemu-server/bootsplash.jpg' \
+  -vnc 'unix:/var/run/qemu-server/8006.vnc,password=on' \
+  -global 'kvm-pit.lost_tick_policy=discard' \
+  -cpu 'qemu64,+aes,-cet-ibt,-cet-ss,enforce,+hv-reenlightenment,hv_ipi,hv_relaxed,hv_reset,hv_runtime,hv_spinlocks=0x1fff,hv_stimer,hv_synic,hv_time,hv_vapic,hv_vpindex,+kvm_pv_eoi,+kvm_pv_unhalt,+pni,+popcnt,+sse4.1,+sse4.2,+ssse3,tsc-frequency=2999999000' \
+  -m 768 \
+  -device 'pci-bridge,id=pci.1,chassis_nr=1,bus=pci.0,addr=0x1e' \
+  -device 'pci-bridge,id=pci.2,chassis_nr=2,bus=pci.0,addr=0x1f' \
+  -device 'piix3-usb-uhci,id=uhci,bus=pci.0,addr=0x1.0x2' \
+  -device 'usb-tablet,id=tablet,bus=uhci.0,port=1' \
+  -device 'VGA,id=vga,bus=pci.0,addr=0x2,edid=off' \
+  -device 'virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3' \
+  -iscsi 'initiator-name=iqn.1993-08.org.debian:01:aabbccddeeff' \
+  -rtc 'driftfix=slew,base=localtime' \
+  -machine 'hpet=off,type=pc-i440fx-5.1+pve0'
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH qemu-server v2 12/20] migrate: block migration to nodes with incompatible TSC for re-enlightenment
  2026-11-24 16:30 [PATCH docs/manager/qemu-server v2 00/20] check the target node's CPU before live migrating a VM Jonas Theisen
                   ` (10 preceding siblings ...)
  2026-11-24 16:30 ` [PATCH qemu-server v2 11/20] cpu config: add hv-reenlightenment flag and set TSC frequency for it Jonas Theisen
@ 2026-11-24 16:30 ` Jonas Theisen
  2026-11-24 16:30 ` [PATCH qemu-server v2 13/20] cpu config: set TSC frequency for invtsc to allow live migration Jonas Theisen
                   ` (7 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Jonas Theisen @ 2026-11-24 16:30 UTC (permalink / raw)
  To: pve-devel

A VM with 'hv-reenlightenment' runs with the TSC frequency of the host
it was started on. QEMU on the target node can only use it if KVM
there supports TSC scaling, or if the target's TSC frequency is within
250 ppm, which KVM accepts without scaling. QEMU hard-codes this
bound [0], matching the default of KVM's 'tsc_tolerance_ppm' module
parameter [1]. Otherwise the target instance fails to start and the
migration is aborted only after its preparation, for example after
local disks were already allocated on the target.

Broadcast the TSC frequency and scaling support as part of the node's
CPU information, and check this upfront. Target nodes that do not
broadcast this information yet are not blocked, but a warning is
logged, as for the other checks.

[0]: https://gitlab.com/qemu-project/qemu/-/blob/v11.1.0/target/i386/kvm/kvm.c#L886
[1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/x86/kvm/x86.c?h=v7.0#n164

Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
 src/PVE/API2/Qemu.pm               |   8 +-
 src/PVE/QemuMigrate/Helpers.pm     |  28 +++++
 src/PVE/QemuServer/Helpers.pm      |  12 ++
 src/test/run_qemu_migrate_tests.pl | 183 +++++++++++++++++++++++++++++
 4 files changed, 229 insertions(+), 2 deletions(-)

diff --git a/src/PVE/API2/Qemu.pm b/src/PVE/API2/Qemu.pm
index ba1ac71c..14032b9d 100644
--- a/src/PVE/API2/Qemu.pm
+++ b/src/PVE/API2/Qemu.pm
@@ -5619,8 +5619,12 @@ __PACKAGE__->register_method({
                                     type => {
                                         type => 'string',
                                         description => "The check that failed.",
-                                        enum =>
-                                            ['cpu-vendor', 'host-cpu-flags', 'vm-cpu-flags'],
+                                        enum => [
+                                            'cpu-vendor',
+                                            'host-cpu-flags',
+                                            'vm-cpu-flags',
+                                            'tsc-frequency',
+                                        ],
                                     },
                                     message => {
                                         type => 'string',
diff --git a/src/PVE/QemuMigrate/Helpers.pm b/src/PVE/QemuMigrate/Helpers.pm
index 817bd923..e69f7652 100644
--- a/src/PVE/QemuMigrate/Helpers.pm
+++ b/src/PVE/QemuMigrate/Helpers.pm
@@ -340,6 +340,34 @@ my $target_cpu_checks = [
                 . format_flag_list(\@missing);
         },
     },
+    {
+        type => 'tsc-frequency',
+        severity => 'error',
+        needs => ['tsc-scaling'],
+        applies => sub {
+            my ($cpu) = @_;
+            return $cpu->{flags}->{'hv-reenlightenment'} && $cpu->{props}->{'tsc-frequency'};
+        },
+        check => sub {
+            my ($cpu, $source, $target) = @_;
+
+            return if $target->{'tsc-scaling'};
+
+            my $vm_khz = int($cpu->{props}->{'tsc-frequency'} / 1000);
+            my $requirement = "'hv-reenlightenment' requires TSC scaling support or a TSC"
+                . " frequency within 250 ppm of the VM's $vm_khz kHz";
+
+            my $target_khz = $target->{'tsc-khz'}
+                or return "$requirement, but the node's TSC frequency is unknown";
+
+            # without TSC scaling, KVM can only set frequencies within 250 ppm, which QEMU
+            # considers to be within NTP correction bounds
+            my $tolerance = int($target_khz * 250 / 1_000_000);
+            return if abs($vm_khz - $target_khz) <= $tolerance;
+
+            return "$requirement, but the node has $target_khz kHz without TSC scaling";
+        },
+    },
 ];
 
 # Returns the issues of the target node, and whether all checks that can prevent the migration
diff --git a/src/PVE/QemuServer/Helpers.pm b/src/PVE/QemuServer/Helpers.pm
index 95a3d23b..f82daf12 100644
--- a/src/PVE/QemuServer/Helpers.pm
+++ b/src/PVE/QemuServer/Helpers.pm
@@ -431,6 +431,10 @@ encoded as JSON. The returned hash contains:
 
 =item C<model-name>: the CPU model name, for example C<AMD EPYC 7302 16-Core Processor>
 
+=item C<tsc-khz>: the TSC frequency in kHz that KVM uses for new vCPUs
+
+=item C<tsc-scaling>: whether KVM can run vCPUs with a different TSC frequency
+
 =back
 
 Properties that cannot be determined are missing. Consumers of the broadcast information must
@@ -448,6 +452,14 @@ sub get_host_cpu_info {
     $info->{vendor} = $cpuinfo->{vendor} if $known->($cpuinfo->{vendor});
     $info->{'model-name'} = $cpuinfo->{model} if $known->($cpuinfo->{model});
 
+    my $tsc_info = eval { get_host_tsc_info() };
+    warn "unable to query TSC information - $@" if $@;
+
+    if ($tsc_info) {
+        $info->{'tsc-khz'} = $tsc_info->{khz} if defined($tsc_info->{khz});
+        $info->{'tsc-scaling'} = $tsc_info->{scaling};
+    }
+
     return $info;
 }
 
diff --git a/src/test/run_qemu_migrate_tests.pl b/src/test/run_qemu_migrate_tests.pl
index 90e42f2e..70fc2d87 100755
--- a/src/test/run_qemu_migrate_tests.pl
+++ b/src/test/run_qemu_migrate_tests.pl
@@ -2205,6 +2205,189 @@ my $tests = [
             },
         },
     },
+    {
+        name => '1033_running_hv_reenlightenment_tsc_within_bounds',
+        target => 'pve1',
+        vmid => 1033,
+        vm_status => {
+            running => 1,
+            runningmachine => 'pc-q35-5.0+pve0',
+            runningcpu => 'kvm64,+hv-reenlightenment,tsc-frequency=2999999000',
+        },
+        cpu_info => {
+            nodes => {
+                pve1 => { vendor => 'GenuineIntel', 'tsc-khz' => 3000500, 'tsc-scaling' => 0 },
+            },
+        },
+        opts => {
+            online => 1,
+        },
+        config_patch => {
+            cpu => 'kvm64,flags=+hv-reenlightenment',
+        },
+        expected_calls => $default_expected_calls_online,
+        expected => {
+            source_volids => {},
+            target_volids => {},
+            vm_config => get_patched_config(1033, {
+                    cpu => 'kvm64,flags=+hv-reenlightenment',
+            }),
+            vm_status => {
+                running => 1,
+                runningmachine => 'pc-q35-5.0+pve0',
+                runningcpu => 'kvm64,+hv-reenlightenment,tsc-frequency=2999999000',
+            },
+        },
+    },
+    {
+        name => '1033_running_hv_reenlightenment_tsc_scaling',
+        target => 'pve1',
+        vmid => 1033,
+        vm_status => {
+            running => 1,
+            runningmachine => 'pc-q35-5.0+pve0',
+            runningcpu => 'kvm64,+hv-reenlightenment,tsc-frequency=2999999000',
+        },
+        cpu_info => {
+            nodes => {
+                pve1 => { vendor => 'GenuineIntel', 'tsc-khz' => 2400000, 'tsc-scaling' => 1 },
+            },
+        },
+        opts => {
+            online => 1,
+        },
+        config_patch => {
+            cpu => 'kvm64,flags=+hv-reenlightenment',
+        },
+        expected_calls => $default_expected_calls_online,
+        expected => {
+            source_volids => {},
+            target_volids => {},
+            vm_config => get_patched_config(1033, {
+                    cpu => 'kvm64,flags=+hv-reenlightenment',
+            }),
+            vm_status => {
+                running => 1,
+                runningmachine => 'pc-q35-5.0+pve0',
+                runningcpu => 'kvm64,+hv-reenlightenment,tsc-frequency=2999999000',
+            },
+        },
+    },
+    {
+        name => '1033_running_hv_reenlightenment_tsc_mismatch',
+        target => 'pve1',
+        vmid => 1033,
+        vm_status => {
+            running => 1,
+            runningmachine => 'pc-q35-5.0+pve0',
+            runningcpu => 'kvm64,+hv-reenlightenment,tsc-frequency=2999999000',
+        },
+        cpu_info => {
+            nodes => {
+                pve1 => { vendor => 'GenuineIntel', 'tsc-khz' => 2400000, 'tsc-scaling' => 0 },
+            },
+        },
+        opts => {
+            online => 1,
+        },
+        config_patch => {
+            cpu => 'kvm64,flags=+hv-reenlightenment',
+        },
+        expected_calls => {},
+        expect_die => "can't migrate VM to 'pve1' - incompatible CPU: 'hv-reenlightenment'"
+            . " requires TSC scaling support or a TSC frequency within 250 ppm of the VM's"
+            . " 2999999 kHz, but the node has 2400000 kHz without TSC scaling",
+        expected => {
+            source_volids => {},
+            target_volids => {},
+            vm_config => get_patched_config(1033, {
+                    cpu => 'kvm64,flags=+hv-reenlightenment',
+            }),
+            vm_status => {
+                running => 1,
+                runningmachine => 'pc-q35-5.0+pve0',
+                runningcpu => 'kvm64,+hv-reenlightenment,tsc-frequency=2999999000',
+            },
+        },
+    },
+    {
+        name => '1033_running_hv_reenlightenment_tsc_unknown',
+        target => 'pve1',
+        vmid => 1033,
+        vm_status => {
+            running => 1,
+            runningmachine => 'pc-q35-5.0+pve0',
+            runningcpu => 'kvm64,+hv-reenlightenment,tsc-frequency=2999999000',
+        },
+        cpu_info => {
+            nodes => {
+                pve1 => { vendor => 'GenuineIntel', 'tsc-scaling' => 0 },
+            },
+        },
+        opts => {
+            online => 1,
+        },
+        config_patch => {
+            cpu => 'kvm64,flags=+hv-reenlightenment',
+        },
+        expected_calls => {},
+        expect_die => "can't migrate VM to 'pve1' - incompatible CPU: 'hv-reenlightenment'"
+            . " requires TSC scaling support or a TSC frequency within 250 ppm of the VM's"
+            . " 2999999 kHz, but the node's TSC frequency is unknown",
+        expected => {
+            source_volids => {},
+            target_volids => {},
+            vm_config => get_patched_config(1033, {
+                    cpu => 'kvm64,flags=+hv-reenlightenment',
+            }),
+            vm_status => {
+                running => 1,
+                runningmachine => 'pc-q35-5.0+pve0',
+                runningcpu => 'kvm64,+hv-reenlightenment,tsc-frequency=2999999000',
+            },
+        },
+    },
+    {
+        name => '1033_running_hv_reenlightenment_target_without_tsc_info',
+        target => 'pve1',
+        vmid => 1033,
+        vm_status => {
+            running => 1,
+            runningmachine => 'pc-q35-5.0+pve0',
+            runningcpu => 'kvm64,+hv-reenlightenment,tsc-frequency=2999999000',
+        },
+        cpu_info => {
+            nodes => {
+                pve1 => { vendor => 'GenuineIntel' },
+            },
+            'kvm-flags' => {
+                pve0 => 'fpu hv-reenlightenment sse',
+                pve1 => 'fpu hv-reenlightenment sse',
+            },
+        },
+        opts => {
+            online => 1,
+        },
+        config_patch => {
+            cpu => 'kvm64,flags=+hv-reenlightenment',
+        },
+        expected_calls => $default_expected_calls_online,
+        expect_log => [
+            "unable to check CPU compatibility of node 'pve1' - CPU information not available",
+        ],
+        expected => {
+            source_volids => {},
+            target_volids => {},
+            vm_config => get_patched_config(1033, {
+                    cpu => 'kvm64,flags=+hv-reenlightenment',
+            }),
+            vm_status => {
+                running => 1,
+                runningmachine => 'pc-q35-5.0+pve0',
+                runningcpu => 'kvm64,+hv-reenlightenment,tsc-frequency=2999999000',
+            },
+        },
+    },
     {
         name => '105_replicated_to_non_replication_target',
         target => 'pve1',
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH qemu-server v2 13/20] cpu config: set TSC frequency for invtsc to allow live migration
  2026-11-24 16:30 [PATCH docs/manager/qemu-server v2 00/20] check the target node's CPU before live migrating a VM Jonas Theisen
                   ` (11 preceding siblings ...)
  2026-11-24 16:30 ` [PATCH qemu-server v2 12/20] migrate: block migration to nodes with incompatible TSC for re-enlightenment Jonas Theisen
@ 2026-11-24 16:30 ` Jonas Theisen
  2026-11-24 16:30 ` [PATCH qemu-server v2 14/20] migrate: factor out asserting the CPU compatibility of the target Jonas Theisen
                   ` (6 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Jonas Theisen @ 2026-11-24 16:30 UTC (permalink / raw)
  To: pve-devel

The invariant TSC flag can be enabled with custom CPU models. Unless
the TSC frequency is set explicitly, QEMU blocks live migration,
snapshots with RAM and hibernation of such VMs, as KVM does not emulate
the TSC frequency of the source host afterwards.

Set it to the host's TSC frequency, as for 'hv-reenlightenment', and
extend the check for a compatible TSC on the migration target to the
flag. As VMs with custom CPU models keep the CPU of the running
instance, the frequency stays the same across live migrations.

VMs that were started without an explicit TSC frequency still cannot
be migrated until they are restarted.

Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
 src/PVE/QemuMigrate/Helpers.pm              |  16 ++-
 src/PVE/QemuServer/CPUConfig.pm             |  31 ++++--
 src/test/QemuServerTest/CommandLineMocks.pm |   4 +
 src/test/cfg2cmd/cpu-invtsc.conf            |   6 ++
 src/test/cfg2cmd/cpu-invtsc.conf.cmd        |  27 +++++
 src/test/run_qemu_migrate_tests.pl          | 110 ++++++++++++++++++++
 6 files changed, 184 insertions(+), 10 deletions(-)
 create mode 100644 src/test/cfg2cmd/cpu-invtsc.conf
 create mode 100644 src/test/cfg2cmd/cpu-invtsc.conf.cmd

diff --git a/src/PVE/QemuMigrate/Helpers.pm b/src/PVE/QemuMigrate/Helpers.pm
index e69f7652..1ac0e7f9 100644
--- a/src/PVE/QemuMigrate/Helpers.pm
+++ b/src/PVE/QemuMigrate/Helpers.pm
@@ -184,6 +184,12 @@ my sub vendors_differ {
     return defined($source_vendor) && defined($target_vendor) && $source_vendor ne $target_vendor;
 }
 
+# Returns the enabled flags that make the VM run with the TSC frequency of the host it started on.
+my sub get_enabled_tsc_frequency_flags {
+    my ($cpu) = @_;
+    return grep { $cpu->{flags}->{$_} } PVE::QemuServer::CPUConfig::get_tsc_frequency_flags();
+}
+
 my sub format_flag_list {
     my ($flags) = @_;
 
@@ -346,7 +352,8 @@ my $target_cpu_checks = [
         needs => ['tsc-scaling'],
         applies => sub {
             my ($cpu) = @_;
-            return $cpu->{flags}->{'hv-reenlightenment'} && $cpu->{props}->{'tsc-frequency'};
+            return
+                scalar(get_enabled_tsc_frequency_flags($cpu)) && $cpu->{props}->{'tsc-frequency'};
         },
         check => sub {
             my ($cpu, $source, $target) = @_;
@@ -354,8 +361,11 @@ my $target_cpu_checks = [
             return if $target->{'tsc-scaling'};
 
             my $vm_khz = int($cpu->{props}->{'tsc-frequency'} / 1000);
-            my $requirement = "'hv-reenlightenment' requires TSC scaling support or a TSC"
-                . " frequency within 250 ppm of the VM's $vm_khz kHz";
+            my @flags = get_enabled_tsc_frequency_flags($cpu);
+            my $requirement =
+                join(' and ', map { "'$_'" } @flags)
+                . (scalar(@flags) > 1 ? " require" : " requires")
+                . " TSC scaling support or a TSC frequency within 250 ppm of the VM's $vm_khz kHz";
 
             my $target_khz = $target->{'tsc-khz'}
                 or return "$requirement, but the node's TSC frequency is unknown";
diff --git a/src/PVE/QemuServer/CPUConfig.pm b/src/PVE/QemuServer/CPUConfig.pm
index d629a2c6..082f8328 100644
--- a/src/PVE/QemuServer/CPUConfig.pm
+++ b/src/PVE/QemuServer/CPUConfig.pm
@@ -864,6 +864,19 @@ my sub check_phys_bits_above_40_compat($bios, $cpu_type, $cpu_flags) {
     }
 }
 
+=head3 get_tsc_frequency_flags
+
+    my @flags = get_tsc_frequency_flags();
+
+Returns the CPU flags for which the TSC frequency of the VM is set to the one of the host it is
+started on, as QEMU cannot migrate VMs with these flags otherwise.
+
+=cut
+
+sub get_tsc_frequency_flags() {
+    return qw(hv-reenlightenment invtsc);
+}
+
 # Calculate QEMU's '-cpu' argument from a given VM configuration
 sub get_cpu_options(
     $conf, $arch, $kvm, $kvm_off, $version_guard, $winversion, $gpu_passthrough,
@@ -969,17 +982,21 @@ sub get_cpu_options(
         $pve_forced_flags,
     );
 
-    # Without an explicit TSC frequency, QEMU refuses to migrate a guest that enabled
-    # re-enlightenment notifications, as KVM does not emulate the old frequency afterwards.
-    my $reenlightenment = $resolved_flags->{'hv-reenlightenment'};
-    if ($kvm && $arch eq 'x86_64' && $reenlightenment && $reenlightenment->{op} ne '-') {
+    # Without an explicit TSC frequency, QEMU refuses to migrate a guest with an invariant TSC or
+    # one that enabled re-enlightenment notifications, as KVM does not emulate the old frequency
+    # afterwards.
+    my @tsc_frequency_flags = grep {
+        my $flag = $resolved_flags->{$_};
+        $flag && $flag->{op} ne '-';
+    } get_tsc_frequency_flags();
+    if ($kvm && $arch eq 'x86_64' && scalar(@tsc_frequency_flags)) {
         my $tsc_khz = PVE::QemuServer::Helpers::get_host_tsc_info()->{khz}
-            or die "unable to determine the host TSC frequency required for"
-            . " 'hv-reenlightenment'\n";
+            or die "unable to determine the host TSC frequency required for "
+            . join(' and ', map { "'$_'" } @tsc_frequency_flags) . "\n";
         $resolved_flags->{'tsc-frequency'} = {
             op => '',
             value => $tsc_khz * 1000,
-            reason => "required by hv-reenlightenment",
+            reason => "required by " . join(' & ', @tsc_frequency_flags),
         };
     }
 
diff --git a/src/test/QemuServerTest/CommandLineMocks.pm b/src/test/QemuServerTest/CommandLineMocks.pm
index d0cd31c2..187215cf 100644
--- a/src/test/QemuServerTest/CommandLineMocks.pm
+++ b/src/test/QemuServerTest/CommandLineMocks.pm
@@ -483,6 +483,10 @@ cpu-model: qemu64
 
 cpu-model: alldefault
 
+cpu-model: invtsc
+    reported-model kvm64
+    flags +invtsc
+
 EOF
         );
     },
diff --git a/src/test/cfg2cmd/cpu-invtsc.conf b/src/test/cfg2cmd/cpu-invtsc.conf
new file mode 100644
index 00000000..d5c60fb4
--- /dev/null
+++ b/src/test/cfg2cmd/cpu-invtsc.conf
@@ -0,0 +1,6 @@
+# TEST: Test that enabling invtsc sets the TSC frequency of the host
+cpu: custom-invtsc
+memory: 768
+numa: 0
+ostype: l26
+sockets: 1
diff --git a/src/test/cfg2cmd/cpu-invtsc.conf.cmd b/src/test/cfg2cmd/cpu-invtsc.conf.cmd
new file mode 100644
index 00000000..61884c4b
--- /dev/null
+++ b/src/test/cfg2cmd/cpu-invtsc.conf.cmd
@@ -0,0 +1,27 @@
+/usr/bin/kvm \
+  -id 8006 \
+  -name vm8006 \
+  -no-shutdown \
+  -chardev 'socket,id=qmp,path=/var/run/qemu-server/8006.qmp,server=on,wait=off' \
+  -object 'monitor-qmp,chardev=qmp,id=monitor-qmp' \
+  -chardev 'socket,id=qmp-event,path=/var/run/qmeventd.sock,reconnect-ms=5000' \
+  -object 'monitor-qmp,chardev=qmp-event,id=monitor-qmp-event' \
+  -pidfile /var/run/qemu-server/8006.pid \
+  -daemonize \
+  -smp '1,sockets=1,cores=1,maxcpus=1' \
+  -nodefaults \
+  -boot 'menu=on,strict=on,reboot-timeout=1000,splash=/usr/share/qemu-server/bootsplash.jpg' \
+  -vnc 'unix:/var/run/qemu-server/8006.vnc,password=on' \
+  -cpu 'kvm64,enforce,+invtsc,+kvm_pv_eoi,+kvm_pv_unhalt,+lahf_lm,+sep,tsc-frequency=2999999000' \
+  -m 768 \
+  -global 'PIIX4_PM.disable_s3=1' \
+  -global 'PIIX4_PM.disable_s4=1' \
+  -device 'pci-bridge,id=pci.1,chassis_nr=1,bus=pci.0,addr=0x1e' \
+  -device 'pci-bridge,id=pci.2,chassis_nr=2,bus=pci.0,addr=0x1f' \
+  -device 'pci-bridge,id=pci.4,chassis_nr=4,bus=pci.1,addr=0x1c' \
+  -device 'piix3-usb-uhci,id=uhci,bus=pci.0,addr=0x1.0x2' \
+  -device 'usb-tablet,id=tablet,bus=uhci.0,port=1' \
+  -device 'VGA,id=vga,bus=pci.0,addr=0x2' \
+  -device 'virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3,free-page-reporting=on' \
+  -iscsi 'initiator-name=iqn.1993-08.org.debian:01:aabbccddeeff' \
+  -machine 'hpet=off,type=pc+pve0'
\ No newline at end of file
diff --git a/src/test/run_qemu_migrate_tests.pl b/src/test/run_qemu_migrate_tests.pl
index 70fc2d87..c8ef0f00 100755
--- a/src/test/run_qemu_migrate_tests.pl
+++ b/src/test/run_qemu_migrate_tests.pl
@@ -2388,6 +2388,116 @@ my $tests = [
             },
         },
     },
+    {
+        name => '1033_running_invtsc_tsc_scaling',
+        target => 'pve1',
+        vmid => 1033,
+        vm_status => {
+            running => 1,
+            runningmachine => 'pc-q35-5.0+pve0',
+            runningcpu => 'kvm64,enforce,+invtsc,tsc-frequency=2999999000',
+        },
+        cpu_info => {
+            nodes => {
+                pve1 => { vendor => 'GenuineIntel', 'tsc-khz' => 2400000, 'tsc-scaling' => 1 },
+            },
+        },
+        opts => {
+            online => 1,
+        },
+        config_patch => {
+            cpu => 'custom-invtsc',
+        },
+        expected_calls => $default_expected_calls_online,
+        expected => {
+            source_volids => {},
+            target_volids => {},
+            vm_config => get_patched_config(1033, {
+                    cpu => 'custom-invtsc',
+            }),
+            vm_status => {
+                running => 1,
+                runningmachine => 'pc-q35-5.0+pve0',
+                runningcpu => 'kvm64,enforce,+invtsc,tsc-frequency=2999999000',
+            },
+        },
+    },
+    {
+        name => '1033_running_invtsc_tsc_mismatch',
+        target => 'pve1',
+        vmid => 1033,
+        vm_status => {
+            running => 1,
+            runningmachine => 'pc-q35-5.0+pve0',
+            runningcpu => 'kvm64,enforce,+invtsc,tsc-frequency=2999999000',
+        },
+        cpu_info => {
+            nodes => {
+                pve1 => { vendor => 'GenuineIntel', 'tsc-khz' => 2400000, 'tsc-scaling' => 0 },
+            },
+        },
+        opts => {
+            online => 1,
+        },
+        config_patch => {
+            cpu => 'custom-invtsc',
+        },
+        expected_calls => {},
+        expect_die =>
+            "can't migrate VM to 'pve1' - incompatible CPU: 'invtsc' requires TSC scaling"
+            . " support or a TSC frequency within 250 ppm of the VM's 2999999 kHz, but the"
+            . " node has 2400000 kHz without TSC scaling",
+        expected => {
+            source_volids => {},
+            target_volids => {},
+            vm_config => get_patched_config(1033, {
+                    cpu => 'custom-invtsc',
+            }),
+            vm_status => {
+                running => 1,
+                runningmachine => 'pc-q35-5.0+pve0',
+                runningcpu => 'kvm64,enforce,+invtsc,tsc-frequency=2999999000',
+            },
+        },
+    },
+    {
+        name => '1033_running_hv_reenlightenment_invtsc_tsc_mismatch',
+        target => 'pve1',
+        vmid => 1033,
+        vm_status => {
+            running => 1,
+            runningmachine => 'pc-q35-5.0+pve0',
+            runningcpu => 'kvm64,enforce,+hv-reenlightenment,+invtsc,tsc-frequency=2999999000',
+        },
+        cpu_info => {
+            nodes => {
+                pve1 => { vendor => 'GenuineIntel', 'tsc-khz' => 2400000, 'tsc-scaling' => 0 },
+            },
+        },
+        opts => {
+            online => 1,
+        },
+        config_patch => {
+            cpu => 'custom-invtsc,flags=+hv-reenlightenment',
+        },
+        expected_calls => {},
+        expect_die => "can't migrate VM to 'pve1' - incompatible CPU: 'hv-reenlightenment' and"
+            . " 'invtsc' require TSC scaling support or a TSC frequency within 250 ppm of"
+            . " the VM's 2999999 kHz, but the node has 2400000 kHz without TSC scaling",
+        expected => {
+            source_volids => {},
+            target_volids => {},
+            vm_config => get_patched_config(1033, {
+                    cpu => 'custom-invtsc,flags=+hv-reenlightenment',
+            }),
+            vm_status => {
+                running => 1,
+                runningmachine => 'pc-q35-5.0+pve0',
+                runningcpu =>
+                    'kvm64,enforce,+hv-reenlightenment,+invtsc,tsc-frequency=2999999000',
+            },
+        },
+    },
     {
         name => '105_replicated_to_non_replication_target',
         target => 'pve1',
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH qemu-server v2 14/20] migrate: factor out asserting the CPU compatibility of the target
  2026-11-24 16:30 [PATCH docs/manager/qemu-server v2 00/20] check the target node's CPU before live migrating a VM Jonas Theisen
                   ` (12 preceding siblings ...)
  2026-11-24 16:30 ` [PATCH qemu-server v2 13/20] cpu config: set TSC frequency for invtsc to allow live migration Jonas Theisen
@ 2026-11-24 16:30 ` Jonas Theisen
  2026-11-24 16:30 ` [PATCH qemu-server v2 15/20] api: migrate: check the CPU of the target before requesting HA migration Jonas Theisen
                   ` (5 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Jonas Theisen @ 2026-11-24 16:30 UTC (permalink / raw)
  To: pve-devel

Move deciding which CPU incompatibilities of the target node prevent
the migration, and which are only logged, out of the migration
preparation into a helper, so that the API can check this before
handing a migration over to the HA stack.

No functional change intended.

Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
 src/PVE/QemuMigrate.pm         | 38 +++-----------------------
 src/PVE/QemuMigrate/Helpers.pm | 50 ++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 34 deletions(-)

diff --git a/src/PVE/QemuMigrate.pm b/src/PVE/QemuMigrate.pm
index 0b286f58..5c85ec36 100644
--- a/src/PVE/QemuMigrate.pm
+++ b/src/PVE/QemuMigrate.pm
@@ -326,40 +326,10 @@ sub prepare {
 
     # nodes of other clusters do not broadcast their CPU information to this cluster
     if (!$self->{opts}->{remote}) {
-        my $node = $self->{node};
-        my ($cpu_issues, $unchecked_nodes) =
-            PVE::QemuMigrate::Helpers::check_target_cpu_compatibility(
-                $vmid, $conf, $running, [$node],
-            );
-
-        my @errors;
-        for my $issue (($cpu_issues->{$node} // [])->@*) {
-            my $override = $issue->{override};
-            if ($issue->{severity} eq 'warning') {
-                log_warn("CPU of node '$node' might be incompatible: $issue->{message}");
-            } elsif (defined($override) && $self->{opts}->{$override}) {
-                log_warn("ignoring incompatible CPU of node '$node' due to '$override':"
-                    . " $issue->{message}");
-            } else {
-                push @errors, $issue;
-            }
-        }
-        if (scalar(@errors)) {
-            my $hint = '';
-            if (!grep { !defined($_->{override}) } @errors) {
-                my %overrides = map { $_->{override} => 1 } @errors;
-                $hint =
-                    " - use " . join(' and ', map { "'$_'" } sort keys %overrides) . " to override";
-            }
-            die "can't migrate VM to '$node' - incompatible CPU: "
-                . join('; ', map { $_->{message} } @errors)
-                . "$hint\n";
-        }
-
-        if (scalar($unchecked_nodes->@*)) {
-            log_warn("unable to check CPU compatibility of node '$node' - CPU information not"
-                . " available");
-        }
+        my $warnings = PVE::QemuMigrate::Helpers::assert_target_cpu_compatibility(
+            $vmid, $conf, $running, $self->{node}, $self->{opts},
+        );
+        log_warn($_) for $warnings->@*;
     }
 
     my $vollist = PVE::QemuServer::get_vm_volumes($conf);
diff --git a/src/PVE/QemuMigrate/Helpers.pm b/src/PVE/QemuMigrate/Helpers.pm
index 1ac0e7f9..c4995672 100644
--- a/src/PVE/QemuMigrate/Helpers.pm
+++ b/src/PVE/QemuMigrate/Helpers.pm
@@ -500,6 +500,56 @@ sub check_target_cpu_compatibility {
     return ($issues_by_node, $unchecked_nodes);
 }
 
+=head3 assert_target_cpu_compatibility
+
+    my $warnings = assert_target_cpu_compatibility($vmid, $conf, $pid, $node, $opts);
+
+Checks whether the running VM can run with its current virtual CPU on the node C<$node>, see
+check_target_cpu_compatibility(). Dies if the node is incompatible, unless the migration options
+C<$opts> override all the incompatibilities.
+
+Returns an array reference with the warnings to log, about possible incompatibilities, overridden
+incompatibilities, and missing CPU information of the node.
+
+=cut
+
+sub assert_target_cpu_compatibility {
+    my ($vmid, $conf, $pid, $node, $opts) = @_;
+
+    my ($issues_by_node, $unchecked_nodes) =
+        check_target_cpu_compatibility($vmid, $conf, $pid, [$node]);
+
+    my ($errors, $warnings) = ([], []);
+    for my $issue (($issues_by_node->{$node} // [])->@*) {
+        my $override = $issue->{override};
+        if ($issue->{severity} eq 'warning') {
+            push $warnings->@*, "CPU of node '$node' might be incompatible: $issue->{message}";
+        } elsif (defined($override) && $opts->{$override}) {
+            push $warnings->@*,
+                "ignoring incompatible CPU of node '$node' due to '$override': $issue->{message}";
+        } else {
+            push $errors->@*, $issue;
+        }
+    }
+
+    if (scalar($errors->@*)) {
+        my $hint = '';
+        if (!grep { !defined($_->{override}) } $errors->@*) {
+            my %overrides = map { $_->{override} => 1 } $errors->@*;
+            $hint = " - use " . join(' and ', map { "'$_'" } sort keys %overrides) . " to override";
+        }
+        die "can't migrate VM to '$node' - incompatible CPU: "
+            . join('; ', map { $_->{message} } $errors->@*)
+            . "$hint\n";
+    }
+
+    push $warnings->@*,
+        "unable to check CPU compatibility of node '$node' - CPU information not available"
+        if scalar($unchecked_nodes->@*);
+
+    return $warnings;
+}
+
 sub set_migration_caps {
     my ($vmid, $savevm) = @_;
 
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH qemu-server v2 15/20] api: migrate: check the CPU of the target before requesting HA migration
  2026-11-24 16:30 [PATCH docs/manager/qemu-server v2 00/20] check the target node's CPU before live migrating a VM Jonas Theisen
                   ` (13 preceding siblings ...)
  2026-11-24 16:30 ` [PATCH qemu-server v2 14/20] migrate: factor out asserting the CPU compatibility of the target Jonas Theisen
@ 2026-11-24 16:30 ` Jonas Theisen
  2026-11-24 16:30 ` [PATCH manager v2 16/20] pvestatd: broadcast host CPU information relevant for live migration Jonas Theisen
                   ` (4 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Jonas Theisen @ 2026-11-24 16:30 UTC (permalink / raw)
  To: pve-devel

For HA-managed VMs, the migrate API only requests the migration from
the HA stack, which then runs it in a separate task on the LRM. If the
target node's CPU cannot run the VM, that task fails, but the API call
and its task have already succeeded, so the caller only learns about it
from the LRM's task log or the HA status.

Run the CPU compatibility check before requesting the HA migration, as
done for the storage checks already, so that the API call fails with
the reason directly. Options that override an incompatibility, like
'allow-missing-cpu-flags', are honored as in the migration itself. The
warnings are not reported here, as the migration task of the LRM logs
them.

Migrations that the HA stack starts on its own, for example for
maintenance mode or automatic rebalancing, do not use this API path and
still fail in the migration task, after which the HA stack currently
retries them without backoff, see bug #8059.

Link: https://bugzilla.proxmox.com/show_bug.cgi?id=8059
Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
 src/PVE/API2/Qemu.pm | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/PVE/API2/Qemu.pm b/src/PVE/API2/Qemu.pm
index 14032b9d..55212792 100644
--- a/src/PVE/API2/Qemu.pm
+++ b/src/PVE/API2/Qemu.pm
@@ -5956,7 +5956,8 @@ __PACKAGE__->register_method({
 
         PVE::QemuConfig->check_lock($conf);
 
-        if (PVE::QemuServer::check_running($vmid)) {
+        my $pid = PVE::QemuServer::check_running($vmid);
+        if ($pid) {
             die "can't migrate running VM without --online\n" if !$param->{online};
 
             my $repl_conf = PVE::ReplicationConfig->new();
@@ -6002,6 +6003,11 @@ __PACKAGE__->register_method({
         }
 
         if (PVE::HA::Config::vm_is_ha_managed($vmid) && $rpcenv->{type} ne 'ha') {
+            # The HA stack migrates the VM in a separate task later, so refuse an incompatible
+            # target here, where the caller sees why. The task logs the warnings.
+            PVE::QemuMigrate::Helpers::assert_target_cpu_compatibility(
+                $vmid, $conf, $pid, $target, $param,
+            ) if $param->{online};
 
             my $hacmd = sub {
                 my $upid = shift;
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH manager v2 16/20] pvestatd: broadcast host CPU information relevant for live migration
  2026-11-24 16:30 [PATCH docs/manager/qemu-server v2 00/20] check the target node's CPU before live migrating a VM Jonas Theisen
                   ` (14 preceding siblings ...)
  2026-11-24 16:30 ` [PATCH qemu-server v2 15/20] api: migrate: check the CPU of the target before requesting HA migration Jonas Theisen
@ 2026-11-24 16:30 ` Jonas Theisen
  2026-11-24 16:30 ` [PATCH manager v2 17/20] ui: migrate: show why the CPU of the target node is incompatible Jonas Theisen
                   ` (3 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Jonas Theisen @ 2026-11-24 16:30 UTC (permalink / raw)
  To: pve-devel

qemu-server checks whether the CPU of a target node can run a VM after
a live migration, for example whether it supports the TSC frequency
a VM with 'hv-reenlightenment' requires, or has the same vendor and
model as the source for VMs with the 'host' CPU model.

Broadcast the information qemu-server provides for this, currently the
CPU vendor and model name, TSC frequency and TSC scaling support of the
node, so that the source node of a migration can check this. The
information cannot change while pvestatd runs, so it is only queried
once, but broadcast again if the node key-value entry got lost.

Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
 PVE/Service/pvestatd.pm | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/PVE/Service/pvestatd.pm b/PVE/Service/pvestatd.pm
index 2f6a2671..d1e5a91a 100755
--- a/PVE/Service/pvestatd.pm
+++ b/PVE/Service/pvestatd.pm
@@ -23,6 +23,7 @@ use PVE::Storage;
 use PVE::Multipath::Status;
 use PVE::MultipathNotification;
 use PVE::QemuServer;
+use PVE::QemuServer::Helpers;
 use PVE::QemuServer::Monitor;
 use PVE::LXC;
 use PVE::CGroup;
@@ -170,6 +171,19 @@ my sub broadcast_static_node_info {
     }
 }
 
+# the host CPU cannot change while pvestatd is running
+my $host_cpu_info;
+
+my sub broadcast_host_cpu_info {
+    $host_cpu_info //= PVE::QemuServer::Helpers::get_host_cpu_info();
+
+    my $info = JSON->new->canonical->encode($host_cpu_info);
+
+    # re-broadcast if the entry got lost, for example after a restart of pmxcfs
+    my $old = PVE::Cluster::get_node_kv('host-cpu-info', $nodename)->{$nodename};
+    PVE::Cluster::broadcast_node_kv('host-cpu-info', $info) if ($old // '') ne $info;
+}
+
 my ($cached_ip_links, $cached_ip_link_last_update) = (undef, 0);
 my $MAX_IP_LINK_CACHE_AGE_SECONDS = 15 * 60; # every 15 minutes
 
@@ -295,6 +309,7 @@ sub update_node_status {
     PVE::PullMetric::update($pull_txn, 'node', $node_metric, $ctime);
 
     broadcast_static_node_info($maxcpu, $meminfo->{memtotal});
+    broadcast_host_cpu_info();
 }
 
 sub auto_ballooning {
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH manager v2 17/20] ui: migrate: show why the CPU of the target node is incompatible
  2026-11-24 16:30 [PATCH docs/manager/qemu-server v2 00/20] check the target node's CPU before live migrating a VM Jonas Theisen
                   ` (15 preceding siblings ...)
  2026-11-24 16:30 ` [PATCH manager v2 16/20] pvestatd: broadcast host CPU information relevant for live migration Jonas Theisen
@ 2026-11-24 16:30 ` Jonas Theisen
  2026-11-24 16:30 ` [PATCH manager v2 18/20] fix #6535: ui: migrate: show CPU warnings for the target node Jonas Theisen
                   ` (2 subsequent siblings)
  19 siblings, 0 replies; 21+ messages in thread
From: Jonas Theisen @ 2026-11-24 16:30 UTC (permalink / raw)
  To: pve-devel

Show the reasons the migration precondition API reports for target
nodes whose CPU cannot run a VM after a live migration, instead of
only failing once the migration task runs.

If root can override all of these reasons with migration options, offer
a checkbox to ignore the incompatibility, which sets these options and
shows the reasons as warnings instead. Which options to set is taken
from the API, so that further overridable checks need no UI changes.
The checkbox is also shown for HA-managed VMs, as the migration API
forwards the override options to the HA stack.

Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
 www/manager6/window/Migrate.js | 54 ++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/www/manager6/window/Migrate.js b/www/manager6/window/Migrate.js
index dcfcf2aa..9b8d8692 100644
--- a/www/manager6/window/Migrate.js
+++ b/www/manager6/window/Migrate.js
@@ -29,6 +29,8 @@ Ext.define('PVE.window.Migrate', {
                 allowedNodes: undefined,
                 overwriteLocalResourceCheck: false,
                 hasLocalResources: false,
+                ignoreCpuIncompatibility: false,
+                cpuOverrides: [],
                 withConntrackState: true,
                 bothHaveDbusVmstate: false,
                 configCheck: true,
@@ -64,6 +66,7 @@ Ext.define('PVE.window.Migrate', {
                     return false;
                 }
             },
+            cpuOverrideCheckboxHidden: (get) => !get('migration.cpuOverrides').length,
             conntrackStateCheckboxHidden: (get) =>
                 !get('running') ||
                 get('vmtype') !== 'qemu' ||
@@ -147,6 +150,12 @@ Ext.define('PVE.window.Migrate', {
                 params.force = 1;
             }
 
+            if (vm.get('migration.ignoreCpuIncompatibility')) {
+                for (const override of vm.get('migration.cpuOverrides')) {
+                    params[override] = 1;
+                }
+            }
+
             if (vm.get('migration.bothHaveDbusVmstate') && vm.get('migration.withConntrackState')) {
                 params['with-conntrack-state'] = 1;
             }
@@ -326,6 +335,30 @@ Ext.define('PVE.window.Migrate', {
 
             me.checkGuestIdentitySupport(migration, disallowed);
 
+            let cpuBlockers = disallowed['incompatible-cpu'] ?? [];
+            // the override options are reserved for root
+            let canOverrideCpu =
+                Proxmox.UserName === 'root@pam' &&
+                cpuBlockers.length > 0 &&
+                cpuBlockers.every((blocker) => blocker.override);
+            migration.cpuOverrides = canOverrideCpu
+                ? [...new Set(cpuBlockers.map((blocker) => blocker.override))]
+                : [];
+
+            for (const cpuBlocker of cpuBlockers) {
+                const text = Ext.String.format(
+                    gettext('CPU of selected target is incompatible: {0}'),
+                    cpuBlocker.message,
+                );
+
+                if (canOverrideCpu && migration.ignoreCpuIncompatibility) {
+                    migration.preconditions.push({ text, severity: 'warning' });
+                } else {
+                    migration.possible = false;
+                    migration.preconditions.push({ text, severity: 'error' });
+                }
+            }
+
             let blockingResources = [];
             let mappedResources = migrateStats['mapped-resource-info'] ?? {};
 
@@ -717,6 +750,27 @@ Ext.define('PVE.window.Migrate', {
                                 },
                             },
                         },
+                        {
+                            xtype: 'proxmoxcheckbox',
+                            name: 'ignoreCpuIncompatibility',
+                            fieldLabel: gettext('Ignore CPU incompatibility'),
+                            autoEl: {
+                                tag: 'div',
+                                'data-qtip': gettext(
+                                    'Migrate even if the CPU of the selected target is incompatible. The VM might crash or fail to migrate.',
+                                ),
+                            },
+                            bind: {
+                                hidden: '{cpuOverrideCheckboxHidden}',
+                                value: '{migration.ignoreCpuIncompatibility}',
+                            },
+                            listeners: {
+                                change: {
+                                    fn: 'checkMigratePreconditions',
+                                    extraArg: true,
+                                },
+                            },
+                        },
                         {
                             xtype: 'proxmoxcheckbox',
                             name: 'withConntrackState',
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH manager v2 18/20] fix #6535: ui: migrate: show CPU warnings for the target node
  2026-11-24 16:30 [PATCH docs/manager/qemu-server v2 00/20] check the target node's CPU before live migrating a VM Jonas Theisen
                   ` (16 preceding siblings ...)
  2026-11-24 16:30 ` [PATCH manager v2 17/20] ui: migrate: show why the CPU of the target node is incompatible Jonas Theisen
@ 2026-11-24 16:30 ` Jonas Theisen
  2026-11-24 16:30 ` [PATCH manager v2 19/20] api: nodes: migrateall: skip VMs whose CPU is incompatible with the target Jonas Theisen
  2026-11-24 16:30 ` [PATCH docs v2 20/20] qm: document hv-reenlightenment, invtsc and CPU checks for migration Jonas Theisen
  19 siblings, 0 replies; 21+ messages in thread
From: Jonas Theisen @ 2026-11-24 16:30 UTC (permalink / raw)
  To: pve-devel

Show the warnings the migration precondition API reports for the CPU
of the selected target node, for example when live migrating between
CPU vendors, which is not guaranteed to work.

Fixes: https://bugzilla.proxmox.com/show_bug.cgi?id=6535
Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
 www/manager6/window/Migrate.js | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/www/manager6/window/Migrate.js b/www/manager6/window/Migrate.js
index 9b8d8692..f5bfa899 100644
--- a/www/manager6/window/Migrate.js
+++ b/www/manager6/window/Migrate.js
@@ -359,6 +359,15 @@ Ext.define('PVE.window.Migrate', {
                 }
             }
 
+            for (const cpuWarning of migrateStats['cpu-warnings']?.[target] ?? []) {
+                const text = Ext.String.format(
+                    gettext('CPU of selected target might be incompatible: {0}'),
+                    cpuWarning.message,
+                );
+
+                migration.preconditions.push({ text, severity: 'warning' });
+            }
+
             let blockingResources = [];
             let mappedResources = migrateStats['mapped-resource-info'] ?? {};
 
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH manager v2 19/20] api: nodes: migrateall: skip VMs whose CPU is incompatible with the target
  2026-11-24 16:30 [PATCH docs/manager/qemu-server v2 00/20] check the target node's CPU before live migrating a VM Jonas Theisen
                   ` (17 preceding siblings ...)
  2026-11-24 16:30 ` [PATCH manager v2 18/20] fix #6535: ui: migrate: show CPU warnings for the target node Jonas Theisen
@ 2026-11-24 16:30 ` Jonas Theisen
  2026-11-24 16:30 ` [PATCH docs v2 20/20] qm: document hv-reenlightenment, invtsc and CPU checks for migration Jonas Theisen
  19 siblings, 0 replies; 21+ messages in thread
From: Jonas Theisen @ 2026-11-24 16:30 UTC (permalink / raw)
  To: pve-devel

The migration precondition API reports target nodes whose CPU cannot
run a VM after a live migration. Skip such VMs with the reason in the
log, like for the other failed preconditions, instead of starting
a migration task that fails right away.

Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
 PVE/API2/Nodes.pm | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/PVE/API2/Nodes.pm b/PVE/API2/Nodes.pm
index aa35a696..4eb36fe2 100644
--- a/PVE/API2/Nodes.pm
+++ b/PVE/API2/Nodes.pm
@@ -2684,6 +2684,11 @@ my $create_migrate_worker = sub {
                 $invalidConditions .= "\n  Has unavailable resources: ";
                 $invalidConditions .= join(', ', $unavail_resources->@*);
             }
+
+            if (my $incompatible_cpu = $not_allowed_nodes->{$target}->{'incompatible-cpu'}) {
+                $invalidConditions .= "\n  Has incompatible CPU: ";
+                $invalidConditions .= join('; ', map { $_->{message} } $incompatible_cpu->@*);
+            }
         }
 
         if ($invalidConditions && $invalidConditions ne '') {
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH docs v2 20/20] qm: document hv-reenlightenment, invtsc and CPU checks for migration
  2026-11-24 16:30 [PATCH docs/manager/qemu-server v2 00/20] check the target node's CPU before live migrating a VM Jonas Theisen
                   ` (18 preceding siblings ...)
  2026-11-24 16:30 ` [PATCH manager v2 19/20] api: nodes: migrateall: skip VMs whose CPU is incompatible with the target Jonas Theisen
@ 2026-11-24 16:30 ` Jonas Theisen
  19 siblings, 0 replies; 21+ messages in thread
From: Jonas Theisen @ 2026-11-24 16:30 UTC (permalink / raw)
  To: pve-devel

Explain what the new 'hv-reenlightenment' CPU flag is for, and that
custom CPU types with 'invtsc' can now be live migrated. Both restrict
the nodes a VM can be live migrated to, as the target's TSC frequency
must be compatible.

Also document that live migrations known not to work because of the
target node's CPU are now refused, for all CPU types, how root can
override the check of the CPU flags for VMs with the 'host' or 'max'
CPU type, the warnings about live migrations between different CPU
vendors and models, and how the checks apply to HA-managed VMs.

Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
 qm.adoc | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/qm.adoc b/qm.adoc
index cfa8587..fd37e02 100644
--- a/qm.adoc
+++ b/qm.adoc
@@ -571,6 +571,16 @@ listings, `Mapping.Modify` gates create/update/delete in the panel, and
 enforced on VM create, VM update, and VM clone, so a user who can clone a VM
 that uses a custom model still needs `Mapping.Use` on that model's ACL path.
 
+Custom CPU types can enable the invariant TSC flag `invtsc`, which guests need
+to rely on the TSC as clock source, for example for applications reading it
+directly or for nested hypervisors. The host CPU must have an invariant TSC as
+well. For CPU types based on `host`, QEMU otherwise starts the VM without the
+flag and only logs a warning. {pve} sets the TSC frequency of such VMs to the
+frequency of the host they are started on, as QEMU requires it for live
+migration, snapshots including RAM, and hibernation. Such a VM can only be live
+migrated to nodes that support `invtsc`, and either support TSC scaling or
+have a TSC frequency within 250 ppm of the VM's.
+
 [[qm_meltdown_spectre]]
 Meltdown / Spectre related CPU flags
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -699,6 +709,13 @@ guests on recent Intel hardware:
   only applies for x86_64 vCPUs; it is silently ignored on other
   architectures.
 
+* The `hv-reenlightenment` flag allows nested Hyper-V guests, for example
+  Windows with WSL2 or virtualization-based security enabled, to keep a stable
+  clock source across live migrations. {pve} then sets the TSC frequency of
+  the VM to the frequency of the host it is started on. Such a VM can only be
+  live migrated to nodes that support TSC scaling, or whose TSC frequency is
+  within 250 ppm of the VM's.
+
 
 NUMA
 ^^^^
@@ -1867,6 +1884,40 @@ For Live Migration to work, there are some things required:
   vendor  *might* work depending on the actual models and VMs CPU type
   configured, but it cannot be guaranteed - so please test before deploying
   such a setup in production.
++
+{pve} refuses live migrations that are known not to work:
++
+--
+** VMs with the CPU type `host` or `max` to a node with a CPU from a different
+   vendor, or whose CPU lacks flags of the source node's CPU, as the guest
+   might use them.
+** VMs with any other CPU type, for example `x86-64-v3` or a custom CPU type, to
+   a node that does not support all flags of the VM's virtual CPU, including
+   the flags the CPU type enables by default. QEMU would refuse to start the
+   VM on such a node.
+** VMs with the `hv-reenlightenment` or `invtsc` CPU flag to a node with an
+   incompatible TSC frequency.
+--
++
+The migration dialog and `qm migrate` show the reason, and migrating all VMs
+of a node skips such VMs. For live migrations between CPU vendors with other
+CPU types, a warning is shown, as guests can become unstable, sometimes only a
+while after the migration. A warning is also shown for VMs with the CPU type
+`host` or `max` if the CPU models of the nodes differ, as live migration with
+these CPU types is only reliable between identical CPUs. Most of these checks
+only apply if the target node runs a {pve} version that reports its CPU
+information.
++
+As the flags supported by KVM also depend on the kernel version, `root@pam`
+can override the check of the flags for the CPU types `host` and `max` with
+the `--allow-missing-cpu-flags` option of `qm migrate`, or the corresponding
+option in the migration dialog. The `--force` option, which the HA stack uses
+for its migrations, does not override this check.
++
+The checks also apply to migrations of HA-managed VMs. A migration requested
+through the API or web interface is refused right away. Migrations that the HA
+stack starts on its own, for example for maintenance mode, cannot override the
+check and fail.
 
 Conntrack State Migration
 ^^^^^^^^^^^^^^^^^^^^^^^^^
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2026-11-24 16:35 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 16:30 [PATCH docs/manager/qemu-server v2 00/20] check the target node's CPU before live migrating a VM Jonas Theisen
2026-11-24 16:30 ` [PATCH qemu-server v2 01/20] test: migration: allow checking for warnings and errors in the log Jonas Theisen
2026-11-24 16:30 ` [PATCH qemu-server v2 02/20] migrate: block live migration of host CPU VMs between CPU vendors Jonas Theisen
2026-11-24 16:30 ` [PATCH qemu-server v2 03/20] fix #6535: migrate: warn about live migration " Jonas Theisen
2026-11-24 16:30 ` [PATCH qemu-server v2 04/20] cpu flags: factor out parsing the broadcast CPU flags of a node Jonas Theisen
2026-11-24 16:30 ` [PATCH qemu-server v2 05/20] fix #2924: migrate: block live migration of host CPU VMs to nodes lacking flags Jonas Theisen
2026-11-24 16:30 ` [PATCH qemu-server v2 06/20] migrate: warn about live migration of host CPU VMs between CPU models Jonas Theisen
2026-11-24 16:30 ` [PATCH qemu-server v2 07/20] migrate: factor out whether the running virtual CPU is kept Jonas Theisen
2026-11-24 16:30 ` [PATCH qemu-server v2 08/20] migrate: block migration if the target cannot run the virtual CPU Jonas Theisen
2026-11-24 16:30 ` [PATCH qemu-server v2 09/20] cpu flags: report invtsc support of nodes Jonas Theisen
2026-11-24 16:30 ` [PATCH qemu-server v2 10/20] helpers: add helper to query the host's TSC frequency and scaling support Jonas Theisen
2026-11-24 16:30 ` [PATCH qemu-server v2 11/20] cpu config: add hv-reenlightenment flag and set TSC frequency for it Jonas Theisen
2026-11-24 16:30 ` [PATCH qemu-server v2 12/20] migrate: block migration to nodes with incompatible TSC for re-enlightenment Jonas Theisen
2026-11-24 16:30 ` [PATCH qemu-server v2 13/20] cpu config: set TSC frequency for invtsc to allow live migration Jonas Theisen
2026-11-24 16:30 ` [PATCH qemu-server v2 14/20] migrate: factor out asserting the CPU compatibility of the target Jonas Theisen
2026-11-24 16:30 ` [PATCH qemu-server v2 15/20] api: migrate: check the CPU of the target before requesting HA migration Jonas Theisen
2026-11-24 16:30 ` [PATCH manager v2 16/20] pvestatd: broadcast host CPU information relevant for live migration Jonas Theisen
2026-11-24 16:30 ` [PATCH manager v2 17/20] ui: migrate: show why the CPU of the target node is incompatible Jonas Theisen
2026-11-24 16:30 ` [PATCH manager v2 18/20] fix #6535: ui: migrate: show CPU warnings for the target node Jonas Theisen
2026-11-24 16:30 ` [PATCH manager v2 19/20] api: nodes: migrateall: skip VMs whose CPU is incompatible with the target Jonas Theisen
2026-11-24 16:30 ` [PATCH docs v2 20/20] qm: document hv-reenlightenment, invtsc and CPU checks for migration Jonas Theisen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal