From: Jonas Theisen <j.theisen@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH qemu-server v3 08/18] migrate: block live migration of host CPU VMs between CPU vendors
Date: Mon, 30 Nov 2026 19:09:40 +0100 [thread overview]
Message-ID: <20261130181007.596064-9-j.theisen@proxmox.com> (raw)
In-Reply-To: <20261130181007.596064-1-j.theisen@proxmox.com>
The 'host' and 'max' CPU models pass the features of the host CPU
through to the guest, including vendor-specific ones. A guest that was
started on an AMD CPU is likely to crash after a live migration to an
Intel CPU, or vice versa, as the CPU it detected during boot changed
underneath it.
Check this before the migration, based on CPU information that each
node broadcasts to the cluster as the 'host-cpu-info' node key-value
entry, which pvestatd needs to do. Report such nodes as not allowed in
the migration precondition API, so they can be shown as such before
the migration is started, and refuse to migrate to them. Nodes that do
not broadcast the information, for example because they run an older
version, are not blocked, as it is unknown whether they are
compatible, but a warning is logged. It counts as a task warning, so
that the task status shows it. Warnings are only logged if the
migration is not refused anyway, as they do not matter then.
Also report such nodes with a warning in the migration precondition
API, as the task log only shows it once the migration is started.
Missing information is only reported for checks that can prevent the
migration, so that checks that only warn do not cause a warning for
every live migration to a node running an older version. It is not
reported either if this node lacks it as well, as for example the CPU
vendor on aarch64 hosts.
The checks are defined in a list, so that further combinations of VM
CPU settings and node CPUs that cannot work, or are known to be prone
to problems, can be added easily. They are only done for running VMs,
as stopped VMs are started with a virtual CPU based on the target
node, and operate on the QEMU CPU of the running instance, so they
also apply to settings from custom CPU models. With TCG, which VMs of
another architecture than the host's use by default, the 'max' model
is fully emulated and therefore not affected.
Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
src/PVE/API2/Qemu.pm | 65 +++++++-
src/PVE/QemuMigrate.pm | 9 +
src/PVE/QemuMigrate/Helpers.pm | 191 ++++++++++++++++++++++
src/PVE/QemuServer/Helpers.pm | 31 ++++
src/test/MigrationTest/QemuMigrateMock.pm | 33 ++++
src/test/run_api_tests.pl | 79 +++++++++
src/test/run_qemu_migrate_tests.pl | 122 ++++++++++++++
7 files changed, 529 insertions(+), 1 deletion(-)
diff --git a/src/PVE/API2/Qemu.pm b/src/PVE/API2/Qemu.pm
index 2119e69e..14057010 100644
--- a/src/PVE/API2/Qemu.pm
+++ b/src/PVE/API2/Qemu.pm
@@ -5599,6 +5599,27 @@ __PACKAGE__->register_method({
description => 'The config key of a mapped resource',
},
},
+ 'incompatible-cpu' => {
+ description =>
+ "Reasons why the node's CPU cannot run the running VM"
+ . " after a live migration.",
+ type => 'array',
+ optional => 1,
+ items => {
+ type => 'object',
+ properties => {
+ type => {
+ type => 'string',
+ description => "The check that failed.",
+ enum => ['cpu-vendor'],
+ },
+ message => {
+ type => 'string',
+ description => "Why the node's CPU is incompatible.",
+ },
+ },
+ },
+ },
'blocking-ha-resources' => {
description => "HA resources, which are blocking the"
. " VM from being migrated to the node.",
@@ -5676,6 +5697,29 @@ __PACKAGE__->register_method({
description =>
"Object of mapped resources with additional information such if they're live migratable.",
},
+ 'cpu-warnings' => {
+ type => 'object',
+ optional => 1,
+ description => "For each node, reasons why the VM might not run reliably on its"
+ . " CPU after a live migration.",
+ additionalProperties => {
+ type => 'array',
+ items => {
+ type => 'object',
+ properties => {
+ type => {
+ type => 'string',
+ description => "The check that reported the warning.",
+ enum => ['missing-cpu-info'],
+ },
+ message => {
+ type => 'string',
+ description => "Why the VM might not run reliably.",
+ },
+ },
+ },
+ },
+ },
'has-dbus-vmstate' => {
type => 'boolean',
description => 'Whether the VM host supports migrating additional VM state, '
@@ -5716,7 +5760,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 +5791,15 @@ __PACKAGE__->register_method({
my $has_identity = PVE::QemuConfig->has_stored_identity($vmid);
my $nodelist = PVE::Cluster::get_nodelist();
+
+ my $cpu_issues_by_node = eval {
+ my $targets = [grep { $_ ne $localnode } $nodelist->@*];
+ return PVE::QemuMigrate::Helpers::check_target_cpu_compatibility(
+ $vmid, $vmconf, $pid, $targets,
+ );
+ } // {};
+ warn "unable to check CPU compatibility of target nodes - $@" if $@;
+
for my $node ($nodelist->@*) {
next if $node eq $localnode;
@@ -5761,6 +5815,15 @@ __PACKAGE__->register_method({
$missing_mappings;
}
+ for my $issue (($cpu_issues_by_node->{$node} // [])->@*) {
+ my $reason = { type => $issue->{type}, message => $issue->{message} };
+ 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..419f1bba 100644
--- a/src/PVE/QemuMigrate.pm
+++ b/src/PVE/QemuMigrate.pm
@@ -18,6 +18,7 @@ use PVE::GuestHelpers qw(safe_boolean_ne safe_string_ne);
use PVE::GuestID;
use PVE::INotify;
use PVE::JSONSchema;
+use PVE::RESTEnvironment qw(log_warn);
use PVE::RPCEnvironment;
use PVE::Replication;
use PVE::ReplicationConfig;
@@ -323,6 +324,14 @@ sub prepare {
}
}
+ # nodes of other clusters do not broadcast their CPU information to this cluster
+ if (!$self->{opts}->{remote}) {
+ my $warnings = PVE::QemuMigrate::Helpers::assert_target_cpu_compatibility(
+ $vmid, $conf, $running, $self->{node},
+ );
+ log_warn($_) for $warnings->@*;
+ }
+
my $vollist = PVE::QemuServer::get_vm_volumes($conf);
my $storages = {};
diff --git a/src/PVE/QemuMigrate/Helpers.pm b/src/PVE/QemuMigrate/Helpers.pm
index e0eec8b1..58360a71 100644
--- a/src/PVE/QemuMigrate/Helpers.pm
+++ b/src/PVE/QemuMigrate/Helpers.pm
@@ -6,11 +6,15 @@ use warnings;
use JSON;
use PVE::Cluster;
+use PVE::INotify;
use PVE::JSONSchema qw(parse_property_string);
use PVE::Mapping::Dir;
use PVE::Mapping::PCI;
use PVE::Mapping::USB;
+use PVE::QemuServer::CPUConfig;
+use PVE::QemuServer::CPUFlags;
+use PVE::QemuServer::Helpers;
use PVE::QemuServer::Monitor qw(mon_cmd);
use PVE::QemuServer::Virtiofs;
@@ -113,6 +117,113 @@ sub check_local_resources {
return wantarray ? (\@loc_res, $mapped_res, $missing_mappings_by_node) : \@loc_res;
}
+# Returns the CPU information the node broadcasts, see get_host_cpu_info() in
+# PVE::QemuServer::Helpers. Information the node does not broadcast is missing.
+my sub get_node_cpu_info {
+ my ($node) = @_;
+
+ my $raw = PVE::Cluster::get_node_kv('host-cpu-info', $node)->{$node};
+ my $info = defined($raw) ? eval { decode_json($raw) } : undef;
+
+ return ref($info) eq 'HASH' ? $info : {};
+}
+
+# Parses a QEMU '-cpu' argument into the CPU model and its properties. Flags given without a value
+# are stored as 'on' or 'off'.
+my sub parse_qemu_cpu_string {
+ my ($cpu_str) = @_;
+
+ my ($model, @options) = split(/,/, $cpu_str);
+
+ my $props = {};
+ for my $option (@options) {
+ my ($op, $name, $value) = $option =~ m/^([+-]?)([^=]+)(?:=(.*))?$/ or next;
+ $name = PVE::QemuServer::CPUFlags::normalize_cpu_flag($name);
+ $value = $op eq '-' ? 'off' : 'on' if !defined($value);
+ $props->{$name} = $value;
+ }
+
+ return { model => $model, props => $props };
+}
+
+my sub is_host_cpu_model {
+ my ($cpu) = @_;
+ # with TCG, 'max' is fully emulated instead of passing through the host CPU
+ return $cpu->{model} eq 'host' || ($cpu->{model} eq 'max' && $cpu->{kvm});
+}
+
+my sub vendors_differ {
+ my ($source, $target) = @_;
+
+ my ($source_vendor, $target_vendor) = ($source->{vendor}, $target->{vendor});
+ return defined($source_vendor) && defined($target_vendor) && $source_vendor ne $target_vendor;
+}
+
+# Checks whether the CPU of a target node can run a running VM after a live migration. 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 of the target node the check requires, 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
+#
+# 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);
+
+ return "CPU model '$cpu->{model}' requires the same CPU vendor as on the source"
+ . " node ($source->{vendor}), but the node has $target->{vendor}";
+ },
+ },
+];
+
+# Returns the issues of the target node. 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 CPU vendor on aarch64, is not reported.
+my sub get_target_cpu_issues {
+ my ($cpu, $checks, $source_info, $target_info) = @_;
+
+ my ($issues, $complete) = ([], 1);
+ for my $check ($checks->@*) {
+ my @missing = grep { !defined($target_info->{$_}) } $check->{needs}->@*;
+ if (scalar(@missing)) {
+ $complete = 0
+ if $check->{severity} eq 'error' && grep { defined($source_info->{$_}) } @missing;
+ next;
+ }
+
+ my $message = $check->{check}->($cpu, $source_info, $target_info) or next;
+ push $issues->@*,
+ { type => $check->{type}, severity => $check->{severity}, message => $message };
+ }
+
+ if (!$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 +240,86 @@ 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.
+
+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, and a human-readable C<message>. 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) = @_;
+
+ return {} if !$pid;
+
+ 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.
+
+=cut
+
+sub assert_target_cpu_compatibility {
+ my ($vmid, $conf, $pid, $node) = @_;
+
+ my $issues_by_node = check_target_cpu_compatibility($vmid, $conf, $pid, [$node]);
+
+ 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..fb62e3b8 100644
--- a/src/test/MigrationTest/QemuMigrateMock.pm
+++ b/src/test/MigrationTest/QemuMigrateMock.pm
@@ -31,6 +31,7 @@ my $migrate_params = decode_json(file_get_contents("${RUN_DIR_PATH}/migrate_para
my $test_vmid = $migrate_params->{vmid};
my $test_target = $migrate_params->{target};
my $test_opts = $migrate_params->{opts};
+my $test_cpu_info = $migrate_params->{cpu_info} // {};
my $current_log = '';
my $vm_stop_executed = 0;
@@ -116,6 +117,10 @@ $qemu_migrate_module->mock(
my ($self, $level, $message) = @_;
$current_log .= "$level: $message\n";
},
+ log_warn => sub {
+ my ($message) = @_;
+ $current_log .= "warn: $message\n";
+ },
mon_cmd => sub {
my ($vmid, $command, %params) = @_;
@@ -225,8 +230,36 @@ $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});
+ 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;
},
diff --git a/src/test/run_api_tests.pl b/src/test/run_api_tests.pl
index f2916346..aee75711 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,84 @@ 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'",
+ );
+
+ $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..879781ca 100755
--- a/src/test/run_qemu_migrate_tests.pl
+++ b/src/test/run_qemu_migrate_tests.pl
@@ -520,6 +520,71 @@ 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, 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, $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} || $cpu_kept;
+
+ 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 +595,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', 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 +1547,59 @@ 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(
+ 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 on aarch64, 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 +2021,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
next prev parent reply other threads:[~2026-11-30 18:11 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 18:09 [PATCH docs/manager/qemu-server v3 00/18] check the target node's CPU before live migrating a VM Jonas Theisen
2026-11-30 18:09 ` [PATCH qemu-server v3 01/18] buildsys: ignore migration test runtime files Jonas Theisen
2026-11-30 18:09 ` [PATCH qemu-server v3 02/18] test: migration: allow checking for warnings and errors in the log Jonas Theisen
2026-11-30 18:09 ` [PATCH qemu-server v3 03/18] cpu flags: normalize underscores in all CPU flag names Jonas Theisen
2026-11-30 18:09 ` [PATCH qemu-server v3 04/18] test: api: factor out validating the migration preconditions Jonas Theisen
2026-11-30 18:09 ` [PATCH qemu-server v3 05/18] cpu flags: factor out parsing the broadcast CPU flags of a node Jonas Theisen
2026-11-30 18:09 ` [PATCH qemu-server v3 06/18] migrate: factor out whether the running virtual CPU is kept Jonas Theisen
2026-11-30 18:09 ` [PATCH qemu-server v3 07/18] cpu flags: factor out the flags of a CPU model expansion Jonas Theisen
2026-11-30 18:09 ` Jonas Theisen [this message]
2026-11-30 18:09 ` [PATCH qemu-server v3 09/18] fix #6535: migrate: warn about live migration between CPU vendors Jonas Theisen
2026-11-30 18:09 ` [PATCH qemu-server v3 10/18] fix #2924: migrate: block live migration of host CPU VMs to nodes lacking flags Jonas Theisen
2026-11-30 18:09 ` [PATCH qemu-server v3 11/18] migrate: warn about live migration of host CPU VMs between CPU models Jonas Theisen
2026-11-30 18:09 ` [PATCH qemu-server v3 12/18] migrate: block live migration if the target cannot run the virtual CPU Jonas Theisen
2026-11-30 18:09 ` [PATCH qemu-server v3 13/18] api: migrate: check the CPU of the target before requesting HA migration Jonas Theisen
2026-11-30 18:09 ` [PATCH manager v3 14/18] pvestatd: broadcast host CPU information relevant for live migration Jonas Theisen
2026-11-30 18:09 ` [PATCH manager v3 15/18] ui: migrate: show why the CPU of the target node is incompatible Jonas Theisen
2026-11-30 18:09 ` [PATCH manager v3 16/18] fix #6535: ui: migrate: show CPU warnings for the target node Jonas Theisen
2026-11-30 18:09 ` [PATCH manager v3 17/18] api: nodes: migrateall: skip VMs whose CPU is incompatible with the target Jonas Theisen
2026-11-30 18:09 ` [PATCH docs v3 18/18] qm: document the CPU checks for live migration Jonas Theisen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261130181007.596064-9-j.theisen@proxmox.com \
--to=j.theisen@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.