public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [PATCH qemu-server v2] remote migration: validate custom CPU configs
@ 2026-07-01 13:52 Erik Fastermann
  0 siblings, 0 replies; only message in thread
From: Erik Fastermann @ 2026-07-01 13:52 UTC (permalink / raw)
  To: pve-devel; +Cc: Erik Fastermann

Previously, a remote migration would fail with a cryptic error message
if a custom CPU model was selected that did not exist on the target
server. Furthermore, no validation was performed to ensure that the
custom CPU definitions matched between the source and target.

Fix this by comparing the CPU configurations before initiating the
migration and aborting early if they do not match.

Reported-by: Walter Hoos <w.hoos@proxmox.com>
Suggested-by: Fiona Ebner <f.ebner@proxmox.com>
Tested-by: Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
Reviewed-by: Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
Signed-off-by: Erik Fastermann <e.fastermann@proxmox.com>
---

 changes since v1:
 * fix noop JSONSchema::validate
 * error handling with post-ifs
 * more general error message for not found errors and similar
 * move comparison to helper assert_custom_model_compatibility
 * simplified sorted flags comparison

 src/PVE/API2/Qemu.pm            | 25 +++++++++++++++++++++++++
 src/PVE/QemuServer/CPUConfig.pm | 21 +++++++++++++++++++++
 2 files changed, 46 insertions(+)

diff --git a/src/PVE/API2/Qemu.pm b/src/PVE/API2/Qemu.pm
index 54883f1e..e2e87999 100644
--- a/src/PVE/API2/Qemu.pm
+++ b/src/PVE/API2/Qemu.pm
@@ -5745,6 +5745,31 @@ __PACKAGE__->register_method({
             $param->{online} = 0;
         }
 
+        if (defined($conf->{cpu})) {
+            my $cpu = PVE::JSONSchema::parse_property_string('pve-vm-cpu-conf', $conf->{cpu});
+            my $cputype = $cpu->{cputype};
+            if (defined($cputype) && PVE::QemuServer::CPUConfig::is_custom_model($cputype)) {
+                my $custom_cpu = PVE::QemuServer::CPUConfig::get_custom_model($cputype);
+
+                my $remote_custom_cpu = eval {
+                    $api_client->get("/cluster/qemu/custom-cpu-models/"
+                        . URI::Escape::uri_escape_utf8($cputype));
+                };
+                die "could not validate custom CPU model compatibility: $@\n" if $@;
+
+                my $cpu_schema = {
+                    type => 'object',
+                    properties => PVE::QemuServer::CPUConfig->options(),
+                };
+                eval { PVE::JSONSchema::validate($remote_custom_cpu, $cpu_schema); };
+                die "could not validate custom CPU model compatibility: $@\n" if $@;
+
+                PVE::QemuServer::CPUConfig::assert_custom_model_compatibility(
+                    $custom_cpu, $remote_custom_cpu,
+                );
+            }
+        }
+
         my $storecfg = PVE::Storage::config();
         my $target_storage = extract_param($param, 'target-storage');
         my $storagemap =
diff --git a/src/PVE/QemuServer/CPUConfig.pm b/src/PVE/QemuServer/CPUConfig.pm
index 9be145ef..df3e2b92 100644
--- a/src/PVE/QemuServer/CPUConfig.pm
+++ b/src/PVE/QemuServer/CPUConfig.pm
@@ -647,6 +647,27 @@ sub get_custom_model($name, $noerr = undef, $conf = undef) {
     return $model;
 }
 
+sub assert_custom_model_compatibility($local_cpu, $remote_cpu) {
+    my $cputype = $local_cpu->{cputype};
+
+    my $local_cpu_flags = join ';', sort split /;/, ($local_cpu->{flags} // '');
+    my $remote_cpu_flags = join ';', sort split /;/, ($remote_cpu->{flags} // '');
+
+    die "CPU $cputype config mismatch for flags: local="
+        . $local_cpu_flags
+        . ",remote="
+        . $remote_cpu_flags . "\n"
+        if $local_cpu_flags ne $remote_cpu_flags;
+
+    for my $key (sort keys %$cpu_fmt) {
+        next if $key eq 'flags';
+        my $v1 = $local_cpu->{$key} // '';
+        my $v2 = $remote_cpu->{$key} // '';
+        die "CPU $cputype config mismatch for $key: local=$v1,remote=$v2\n"
+            if $v1 ne $v2;
+    }
+}
+
 # Print a QEMU device node for a given VM configuration for hotplugging CPUs
 sub print_cpu_device($conf, $arch, $id) {
 
-- 
2.47.3




^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-07-01 13:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-01 13:52 [PATCH qemu-server v2] remote migration: validate custom CPU configs Erik Fastermann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal