From: Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH qemu-server v3 1/2] cpu config: Add 'arch' property to cpu_fmt
Date: Tue, 17 Feb 2026 15:06:51 +0100 [thread overview]
Message-ID: <20260217141036.338747-1-a.bied-charreton@proxmox.com> (raw)
Preparatory step for adding support for configuring custom CPU types in
the PVE UI.
Add optional property 'arch' (x86_64|aarch64) to cpu_fmt to allow custom
models to indicate which architecture they belong to, default to x86_64
for backwards compatibility.
Add checks to get_cpu_options and validate_cpu_conf to deny illegal
configs early.
Signed-off-by: Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
---
Changes since v1:
* add checks to validate_cpu_conf + get_cpu_options to fail early on
misconfigurations
* reuse the pve-qm-cpu-arch standard option for cpu_fmt's arch property
* do not use single quotes for hash keys if not needed
* do not use parentheses for post-ifs
Changes since v2:
* use get_standard_option for getting the pve-qm-cpu-arch standard
option instead of accessing the arch_desc directly
src/PVE/QemuServer/CPUConfig.pm | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/src/PVE/QemuServer/CPUConfig.pm b/src/PVE/QemuServer/CPUConfig.pm
index 32ec4954..a8e146d7 100644
--- a/src/PVE/QemuServer/CPUConfig.pm
+++ b/src/PVE/QemuServer/CPUConfig.pm
@@ -374,6 +374,12 @@ my $cpu_fmt = {
. " note that doing so will break live migration to CPUs with other values.",
optional => 1,
},
+ arch => {
+ %{ PVE::JSONSchema::get_standard_option('pve-qm-cpu-arch') },
+ default => 'x86_64',
+ description => 'The architecture the CPU model belongs to.',
+ optional => 1,
+ },
};
my $sev_fmt = {
@@ -475,6 +481,13 @@ sub validate_cpu_conf {
my ($cpu) = @_;
# required, but can't be forced in schema since it's encoded in section header for custom models
die "CPU is missing cputype\n" if !$cpu->{cputype};
+
+ if (my $reported_model = $cpu->{'reported-model'}) {
+ my $arch = $cpu->{arch} // $cpu_fmt->{arch}->{default};
+ die "reported model '$reported_model' is not valid for architecture '$arch'\n"
+ if !$cpu_models_by_arch->{$arch}->{$reported_model};
+ }
+
return $cpu;
}
PVE::JSONSchema::register_format('pve-vm-cpu-conf', $cpu_fmt, \&validate_vm_cpu_conf);
@@ -612,6 +625,10 @@ sub get_cpu_models {
my $conf = load_custom_model_conf();
for my $custom_model (keys %{ $conf->{ids} }) {
+ my $custom_model_arch = $conf->{ids}->{$custom_model}->{arch};
+ $custom_model_arch //= $cpu_fmt->{arch}->{default};
+ next if $custom_model_arch ne $arch;
+
my $reported_model = $conf->{ids}->{$custom_model}->{'reported-model'};
$reported_model //= $cpu_fmt->{'reported-model'}->{default};
my $vendor = $all_cpu_models->{$reported_model};
@@ -854,6 +871,9 @@ sub get_cpu_options {
$builtin_cpu->{flags} = $model->{'flags'};
} elsif (is_custom_model($cputype)) {
$custom_cpu = get_custom_model($cputype);
+ my $custom_cpu_arch = $custom_cpu->{arch} // $cpu_fmt->{arch}->{default};
+ die "custom CPU model has architecture '$custom_cpu_arch', but VM has '$arch'\n"
+ if $custom_cpu_arch ne $arch;
$cputype = $custom_cpu->{'reported-model'} // $cpu_fmt->{'reported-model'}->{default};
$kvm_off = $custom_cpu->{hidden} if defined($custom_cpu->{hidden});
--
2.47.3
next reply other threads:[~2026-02-17 14:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-17 14:06 Arthur Bied-Charreton [this message]
2026-02-17 14:06 ` [PATCH qemu-server v3 2/2] cpu config: Add tests for arch/reported-model misconfigurations Arthur Bied-Charreton
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=20260217141036.338747-1-a.bied-charreton@proxmox.com \
--to=a.bied-charreton@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox