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 213111FF0E2 for ; Thu, 30 Jul 2026 16:15:36 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 190EB214F8; Thu, 30 Jul 2026 16:15:31 +0200 (CEST) From: Fiona Ebner To: pve-devel@lists.proxmox.com Subject: [PATCH qemu-server 2/2] cpu flags: introduce get_cpu_model_expansions() helper Date: Thu, 30 Jul 2026 16:15:10 +0200 Message-ID: <20260730141522.203966-3-f.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260730141522.203966-1-f.ebner@proxmox.com> References: <20260730141522.203966-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1785420917717 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.160 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_LOW -0.7 Sender listed at https://www.dnswl.org/, low trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: 4VG77JX2YV3MWBAN5EXYURHUIJ3OCBSI X-Message-ID-Hash: 4VG77JX2YV3MWBAN5EXYURHUIJ3OCBSI X-MailFrom: f.ebner@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 X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Make the static list of CPU model expansions, which is newly shipped by pve-qemu-kvm, accessible in qemu-server. Note that some CPU flags in the expansions are gated behind others and thus cannot be queried via the static expansions. Most prominently, this is the case for the flags for nested virtualization. For example, 'Skylake-Server' will not support any vmx-* flags, but 'Skylake-Server,+vmx' would. Signed-off-by: Fiona Ebner --- src/PVE/QemuServer/CPUFlags.pm | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/PVE/QemuServer/CPUFlags.pm b/src/PVE/QemuServer/CPUFlags.pm index 0d3206b2..60683486 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 qw(); use PVE::Cluster; use PVE::File; @@ -129,6 +130,32 @@ my $qemu_cpu_flag_alias_map = { lbr_fmt => 'lbr-fmt', }; +my $cpu_model_expansions; + +=head3 get_cpu_model_expansions($arch) + +Get the CPU model expansions for the given architecture C<$arch>. Will return C for QEMU +package versions that don't yet ship the static model expansions. Note that some CPU flags in the +expansions are gated behind others and thus cannot be queried via the static expansions. Most +prominently, this is the case for the flags for nested virtualization. For example, +C will not support any C flags, but C would. The latter +cannot be queried here. + +=cut + +my sub get_cpu_model_expansions($arch) { + if (!defined($cpu_model_expansions->{$arch})) { + my $cpu_models_file = "/usr/share/kvm/cpu-model-expansions-${arch}.json"; + return if !PVE::File::file_exists($cpu_models_file); + + my $data = PVE::File::file_get_contents($cpu_models_file, 10 * 1024 * 1024); + + $cpu_model_expansions->{$arch} = JSON::decode_json($data); + } + + return $cpu_model_expansions->{$arch}; +} + =head3 normalize_cpu_flag($flag) Normalize a CPU flag to its QEMU form. -- 2.47.3