* [PATCH qemu-server v4 01/21] buildsys: ignore migration test runtime files
2026-12-02 15:17 [PATCH docs/manager/qemu-server v4 00/21] check the target node's CPU before live migrating a VM Jonas Theisen
@ 2026-12-02 15:17 ` Jonas Theisen
2026-12-02 15:17 ` [PATCH qemu-server v4 02/21] test: migration: allow checking for warnings and errors in the log Jonas Theisen
` (19 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Jonas Theisen @ 2026-12-02 15:17 UTC (permalink / raw)
To: pve-devel
The migration tests leave their runtime files in MigrationTest/run,
which only 'make clean' removes. Ignore them, so that they cannot be
committed by accident.
Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
.gitignore | 1 +
1 file changed, 1 insertion(+)
diff --git a/.gitignore b/.gitignore
index 3658c855..0e2993b1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,6 +7,7 @@
*.deb
/.vscode/
/qemu-server-[0-9]*/
+/src/test/MigrationTest/run/
build
qm.bash-completion
sparsecp
--
2.47.3
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH qemu-server v4 02/21] test: migration: allow checking for warnings and errors in the log
2026-12-02 15:17 [PATCH docs/manager/qemu-server v4 00/21] check the target node's CPU before live migrating a VM Jonas Theisen
2026-12-02 15:17 ` [PATCH qemu-server v4 01/21] buildsys: ignore migration test runtime files Jonas Theisen
@ 2026-12-02 15:17 ` Jonas Theisen
2026-12-02 15:17 ` [PATCH qemu-server v4 03/21] cpu flags: normalize underscores in all CPU flag names Jonas Theisen
` (18 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Jonas Theisen @ 2026-12-02 15:17 UTC (permalink / raw)
To: pve-devel
So far, the log is only checked for the error of a migration that is
expected to fail. Allow tests to also check for warnings, as the
migration continues after them, and for the absence of other warnings
or errors about a topic, as a migration that logs an unintended
warning still succeeds. Checking for the absence of all other messages
is not feasible, as every test migration logs unrelated warnings, for
example that conntrack state migration is not supported.
Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
src/test/run_qemu_migrate_tests.pl | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/src/test/run_qemu_migrate_tests.pl b/src/test/run_qemu_migrate_tests.pl
index 1936812e..d22c64c1 100755
--- a/src/test/run_qemu_migrate_tests.pl
+++ b/src/test/run_qemu_migrate_tests.pl
@@ -534,6 +534,10 @@ 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
+ # unexpected_log - list of texts that no warning or error message in the log
+ # may contain, unless it matches expect_die or expect_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 +1946,21 @@ foreach my $test (@{$tests}) {
note("mocked migrate call failed, but it was not expected - check log");
}
+ my @messages = grep { m/^(?:err|warn):/ } split(/\n/, file_get_contents("${run_dir}/log"));
+ my $expect_log = $test->{expect_log} // [];
+ for my $text ($expect_log->@*) {
+ next if grep { m/\Q${text}\E/ } @messages;
+ fail($name);
+ note("expected message '$text' is not present in log");
+ }
+ my @expected_texts = ($expect_log->@*, grep { defined } $expect_die);
+ for my $message (@messages) {
+ next if grep { $message =~ m/\Q$_\E/ } @expected_texts;
+ my ($text) = grep { $message =~ m/\Q$_\E/ } ($test->{unexpected_log} // [])->@* or next;
+ fail($name);
+ note("unexpected message containing '$text' in log: $message");
+ }
+
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] 22+ messages in thread* [PATCH qemu-server v4 03/21] cpu flags: normalize underscores in all CPU flag names
2026-12-02 15:17 [PATCH docs/manager/qemu-server v4 00/21] check the target node's CPU before live migrating a VM Jonas Theisen
2026-12-02 15:17 ` [PATCH qemu-server v4 01/21] buildsys: ignore migration test runtime files Jonas Theisen
2026-12-02 15:17 ` [PATCH qemu-server v4 02/21] test: migration: allow checking for warnings and errors in the log Jonas Theisen
@ 2026-12-02 15:17 ` Jonas Theisen
2026-12-02 15:18 ` [PATCH qemu-server v4 04/21] test: api: factor out validating the migration preconditions Jonas Theisen
` (17 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Jonas Theisen @ 2026-12-02 15:17 UTC (permalink / raw)
To: pve-devel
QEMU replaces underscores with dashes in the flags of the '-cpu' option
that are not prefixed with '+' or '-', see feat2prop() in
target/i386/cpu.c. For some flags, it also registers aliases with
underscores, which work with these prefixes as well. The alias map only
covers the latter, so other flags kept underscores, for example the
Hyper-V enlightenments that qemu-server passes as 'hv_stimer', while
QEMU reports 'hv-stimer'.
Replace underscores in general, as every spelling QEMU accepts refers
to the flag with dashes, so that flags from a QEMU command line can be
compared with the flags QEMU reports, and drop the now redundant
aliases.
Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
src/PVE/QemuServer/CPUFlags.pm | 37 ++++++++--------------------------
1 file changed, 8 insertions(+), 29 deletions(-)
diff --git a/src/PVE/QemuServer/CPUFlags.pm b/src/PVE/QemuServer/CPUFlags.pm
index 0d3206b2..57fdabcf 100644
--- a/src/PVE/QemuServer/CPUFlags.pm
+++ b/src/PVE/QemuServer/CPUFlags.pm
@@ -93,7 +93,8 @@ for my $arch (keys $supported_vm_specific_cpu_flags_by_arch->%*) {
my @supported_cpu_flags_name_sorted = sort keys $all_supported_vm_specific_cpu_flags->%*;
-# qemu/target/i386/cpu.c, x86_cpu_initfn()
+# qemu/target/i386/cpu.c, x86_cpu_initfn(), without the aliases that only replace dashes by
+# underscores, as normalize_cpu_flag() handles these
my $qemu_cpu_flag_alias_map = {
sse3 => 'pni',
pclmuldq => 'pclmulqdq',
@@ -102,46 +103,24 @@ my $qemu_cpu_flag_alias_map = {
xd => 'nx',
ffxsr => 'fxsr-opt',
i64 => 'lm',
- ds_cpl => 'ds-cpl',
- tsc_adjust => 'tsc-adjust',
- fxsr_opt => 'fxsr-opt',
- lahf_lm => 'lahf-lm',
- cmp_legacy => 'cmp-legacy',
- nodeid_msr => 'nodeid-msr',
- perfctr_core => 'perfctr-core',
- perfctr_nb => 'perfctr-nb',
- kvm_nopiodelay => 'kvm-nopiodelay',
- kvm_mmu => 'kvm-mmu',
- kvm_asyncpf => 'kvm-asyncpf',
- kvm_asyncpf_int => 'kvm-asyncpf-int',
- kvm_steal_time => 'kvm-steal-time',
- kvm_pv_eoi => 'kvm-pv-eoi',
- kvm_pv_unhalt => 'kvm-pv-unhalt',
- kvm_poll_control => 'kvm-poll-control',
- svm_lock => 'svm-lock',
- nrip_save => 'nrip-save',
- tsc_scale => 'tsc-scale',
- vmcb_clean => 'vmcb-clean',
- pause_filter => 'pause-filter',
- sse4_1 => 'sse4.1',
- sse4_2 => 'sse4.2',
'hv-apicv' => 'hv-avic',
- lbr_fmt => 'lbr-fmt',
};
=head3 normalize_cpu_flag($flag)
Normalize a CPU flag to its QEMU form.
-QEMU defines aliases for some CPU flags (see C<x86_cpu_initfn()> in
-C<target/i386/cpu.c>). For example, C<sse4_2> and C<sse4-2> are both aliases for
-C<sse4.2>.
+QEMU replaces underscores with dashes in CPU flags given without C<+> or C<-> (see C<feat2prop()>
+in C<target/i386/cpu.c>), and defines aliases for some CPU flags (see C<x86_cpu_initfn()>), which
+include underscore spellings that also work with these prefixes. For example, C<sse4_2> and
+C<sse4-2> are both aliases for C<sse4.2>, and C<hv_stimer> is the same as C<hv-stimer>.
-If C<$flag> has a known alias, return that, otherwise return C<$flag> unchanged.
+Return C<$flag> with underscores replaced by dashes, or the flag it is an alias for.
=cut
sub normalize_cpu_flag($flag) {
+ $flag =~ s/_/-/g;
return $qemu_cpu_flag_alias_map->{$flag} // $flag;
}
--
2.47.3
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH qemu-server v4 04/21] test: api: factor out validating the migration preconditions
2026-12-02 15:17 [PATCH docs/manager/qemu-server v4 00/21] check the target node's CPU before live migrating a VM Jonas Theisen
` (2 preceding siblings ...)
2026-12-02 15:17 ` [PATCH qemu-server v4 03/21] cpu flags: normalize underscores in all CPU flag names Jonas Theisen
@ 2026-12-02 15:18 ` Jonas Theisen
2026-12-02 15:18 ` [PATCH qemu-server v4 05/21] cpu flags: factor out parsing the broadcast CPU flags of a node Jonas Theisen
` (16 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Jonas Theisen @ 2026-12-02 15:18 UTC (permalink / raw)
To: pve-devel
Move validating a result of the migration precondition API against its
schema into a helper, so that further tests can check that the reasons
they produce are documented as well.
No functional change intended.
Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
src/test/run_api_tests.pl | 33 ++++++++++++++++++++++++---------
1 file changed, 24 insertions(+), 9 deletions(-)
diff --git a/src/test/run_api_tests.pl b/src/test/run_api_tests.pl
index d8f26e32..f2916346 100755
--- a/src/test/run_api_tests.pl
+++ b/src/test/run_api_tests.pl
@@ -256,6 +256,20 @@ is(
'clone_vm: no check without target node',
);
+# Returns the error of validating a result of migrate_vm_precondition against its schema, which
+# also requires every reason why a node is not allowed to be documented.
+sub validate_migration_preconditions {
+ my ($res) = @_;
+
+ my $returns = PVE::API2::Qemu->map_method_by_name('migrate_vm_precondition')->{returns};
+ my $strict = dclone($returns);
+ my $node_schema = $strict->{properties}->{not_allowed_nodes}->{additionalProperties};
+ $node_schema->{additionalProperties} = 0;
+ eval { PVE::JSONSchema::validate($res, $strict) };
+
+ return $@;
+}
+
subtest 'migration preconditions' => sub {
my $nodes = ['localhost', 'pve2', 'pve3', 'pve4'];
$cluster_module->mock(get_nodelist => sub { return $nodes; });
@@ -303,16 +317,17 @@ subtest 'migration preconditions' => sub {
'node with an older version is not allowed',
);
- my $returns = PVE::API2::Qemu->map_method_by_name('migrate_vm_precondition')->{returns};
- # every reason of a node must be documented
- my $strict = dclone($returns);
- my $node_schema = $strict->{properties}->{not_allowed_nodes}->{additionalProperties};
- $node_schema->{additionalProperties} = 0;
- eval { PVE::JSONSchema::validate($res, $strict) };
- is($@, '', 'result matches the schema, including the reasons of each node');
+ is(
+ validate_migration_preconditions($res),
+ '',
+ 'result matches the schema, including the reasons of each node',
+ );
my $undocumented = { $res->%*, not_allowed_nodes => { pve3 => { 'other-reason' => 1 } } };
- eval { PVE::JSONSchema::validate($undocumented, $strict) };
- like($@, qr/other-reason/, 'an undocumented reason does not');
+ like(
+ validate_migration_preconditions($undocumented),
+ qr/other-reason/,
+ 'an undocumented reason does not',
+ );
$cluster_module->unmock('get_nodelist', 'get_config');
mock_unreachable_config();
--
2.47.3
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH qemu-server v4 05/21] cpu flags: factor out parsing the broadcast CPU flags of a node
2026-12-02 15:17 [PATCH docs/manager/qemu-server v4 00/21] check the target node's CPU before live migrating a VM Jonas Theisen
` (3 preceding siblings ...)
2026-12-02 15:18 ` [PATCH qemu-server v4 04/21] test: api: factor out validating the migration preconditions Jonas Theisen
@ 2026-12-02 15:18 ` Jonas Theisen
2026-12-02 15:18 ` [PATCH qemu-server v4 06/21] migrate: factor out whether the running virtual CPU is kept Jonas Theisen
` (15 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Jonas Theisen @ 2026-12-02 15:18 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 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 57fdabcf..3b74dbb6 100644
--- a/src/PVE/QemuServer/CPUFlags.pm
+++ b/src/PVE/QemuServer/CPUFlags.pm
@@ -124,6 +124,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";
@@ -274,12 +288,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] 22+ messages in thread* [PATCH qemu-server v4 06/21] migrate: factor out whether the running virtual CPU is kept
2026-12-02 15:17 [PATCH docs/manager/qemu-server v4 00/21] check the target node's CPU before live migrating a VM Jonas Theisen
` (4 preceding siblings ...)
2026-12-02 15:18 ` [PATCH qemu-server v4 05/21] cpu flags: factor out parsing the broadcast CPU flags of a node Jonas Theisen
@ 2026-12-02 15:18 ` Jonas Theisen
2026-12-02 15:18 ` [PATCH qemu-server v4 07/21] cpu flags: factor out the flags of a CPU model expansion Jonas Theisen
` (14 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Jonas Theisen @ 2026-12-02 15:18 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 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 67b72598..d3f6f155 100644
--- a/src/PVE/QemuMigrate.pm
+++ b/src/PVE/QemuMigrate.pm
@@ -242,7 +242,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 466517da..e0eec8b1 100644
--- a/src/PVE/QemuMigrate/Helpers.pm
+++ b/src/PVE/QemuMigrate/Helpers.pm
@@ -113,6 +113,22 @@ sub check_local_resources {
return wantarray ? (\@loc_res, $mapped_res, $missing_mappings_by_node) : \@loc_res;
}
+=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;
+}
+
sub set_migration_caps {
my ($vmid, $savevm) = @_;
--
2.47.3
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH qemu-server v4 07/21] cpu flags: factor out the flags of a CPU model expansion
2026-12-02 15:17 [PATCH docs/manager/qemu-server v4 00/21] check the target node's CPU before live migrating a VM Jonas Theisen
` (5 preceding siblings ...)
2026-12-02 15:18 ` [PATCH qemu-server v4 06/21] migrate: factor out whether the running virtual CPU is kept Jonas Theisen
@ 2026-12-02 15:18 ` Jonas Theisen
2026-12-02 15:18 ` [PATCH qemu-server v4 08/21] cpu config: factor out whether hv-evmcs is enabled for a CPU vendor Jonas Theisen
` (13 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Jonas Theisen @ 2026-12-02 15:18 UTC (permalink / raw)
To: pve-devel
Move collecting the flags that a 'query-cpu-model-expansion' result
enables into a helper, so that checks of the virtual CPU of a running
VM can read the flags of its CPU model the same way as the flags
supported by a node.
No functional change intended.
Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
src/PVE/QemuServer.pm | 9 ++-------
src/PVE/QemuServer/CPUFlags.pm | 14 ++++++++++++++
2 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index 1d665877..f8b3094f 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -3038,13 +3038,8 @@ sub query_supported_cpu_flags {
model => $model,
);
- my $props = $cmd_result->{model}->{props};
- foreach my $prop (keys %$props) {
- next if $props->{$prop} ne JSON::true;
- $prop = PVE::QemuServer::CPUFlags::normalize_cpu_flag($prop);
-
- $flags->{$prop} = 1;
- }
+ $flags->{$_} = 1
+ for PVE::QemuServer::CPUFlags::get_cpu_expansion_flags($cmd_result);
};
my $err = $@;
diff --git a/src/PVE/QemuServer/CPUFlags.pm b/src/PVE/QemuServer/CPUFlags.pm
index 3b74dbb6..27b64da7 100644
--- a/src/PVE/QemuServer/CPUFlags.pm
+++ b/src/PVE/QemuServer/CPUFlags.pm
@@ -3,6 +3,7 @@ package PVE::QemuServer::CPUFlags;
use v5.36;
use Exporter qw(import);
+use JSON ();
use PVE::Cluster;
use PVE::File;
@@ -124,6 +125,19 @@ sub normalize_cpu_flag($flag) {
return $qemu_cpu_flag_alias_map->{$flag} // $flag;
}
+=head3 get_cpu_expansion_flags($expansion)
+
+Return the CPU flags that a result of the QMP command C<query-cpu-model-expansion> enables,
+normalized with C<normalize_cpu_flag()>. As the expansion also includes CPU properties that are no
+flags, the result can contain these as well.
+
+=cut
+
+sub get_cpu_expansion_flags($expansion) {
+ my $props = $expansion->{model}->{props} // {};
+ return map { normalize_cpu_flag($_) } grep { ($props->{$_} // '') eq JSON::true } keys %$props;
+}
+
=head3 parse_node_cpu_flags($raw)
Parse the CPU flags of a node, as C<pvestatd> broadcasts them in the C<cpuflags-$accel> node
--
2.47.3
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH qemu-server v4 08/21] cpu config: factor out whether hv-evmcs is enabled for a CPU vendor
2026-12-02 15:17 [PATCH docs/manager/qemu-server v4 00/21] check the target node's CPU before live migrating a VM Jonas Theisen
` (6 preceding siblings ...)
2026-12-02 15:18 ` [PATCH qemu-server v4 07/21] cpu flags: factor out the flags of a CPU model expansion Jonas Theisen
@ 2026-12-02 15:18 ` Jonas Theisen
2026-12-02 15:18 ` [PATCH qemu-server v4 09/21] migrate: block live migration of host CPU VMs between CPU vendors Jonas Theisen
` (12 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Jonas Theisen @ 2026-12-02 15:18 UTC (permalink / raw)
To: pve-devel
The Hyper-V enlightenment hv-evmcs is only enabled automatically on
Intel hosts. Make this decision reusable, as the migration checks need
to know whether a target with another CPU vendor enables it as well
when generating the CPU of a VM again.
Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
src/PVE/QemuServer/CPUConfig.pm | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/src/PVE/QemuServer/CPUConfig.pm b/src/PVE/QemuServer/CPUConfig.pm
index 414682a6..689bfe89 100644
--- a/src/PVE/QemuServer/CPUConfig.pm
+++ b/src/PVE/QemuServer/CPUConfig.pm
@@ -1071,6 +1071,20 @@ sub get_pve_cpu_flags(
return $pve_flags;
}
+=head3 is_hyperv_evmcs_vendor
+
+ my $automatic = is_hyperv_evmcs_vendor($vendor);
+
+Returns whether the Hyper-V enlightenment C<hv-evmcs> is enabled automatically on hosts with the
+CPU vendor C<$vendor>, as far as the other conditions are met. It is only available on Intel
+CPUs.
+
+=cut
+
+sub is_hyperv_evmcs_vendor($vendor) {
+ return $vendor eq 'GenuineIntel';
+}
+
sub get_hyperv_enlightenments(
$winversion, $version_guard, $bios, $gpu_passthrough, $hv_vendor_id = undef,
) {
@@ -1129,7 +1143,7 @@ sub get_hyperv_enlightenments(
}
if (
- PVE::ProcFSTools::read_cpuinfo->{vendor} eq 'GenuineIntel'
+ is_hyperv_evmcs_vendor(PVE::ProcFSTools::read_cpuinfo->{vendor})
&& $winversion >= 11
&& $version_guard->(11, 0, 2)
) {
--
2.47.3
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH qemu-server v4 09/21] migrate: block live migration of host CPU VMs between CPU vendors
2026-12-02 15:17 [PATCH docs/manager/qemu-server v4 00/21] check the target node's CPU before live migrating a VM Jonas Theisen
` (7 preceding siblings ...)
2026-12-02 15:18 ` [PATCH qemu-server v4 08/21] cpu config: factor out whether hv-evmcs is enabled for a CPU vendor Jonas Theisen
@ 2026-12-02 15:18 ` Jonas Theisen
2026-12-02 15:18 ` [PATCH qemu-server v4 10/21] fix #6535: migrate: warn about live migration " Jonas Theisen
` (11 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Jonas Theisen @ 2026-12-02 15:18 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 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 the CPU information each node
broadcasts as the new 'host-cpu-info' node key-value entry, which
pvestatd of pve-manager is extended to broadcast. Refuse to migrate to
such nodes, and report them as not allowed in the migration precondition
API, so that clients can show this upfront. Besides the message, the API
reports the values it contains, here the CPU vendors, as typed details,
so that clients can present and translate them without parsing the
message.
Nodes that do not broadcast the information, for example as they run
an older version, are not blocked, but a task warning is logged and
the precondition API reports a warning. This is only done for checks
that can block the migration, so that checks that only warn do not
warn about every migration to an older node, and not if this node
lacks the information as well, like the vendor of an ARM CPU with an
unknown implementer. Warnings are skipped if the migration is refused
anyway.
The checks are defined in a list, so that further combinations of VM
CPU settings and node CPUs that cannot work, or are prone to problems,
can be added easily. They only apply to running VMs, as stopped VMs
are started with a virtual CPU based on the target node, and not to
confidential VMs, which cannot be live migrated at all. They operate
on the QEMU CPU of the running instance, so they also cover custom CPU
models, and parse it with QEMU's precedence: flags with '+' override
properties and flags with '-' override both, regardless of position.
With TCG, which VMs of a foreign architecture use by default, 'max' is
fully emulated and therefore not affected.
If the check itself fails, for example as the QEMU command line of the
VM cannot be read, the migration is not refused, but a task warning is
logged and the precondition API reports a warning for each node. The
check only guards migrations that work without it, so a failure must
not block them, for example the migrations of HA maintenance mode.
The check runs before the conntrack state helper is set up, as a
failed preparation is not cleaned up, so the helper would keep
running.
Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
src/PVE/API2/Qemu.pm | 80 ++++++-
src/PVE/QemuMigrate.pm | 10 +
src/PVE/QemuMigrate/Helpers.pm | 245 ++++++++++++++++++++++
src/PVE/QemuServer/Helpers.pm | 31 +++
src/test/MigrationTest/QemuMigrateMock.pm | 44 ++++
src/test/run_api_tests.pl | 109 ++++++++++
src/test/run_qemu_migrate_tests.pl | 149 +++++++++++++
7 files changed, 667 insertions(+), 1 deletion(-)
diff --git a/src/PVE/API2/Qemu.pm b/src/PVE/API2/Qemu.pm
index 2119e69e..a3f44ac0 100644
--- a/src/PVE/API2/Qemu.pm
+++ b/src/PVE/API2/Qemu.pm
@@ -5599,6 +5599,28 @@ __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.",
+ },
+ PVE::QemuMigrate::Helpers::cpu_issue_details_schema()->%*,
+ },
+ },
+ },
'blocking-ha-resources' => {
description => "HA resources, which are blocking the"
. " VM from being migrated to the node.",
@@ -5676,6 +5698,30 @@ __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 => ['missing-cpu-info', 'cpu-check-failed'],
+ },
+ message => {
+ type => 'string',
+ description => "Why the VM might not run reliably.",
+ },
+ PVE::QemuMigrate::Helpers::cpu_issue_details_schema()->%*,
+ },
+ },
+ },
+ },
'has-dbus-vmstate' => {
type => 'boolean',
description => 'Whether the VM host supports migrating additional VM state, '
@@ -5716,7 +5762,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 +5793,24 @@ __PACKAGE__->register_method({
my $has_identity = PVE::QemuConfig->has_stored_identity($vmid);
my $nodelist = PVE::Cluster::get_nodelist();
+
+ my $targets = [grep { $_ ne $localnode } $nodelist->@*];
+ my $cpu_issues_by_node = eval {
+ PVE::QemuMigrate::Helpers::check_target_cpu_compatibility(
+ $vmid, $vmconf, $pid, $targets,
+ );
+ };
+ if (my $err = $@) {
+ chomp($err);
+ # the migration does not refuse the nodes either, but warns about the failed check
+ my $issue = {
+ type => 'cpu-check-failed',
+ severity => 'warning',
+ message => "unable to check whether the node's CPU can run the VM - $err",
+ };
+ $cpu_issues_by_node = { map { $_ => [$issue] } $targets->@* };
+ }
+
for my $node ($nodelist->@*) {
next if $node eq $localnode;
@@ -5761,6 +5826,19 @@ __PACKAGE__->register_method({
$missing_mappings;
}
+ for my $issue (($cpu_issues_by_node->{$node} // [])->@*) {
+ my $reason = {
+ type => $issue->{type},
+ message => $issue->{message},
+ ($issue->{details} // {})->%*,
+ };
+ if ($issue->{severity} eq 'error') {
+ push $res->{not_allowed_nodes}->{$node}->{'incompatible-cpu'}->@*, $reason;
+ } else {
+ push $res->{'cpu-warnings'}->{$node}->@*, $reason;
+ }
+ }
+
# 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 d3f6f155..d450cd23 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;
@@ -250,6 +251,15 @@ sub prepare {
# during migration and remain paused after migration finishes.
$self->{vm_was_paused} = 1 if PVE::QemuServer::vm_is_paused($vmid, 0);
+ # Nodes of other clusters do not broadcast their CPU information to this cluster. Checked
+ # before setting up the conntrack state helper, as a failing preparation is not cleaned up.
+ if (!$self->{opts}->{remote}) {
+ my $warnings = PVE::QemuMigrate::Helpers::assert_target_cpu_compatibility(
+ $vmid, $conf, $pid, $self->{node},
+ );
+ log_warn($_) for $warnings->@*;
+ }
+
if ($self->{opts}->{'with-conntrack-state'}) {
if ($self->{opts}->{remote}) {
# shouldn't be reached in normal circumstances anyway, as we prevent it on
diff --git a/src/PVE/QemuMigrate/Helpers.pm b/src/PVE/QemuMigrate/Helpers.pm
index e0eec8b1..23f4d589 100644
--- a/src/PVE/QemuMigrate/Helpers.pm
+++ b/src/PVE/QemuMigrate/Helpers.pm
@@ -4,13 +4,18 @@ use strict;
use warnings;
use JSON;
+use Storable qw(dclone);
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 +118,156 @@ 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'. As in QEMU, flags with '+' override properties, and flags with '-'
+# override both, regardless of their position.
+my sub parse_qemu_cpu_string {
+ my ($cpu_str) = @_;
+
+ my ($model, @options) = split(/,/, $cpu_str);
+
+ my ($props, $plus, $minus) = ({}, [], []);
+ for my $option (@options) {
+ my ($op, $name, $value) = $option =~ m/^([+-]?)([^=]+)(?:=(.*))?$/ or next;
+ $name = PVE::QemuServer::CPUFlags::normalize_cpu_flag($name);
+ if ($op eq '+') {
+ push $plus->@*, $name;
+ } elsif ($op eq '-') {
+ push $minus->@*, $name;
+ } else {
+ $props->{$name} = $value // 'on';
+ }
+ }
+ $props->{$_} = 'on' for $plus->@*;
+ $props->{$_} = 'off' for $minus->@*;
+
+ 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;
+}
+
+# The values of CPU issues, so that API clients do not need to parse them from the message.
+my $cpu_issue_details = {
+ 'source-vendor' => {
+ type => 'string',
+ optional => 1,
+ description => "The CPU vendor of the source node.",
+ },
+ 'target-vendor' => {
+ type => 'string',
+ optional => 1,
+ description => "The CPU vendor of the target node.",
+ },
+};
+
+my sub vendor_details {
+ my ($source, $target) = @_;
+ return { 'source-vendor' => $source->{vendor}, 'target-vendor' => $target->{vendor} };
+}
+
+=head3 cpu_issue_details_schema
+
+ my $properties = cpu_issue_details_schema();
+
+Returns the JSON schema properties of the C<details> of CPU issues, see
+check_target_cpu_compatibility().
+
+=cut
+
+sub cpu_issue_details_schema {
+ return dclone($cpu_issue_details);
+}
+
+# Checks whether the CPU of a target node can run a running VM after a live migration. Each check
+# has:
+# - 'type', identifying the check
+# - 'severity', 'error' if an incompatibility prevents the migration, 'warning' if it is only
+# reported
+# - 'needs', listing the CPU information the check requires of the target node and, to compare
+# them, of this node, nodes lacking any of it are skipped
+# - 'applies', returning true if the check is relevant for the VM's CPU
+# - 'check', returning why the target node is incompatible, if it is, and optionally the details
+# of the incompatibility, see $cpu_issue_details
+#
+# The VM's CPU is parsed by parse_qemu_cpu_string(), with:
+# - 'kvm' set if the VM uses KVM
+#
+# The CPU information of the nodes is in the format of get_host_cpu_info().
+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);
+
+ my $message = "CPU model '$cpu->{model}' requires the same CPU vendor as on the"
+ . " source node ($source->{vendor}), but the node has $target->{vendor}";
+ return ($message, vendor_details($source, $target));
+ },
+ },
+];
+
+# Returns the issues of the target node. If it lacks CPU information needed by a check that can
+# prevent the migration, that is an issue as well, but only a warning, as the node is not refused.
+# Information this node lacks as well, for example the vendor of an unknown ARM CPU, is not
+# reported.
+my sub get_target_cpu_issues {
+ my ($cpu, $checks, $source_info, $target_info) = @_;
+
+ my ($issues, $target_complete) = ([], 1);
+ for my $check ($checks->@*) {
+ my @missing = grep { !defined($target_info->{$_}) } $check->{needs}->@*;
+ if (scalar(@missing)) {
+ $target_complete = 0
+ if $check->{severity} eq 'error' && grep { defined($source_info->{$_}) } @missing;
+ next;
+ }
+
+ my ($message, $details) = $check->{check}->($cpu, $source_info, $target_info) or next;
+ my $issue = { type => $check->{type}, severity => $check->{severity}, message => $message };
+ $issue->{details} = $details if $details;
+ push $issues->@*, $issue;
+ }
+
+ if (!$target_complete) {
+ my $message = "the node does not provide the CPU information needed to check it, for"
+ . " example as it runs an older version";
+ push $issues->@*,
+ { type => 'missing-cpu-info', severity => 'warning', message => $message };
+ }
+ return $issues;
+}
+
=head3 is_running_cpu_kept
my $kept = is_running_cpu_kept($conf);
@@ -129,6 +284,96 @@ sub is_running_cpu_kept {
return $conf->{cpu} && PVE::QemuServer::CPUConfig::is_abstracted($conf->{cpu}) ? 1 : 0;
}
+=head3 check_target_cpu_compatibility
+
+ my $issues_by_node = check_target_cpu_compatibility($vmid, $conf, $pid, $nodes);
+
+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, and not to confidential VMs, which cannot be live migrated
+at all.
+
+Returns a hash reference with the list of issues for each node that has any. 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, a human-readable C<message>, and optionally C<details> with the
+values the message contains, see cpu_issue_details_schema(). Nodes that lack CPU information
+needed by a check that can prevent the migration, for example as they run an older version, have
+an issue of type C<missing-cpu-info> with severity C<warning>, unless this node lacks that
+information as well.
+
+=cut
+
+sub check_target_cpu_compatibility {
+ my ($vmid, $conf, $pid, $nodes) = @_;
+
+ # confidential VMs cannot be live migrated at all
+ return {} if !$pid || PVE::QemuServer::CPUConfig::get_cvm_type($conf);
+
+ my $cpu = parse_qemu_cpu_string(PVE::QemuServer::CPUConfig::get_cpu_from_running_vm($pid));
+ my $arch = PVE::QemuServer::Helpers::get_vm_arch($conf);
+ $cpu->{kvm} = $conf->{kvm} // PVE::QemuServer::CPUConfig::is_native_arch($arch);
+
+ 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 = {};
+ for my $node ($nodes->@*) {
+ my $target_info = get_node_cpu_info($node);
+
+ my $issues = get_target_cpu_issues($cpu, $checks, $source_info, $target_info);
+ $issues_by_node->{$node} = $issues if scalar($issues->@*);
+ }
+
+ return $issues_by_node;
+}
+
+=head3 assert_target_cpu_compatibility
+
+ my $warnings = assert_target_cpu_compatibility($vmid, $conf, $pid, $node);
+
+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.
+
+Returns an array reference with the warnings to log, about possible incompatibilities, including
+missing CPU information of the node. If the check itself fails, the node is not refused, but a
+warning about the failure is returned, as the check only guards migrations that work without it.
+
+=cut
+
+sub assert_target_cpu_compatibility {
+ my ($vmid, $conf, $pid, $node) = @_;
+
+ my $issues_by_node = eval { check_target_cpu_compatibility($vmid, $conf, $pid, [$node]) };
+ if (my $err = $@) {
+ chomp($err);
+ return ["unable to check whether the CPU of node '$node' can run the VM, migrating anyway"
+ . " - $err"
+ ];
+ }
+
+ my ($errors, $warnings) = ([], []);
+ for my $issue (($issues_by_node->{$node} // [])->@*) {
+ if ($issue->{severity} eq 'warning') {
+ push $warnings->@*, "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";
+ }
+
+ return $warnings;
+}
+
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..bfccef5a 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,13 +230,52 @@ $qemu_server_cpuconfig_module->mock(
},
);
+$MigrationTest::Shared::qemu_migrate_helpers_module->mock(
+ check_target_cpu_compatibility => sub {
+ 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});
+ die $test_cpu_info->{'check-error'} if defined($test_cpu_info->{'check-error'});
+ 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 {
+ # the source node's broadcast reflects what it reads locally
+ return { ($test_cpu_info->{source} // { vendor => 'GenuineIntel' })->%* };
+ },
vm_running_locally => sub {
return $vm_status->{running} && !$vm_stop_executed;
},
);
+my $dbus_vmstate_module = Test::MockModule->new("PVE::QemuServer::DBusVMState");
+$dbus_vmstate_module->mock(
+ # only migrations that are refused before starting the helper are tested
+ qemu_add_dbus_vmstate => sub { die "conntrack state helper started\n"; },
+);
+
+# the tests assume an x86_64 host, also when run on another architecture
+my $tools_module = Test::MockModule->new("PVE::Tools");
+$tools_module->mock(get_host_arch => sub { return 'x86_64'; });
+
my $qemu_server_machine_module = Test::MockModule->new("PVE::QemuServer::Machine");
$qemu_server_machine_module->mock(
qemu_machine_pxe => sub {
diff --git a/src/test/run_api_tests.pl b/src/test/run_api_tests.pl
index f2916346..22a0533b 100755
--- a/src/test/run_api_tests.pl
+++ b/src/test/run_api_tests.pl
@@ -8,6 +8,7 @@ use warnings;
use lib qw(..);
+use JSON;
use Storable qw(dclone);
use Test::MockModule;
use Test::More;
@@ -333,6 +334,114 @@ subtest 'migration preconditions' => sub {
mock_unreachable_config();
};
+subtest 'migration preconditions of the CPU of a running VM' => sub {
+ # the node key-value entries of the source node 'localhost' and of the target nodes, which
+ # differ from the source as their names say, while 'no-cpu-info' broadcasts none
+ my $entries = sub {
+ my ($info) = @_;
+ return { 'host-cpu-info' => encode_json($info) };
+ };
+ my $source = { vendor => 'GenuineIntel' };
+ my $node_kv = {
+ localhost => $entries->($source),
+ 'other-vendor' => $entries->({ $source->%*, vendor => 'AuthenticAMD' }),
+ };
+ my $nodes = ['localhost', 'other-vendor', 'no-cpu-info'];
+
+ my $inotify_module = Test::MockModule->new('PVE::INotify');
+ $inotify_module->mock(nodename => sub { return 'localhost'; });
+ my $ha_config_module = Test::MockModule->new('PVE::HA::Config');
+ $ha_config_module->mock(vm_is_ha_managed => sub { return 0; });
+ my $migrate_helpers_module = Test::MockModule->new('PVE::QemuMigrate::Helpers');
+ $migrate_helpers_module->mock(
+ check_local_resources => sub {
+ return ([], {}, { map { $_ => [] } $nodes->@* });
+ },
+ );
+ $qemu_config_module->mock(load_config => sub { return { memory => 512 }; });
+ $qemu_server_module->mock(check_running => sub { return 1234; });
+ my $running_cpu;
+ my $cpu_config_module = Test::MockModule->new('PVE::QemuServer::CPUConfig');
+ $cpu_config_module->mock(get_cpu_from_running_vm => sub { return $running_cpu; });
+ $cluster_module->mock(
+ get_nodelist => sub { return $nodes; },
+ get_config => sub { return $raw_without_identity; },
+ get_node_kv => sub {
+ my ($key, $node) = @_;
+ my $value = $node_kv->{$node}->{$key} // return {};
+ return { $node => $value };
+ },
+ );
+
+ # Returns the CPU reasons of each node for the VM running with the QEMU CPU $running_cpu, the
+ # types of the incompatibilities with their override option, and of the warnings, prefixed.
+ my $cpu_reasons = sub {
+ ($running_cpu) = @_;
+
+ my $res =
+ PVE::API2::Qemu->migrate_vm_precondition({ node => 'localhost', vmid => 100 });
+ is(validate_migration_preconditions($res), '', "$running_cpu: reasons are documented");
+
+ my $reasons = {};
+ for my $node (keys $res->{not_allowed_nodes}->%*) {
+ for my $error (
+ ($res->{not_allowed_nodes}->{$node}->{'incompatible-cpu'} // [])->@*
+ ) {
+ my $override = defined($error->{override}) ? " ($error->{override})" : '';
+ push $reasons->{$node}->@*, "$error->{type}$override";
+ }
+ }
+ for my $node (keys(($res->{'cpu-warnings'} // {})->%*)) {
+ push $reasons->{$node}->@*,
+ map { "warning: $_->{type}" } $res->{'cpu-warnings'}->{$node}->@*;
+ }
+ return $reasons;
+ };
+
+ is_deeply(
+ $cpu_reasons->('host,+kvm_pv_eoi,+kvm_pv_unhalt'),
+ {
+ 'other-vendor' => ['cpu-vendor'],
+ 'no-cpu-info' => ['warning: missing-cpu-info'],
+ },
+ "reasons for 'host'",
+ );
+
+ # confidential VMs cannot be live migrated at all
+ $qemu_config_module->mock(
+ load_config => sub { return { memory => 512, 'intel-tdx' => 'type=tdx' }; });
+ is_deeply(
+ $cpu_reasons->('host,+kvm_pv_eoi,+kvm_pv_unhalt'),
+ {},
+ 'confidential VM not checked',
+ );
+ $qemu_config_module->mock(load_config => sub { return { memory => 512 }; });
+
+ my $res = PVE::API2::Qemu->migrate_vm_precondition({ node => 'localhost', vmid => 100 });
+ my $vendor_reason = $res->{not_allowed_nodes}->{'other-vendor'}->{'incompatible-cpu'}->[0];
+ is_deeply(
+ [$vendor_reason->@{qw(source-vendor target-vendor)}],
+ ['GenuineIntel', 'AuthenticAMD'],
+ 'reasons include their values as details',
+ );
+
+ # the migration only warns about a failed check as well
+ $cpu_config_module->mock(
+ get_cpu_from_running_vm =>
+ sub { die "could not read commandline of running machine\n"; },
+ );
+ is_deeply(
+ $cpu_reasons->('host'),
+ { map { $_ => ['warning: cpu-check-failed'] } grep { $_ ne 'localhost' } $nodes->@* },
+ 'failed check reported as warning for each node',
+ );
+ $cpu_config_module->mock(get_cpu_from_running_vm => sub { return $running_cpu; });
+
+ $qemu_server_module->mock(check_running => sub { return 0; });
+ $cluster_module->unmock('get_nodelist', 'get_config', 'get_node_kv');
+ mock_unreachable_config();
+};
+
subtest 'clone target nodes' => sub {
my $inotify_module = Test::MockModule->new('PVE::INotify');
$inotify_module->mock(nodename => sub { return 'pve1'; });
diff --git a/src/test/run_qemu_migrate_tests.pl b/src/test/run_qemu_migrate_tests.pl
index d22c64c1..b2b4d954 100755
--- a/src/test/run_qemu_migrate_tests.pl
+++ b/src/test/run_qemu_migrate_tests.pl
@@ -520,6 +520,70 @@ sub local_volids_for_vm {
return $res;
}
+# Returns a copy of $base, with the values of $override set recursively in nested hashes. An
+# undefined value removes the key instead.
+sub merge_hash {
+ my ($base, $override) = @_;
+
+ my $merged = { $base->%* };
+ for my $key (keys $override->%*) {
+ my $value = $override->{$key};
+ if (!defined($value)) {
+ delete $merged->{$key};
+ } elsif (ref($value) eq 'HASH' && ref($merged->{$key}) eq 'HASH') {
+ $merged->{$key} = merge_hash($merged->{$key}, $value);
+ } else {
+ $merged->{$key} = $value;
+ }
+ }
+
+ return $merged;
+}
+
+# CPU information of the source node 'pve0' and the target node 'pve1' in the CPU migration tests,
+# with nothing preventing the migration. The tests override what they check.
+my $default_cpu_info = {
+ source => { vendor => 'GenuineIntel' },
+ nodes => {
+ pve1 => { vendor => 'GenuineIntel' },
+ },
+};
+
+# Returns a test of the CPU checks for a live migration of VM 1033 to 'pve1'. The VM is configured
+# with the CPU 'cpu' and further settings in 'config', and runs with the QEMU CPU 'runningcpu'.
+# 'cpu_info' overrides $default_cpu_info. Without 'expect_die', the migration must succeed.
+# Warnings and errors about the CPU must be expected. Other keys are passed through.
+sub cpu_migration_test {
+ my (%test) = @_;
+
+ my $runningcpu = delete $test{runningcpu};
+ my $config_patch = { (delete($test{config}) // {})->%* };
+ my $cpu = delete $test{cpu};
+ $config_patch->{cpu} = $cpu if defined($cpu);
+
+ my $expected_status = { running => 1, runningmachine => 'pc-q35-5.0+pve0' };
+ $expected_status->{runningcpu} = $runningcpu if $test{expect_die};
+
+ return {
+ target => 'pve1',
+ vmid => 1033,
+ vm_status =>
+ { running => 1, runningmachine => 'pc-q35-5.0+pve0', runningcpu => $runningcpu },
+ opts => { online => 1, (delete($test{opts}) // {})->%* },
+ config_patch => $config_patch,
+ cpu_info => merge_hash($default_cpu_info, delete($test{cpu_info}) // {}),
+ expected_calls => $test{expect_die} ? {} : $default_expected_calls_online,
+ unexpected_log => ['CPU'],
+ expected => {
+ source_volids => {},
+ target_volids => {},
+ vm_config => get_patched_config(1033, $config_patch),
+ vm_status => $expected_status,
+ },
+ %test,
+ };
+}
+
my $tests = [
# each test consists of the following:
# name - unique name for the test which also serves as a dir name.
@@ -530,6 +594,9 @@ 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'. With 'check-error', the CPU check fails
+ # with it. See cpu_migration_test() for tests of the CPU checks.
# 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
@@ -1479,6 +1546,87 @@ my $tests = [
},
},
},
+ cpu_migration_test(
+ name => '1033_running_host_cpu_other_vendor',
+ cpu => 'host',
+ runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+ cpu_info => {
+ source => { vendor => 'AuthenticAMD' },
+ },
+ 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",
+ ),
+ cpu_migration_test(
+ # refused before starting the conntrack state helper, as a failed preparation is not
+ # cleaned up
+ name => '1033_running_host_cpu_other_vendor_conntrack',
+ cpu => 'host',
+ runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+ opts => { 'with-conntrack-state' => 1 },
+ cpu_info => {
+ source => { vendor => 'AuthenticAMD' },
+ },
+ 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",
+ ),
+ cpu_migration_test(
+ # the check only guards migrations that work without it
+ name => '1033_running_cpu_check_failed',
+ cpu => 'host',
+ runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+ cpu_info => {
+ source => { vendor => 'AuthenticAMD' },
+ 'check-error' => "could not read commandline of running machine\n",
+ },
+ expect_log => [
+ "unable to check whether the CPU of node 'pve1' can run the VM, migrating anyway -"
+ . " could not read commandline of running machine",
+ ],
+ ),
+ cpu_migration_test(
+ name => '1033_running_host_cpu_target_without_cpu_info',
+ cpu => 'host',
+ runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+ cpu_info => {
+ nodes => { pve1 => undef },
+ },
+ expect_log => [
+ "CPU of node 'pve1' might be incompatible: the node does not provide the CPU"
+ . " information needed to check it",
+ ],
+ ),
+ cpu_migration_test(
+ # with TCG, 'max' is fully emulated instead of passing through the host CPU
+ name => '1033_running_max_cpu_tcg_other_vendor',
+ cpu => 'max',
+ config => { kvm => 0 },
+ runningcpu => 'max',
+ cpu_info => {
+ source => { vendor => 'AuthenticAMD' },
+ },
+ ),
+ cpu_migration_test(
+ # VMs of another architecture than the host's run with TCG by default
+ name => '1033_running_max_cpu_emulated_other_vendor',
+ cpu => 'max',
+ config => { arch => 'aarch64' },
+ runningcpu => 'max',
+ cpu_info => {
+ source => { vendor => 'AuthenticAMD' },
+ },
+ ),
+ cpu_migration_test(
+ # for example with ARM CPUs of an unknown implementer, no node knows its CPU vendor
+ name => '1033_running_host_cpu_vendor_unknown',
+ cpu => 'host',
+ runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+ cpu_info => {
+ source => { vendor => undef },
+ nodes => { pve1 => { vendor => undef } },
+ },
+ ),
{
name => '105_replicated_to_non_replication_target',
target => 'pve1',
@@ -1900,6 +2048,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] 22+ messages in thread* [PATCH qemu-server v4 10/21] fix #6535: migrate: warn about live migration between CPU vendors
2026-12-02 15:17 [PATCH docs/manager/qemu-server v4 00/21] check the target node's CPU before live migrating a VM Jonas Theisen
` (8 preceding siblings ...)
2026-12-02 15:18 ` [PATCH qemu-server v4 09/21] migrate: block live migration of host CPU VMs between CPU vendors Jonas Theisen
@ 2026-12-02 15:18 ` Jonas Theisen
2026-12-02 15:18 ` [PATCH qemu-server v4 11/21] fix #2924: migrate: block live migration of host CPU VMs to nodes lacking flags Jonas Theisen
` (10 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Jonas Theisen @ 2026-12-02 15:18 UTC (permalink / raw)
To: pve-devel
Live migrating a VM between CPU 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, and in the
migration precondition API, with the CPU vendors as details. VMs with
the 'host' or 'max' CPU model stay blocked.
Fixes: https://bugzilla.proxmox.com/show_bug.cgi?id=6535
Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
src/PVE/API2/Qemu.pm | 2 +-
src/PVE/QemuMigrate/Helpers.pm | 20 ++++++++++++++++++++
src/test/run_api_tests.pl | 17 +++++++++++++++++
src/test/run_qemu_migrate_tests.pl | 11 +++++++++++
4 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/src/PVE/API2/Qemu.pm b/src/PVE/API2/Qemu.pm
index a3f44ac0..2e916bb2 100644
--- a/src/PVE/API2/Qemu.pm
+++ b/src/PVE/API2/Qemu.pm
@@ -5711,7 +5711,7 @@ __PACKAGE__->register_method({
type => {
type => 'string',
description => "The check that reported the warning.",
- enum => ['missing-cpu-info', 'cpu-check-failed'],
+ enum => ['cpu-vendor', 'missing-cpu-info', 'cpu-check-failed'],
},
message => {
type => 'string',
diff --git a/src/PVE/QemuMigrate/Helpers.pm b/src/PVE/QemuMigrate/Helpers.pm
index 23f4d589..583d77bc 100644
--- a/src/PVE/QemuMigrate/Helpers.pm
+++ b/src/PVE/QemuMigrate/Helpers.pm
@@ -235,6 +235,26 @@ my $target_cpu_checks = [
return ($message, vendor_details($source, $target));
},
},
+ {
+ 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
+ my $message =
+ "live migration from $source->{vendor} to $target->{vendor} is not guaranteed"
+ . " to work";
+ return ($message, vendor_details($source, $target));
+ },
+ },
];
# Returns the issues of the target node. If it lacks CPU information needed by a check that can
diff --git a/src/test/run_api_tests.pl b/src/test/run_api_tests.pl
index 22a0533b..8a546ac0 100755
--- a/src/test/run_api_tests.pl
+++ b/src/test/run_api_tests.pl
@@ -406,6 +406,13 @@ subtest 'migration preconditions of the CPU of a running VM' => sub {
},
"reasons for 'host'",
);
+ is_deeply(
+ $cpu_reasons->('kvm64,enforce,+avx512f,+kvm_pv_eoi,+kvm_pv_unhalt'),
+ {
+ 'other-vendor' => ['warning: cpu-vendor'],
+ },
+ 'reasons for another CPU model',
+ );
# confidential VMs cannot be live migrated at all
$qemu_config_module->mock(
@@ -417,6 +424,7 @@ subtest 'migration preconditions of the CPU of a running VM' => sub {
);
$qemu_config_module->mock(load_config => sub { return { memory => 512 }; });
+ $running_cpu = 'host,+kvm_pv_eoi,+kvm_pv_unhalt';
my $res = PVE::API2::Qemu->migrate_vm_precondition({ node => 'localhost', vmid => 100 });
my $vendor_reason = $res->{not_allowed_nodes}->{'other-vendor'}->{'incompatible-cpu'}->[0];
is_deeply(
@@ -425,6 +433,15 @@ subtest 'migration preconditions of the CPU of a running VM' => sub {
'reasons include their values as details',
);
+ $running_cpu = 'kvm64,enforce,+kvm_pv_eoi,+kvm_pv_unhalt';
+ $res = PVE::API2::Qemu->migrate_vm_precondition({ node => 'localhost', vmid => 100 });
+ my $vendor_warning = $res->{'cpu-warnings'}->{'other-vendor'}->[0];
+ is_deeply(
+ [$vendor_warning->@{qw(source-vendor target-vendor)}],
+ ['GenuineIntel', 'AuthenticAMD'],
+ 'warnings include their values as details',
+ );
+
# the migration only warns about a failed check as well
$cpu_config_module->mock(
get_cpu_from_running_vm =>
diff --git a/src/test/run_qemu_migrate_tests.pl b/src/test/run_qemu_migrate_tests.pl
index b2b4d954..41475b81 100755
--- a/src/test/run_qemu_migrate_tests.pl
+++ b/src/test/run_qemu_migrate_tests.pl
@@ -1627,6 +1627,17 @@ my $tests = [
nodes => { pve1 => { vendor => undef } },
},
),
+ cpu_migration_test(
+ name => '1033_running_kvm64_cpu_other_vendor',
+ runningcpu => 'kvm64,enforce,+kvm_pv_eoi,+kvm_pv_unhalt,+lahf_lm,+sep',
+ cpu_info => {
+ source => { vendor => 'AuthenticAMD' },
+ },
+ expect_log => [
+ "CPU of node 'pve1' might be incompatible: live migration from AuthenticAMD to"
+ . " GenuineIntel is not guaranteed to work",
+ ],
+ ),
{
name => '105_replicated_to_non_replication_target',
target => 'pve1',
--
2.47.3
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH qemu-server v4 11/21] fix #2924: migrate: block live migration of host CPU VMs to nodes lacking flags
2026-12-02 15:17 [PATCH docs/manager/qemu-server v4 00/21] check the target node's CPU before live migrating a VM Jonas Theisen
` (9 preceding siblings ...)
2026-12-02 15:18 ` [PATCH qemu-server v4 10/21] fix #6535: migrate: warn about live migration " Jonas Theisen
@ 2026-12-02 15:18 ` Jonas Theisen
2026-12-02 15:18 ` [PATCH qemu-server v4 12/21] migrate: warn about live migration of host CPU VMs between CPU models Jonas Theisen
` (9 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Jonas Theisen @ 2026-12-02 15:18 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 CPU lacks flags 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 afterwards.
Compare the CPU flags KVM supports on the source and the target, which
pvestatd already broadcasts, so this also works for targets running an
older version, and refuse the migration if the target lacks any.
Ignored are flags disabled for the VM, Hyper-V enlightenments, which
are not passed through, and properties QEMU does not recognize as
flags, like 'migratable' or 'l3-cache', which the broadcast includes
and which can differ between QEMU versions. The message lists at most
ten missing flags, the precondition API reports all of them as
details.
Flags that only tell the guest which CPU vulnerabilities do not affect
it, those of the IA32_ARCH_CAPABILITIES MSR on Intel, like 'its-no' or
'gds-no', and CPUID flags on AMD, like 'srso-no' or 'tsa-l1-no', only
cause a warning, as KVM reports some of them only with newer kernels.
A guest that saw them might have skipped a mitigation, which only
matters if the target CPU is affected, but it keeps running. 'tsx-ctrl'
is still checked, as it allows the guest to access an MSR.
Warn if the broadcast flags of this node are missing, for example as
the entry got lost when pmxcfs was restarted, instead of silently
skipping the check.
The flags of the source node only approximate those of the VM, as it
might have been started on another node, and they depend on the kernel
version. So allow overriding the check with the new
'allow-missing-cpu-flags' option. It only risks a failed migration or
a crash of the migrated guest, so it needs no privilege beyond
'VM.Migrate'. 'force' is not reused, as the HA stack always sets it.
The option is forwarded to the HA stack like other migration options.
This requires pve-manager 9.2.31 or newer on this node, otherwise the
precondition API does not offer it for HA-managed VMs. As the HA stack
passes it on to VMs in positive affinity, forwarding it requires
'VM.Migrate' on these as well.
Fixes: https://bugzilla.proxmox.com/show_bug.cgi?id=2924
Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
src/PVE/API2/Qemu.pm | 53 ++++++-
src/PVE/QemuMigrate.pm | 2 +-
src/PVE/QemuMigrate/Helpers.pm | 183 ++++++++++++++++++++--
src/test/MigrationTest/QemuMigrateMock.pm | 12 ++
src/test/run_api_tests.pl | 108 ++++++++++++-
src/test/run_qemu_migrate_tests.pl | 142 ++++++++++++++++-
6 files changed, 473 insertions(+), 27 deletions(-)
diff --git a/src/PVE/API2/Qemu.pm b/src/PVE/API2/Qemu.pm
index 2e916bb2..5227a0cc 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.",
+ },
};
# Properties that will be forwarded via the HA stack to the LRM, which will then use them for its
@@ -163,8 +170,16 @@ my $migrate_json_properties = {
my $ha_migrate_props = {
'with-conntrack-state' => 1,
'skip-config-check' => 1,
+ 'allow-missing-cpu-flags' => 1,
};
+# Only nodes with pve-manager 9.2.31 or newer have an ha-manager that accepts additional migration
+# options.
+my sub ha_forwards_migrate_options {
+ my ($node) = @_;
+ return PVE::Cluster::node_pvecfg_version_at_least($node, 9, 2, 31);
+}
+
sub ha_migrate_json_properties {
my $forwarded_props = {};
$forwarded_props->{$_} = $migrate_json_properties->{$_} for keys $ha_migrate_props->%*;
@@ -5611,12 +5626,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.",
+ },
PVE::QemuMigrate::Helpers::cpu_issue_details_schema()->%*,
},
},
@@ -5711,7 +5732,12 @@ __PACKAGE__->register_method({
type => {
type => 'string',
description => "The check that reported the warning.",
- enum => ['cpu-vendor', 'missing-cpu-info', 'cpu-check-failed'],
+ enum => [
+ 'cpu-vendor',
+ 'missing-cpu-info',
+ 'host-cpu-flags',
+ 'cpu-check-failed',
+ ],
},
message => {
type => 'string',
@@ -5782,12 +5808,14 @@ __PACKAGE__->register_method({
PVE::QemuServer::check_local_storage_availability($vmconf, $storecfg);
my $blocking_ha_resources_by_node = {};
+ my $offers_overrides = 1;
if (PVE::HA::Config::vm_is_ha_managed($vmid)) {
(my $dependent_ha_resource, $blocking_ha_resources_by_node) =
PVE::HA::Config::get_resource_motion_info("vm:$vmid");
$res->{'dependent-ha-resources'} = $dependent_ha_resource // [];
+ $offers_overrides = ha_forwards_migrate_options($localnode);
}
my $has_identity = PVE::QemuConfig->has_stored_identity($vmid);
@@ -5833,6 +5861,8 @@ __PACKAGE__->register_method({
($issue->{details} // {})->%*,
};
if ($issue->{severity} eq 'error') {
+ $reason->{override} = $issue->{override}
+ if defined($issue->{override}) && $offers_overrides;
push $res->{not_allowed_nodes}->{$node}->{'incompatible-cpu'}->@*, $reason;
} else {
push $res->{'cpu-warnings'}->{$node}->@*, $reason;
@@ -5976,15 +6006,14 @@ __PACKAGE__->register_method({
}
if (PVE::HA::Config::vm_is_ha_managed($vmid) && $rpcenv->{type} ne 'ha') {
+ my $forwards_options = ha_forwards_migrate_options($localnode);
my $hacmd = sub {
my $upid = shift;
my $extra_opts = '';
my $cmd = ['ha-manager', 'migrate', "vm:$vmid", $target];
- # Only nodes with pve-manager 9.2.31 or newer have an ha-manager that accepts
- # additional migration options.
- if (PVE::Cluster::node_pvecfg_version_at_least($localnode, 9, 2, 31)) {
+ if ($forwards_options) {
for my $prop (sort keys $ha_migrate_props->%*) {
if (defined(my $value = $param->{$prop})) {
push($cmd->@*, "--$prop", $value);
@@ -6002,6 +6031,20 @@ __PACKAGE__->register_method({
return;
};
+ # The HA stack passes the options on to the VMs in positive affinity with this one.
+ if ($forwards_options && $param->{'allow-missing-cpu-flags'}) {
+ my ($dependent_resources) =
+ PVE::HA::Config::get_resource_motion_info("vm:$vmid");
+ for my $sid ($dependent_resources->@*) {
+ my ($type, $id) = PVE::HA::Config::parse_sid($sid);
+ next if $type ne 'vm';
+ raise_perm_exc(
+ "/vms/$id, VM.Migrate - 'allow-missing-cpu-flags' also applies"
+ . " to HA resource '$sid' in positive affinity")
+ if !$rpcenv->check_vm_perm($authuser, $id, undef, ['VM.Migrate'], 0, 1);
+ }
+ }
+
return $rpcenv->fork_worker('hamigrate', $vmid, $authuser, $hacmd);
} else {
diff --git a/src/PVE/QemuMigrate.pm b/src/PVE/QemuMigrate.pm
index d450cd23..21c0a73d 100644
--- a/src/PVE/QemuMigrate.pm
+++ b/src/PVE/QemuMigrate.pm
@@ -255,7 +255,7 @@ sub prepare {
# before setting up the conntrack state helper, as a failing preparation is not cleaned up.
if (!$self->{opts}->{remote}) {
my $warnings = PVE::QemuMigrate::Helpers::assert_target_cpu_compatibility(
- $vmid, $conf, $pid, $self->{node},
+ $vmid, $conf, $pid, $self->{node}, $self->{opts},
);
log_warn($_) for $warnings->@*;
}
diff --git a/src/PVE/QemuMigrate/Helpers.pm b/src/PVE/QemuMigrate/Helpers.pm
index 583d77bc..c346128c 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 Storable qw(dclone);
use PVE::Cluster;
@@ -129,6 +130,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'. As in QEMU, flags with '+' override properties, and flags with '-'
# override both, regardless of their position.
@@ -180,6 +198,12 @@ my $cpu_issue_details = {
optional => 1,
description => "The CPU vendor of the target node.",
},
+ 'missing-flags' => {
+ type => 'array',
+ optional => 1,
+ description => "The CPU flags the message refers to, as it might only list some.",
+ items => { type => 'string' },
+ },
};
my sub vendor_details {
@@ -200,11 +224,64 @@ sub cpu_issue_details_schema {
return dclone($cpu_issue_details);
}
+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;
+}
+
+# Bits of the IA32_ARCH_CAPABILITIES MSR on Intel that only tell the guest which CPU
+# vulnerabilities do not affect it or how to mitigate them, and CPUID bits on AMD that only tell it
+# which do not affect it. KVM reports some of them only with newer kernels. A guest that saw them
+# might skip mitigations, but does not need them to keep running. tsx-ctrl is not included, as it
+# allows the guest to access an MSR.
+my $vulnerability_info_flags = {
+ map { $_ => 1 }
+ qw(
+ amd-no-ssb bhi-no fb-clear fbsdp-no gds-no ibrs-all its-no mds-no pbrsb-no pschange-mc-no
+ psdp-no rdctl-no rfds-clear rfds-no rsba sbdr-ssdp-no skip-l1dfl-vmentry srso-no
+ srso-user-kernel-no ssb-no taa-no tsa-l1-no tsa-sq-no
+ )
+};
+
+# Returns the flags of the source node that the target node lacks and that the VM might use, and
+# separately those that only inform the guest about CPU vulnerabilities.
+my sub get_missing_host_cpu_flags {
+ 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'});
+
+ # 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->{$_}
+ && (PVE::JSONSchema::parse_boolean($cpu->{props}->{$_} // 'on') // 1)
+ } @flags;
+
+ my $info = [grep { $vulnerability_info_flags->{$_} } @missing];
+ my $other = [grep { !$vulnerability_info_flags->{$_} } @missing];
+ return ($other, $info);
+}
+
# Checks whether the CPU of a target node can run a running VM after a live migration. Each check
# has:
# - 'type', identifying the check
# - 'severity', 'error' if an incompatibility prevents the migration, 'warning' if it is only
# reported
+# - 'override', optionally, the migration option that allows ignoring an error
# - 'needs', listing the CPU information the check requires of the target node and, to compare
# them, of this node, nodes lacking any of it are skipped
# - 'applies', returning true if the check is relevant for the VM's CPU
@@ -214,7 +291,9 @@ sub cpu_issue_details_schema {
# The VM's CPU is parsed by parse_qemu_cpu_string(), with:
# - 'kvm' set if the VM uses KVM
#
-# The CPU information of the nodes is in the format of get_host_cpu_info().
+# The CPU information of the nodes is in the format of get_host_cpu_info(), plus:
+# - the CPU flags KVM supports as 'kvm-flags' hash
+# - for the source node, the CPU flags QEMU recognizes as 'understood-flags' hash, if known
my $target_cpu_checks = [
{
type => 'cpu-vendor',
@@ -255,33 +334,91 @@ my $target_cpu_checks = [
return ($message, vendor_details($source, $target));
},
},
+ {
+ 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) = @_;
+
+ my ($missing) = get_missing_host_cpu_flags($cpu, $source, $target);
+ return if !scalar($missing->@*);
+
+ my $message =
+ "CPU model '$cpu->{model}' passes through the flags of the host CPU, but the"
+ . " node lacks: "
+ . format_flag_list($missing);
+ return ($message, { 'missing-flags' => $missing });
+ },
+ },
+ {
+ type => 'host-cpu-flags',
+ severity => 'warning',
+ needs => ['kvm-flags'],
+ applies => sub {
+ my ($cpu) = @_;
+ return is_host_cpu_model($cpu);
+ },
+ check => sub {
+ my ($cpu, $source, $target) = @_;
+
+ my (undef, $missing) = get_missing_host_cpu_flags($cpu, $source, $target);
+ return if !scalar($missing->@*);
+
+ my $message =
+ "the node does not report CPU flags that tell the guest which CPU"
+ . " vulnerabilities do not affect it, for example as it runs another kernel"
+ . " version, so the guest might not mitigate them: "
+ . format_flag_list($missing);
+ return ($message, { 'missing-flags' => $missing });
+ },
+ },
];
# Returns the issues of the target node. If it lacks CPU information needed by a check that can
# prevent the migration, that is an issue as well, but only a warning, as the node is not refused.
# Information this node lacks as well, for example the vendor of an unknown ARM CPU, is not
-# reported.
+# reported. Lost CPU flags of this node are reported, as it cannot determine them itself.
my sub get_target_cpu_issues {
my ($cpu, $checks, $source_info, $target_info) = @_;
- my ($issues, $target_complete) = ([], 1);
+ my ($issues, $target_complete, $source_complete) = ([], 1, 1);
for my $check ($checks->@*) {
+ my $blocking = $check->{severity} eq 'error';
my @missing = grep { !defined($target_info->{$_}) } $check->{needs}->@*;
if (scalar(@missing)) {
- $target_complete = 0
- if $check->{severity} eq 'error' && grep { defined($source_info->{$_}) } @missing;
+ $target_complete = 0 if $blocking && grep { defined($source_info->{$_}) } @missing;
+ next;
+ }
+ if (my @source_missing = grep { !defined($source_info->{$_}) } $check->{needs}->@*) {
+ # This node determines its other information itself if it does not broadcast it, but
+ # its CPU flags can get lost, for example as pmxcfs was restarted.
+ $source_complete = 0 if $blocking && grep { $_ eq 'kvm-flags' } @source_missing;
next;
}
my ($message, $details) = $check->{check}->($cpu, $source_info, $target_info) or next;
my $issue = { type => $check->{type}, severity => $check->{severity}, message => $message };
$issue->{details} = $details if $details;
+ $issue->{override} = $check->{override} if defined($check->{override});
push $issues->@*, $issue;
}
if (!$target_complete) {
my $message = "the node does not provide the CPU information needed to check it, for"
- . " example as it runs an older version";
+ . " example as it runs an older version or pvestatd did not broadcast it yet";
+ push $issues->@*,
+ { type => 'missing-cpu-info', severity => 'warning', message => $message };
+ }
+ if (!$source_complete) {
+ my $message = "the source node does not provide the CPU information needed to check it,"
+ . " for example until pvestatd broadcasts it again after a restart of pmxcfs";
push $issues->@*,
{ type => 'missing-cpu-info', severity => 'warning', message => $message };
}
@@ -320,7 +457,9 @@ or C<warning> if it might not, a human-readable C<message>, and optionally C<det
values the message contains, see cpu_issue_details_schema(). Nodes that lack CPU information
needed by a check that can prevent the migration, for example as they run an older version, have
an issue of type C<missing-cpu-info> with severity C<warning>, unless this node lacks that
-information as well.
+information as well. If this node lacks its broadcast CPU flags, all nodes have such an issue, as
+the checks needing them are skipped. If a migration option allows ignoring an error, C<override>
+names it.
=cut
@@ -339,12 +478,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 = {};
for my $node ($nodes->@*) {
my $target_info = get_node_cpu_info($node);
+ $target_info->{'kvm-flags'} = get_node_kvm_cpu_flags($node);
my $issues = get_target_cpu_issues($cpu, $checks, $source_info, $target_info);
$issues_by_node->{$node} = $issues if scalar($issues->@*);
@@ -355,19 +498,21 @@ sub check_target_cpu_compatibility {
=head3 assert_target_cpu_compatibility
- my $warnings = assert_target_cpu_compatibility($vmid, $conf, $pid, $node);
+ 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.
+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, including
-missing CPU information of the node. If the check itself fails, the node is not refused, but a
-warning about the failure is returned, as the check only guards migrations that work without it.
+missing CPU information of the node, and about overridden incompatibilities. If the check itself
+fails, the node is not refused, but a warning about the failure is returned, as the check only
+guards migrations that work without it.
=cut
sub assert_target_cpu_compatibility {
- my ($vmid, $conf, $pid, $node) = @_;
+ my ($vmid, $conf, $pid, $node, $opts) = @_;
my $issues_by_node = eval { check_target_cpu_compatibility($vmid, $conf, $pid, [$node]) };
if (my $err = $@) {
@@ -379,16 +524,26 @@ sub assert_target_cpu_compatibility {
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->@*) . "\n";
+ . join('; ', map { $_->{message} } $errors->@*)
+ . "$hint\n";
}
return $warnings;
diff --git a/src/test/MigrationTest/QemuMigrateMock.pm b/src/test/MigrationTest/QemuMigrateMock.pm
index bfccef5a..b6e035b8 100644
--- a/src/test/MigrationTest/QemuMigrateMock.pm
+++ b/src/test/MigrationTest/QemuMigrateMock.pm
@@ -244,6 +244,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 =
@@ -255,6 +259,14 @@ $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 gds-no hv-relaxed its-no lahf-lm srso-no sse sse4.2 tsa-l1-no tsx-ctrl)];
+ },
+);
+
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_api_tests.pl b/src/test/run_api_tests.pl
index 8a546ac0..00c5bbdf 100755
--- a/src/test/run_api_tests.pl
+++ b/src/test/run_api_tests.pl
@@ -338,15 +338,17 @@ subtest 'migration preconditions of the CPU of a running VM' => sub {
# the node key-value entries of the source node 'localhost' and of the target nodes, which
# differ from the source as their names say, while 'no-cpu-info' broadcasts none
my $entries = sub {
- my ($info) = @_;
- return { 'host-cpu-info' => encode_json($info) };
+ my ($info, $kvm_flags) = @_;
+ return { 'host-cpu-info' => encode_json($info), 'cpuflags-kvm' => $kvm_flags };
};
my $source = { vendor => 'GenuineIntel' };
my $node_kv = {
- localhost => $entries->($source),
- 'other-vendor' => $entries->({ $source->%*, vendor => 'AuthenticAMD' }),
+ localhost => $entries->($source, 'avx512f fpu sse'),
+ 'other-vendor' =>
+ $entries->({ $source->%*, vendor => 'AuthenticAMD' }, 'avx512f fpu sse'),
+ 'missing-flag' => $entries->($source, 'fpu sse'),
};
- my $nodes = ['localhost', 'other-vendor', 'no-cpu-info'];
+ my $nodes = ['localhost', 'other-vendor', 'no-cpu-info', 'missing-flag'];
my $inotify_module = Test::MockModule->new('PVE::INotify');
$inotify_module->mock(nodename => sub { return 'localhost'; });
@@ -358,6 +360,9 @@ subtest 'migration preconditions of the CPU of a running VM' => sub {
return ([], {}, { map { $_ => [] } $nodes->@* });
},
);
+ my $cpu_flags_module = Test::MockModule->new('PVE::QemuServer::CPUFlags');
+ $cpu_flags_module->mock(
+ query_understood_cpu_flags => sub { return [qw(avx512f fpu sse)]; });
$qemu_config_module->mock(load_config => sub { return { memory => 512 }; });
$qemu_server_module->mock(check_running => sub { return 1234; });
my $running_cpu;
@@ -402,6 +407,7 @@ subtest 'migration preconditions of the CPU of a running VM' => sub {
$cpu_reasons->('host,+kvm_pv_eoi,+kvm_pv_unhalt'),
{
'other-vendor' => ['cpu-vendor'],
+ 'missing-flag' => ['host-cpu-flags (allow-missing-cpu-flags)'],
'no-cpu-info' => ['warning: missing-cpu-info'],
},
"reasons for 'host'",
@@ -432,6 +438,12 @@ subtest 'migration preconditions of the CPU of a running VM' => sub {
['GenuineIntel', 'AuthenticAMD'],
'reasons include their values as details',
);
+ is_deeply(
+ $res->{not_allowed_nodes}->{'missing-flag'}->{'incompatible-cpu'}->[0]
+ ->{'missing-flags'},
+ ['avx512f'],
+ 'reasons include all missing flags',
+ );
$running_cpu = 'kvm64,enforce,+kvm_pv_eoi,+kvm_pv_unhalt';
$res = PVE::API2::Qemu->migrate_vm_precondition({ node => 'localhost', vmid => 100 });
@@ -442,6 +454,24 @@ subtest 'migration preconditions of the CPU of a running VM' => sub {
'warnings include their values as details',
);
+ # overrides only take effect for HA-managed VMs if the HA stack gets them
+ $ha_config_module->mock(
+ vm_is_ha_managed => sub { return 1; },
+ get_resource_motion_info => sub { return ([], {}); },
+ );
+ for my $version ('9.2.30', '9.2.31') {
+ $node_versions->{localhost} = $version;
+ my $forwarded = $version eq '9.2.31';
+ is_deeply(
+ $cpu_reasons->('host,+kvm_pv_eoi,+kvm_pv_unhalt')->{'missing-flag'},
+ [$forwarded ? 'host-cpu-flags (allow-missing-cpu-flags)' : 'host-cpu-flags'],
+ "HA-managed VM, pve-manager $version: override "
+ . ($forwarded ? '' : 'not ')
+ . 'offered',
+ );
+ }
+ $node_versions->{localhost} = undef;
+
# the migration only warns about a failed check as well
$cpu_config_module->mock(
get_cpu_from_running_vm =>
@@ -459,6 +489,74 @@ subtest 'migration preconditions of the CPU of a running VM' => sub {
mock_unreachable_config();
};
+subtest 'override for HA-managed VMs requires VM.Migrate on VMs in positive affinity' => sub {
+ my $inotify_module = Test::MockModule->new('PVE::INotify');
+ $inotify_module->mock(nodename => sub { return 'localhost'; });
+ $cluster_module->mock(get_config => sub { return $raw_without_identity; });
+ $qemu_config_module->mock(
+ load_config => sub { return { memory => 512 }; },
+ check_lock => sub { return; },
+ );
+ $replication_config_module->mock(find_local_replication_job => sub { return; });
+ $qemu_server_module->mock(
+ check_running => sub { return 1234; },
+ check_storage_availability => sub { return; },
+ );
+ my $rpcenv_module = Test::MockModule->new('PVE::RPCEnvironment');
+ my $permitted = { 102 => 0 };
+ $rpcenv_module->mock(
+ fork_worker => sub { die "reached fork_worker\n"; },
+ check_vm_perm => sub {
+ my ($self, $user, $vmid) = @_;
+ die "unexpected permission check of VM $vmid\n" if !exists($permitted->{$vmid});
+ return $permitted->{$vmid};
+ },
+ );
+ my $ha_config_module = Test::MockModule->new('PVE::HA::Config');
+ $ha_config_module->mock(
+ vm_is_ha_managed => sub { return 1; },
+ get_resource_motion_info => sub { return (['ct:101', 'vm:102'], {}); },
+ );
+ # nodes with this version forward the option to the HA stack
+ $node_versions->{localhost} = '9.2.31';
+
+ my $migrate_error = sub {
+ my ($param) = @_;
+ eval { PVE::API2::Qemu->migrate_vm({ node => 'localhost', vmid => 100, $param->%* }) };
+ return "$@";
+ };
+ like(
+ $migrate_error->({ target => 'pve2', online => 1, 'allow-missing-cpu-flags' => 1 }),
+ qr{^403 Permission check failed \(/vms/102, VM\.Migrate - },
+ 'override refused without VM.Migrate on a VM in positive affinity',
+ );
+ is(
+ $migrate_error->({ target => 'pve2', online => 1 }),
+ "reached fork_worker\n",
+ 'VMs in positive affinity are not checked without override',
+ );
+ $permitted->{102} = 1;
+ is(
+ $migrate_error->({ target => 'pve2', online => 1, 'allow-missing-cpu-flags' => 1 }),
+ "reached fork_worker\n",
+ 'override allowed with VM.Migrate on the VMs in positive affinity',
+ );
+ ($permitted->{102}, $node_versions->{localhost}) = (0, '9.2.30');
+ is(
+ $migrate_error->({ target => 'pve2', online => 1, 'allow-missing-cpu-flags' => 1 }),
+ "reached fork_worker\n",
+ 'VMs in positive affinity are not checked if the option is not forwarded',
+ );
+
+ $node_versions->{localhost} = undef;
+ $qemu_server_module->mock(check_running => sub { return 0; });
+ $qemu_server_module->unmock('check_storage_availability');
+ $replication_config_module->unmock('find_local_replication_job');
+ $qemu_config_module->unmock('check_lock');
+ $cluster_module->unmock('get_config');
+ mock_unreachable_config();
+};
+
subtest 'clone target nodes' => sub {
my $inotify_module = Test::MockModule->new('PVE::INotify');
$inotify_module->mock(nodename => sub { return 'pve1'; });
diff --git a/src/test/run_qemu_migrate_tests.pl b/src/test/run_qemu_migrate_tests.pl
index 41475b81..b76bef88 100755
--- a/src/test/run_qemu_migrate_tests.pl
+++ b/src/test/run_qemu_migrate_tests.pl
@@ -547,8 +547,15 @@ my $default_cpu_info = {
nodes => {
pve1 => { vendor => 'GenuineIntel' },
},
+ 'kvm-flags' => {
+ pve0 => 'fpu sse',
+ pve1 => 'fpu sse',
+ },
};
+my $lacks_avx512f =
+ "CPU model 'host' passes through the flags of the host CPU, but the node lacks: avx512f";
+
# Returns a test of the CPU checks for a live migration of VM 1033 to 'pve1'. The VM is configured
# with the CPU 'cpu' and further settings in 'config', and runs with the QEMU CPU 'runningcpu'.
# 'cpu_info' overrides $default_cpu_info. Without 'expect_die', the migration must succeed.
@@ -595,8 +602,9 @@ 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'. With 'check-error', the CPU check fails
- # with it. See cpu_migration_test() for tests of the CPU checks.
+ # other node in 'nodes', and the KVM CPU flags of each node in
+ # 'kvm-flags'. With 'check-error', the CPU check fails with it.
+ # See cpu_migration_test() for tests of the CPU checks.
# 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
@@ -1638,6 +1646,136 @@ my $tests = [
. " GenuineIntel is not guaranteed to work",
],
),
+ cpu_migration_test(
+ # properties that are no CPU flags can differ between QEMU versions
+ name => '1033_running_host_cpu_other_properties',
+ cpu => 'host',
+ runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+ cpu_info => {
+ 'kvm-flags' => { pve0 => 'fpu l3-cache migratable sse x-vendor-cpuid-only-v2' },
+ },
+ ),
+ cpu_migration_test(
+ name => '1033_running_host_cpu_missing_flags',
+ cpu => 'host',
+ runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+ cpu_info => {
+ 'kvm-flags' => { pve0 => 'avx512f fpu hv-relaxed sse' },
+ },
+ expect_die => "can't migrate VM to 'pve1' - incompatible CPU: $lacks_avx512f - use"
+ . " 'allow-missing-cpu-flags' to override",
+ ),
+ cpu_migration_test(
+ # 'force', which the HA stack always sets, must not override the check
+ name => '1033_running_host_cpu_missing_flags_force',
+ cpu => 'host',
+ runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+ opts => { force => 1 },
+ cpu_info => {
+ 'kvm-flags' => { pve0 => 'avx512f fpu hv-relaxed sse' },
+ },
+ expect_die => "can't migrate VM to 'pve1' - incompatible CPU: $lacks_avx512f - use"
+ . " 'allow-missing-cpu-flags' to override",
+ ),
+ cpu_migration_test(
+ name => '1033_running_host_cpu_missing_flags_allowed',
+ cpu => 'host',
+ runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+ opts => { 'allow-missing-cpu-flags' => 1 },
+ cpu_info => {
+ 'kvm-flags' => { pve0 => 'avx512f fpu hv-relaxed sse' },
+ },
+ expect_log => [
+ "ignoring incompatible CPU of node 'pve1' due to 'allow-missing-cpu-flags':"
+ . " $lacks_avx512f",
+ ],
+ ),
+ cpu_migration_test(
+ # 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',
+ cpu => 'host',
+ runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+ cpu_info => {
+ nodes => { pve1 => undef },
+ 'kvm-flags' => { pve0 => 'avx512f fpu hv-relaxed sse' },
+ },
+ expect_die => "can't migrate VM to 'pve1' - incompatible CPU: $lacks_avx512f - use"
+ . " 'allow-missing-cpu-flags' to override",
+ ),
+ cpu_migration_test(
+ # older kernels do not report all flags about unaffected vulnerabilities
+ name => '1033_running_host_cpu_missing_vulnerability_info_flags',
+ cpu => 'host',
+ runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+ cpu_info => {
+ 'kvm-flags' => { pve0 => 'fpu gds-no its-no sse', pve1 => 'fpu gds-no sse' },
+ },
+ expect_log => [
+ "CPU of node 'pve1' might be incompatible: the node does not report CPU flags that"
+ . " tell the guest which CPU vulnerabilities do not affect it, for example as it"
+ . " runs another kernel version, so the guest might not mitigate them: its-no",
+ ],
+ ),
+ cpu_migration_test(
+ # AMD reports unaffected vulnerabilities via CPUID
+ name => '1033_running_host_cpu_missing_amd_vulnerability_info_flags',
+ cpu => 'host',
+ runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+ cpu_info => {
+ 'kvm-flags' => { pve0 => 'fpu srso-no sse tsa-l1-no', pve1 => 'fpu sse tsa-l1-no' },
+ },
+ expect_log => [
+ "CPU of node 'pve1' might be incompatible: the node does not report CPU flags that"
+ . " tell the guest which CPU vulnerabilities do not affect it, for example as it"
+ . " runs another kernel version, so the guest might not mitigate them: srso-no",
+ ],
+ ),
+ cpu_migration_test(
+ # tsx-ctrl allows the guest to access an MSR
+ name => '1033_running_host_cpu_missing_tsx_ctrl',
+ cpu => 'host',
+ runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+ cpu_info => {
+ 'kvm-flags' => { pve0 => 'fpu its-no sse tsx-ctrl', pve1 => 'fpu sse' },
+ },
+ 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: tsx-ctrl - use"
+ . " 'allow-missing-cpu-flags' to override",
+ ),
+ cpu_migration_test(
+ # for example, the entry got lost as pmxcfs was restarted
+ name => '1033_running_host_cpu_source_without_kvm_flags',
+ cpu => 'host',
+ runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+ cpu_info => {
+ 'kvm-flags' => { pve0 => undef, pve1 => 'fpu' },
+ },
+ expect_log => [
+ "CPU of node 'pve1' might be incompatible: the source node does not provide the"
+ . " CPU information needed to check it",
+ ],
+ ),
+ cpu_migration_test(
+ # the guest cannot use flags disabled for the VM
+ name => '1033_running_host_cpu_missing_flags_disabled',
+ cpu => 'host',
+ runningcpu => 'host,-avx512f,sse4.2=false,+kvm_pv_eoi,+kvm_pv_unhalt',
+ cpu_info => {
+ 'kvm-flags' => { pve0 => 'avx512f fpu hv-relaxed sse sse4.2' },
+ },
+ ),
+ cpu_migration_test(
+ # nodes that did not query their flags since an upgrade still broadcast aliases
+ name => '1033_running_host_cpu_missing_flag_alias',
+ cpu => 'host',
+ runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+ cpu_info => {
+ 'kvm-flags' => { pve0 => 'fpu sse sse4_2' },
+ },
+ 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: sse4.2 - use"
+ . " 'allow-missing-cpu-flags' to override",
+ ),
{
name => '105_replicated_to_non_replication_target',
target => 'pve1',
--
2.47.3
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH qemu-server v4 12/21] migrate: warn about live migration of host CPU VMs between CPU models
2026-12-02 15:17 [PATCH docs/manager/qemu-server v4 00/21] check the target node's CPU before live migrating a VM Jonas Theisen
` (10 preceding siblings ...)
2026-12-02 15:18 ` [PATCH qemu-server v4 11/21] fix #2924: migrate: block live migration of host CPU VMs to nodes lacking flags Jonas Theisen
@ 2026-12-02 15:18 ` Jonas Theisen
2026-12-02 15:18 ` [PATCH qemu-server v4 13/21] migrate: block live migration if the target cannot run the virtual CPU Jonas Theisen
` (8 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Jonas Theisen @ 2026-12-02 15:18 UTC (permalink / raw)
To: pve-devel
Even if the target CPU supports all flags of the source CPU, a guest
with the 'host' or 'max' CPU model can run into problems after a live
migration between 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 source and target, with both model names as
details in the precondition API.
Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
src/PVE/API2/Qemu.pm | 1 +
src/PVE/QemuMigrate/Helpers.pm | 37 ++++++++++++++++++++++++++++++
src/PVE/QemuServer/Helpers.pm | 3 +++
src/test/run_api_tests.pl | 20 ++++++++++++----
src/test/run_qemu_migrate_tests.pl | 33 ++++++++++++++++++++++++--
5 files changed, 88 insertions(+), 6 deletions(-)
diff --git a/src/PVE/API2/Qemu.pm b/src/PVE/API2/Qemu.pm
index 5227a0cc..c78aa374 100644
--- a/src/PVE/API2/Qemu.pm
+++ b/src/PVE/API2/Qemu.pm
@@ -5736,6 +5736,7 @@ __PACKAGE__->register_method({
'cpu-vendor',
'missing-cpu-info',
'host-cpu-flags',
+ 'host-cpu-model',
'cpu-check-failed',
],
},
diff --git a/src/PVE/QemuMigrate/Helpers.pm b/src/PVE/QemuMigrate/Helpers.pm
index c346128c..1e675721 100644
--- a/src/PVE/QemuMigrate/Helpers.pm
+++ b/src/PVE/QemuMigrate/Helpers.pm
@@ -204,6 +204,16 @@ my $cpu_issue_details = {
description => "The CPU flags the message refers to, as it might only list some.",
items => { type => 'string' },
},
+ 'source-model-name' => {
+ type => 'string',
+ optional => 1,
+ description => "The CPU model name of the source node.",
+ },
+ 'target-model-name' => {
+ type => 'string',
+ optional => 1,
+ description => "The CPU model name of the target node.",
+ },
};
my sub vendor_details {
@@ -379,6 +389,33 @@ my $target_cpu_checks = [
return ($message, { 'missing-flags' => $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 $source_model eq $target_model;
+
+ # same flags do not imply the same behavior, for example regarding errata
+ my $message =
+ "CPU model '$cpu->{model}' is only reliable for live migration between"
+ . " identical CPUs, but the node has '$target_model' instead of '$source_model'";
+ my $details =
+ { 'source-model-name' => $source_model, 'target-model-name' => $target_model };
+ return ($message, $details);
+ },
+ },
];
# Returns the issues of the target node. If it lacks CPU information needed by a check that can
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_api_tests.pl b/src/test/run_api_tests.pl
index 00c5bbdf..bc8686e1 100755
--- a/src/test/run_api_tests.pl
+++ b/src/test/run_api_tests.pl
@@ -341,14 +341,18 @@ subtest 'migration preconditions of the CPU of a running VM' => sub {
my ($info, $kvm_flags) = @_;
return { 'host-cpu-info' => encode_json($info), 'cpuflags-kvm' => $kvm_flags };
};
- my $source = { vendor => 'GenuineIntel' };
+ my $source = { vendor => 'GenuineIntel', 'model-name' => 'Intel Xeon Gold 6338' };
my $node_kv = {
localhost => $entries->($source, 'avx512f fpu sse'),
- 'other-vendor' =>
- $entries->({ $source->%*, vendor => 'AuthenticAMD' }, 'avx512f fpu sse'),
+ 'other-vendor' => $entries->(
+ { $source->%*, vendor => 'AuthenticAMD', 'model-name' => 'AMD EPYC 7302' },
+ 'avx512f fpu sse',
+ ),
'missing-flag' => $entries->($source, 'fpu sse'),
+ 'other-model' =>
+ $entries->({ $source->%*, 'model-name' => 'Intel Core i9-14900K' }, 'avx512f fpu sse'),
};
- my $nodes = ['localhost', 'other-vendor', 'no-cpu-info', 'missing-flag'];
+ my $nodes = ['localhost', 'other-vendor', 'no-cpu-info', 'missing-flag', 'other-model'];
my $inotify_module = Test::MockModule->new('PVE::INotify');
$inotify_module->mock(nodename => sub { return 'localhost'; });
@@ -406,8 +410,10 @@ subtest 'migration preconditions of the CPU of a running VM' => sub {
is_deeply(
$cpu_reasons->('host,+kvm_pv_eoi,+kvm_pv_unhalt'),
{
+ # the other CPU model is no further reason
'other-vendor' => ['cpu-vendor'],
'missing-flag' => ['host-cpu-flags (allow-missing-cpu-flags)'],
+ 'other-model' => ['warning: host-cpu-model'],
'no-cpu-info' => ['warning: missing-cpu-info'],
},
"reasons for 'host'",
@@ -444,6 +450,12 @@ subtest 'migration preconditions of the CPU of a running VM' => sub {
['avx512f'],
'reasons include all missing flags',
);
+ my $model_warning = $res->{'cpu-warnings'}->{'other-model'}->[0];
+ is_deeply(
+ [$model_warning->@{qw(source-model-name target-model-name)}],
+ ['Intel Xeon Gold 6338', 'Intel Core i9-14900K'],
+ 'warnings include the model names as details',
+ );
$running_cpu = 'kvm64,enforce,+kvm_pv_eoi,+kvm_pv_unhalt';
$res = PVE::API2::Qemu->migrate_vm_precondition({ node => 'localhost', vmid => 100 });
diff --git a/src/test/run_qemu_migrate_tests.pl b/src/test/run_qemu_migrate_tests.pl
index b76bef88..1e17090e 100755
--- a/src/test/run_qemu_migrate_tests.pl
+++ b/src/test/run_qemu_migrate_tests.pl
@@ -543,9 +543,15 @@ sub merge_hash {
# CPU information of the source node 'pve0' and the target node 'pve1' in the CPU migration tests,
# with nothing preventing the migration. The tests override what they check.
my $default_cpu_info = {
- source => { vendor => 'GenuineIntel' },
+ source => {
+ vendor => 'GenuineIntel',
+ 'model-name' => 'Intel(R) Xeon(R) Gold 6338 CPU @ 2.00GHz',
+ },
nodes => {
- pve1 => { vendor => 'GenuineIntel' },
+ pve1 => {
+ vendor => 'GenuineIntel',
+ 'model-name' => 'Intel(R) Xeon(R) Gold 6338 CPU @ 2.00GHz',
+ },
},
'kvm-flags' => {
pve0 => 'fpu sse',
@@ -1776,6 +1782,29 @@ my $tests = [
. " through the flags of the host CPU, but the node lacks: sse4.2 - use"
. " 'allow-missing-cpu-flags' to override",
),
+ cpu_migration_test(
+ # only missing information needed for checks that can prevent the migration is reported
+ name => '1033_running_host_cpu_target_without_model_name',
+ cpu => 'host',
+ runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+ cpu_info => {
+ nodes => { pve1 => { 'model-name' => undef } },
+ },
+ ),
+ cpu_migration_test(
+ name => '1033_running_host_cpu_other_model',
+ cpu => 'host',
+ runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+ cpu_info => {
+ nodes => { pve1 => { 'model-name' => 'Intel(R) Xeon(R) Gold 6342 CPU @ 2.80GHz' } },
+ },
+ 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 'Intel(R) Xeon(R)"
+ . " Gold 6342 CPU @ 2.80GHz' instead of 'Intel(R) Xeon(R) Gold 6338 CPU @"
+ . " 2.00GHz'",
+ ],
+ ),
{
name => '105_replicated_to_non_replication_target',
target => 'pve1',
--
2.47.3
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH qemu-server v4 13/21] migrate: block live migration if the target cannot run the virtual CPU
2026-12-02 15:17 [PATCH docs/manager/qemu-server v4 00/21] check the target node's CPU before live migrating a VM Jonas Theisen
` (11 preceding siblings ...)
2026-12-02 15:18 ` [PATCH qemu-server v4 12/21] migrate: warn about live migration of host CPU VMs between CPU models Jonas Theisen
@ 2026-12-02 15:18 ` Jonas Theisen
2026-12-02 15:18 ` [PATCH qemu-server v4 14/21] api: migrate: check the CPU of the target before requesting HA migration Jonas Theisen
` (7 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Jonas Theisen @ 2026-12-02 15:18 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. It can contain flags that KVM on the
target does not support, like the Intel-only 'hv-evmcs' enlightenment
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 CPU models that do not pass through the host
CPU, like 'x86-64-v3' or 'Skylake-Server'. Their QEMU CPU is generated
again, mostly 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 its defaults. Hyper-V enlightenments are required
regardless of 'enforce', so this also applies to those PVE enables for
Windows guests with 'host' and 'max'.
Check upfront whether KVM on the target supports all enabled Hyper-V
enlightenments of the virtual CPU, and all its other enabled flags if
'enforce' is set. This is not needed with TCG, which emulates all
flags. The default flags of a CPU model are queried from QEMU of the
running VM, the flags of the target from the pvestatd broadcast. The
precondition API reports all missing flags as details. Skipped are:
- the automatically enabled 'hv-evmcs' on non-Intel targets, as a
regenerated CPU only enables it on Intel, unless set for the VM
- flags KVM on the source does not support, and other flags than
enlightenments that QEMU does not recognize as flags, as they are
QEMU CPU properties, like 'host-phys-bits'; enlightenments only if
the source broadcasts any, as nodes broadcast none if their flags
were detected before qemu-server 9.1.17
If the target broadcasts no enlightenments, its support is unknown, so
missing ones only cause a warning.
As PVE sets 'enforce' for 'max' with KVM as well, flags set for such
VMs are reported by this check, and no longer by the overridable check
of the flags passed through by 'host' and 'max', as QEMU on the target
would refuse to start anyway.
Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
src/PVE/API2/Qemu.pm | 4 +-
src/PVE/QemuMigrate/Helpers.pm | 130 ++++++++++++-
src/test/MigrationTest/QemuMigrateMock.pm | 15 +-
src/test/run_api_tests.pl | 4 +
src/test/run_qemu_migrate_tests.pl | 217 +++++++++++++++++++++-
5 files changed, 359 insertions(+), 11 deletions(-)
diff --git a/src/PVE/API2/Qemu.pm b/src/PVE/API2/Qemu.pm
index c78aa374..68f85afd 100644
--- a/src/PVE/API2/Qemu.pm
+++ b/src/PVE/API2/Qemu.pm
@@ -5626,7 +5626,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',
@@ -5737,6 +5738,7 @@ __PACKAGE__->register_method({
'missing-cpu-info',
'host-cpu-flags',
'host-cpu-model',
+ 'vm-cpu-flags',
'cpu-check-failed',
],
},
diff --git a/src/PVE/QemuMigrate/Helpers.pm b/src/PVE/QemuMigrate/Helpers.pm
index 1e675721..20534b71 100644
--- a/src/PVE/QemuMigrate/Helpers.pm
+++ b/src/PVE/QemuMigrate/Helpers.pm
@@ -275,8 +275,11 @@ my sub get_missing_host_cpu_flags {
my @flags = grep { !$understood || $understood->{$_} } keys $source_flags->%*;
my @missing = sort grep {
- # Hyper-V enlightenments are not passed through, but set explicitly
+ # Hyper-V enlightenments are not passed through, but set explicitly. Flags that QEMU
+ # requires due to 'enforce' are reported by the 'vm-cpu-flags' check, as overriding it
+ # would only let QEMU on the target refuse to start.
!m/^hv-/
+ && !($cpu->{enforce} && $cpu->{flags}->{$_})
&& !$target_flags->{$_}
&& (PVE::JSONSchema::parse_boolean($cpu->{props}->{$_} // 'on') // 1)
} @flags;
@@ -286,6 +289,50 @@ my sub get_missing_host_cpu_flags {
return ($other, $info);
}
+# Returns the flags of the VM's virtual CPU that KVM on the target node does not support, and those
+# whose support is unknown, as the node does not report them.
+my sub get_missing_vm_cpu_flags {
+ my ($cpu, $source, $target) = @_;
+
+ my ($source_flags, $target_flags) = ($source->{'kvm-flags'}, $target->{'kvm-flags'});
+
+ # Flags detected before qemu-server 9.1.17 do not include Hyper-V enlightenments.
+ my ($source_reports_hv, $target_reports_hv) =
+ map {
+ scalar(grep { m/^hv-/ } keys $_->%*)
+ } $source_flags, $target_flags;
+
+ # The automatic hv-evmcs of a CPU that is generated again is only enabled on Intel targets.
+ my $target_omits_evmcs = $cpu->{'automatic-evmcs'}
+ && (!defined($target->{vendor})
+ || !PVE::QemuServer::CPUConfig::is_hyperv_evmcs_vendor($target->{vendor}));
+
+ my $understood = $source->{'understood-flags'};
+
+ my ($missing, $unknown) = ([], []);
+ for my $flag (sort keys $cpu->{flags}->%*) {
+ next if $target_flags->{$flag};
+ if ($flag =~ m/^hv-/) {
+ # QEMU refuses to start with unsupported Hyper-V enlightenments, regardless of
+ # 'enforce' and whether the CPU model passes through the host CPU
+ next if $flag eq 'hv-evmcs' && $target_omits_evmcs;
+ # skips properties that are no enlightenments, as far as the source reports them
+ next if $source_reports_hv && !$source_flags->{$flag};
+ push(($target_reports_hv ? $missing : $unknown)->@*, $flag);
+ } elsif (
+ $cpu->{enforce}
+ && $source_flags->{$flag}
+ && (!$understood || $understood->{$flag})
+ ) {
+ # Other flags only with 'enforce'. Like for the CPU model's flags, this skips
+ # properties that are no CPU flags, such as 'host-phys-bits'.
+ push $missing->@*, $flag;
+ }
+ }
+
+ return ($missing, $unknown);
+}
+
# Checks whether the CPU of a target node can run a running VM after a live migration. Each check
# has:
# - 'type', identifying the check
@@ -300,6 +347,11 @@ my sub get_missing_host_cpu_flags {
#
# The VM's CPU is parsed by parse_qemu_cpu_string(), with:
# - 'kvm' set if the VM uses KVM
+# - 'enforce' set if QEMU refuses to start without all enabled flags
+# - 'automatic-evmcs' set if hv-evmcs is enabled automatically and the CPU is generated again on
+# the target, which then enables it depending on its CPU vendor
+# - the enabled flags as 'flags' hash, including the flags the CPU model enables by default if
+# 'enforce' is set
#
# The CPU information of the nodes is in the format of get_host_cpu_info(), plus:
# - the CPU flags KVM supports as 'kvm-flags' hash
@@ -416,6 +468,47 @@ my $target_cpu_checks = [
return ($message, $details);
},
},
+ {
+ type => 'vm-cpu-flags',
+ severity => 'error',
+ needs => ['kvm-flags'],
+ applies => sub {
+ my ($cpu) = @_;
+ # With TCG, all flags are emulated.
+ return $cpu->{kvm};
+ },
+ check => sub {
+ my ($cpu, $source, $target) = @_;
+
+ my ($missing) = get_missing_vm_cpu_flags($cpu, $source, $target);
+ return if !scalar($missing->@*);
+
+ my $message = "KVM on the node does not support flags of the VM's virtual CPU: "
+ . format_flag_list($missing);
+ return ($message, { 'missing-flags' => $missing });
+ },
+ },
+ {
+ type => 'vm-cpu-flags',
+ severity => 'warning',
+ needs => ['kvm-flags'],
+ applies => sub {
+ my ($cpu) = @_;
+ return $cpu->{kvm};
+ },
+ check => sub {
+ my ($cpu, $source, $target) = @_;
+
+ my (undef, $unknown) = get_missing_vm_cpu_flags($cpu, $source, $target);
+ return if !scalar($unknown->@*);
+
+ my $message =
+ "KVM on the node might not support flags of the VM's virtual CPU, as the node"
+ . " does not report them, for example as they were detected by an older version: "
+ . format_flag_list($unknown);
+ return ($message, { 'missing-flags' => $unknown });
+ },
+ },
];
# Returns the issues of the target node. If it lacks CPU information needed by a check that can
@@ -462,6 +555,18 @@ my sub get_target_cpu_issues {
return $issues;
}
+# 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 });
+
+ # the expansion also includes CPU properties that are no flags
+ return [grep { !$understood || $understood->{$_} }
+ PVE::QemuServer::CPUFlags::get_cpu_expansion_flags($expansion)];
+}
+
=head3 is_running_cpu_kept
my $kept = is_running_cpu_kept($conf);
@@ -509,6 +614,27 @@ sub check_target_cpu_compatibility {
my $cpu = parse_qemu_cpu_string(PVE::QemuServer::CPUConfig::get_cpu_from_running_vm($pid));
my $arch = PVE::QemuServer::Helpers::get_vm_arch($conf);
$cpu->{kvm} = $conf->{kvm} // PVE::QemuServer::CPUConfig::is_native_arch($arch);
+ $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});
+ }
+
+ if ($cpu->{flags}->{'hv-evmcs'} && !is_running_cpu_kept($conf)) {
+ my $cpu_conf = $conf->{cpu} ? parse_property_string('pve-vm-cpu-conf', $conf->{cpu}) : {};
+ my $vm_flags = $cpu_conf->{flags} // '';
+ $cpu->{'automatic-evmcs'} = 1 if !grep { $_ eq '+hv-evmcs' } split(/;/, $vm_flags);
+ }
my $checks = [grep { $_->{applies}->($cpu) } $target_cpu_checks->@*];
return {} if !scalar($checks->@*);
@@ -519,7 +645,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 = {};
for my $node ($nodes->@*) {
diff --git a/src/test/MigrationTest/QemuMigrateMock.pm b/src/test/MigrationTest/QemuMigrateMock.pm
index b6e035b8..6554c37e 100644
--- a/src/test/MigrationTest/QemuMigrateMock.pm
+++ b/src/test/MigrationTest/QemuMigrateMock.pm
@@ -239,6 +239,15 @@ $MigrationTest::Shared::qemu_migrate_helpers_module->mock(
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(
@@ -262,8 +271,10 @@ $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 gds-no hv-relaxed its-no lahf-lm srso-no sse sse4.2 tsa-l1-no tsx-ctrl)];
+ return [qw(
+ abm aes avx avx2 avx512f avx512vl fpu gds-no hv-relaxed its-no kvm-pv-eoi lahf-lm pcid
+ srso-no sse sse4.2 svm tsa-l1-no tsx-ctrl vmx
+ )];
},
);
diff --git a/src/test/run_api_tests.pl b/src/test/run_api_tests.pl
index bc8686e1..195e889c 100755
--- a/src/test/run_api_tests.pl
+++ b/src/test/run_api_tests.pl
@@ -363,6 +363,8 @@ subtest 'migration preconditions of the CPU of a running VM' => sub {
check_local_resources => sub {
return ([], {}, { map { $_ => [] } $nodes->@* });
},
+ # the expansion of the CPU model, which enables no flags by default
+ mon_cmd => sub { return { model => { props => {} } }; },
);
my $cpu_flags_module = Test::MockModule->new('PVE::QemuServer::CPUFlags');
$cpu_flags_module->mock(
@@ -422,6 +424,8 @@ subtest 'migration preconditions of the CPU of a running VM' => sub {
$cpu_reasons->('kvm64,enforce,+avx512f,+kvm_pv_eoi,+kvm_pv_unhalt'),
{
'other-vendor' => ['warning: cpu-vendor'],
+ 'missing-flag' => ['vm-cpu-flags'],
+ 'no-cpu-info' => ['warning: missing-cpu-info'],
},
'reasons for another CPU model',
);
diff --git a/src/test/run_qemu_migrate_tests.pl b/src/test/run_qemu_migrate_tests.pl
index 1e17090e..2b9f812a 100755
--- a/src/test/run_qemu_migrate_tests.pl
+++ b/src/test/run_qemu_migrate_tests.pl
@@ -564,18 +564,19 @@ my $lacks_avx512f =
# Returns a test of the CPU checks for a live migration of VM 1033 to 'pve1'. The VM is configured
# with the CPU 'cpu' and further settings in 'config', and runs with the QEMU CPU 'runningcpu'.
-# 'cpu_info' overrides $default_cpu_info. Without 'expect_die', the migration must succeed.
-# Warnings and errors about the CPU must be expected. Other keys are passed through.
+# 'cpu_info' overrides $default_cpu_info. Without 'expect_die', the migration must succeed, and the
+# target keeps the QEMU CPU if 'cpu_kept' is set. Warnings and errors about the CPU must be
+# expected. Other keys are passed through.
sub cpu_migration_test {
my (%test) = @_;
- my $runningcpu = delete $test{runningcpu};
+ my ($runningcpu, $cpu_kept) = delete @test{qw(runningcpu cpu_kept)};
my $config_patch = { (delete($test{config}) // {})->%* };
my $cpu = delete $test{cpu};
$config_patch->{cpu} = $cpu if defined($cpu);
my $expected_status = { running => 1, runningmachine => 'pc-q35-5.0+pve0' };
- $expected_status->{runningcpu} = $runningcpu if $test{expect_die};
+ $expected_status->{runningcpu} = $runningcpu if $test{expect_die} || $cpu_kept;
return {
target => 'pve1',
@@ -608,8 +609,9 @@ 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', and the KVM CPU flags of each node in
- # 'kvm-flags'. With 'check-error', the CPU check fails with it.
+ # other node in 'nodes', the KVM CPU flags of each node in
+ # 'kvm-flags', and the flags each CPU model enables by default in
+ # 'model-flags'. With 'check-error', the CPU check fails with it.
# See cpu_migration_test() for tests of the CPU checks.
# expected_calls - hash whose keys are calls which are required
# to be made if the migration gets far enough
@@ -1805,6 +1807,209 @@ my $tests = [
. " 2.00GHz'",
],
),
+ cpu_migration_test(
+ name => '1033_running_kept_cpu_supported_flags',
+ cpu => 'kvm64,flags=+nested-virt',
+ runningcpu => 'kvm64,enforce,+vmx,hv_evmcs,hv_relaxed,hv_spinlocks=0x1fff,+kvm_pv_eoi',
+ cpu_kept => 1,
+ cpu_info => {
+ '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',
+ },
+ },
+ ),
+ cpu_migration_test(
+ name => '1033_running_kept_cpu_unsupported_flags',
+ cpu => 'kvm64,flags=+nested-virt',
+ runningcpu => 'kvm64,enforce,+vmx,hv_evmcs,hv_relaxed,hv_spinlocks=0x1fff,+kvm_pv_eoi',
+ cpu_info => {
+ 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',
+ },
+ },
+ 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",
+ ),
+ cpu_migration_test(
+ # hv-evmcs is only enabled on Intel hosts, so the target generates the CPU without it
+ name => '1033_running_builtin_cpu_hv_evmcs_other_vendor',
+ cpu => 'x86-64-v2-AES',
+ config => { ostype => 'win11' },
+ runningcpu => 'qemu64,+aes,enforce,hv_evmcs,hv_relaxed,+kvm_pv_eoi,+sse4.2',
+ cpu_info => {
+ nodes => { pve1 => { vendor => 'AuthenticAMD' } },
+ 'kvm-flags' => {
+ pve0 => 'aes fpu hv-evmcs hv-relaxed kvm-pv-eoi sse sse4.2 vmx',
+ pve1 => 'aes fpu hv-relaxed kvm-pv-eoi sse sse4.2 svm',
+ },
+ },
+ expect_log => [
+ "CPU of node 'pve1' might be incompatible: live migration from GenuineIntel to"
+ . " AuthenticAMD is not guaranteed to work",
+ ],
+ ),
+ cpu_migration_test(
+ # 'max' with KVM also sets 'enforce', so QEMU requires flags set for the VM regardless of
+ # the override for 'host-cpu-flags'
+ name => '1033_running_max_cpu_missing_vm_flag',
+ cpu => 'max,flags=+pcid',
+ runningcpu => 'max,enforce,+kvm_pv_eoi,+kvm_pv_unhalt,+pcid',
+ opts => { 'allow-missing-cpu-flags' => 1 },
+ cpu_info => {
+ 'kvm-flags' => { pve0 => 'fpu pcid sse', pve1 => 'fpu sse' },
+ },
+ expect_die => "can't migrate VM to 'pve1' - incompatible CPU: KVM on the node does not"
+ . " support flags of the VM's virtual CPU: pcid",
+ ),
+ cpu_migration_test(
+ # an Intel target enables hv-evmcs as well when generating the CPU
+ name => '1033_running_builtin_cpu_hv_evmcs_unsupported',
+ cpu => 'x86-64-v2-AES',
+ config => { ostype => 'win11' },
+ runningcpu => 'qemu64,+aes,enforce,hv_evmcs,hv_relaxed,+kvm_pv_eoi,+sse4.2',
+ cpu_info => {
+ 'kvm-flags' => {
+ pve0 => 'aes fpu hv-evmcs hv-relaxed kvm-pv-eoi sse sse4.2 vmx',
+ pve1 => 'aes fpu hv-relaxed kvm-pv-eoi sse sse4.2 vmx',
+ },
+ },
+ 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",
+ ),
+ cpu_migration_test(
+ # hv-evmcs set for the VM is also enabled on other targets
+ name => '1033_running_builtin_cpu_vm_hv_evmcs_other_vendor',
+ cpu => 'x86-64-v2-AES,flags=+hv-evmcs',
+ config => { ostype => 'win11' },
+ runningcpu => 'qemu64,+aes,enforce,+hv-evmcs,hv_evmcs,hv_relaxed,+kvm_pv_eoi,+sse4.2',
+ cpu_info => {
+ nodes => { pve1 => { vendor => 'AuthenticAMD' } },
+ 'kvm-flags' => {
+ pve0 => 'aes fpu hv-evmcs hv-relaxed kvm-pv-eoi sse sse4.2 vmx',
+ pve1 => 'aes fpu hv-relaxed kvm-pv-eoi sse sse4.2 svm',
+ },
+ },
+ 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",
+ ),
+ cpu_migration_test(
+ # QEMU applies flags with '-' last, so the VM does not use hv-evmcs
+ name => '1033_running_kept_cpu_hv_evmcs_disabled',
+ cpu => 'x86-64-v2-AES,flags=+nested-virt;-hv-evmcs',
+ config => { ostype => 'win11' },
+ runningcpu =>
+ 'qemu64,+aes,enforce,-hv-evmcs,hv_evmcs,hv_relaxed,+kvm_pv_eoi,+sse4.2,+vmx',
+ cpu_kept => 1,
+ cpu_info => {
+ 'kvm-flags' => {
+ pve0 => 'aes fpu hv-evmcs hv-relaxed kvm-pv-eoi sse sse4.2 vmx',
+ pve1 => 'aes fpu hv-relaxed kvm-pv-eoi sse sse4.2 vmx',
+ },
+ },
+ ),
+ cpu_migration_test(
+ # KVM requires the enlightenments, even though 'host' does not set 'enforce'
+ name => '1033_running_host_cpu_missing_hv_flags',
+ cpu => 'host',
+ config => { ostype => 'win11' },
+ runningcpu => 'host,hv_relaxed,hv_stimer,hv_synic,+kvm_pv_eoi,+kvm_pv_unhalt',
+ cpu_info => {
+ 'kvm-flags' => {
+ pve0 => 'fpu hv-relaxed hv-stimer hv-synic sse',
+ pve1 => 'fpu hv-relaxed hv-synic sse',
+ },
+ },
+ 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-stimer",
+ ),
+ cpu_migration_test(
+ # flags detected before qemu-server 9.1.17 include no Hyper-V enlightenments
+ name => '1033_running_host_cpu_hv_flags_target_without_hv_info',
+ cpu => 'host',
+ config => { ostype => 'win11' },
+ runningcpu => 'host,hv_relaxed,hv_stimer,hv_synic,+kvm_pv_eoi,+kvm_pv_unhalt',
+ cpu_info => {
+ 'kvm-flags' => {
+ pve0 => 'fpu hv-relaxed hv-stimer hv-synic sse',
+ pve1 => 'fpu sse',
+ },
+ },
+ expect_log => [
+ "CPU of node 'pve1' might be incompatible: KVM on the node might not support flags"
+ . " of the VM's virtual CPU, as the node does not report them, for example as they"
+ . " were detected by an older version: hv-relaxed, hv-stimer, hv-synic",
+ ],
+ ),
+ cpu_migration_test(
+ # with TCG, all flags are emulated
+ name => '1033_running_kept_cpu_tcg_target_without_kvm_flags',
+ cpu => 'custom-mycpu',
+ config => { kvm => 0 },
+ runningcpu => 'kvm64,enforce,+sse4.2',
+ cpu_kept => 1,
+ cpu_info => {
+ 'kvm-flags' => { pve1 => undef },
+ },
+ ),
+ cpu_migration_test(
+ name => '1033_running_builtin_cpu_missing_flags',
+ cpu => 'x86-64-v3',
+ 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',
+ },
+ },
+ 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",
+ ),
+ cpu_migration_test(
+ # QEMU CPU properties that are no flags do not depend on KVM
+ name => '1033_running_builtin_cpu_property_not_flag',
+ cpu => 'x86-64-v3',
+ runningcpu => 'qemu64,enforce,+avx,host-phys-bits=on,+kvm_pv_eoi,vendor=GenuineIntel',
+ cpu_info => {
+ 'kvm-flags' => {
+ pve0 => 'avx fpu host-phys-bits kvm-pv-eoi sse',
+ pve1 => 'avx fpu kvm-pv-eoi sse',
+ },
+ },
+ ),
+ cpu_migration_test(
+ name => '1033_running_named_cpu_missing_model_flags',
+ cpu => 'Skylake-Server',
+ 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)],
+ },
+ },
+ 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",
+ ),
+ cpu_migration_test(
+ name => '1033_running_named_cpu_supported_model_flags',
+ cpu => 'Skylake-Server',
+ 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)],
+ },
+ },
+ ),
{
name => '105_replicated_to_non_replication_target',
target => 'pve1',
--
2.47.3
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH qemu-server v4 14/21] api: migrate: check the CPU of the target before requesting HA migration
2026-12-02 15:17 [PATCH docs/manager/qemu-server v4 00/21] check the target node's CPU before live migrating a VM Jonas Theisen
` (12 preceding siblings ...)
2026-12-02 15:18 ` [PATCH qemu-server v4 13/21] migrate: block live migration if the target cannot run the virtual CPU Jonas Theisen
@ 2026-12-02 15:18 ` Jonas Theisen
2026-12-02 15:18 ` [PATCH manager v4 15/21] pvestatd: broadcast the supported CPU flags again if they got lost Jonas Theisen
` (6 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Jonas Theisen @ 2026-12-02 15:18 UTC (permalink / raw)
To: pve-devel
For HA-managed VMs, the migrate API only requests the migration from
the HA stack, which runs it in a separate task on the LRM. If the
target CPU cannot run the VM, only that task fails, and the caller
only learns about it from its task log or the HA status.
Run the CPU compatibility check before requesting the HA migration, as
done for the storage checks, so that the API call fails with the
reason directly. Overrides like 'allow-missing-cpu-flags' are only
honored, and suggested by the error, if they are forwarded to the HA
stack. Warnings are left to the LRM's migration task.
Only the requested VM is checked, VMs in positive affinity are only
checked by their own migration task. Migrations the HA stack starts on
its own, for example for maintenance mode or rebalancing, still fail
only in the migration task, which the HA stack currently retries
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 | 11 ++-
src/PVE/QemuMigrate/Helpers.pm | 7 +-
src/test/run_api_tests.pl | 118 ++++++++++++++++++++++++++++++++-
3 files changed, 131 insertions(+), 5 deletions(-)
diff --git a/src/PVE/API2/Qemu.pm b/src/PVE/API2/Qemu.pm
index 68f85afd..326a1e44 100644
--- a/src/PVE/API2/Qemu.pm
+++ b/src/PVE/API2/Qemu.pm
@@ -5963,7 +5963,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();
@@ -6011,6 +6012,14 @@ __PACKAGE__->register_method({
if (PVE::HA::Config::vm_is_ha_managed($vmid) && $rpcenv->{type} ne 'ha') {
my $forwards_options = ha_forwards_migrate_options($localnode);
+ # 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. Options that
+ # override an incompatibility only count if they reach the HA stack.
+ my $check_opts = $forwards_options ? $param : undef;
+ PVE::QemuMigrate::Helpers::assert_target_cpu_compatibility(
+ $vmid, $conf, $pid, $target, $check_opts,
+ ) if $param->{online};
+
my $hacmd = sub {
my $upid = shift;
diff --git a/src/PVE/QemuMigrate/Helpers.pm b/src/PVE/QemuMigrate/Helpers.pm
index 20534b71..22ed96d7 100644
--- a/src/PVE/QemuMigrate/Helpers.pm
+++ b/src/PVE/QemuMigrate/Helpers.pm
@@ -665,7 +665,8 @@ sub check_target_cpu_compatibility {
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.
+C<$opts> override all the incompatibilities. If C<$opts> is undefined, as no option can override
+them, the error does not suggest any.
Returns an array reference with the warnings to log, about possible incompatibilities, including
missing CPU information of the node, and about overridden incompatibilities. If the check itself
@@ -690,7 +691,7 @@ sub assert_target_cpu_compatibility {
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}) {
+ } elsif (defined($override) && $opts && $opts->{$override}) {
push $warnings->@*,
"ignoring incompatible CPU of node '$node' due to '$override': $issue->{message}";
} else {
@@ -700,7 +701,7 @@ sub assert_target_cpu_compatibility {
if (scalar($errors->@*)) {
my $hint = '';
- if (!grep { !defined($_->{override}) } $errors->@*) {
+ if ($opts && !grep { !defined($_->{override}) } $errors->@*) {
my %overrides = map { $_->{override} => 1 } $errors->@*;
$hint = " - use " . join(' and ', map { "'$_'" } sort keys %overrides) . " to override";
}
diff --git a/src/test/run_api_tests.pl b/src/test/run_api_tests.pl
index 195e889c..36eddd33 100755
--- a/src/test/run_api_tests.pl
+++ b/src/test/run_api_tests.pl
@@ -533,8 +533,10 @@ subtest 'override for HA-managed VMs requires VM.Migrate on VMs in positive affi
vm_is_ha_managed => sub { return 1; },
get_resource_motion_info => sub { return (['ct:101', 'vm:102'], {}); },
);
- # nodes with this version forward the option to the HA stack
+ # nodes with this version forward the option, the CPU check before that is tested separately
$node_versions->{localhost} = '9.2.31';
+ my $migrate_helpers_module = Test::MockModule->new('PVE::QemuMigrate::Helpers');
+ $migrate_helpers_module->mock(assert_target_cpu_compatibility => sub { return []; });
my $migrate_error = sub {
my ($param) = @_;
@@ -573,6 +575,120 @@ subtest 'override for HA-managed VMs requires VM.Migrate on VMs in positive affi
mock_unreachable_config();
};
+subtest 'migration of an HA-managed VM checks the CPU before requesting it' => sub {
+ # the version of the local node decides whether migration options are forwarded to the HA stack
+ my $inotify_module = Test::MockModule->new('PVE::INotify');
+ $inotify_module->mock(nodename => sub { return 'localhost'; });
+ $node_versions->{localhost} = '9.2.31';
+ $cluster_module->mock(get_config => sub { return $raw_without_identity; });
+ $qemu_config_module->mock(
+ load_config => sub { return { memory => 512 }; },
+ check_lock => sub { return; },
+ );
+ $replication_config_module->mock(find_local_replication_job => sub { return; });
+ $qemu_server_module->mock(check_storage_availability => sub { return; });
+ my $rpcenv_module = Test::MockModule->new('PVE::RPCEnvironment');
+ $rpcenv_module->mock(fork_worker => sub { die "reached fork_worker\n"; });
+
+ my $ha_managed;
+ my $ha_config_module = Test::MockModule->new('PVE::HA::Config');
+ $ha_config_module->mock(vm_is_ha_managed => sub { return $ha_managed; });
+
+ # the arguments of the last CPU check, and its error
+ my ($checked, $cpu_error);
+ my $migrate_helpers_module = Test::MockModule->new('PVE::QemuMigrate::Helpers');
+ $migrate_helpers_module->mock(
+ assert_target_cpu_compatibility => sub {
+ my ($vmid, $conf, $pid, $node, $opts) = @_;
+ $checked =
+ { vmid => $vmid, pid => $pid, node => $node, opts => $opts && { $opts->%* } };
+ die $cpu_error if defined($cpu_error);
+ return [];
+ },
+ );
+
+ # stopped VMs are migrated offline, which is expected
+ local $SIG{__WARN__} = sub { warn $_[0] if $_[0] !~ m/^VM isn't running/ };
+
+ my $refused = "can't migrate VM to 'pve2' - incompatible CPU: some reason\n";
+ for my $running (1234, 0) {
+ $qemu_server_module->mock(check_running => sub { return $running; });
+ for my $managed (1, 0) {
+ $ha_managed = $managed;
+ my $what = ($running ? 'running' : 'stopped') . ($managed ? ', HA-managed' : '');
+ my $checks = $running && $managed;
+
+ ($checked, $cpu_error) = (undef, $refused);
+ is(
+ api_error(
+ 'migrate_vm',
+ { target => 'pve2', online => 1, 'allow-missing-cpu-flags' => 1 },
+ ),
+ $checks ? $refused : "reached fork_worker\n",
+ "VM $what: " . ($checks ? 'incompatible CPU refused' : 'CPU not checked'),
+ );
+ next if !$checks;
+
+ is_deeply(
+ [$checked->@{qw(vmid pid node)}, $checked->{opts}->{'allow-missing-cpu-flags'}],
+ [100, 1234, 'pve2', 1],
+ "VM $what: the running VM is checked with the migration options",
+ );
+
+ $cpu_error = undef;
+ is(
+ api_error('migrate_vm', { target => 'pve2', online => 1 }),
+ "reached fork_worker\n",
+ "VM $what: compatible CPU, HA migration requested",
+ );
+ }
+ }
+
+ $qemu_server_module->mock(check_running => sub { return 1234; });
+ ($ha_managed, $cpu_error, $node_versions->{localhost}) = (1, undef, '9.2.30');
+ api_error('migrate_vm', { target => 'pve2', online => 1, 'allow-missing-cpu-flags' => 1 });
+ is(
+ $checked->{opts}->{'allow-missing-cpu-flags'},
+ undef,
+ 'options the HA stack of an older node does not get do not override the check',
+ );
+
+ # the error only suggests options that reach the HA stack
+ $migrate_helpers_module->unmock('assert_target_cpu_compatibility');
+ $migrate_helpers_module->mock(
+ check_target_cpu_compatibility => sub {
+ my $issue = {
+ type => 'host-cpu-flags',
+ severity => 'error',
+ message => 'missing flags',
+ override => 'allow-missing-cpu-flags',
+ };
+ return { pve2 => [$issue] };
+ },
+ );
+ my $refusal = "can't migrate VM to 'pve2' - incompatible CPU: missing flags";
+ is(
+ api_error('migrate_vm', { target => 'pve2', online => 1 }),
+ "$refusal\n",
+ 'older node: no override suggested',
+ );
+ $node_versions->{localhost} = '9.2.31';
+ is(
+ api_error('migrate_vm', { target => 'pve2', online => 1 }),
+ "$refusal - use 'allow-missing-cpu-flags' to override\n",
+ 'override suggested if forwarded',
+ );
+
+ $node_versions->{localhost} = undef;
+
+ $qemu_server_module->mock(check_running => sub { return 0; });
+ $qemu_server_module->unmock('check_storage_availability');
+ $replication_config_module->unmock('find_local_replication_job');
+ $qemu_config_module->unmock('check_lock');
+ $cluster_module->unmock('get_config');
+ mock_unreachable_config();
+};
+
subtest 'clone target nodes' => sub {
my $inotify_module = Test::MockModule->new('PVE::INotify');
$inotify_module->mock(nodename => sub { return 'pve1'; });
--
2.47.3
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH manager v4 15/21] pvestatd: broadcast the supported CPU flags again if they got lost
2026-12-02 15:17 [PATCH docs/manager/qemu-server v4 00/21] check the target node's CPU before live migrating a VM Jonas Theisen
` (13 preceding siblings ...)
2026-12-02 15:18 ` [PATCH qemu-server v4 14/21] api: migrate: check the CPU of the target before requesting HA migration Jonas Theisen
@ 2026-12-02 15:18 ` Jonas Theisen
2026-12-02 15:18 ` [PATCH manager v4 16/21] pvestatd: broadcast host CPU information relevant for live migration Jonas Theisen
` (5 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Jonas Theisen @ 2026-12-02 15:18 UTC (permalink / raw)
To: pve-devel
pvestatd only detects and broadcasts the CPU flags that QEMU supports
when the QEMU version changes. If the node key-value entries get lost,
for example as pmxcfs was restarted, they stay missing until then, so
the CPU flag selector and the live migration checks for missing CPU
flags lack the information of this node.
Remember the broadcast values and broadcast them again if the entries
are missing.
Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
PVE/Service/pvestatd.pm | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/PVE/Service/pvestatd.pm b/PVE/Service/pvestatd.pm
index 2f6a2671..8c0f3c37 100755
--- a/PVE/Service/pvestatd.pm
+++ b/PVE/Service/pvestatd.pm
@@ -79,6 +79,7 @@ sub hup {
}
my $cached_kvm_version = '';
+my $cached_cpuflags = {};
my $next_flag_update_time;
my $failed_flag_update_delay_sec = 120;
@@ -93,7 +94,15 @@ sub update_supported_cpuflags {
# only update when QEMU/KVM version has changed, as that is the only reason
# why flags could change without restarting pvestatd
- return if $cached_kvm_version && $cached_kvm_version eq $kvm_version;
+ if ($cached_kvm_version && $cached_kvm_version eq $kvm_version) {
+ # re-broadcast entries that got lost, for example after a restart of pmxcfs
+ for my $accel (sort keys $cached_cpuflags->%*) {
+ my $old = PVE::Cluster::get_node_kv("cpuflags-$accel", $nodename)->{$nodename};
+ PVE::Cluster::broadcast_node_kv("cpuflags-$accel", $cached_cpuflags->{$accel})
+ if !defined($old);
+ }
+ return;
+ }
if ($next_flag_update_time && $next_flag_update_time > time()) {
return;
@@ -118,15 +127,10 @@ sub update_supported_cpuflags {
}
for my $accel ("tcg", "kvm") {
- if ($supported_cpuflags->{$accel}) {
- PVE::Cluster::broadcast_node_kv(
- "cpuflags-$accel",
- join(' ', @{ $supported_cpuflags->{$accel} }),
- );
- } else {
- # clear potentially invalid data
- PVE::Cluster::broadcast_node_kv("cpuflags-$accel", '');
- }
+ # an empty value clears potentially invalid data
+ my $flags = join(' ', ($supported_cpuflags->{$accel} // [])->@*);
+ PVE::Cluster::broadcast_node_kv("cpuflags-$accel", $flags);
+ $cached_cpuflags->{$accel} = $flags;
}
}
--
2.47.3
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH manager v4 16/21] pvestatd: broadcast host CPU information relevant for live migration
2026-12-02 15:17 [PATCH docs/manager/qemu-server v4 00/21] check the target node's CPU before live migrating a VM Jonas Theisen
` (14 preceding siblings ...)
2026-12-02 15:18 ` [PATCH manager v4 15/21] pvestatd: broadcast the supported CPU flags again if they got lost Jonas Theisen
@ 2026-12-02 15:18 ` Jonas Theisen
2026-12-02 15:18 ` [PATCH manager v4 17/21] ui: migrate: show why the CPU of the target node is incompatible Jonas Theisen
` (4 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Jonas Theisen @ 2026-12-02 15:18 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 has the same vendor and model
as the source for VMs with the 'host' CPU model.
Broadcast the information qemu-server provides for this, for example
the CPU vendor and model name. It is queried in each cycle, so that
information that could not be determined before is broadcast once it
can, and broadcast again if it changed or the entry got lost. This is
cheap, as the CPU information is cached.
Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
PVE/Service/pvestatd.pm | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/PVE/Service/pvestatd.pm b/PVE/Service/pvestatd.pm
index 8c0f3c37..a6ddf82b 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;
@@ -174,6 +175,18 @@ my sub broadcast_static_node_info {
}
}
+# Queried in each cycle, so that information that qemu-server could not determine before is
+# broadcast once it can.
+my sub broadcast_host_cpu_info {
+ my $host_cpu_info = PVE::QemuServer::Helpers::get_host_cpu_info();
+
+ my $info = JSON->new->canonical->utf8->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
@@ -299,6 +312,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] 22+ messages in thread* [PATCH manager v4 17/21] ui: migrate: show why the CPU of the target node is incompatible
2026-12-02 15:17 [PATCH docs/manager/qemu-server v4 00/21] check the target node's CPU before live migrating a VM Jonas Theisen
` (15 preceding siblings ...)
2026-12-02 15:18 ` [PATCH manager v4 16/21] pvestatd: broadcast host CPU information relevant for live migration Jonas Theisen
@ 2026-12-02 15:18 ` Jonas Theisen
2026-12-02 15:18 ` [PATCH manager v4 18/21] fix #6535: ui: migrate: show CPU warnings for the target node Jonas Theisen
` (3 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Jonas Theisen @ 2026-12-02 15:18 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 all reasons can be overridden with migration options, offer a
checkbox to ignore the incompatibility, which sets these options and
shows the reasons as warnings instead. The options are 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 options to the HA stack.
Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
www/manager6/window/Migrate.js | 51 ++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/www/manager6/window/Migrate.js b/www/manager6/window/Migrate.js
index 3dd2b9ee..d2c39af0 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;
}
@@ -358,6 +367,27 @@ Ext.define('PVE.window.Migrate', {
me.checkGuestIdentitySupport(migration, disallowed);
+ let cpuBlockers = disallowed['incompatible-cpu'] ?? [];
+ let canOverrideCpu =
+ 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'] ?? {};
@@ -751,6 +781,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] 22+ messages in thread* [PATCH manager v4 18/21] fix #6535: ui: migrate: show CPU warnings for the target node
2026-12-02 15:17 [PATCH docs/manager/qemu-server v4 00/21] check the target node's CPU before live migrating a VM Jonas Theisen
` (16 preceding siblings ...)
2026-12-02 15:18 ` [PATCH manager v4 17/21] ui: migrate: show why the CPU of the target node is incompatible Jonas Theisen
@ 2026-12-02 15:18 ` Jonas Theisen
2026-12-02 15:18 ` [PATCH manager v4 19/21] api: nodes: migrateall: skip VMs whose CPU is incompatible with the target Jonas Theisen
` (2 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Jonas Theisen @ 2026-12-02 15:18 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 d2c39af0..8d4a23e7 100644
--- a/www/manager6/window/Migrate.js
+++ b/www/manager6/window/Migrate.js
@@ -388,6 +388,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] 22+ messages in thread* [PATCH manager v4 19/21] api: nodes: migrateall: skip VMs whose CPU is incompatible with the target
2026-12-02 15:17 [PATCH docs/manager/qemu-server v4 00/21] check the target node's CPU before live migrating a VM Jonas Theisen
` (17 preceding siblings ...)
2026-12-02 15:18 ` [PATCH manager v4 18/21] fix #6535: ui: migrate: show CPU warnings for the target node Jonas Theisen
@ 2026-12-02 15:18 ` Jonas Theisen
2026-12-02 15:18 ` [PATCH manager v4 20/21] api: cluster: bulk migrate: " Jonas Theisen
2026-12-02 15:18 ` [PATCH docs v4 21/21] qm: document the CPU checks for live migration Jonas Theisen
20 siblings, 0 replies; 22+ messages in thread
From: Jonas Theisen @ 2026-12-02 15:18 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 and log the reason, as
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] 22+ messages in thread* [PATCH manager v4 20/21] api: cluster: bulk migrate: skip VMs whose CPU is incompatible with the target
2026-12-02 15:17 [PATCH docs/manager/qemu-server v4 00/21] check the target node's CPU before live migrating a VM Jonas Theisen
` (18 preceding siblings ...)
2026-12-02 15:18 ` [PATCH manager v4 19/21] api: nodes: migrateall: skip VMs whose CPU is incompatible with the target Jonas Theisen
@ 2026-12-02 15:18 ` Jonas Theisen
2026-12-02 15:18 ` [PATCH docs v4 21/21] qm: document the CPU checks for live migration Jonas Theisen
20 siblings, 0 replies; 22+ messages in thread
From: Jonas Theisen @ 2026-12-02 15:18 UTC (permalink / raw)
To: pve-devel
The source node refuses to live migrate a VM to a node whose CPU
cannot run it, but only in the migration task. Until then, it takes
one of the parallel workers of the bulk migration, and it is counted
as a failed migration without a reason in the bulk migration log.
Check the migration preconditions of each VM first, as the bulk
migration of a node already does, and skip VMs whose CPU is
incompatible with the target with a warning stating the reason, like
VMs that are already on the target. If the preconditions cannot be
queried, the VM is migrated as before.
Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
PVE/API2/Cluster/BulkAction/Guest.pm | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/PVE/API2/Cluster/BulkAction/Guest.pm b/PVE/API2/Cluster/BulkAction/Guest.pm
index 4b0c1760..b6f18547 100644
--- a/PVE/API2/Cluster/BulkAction/Guest.pm
+++ b/PVE/API2/Cluster/BulkAction/Guest.pm
@@ -807,6 +807,21 @@ __PACKAGE__->register_method({
$params->{online} = $param->{online} if defined($param->{online});
$params->{'with-local-disks'} = $param->{'with-local-disks'}
if defined($param->{'with-local-disks'});
+
+ # the migration would be refused anyway, but only after taking a worker slot
+ my $preconditions =
+ eval { make_get_request($api_client, "/nodes/$node/qemu/$vmid/migrate"); };
+ log_warn("unable to check whether VM $vmid can be migrated - $@") if $@;
+ my $not_allowed = ($preconditions // {})->{not_allowed_nodes} // {};
+ my $incompatible_cpu =
+ $not_allowed->{ $param->{target} }->{'incompatible-cpu'};
+ if ($incompatible_cpu) {
+ log_warn(
+ "skipping VM $vmid, the CPU of the target node is incompatible: "
+ . join('; ', map { $_->{message} } $incompatible_cpu->@*)
+ . "\n");
+ return 1;
+ }
}
my $url = "/nodes/$node/$type/$vmid/migrate";
--
2.47.3
^ permalink raw reply related [flat|nested] 22+ messages in thread* [PATCH docs v4 21/21] qm: document the CPU checks for live migration
2026-12-02 15:17 [PATCH docs/manager/qemu-server v4 00/21] check the target node's CPU before live migrating a VM Jonas Theisen
` (19 preceding siblings ...)
2026-12-02 15:18 ` [PATCH manager v4 20/21] api: cluster: bulk migrate: " Jonas Theisen
@ 2026-12-02 15:18 ` Jonas Theisen
20 siblings, 0 replies; 22+ messages in thread
From: Jonas Theisen @ 2026-12-02 15:18 UTC (permalink / raw)
To: pve-devel
Document which live migrations are refused because of the target
node's CPU, for all CPU types and including unsupported Hyper-V
enlightenments, how to override the CPU flag check for the 'host' and
'max' CPU types, the warnings about migrations between CPU vendors and
models, and how the checks apply to HA-managed VMs.
Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
qm.adoc | 46 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/qm.adoc b/qm.adoc
index cfa8587..3856b31 100644
--- a/qm.adoc
+++ b/qm.adoc
@@ -1867,6 +1867,52 @@ 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} checks the CPU of the target node before a live migration and refuses it
+if the VM cannot run there:
++
+--
+** VMs with the CPU type `host` or `max` require a CPU from the same vendor that
+ has all CPU flags of the source node's CPU.
+** VMs with other CPU types, for example `x86-64-v3` or a custom CPU type,
+ require a node that supports all CPU flags of the VM, including the defaults
+ of the CPU type.
+** All VMs require a node that supports their Hyper-V enlightenments, which
+ {pve} enables for Windows guests.
+--
++
+These checks only apply to VMs that use KVM hardware virtualization. The
+migration dialog and `qm migrate` show the reason, and bulk migrations skip
+such VMs.
++
+{pve} only shows a warning if:
++
+--
+** the nodes have CPUs from different vendors, for VMs with other CPU types.
+** the CPU models of the nodes differ, for VMs with the CPU type `host` or
+ `max`, as live migration with these is only reliable between identical CPUs.
+** the target node lacks CPU flags that only tell the guest which CPU
+ vulnerabilities do not affect it, for example `its-no` or `srso-no`. KVM
+ reports some of them only with newer kernels.
+** a node does not report the CPU information needed for a check, for example
+ as the target node runs an older {pve} version. If a node does not report
+ Hyper-V enlightenments, restart its `pvestatd` service to detect them again.
+** the checks themselves fail.
+--
++
+As the flags supported by KVM also depend on the kernel version, you can
+override the check of the CPU flags for `host` and `max` with the
+`--allow-missing-cpu-flags` option of `qm migrate`, or the 'Ignore CPU
+incompatibility' checkbox of the migration dialog. This does not apply to flags
+explicitly enabled for VMs with the CPU type `max`. The `--force` option does
+not override the checks.
++
+The checks also apply to HA-managed VMs. Migrations requested through the API or
+the web interface are refused right away. The override also applies to VMs that
+the HA stack migrates along due to a positive resource affinity rule, so it
+requires the 'VM.Migrate' privilege on these as well. Migrations that the HA
+stack starts on its own, for example for maintenance mode, do not use the
+override and fail.
Conntrack State Migration
^^^^^^^^^^^^^^^^^^^^^^^^^
--
2.47.3
^ permalink raw reply related [flat|nested] 22+ messages in thread