From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 906C91FF13E for ; Wed, 01 Jul 2026 15:52:41 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 4016C2138E; Wed, 01 Jul 2026 15:52:40 +0200 (CEST) From: Erik Fastermann To: pve-devel@lists.proxmox.com Subject: [PATCH qemu-server v2] remote migration: validate custom CPU configs Date: Wed, 1 Jul 2026 15:52:29 +0200 Message-ID: <20260701135229.225599-1-e.fastermann@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 2 DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods RDNS_NONE 1.274 Delivered to internal network by a host with no rDNS SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record Message-ID-Hash: 4SAGCHKEMZT3T7SJLYF46GG3S7RDP7J6 X-Message-ID-Hash: 4SAGCHKEMZT3T7SJLYF46GG3S7RDP7J6 X-MailFrom: efastermann@ruth.proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Erik Fastermann X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 Suggested-by: Fiona Ebner Tested-by: Arthur Bied-Charreton Reviewed-by: Arthur Bied-Charreton Signed-off-by: Erik Fastermann --- 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