From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 504631FF14C for ; Fri, 15 May 2026 11:29:11 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id DD4B614044; Fri, 15 May 2026 11:28:48 +0200 (CEST) From: Arthur Bied-Charreton To: pve-devel@lists.proxmox.com Subject: [PATCH qemu-server v5 05/21] cpu flags: normalize CPU flags to QEMU's format Date: Fri, 15 May 2026 11:28:22 +0200 Message-ID: <20260515092839.238064-6-a.bied-charreton@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260515092839.238064-1-a.bied-charreton@proxmox.com> References: <20260515092839.238064-1-a.bied-charreton@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.135 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods RDNS_NONE 0.793 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: GTP5W4YGBCHLVU6OJDMZLL5KLOGW26KU X-Message-ID-Hash: GTP5W4YGBCHLVU6OJDMZLL5KLOGW26KU X-MailFrom: abied-charreton@jett.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: The QMP commands used in query_supported_cpu_flags() return some flags multiple times in different formats, like for example 'sse4.2', 'sse4-2' and 'sse4_2'. In order to have a unified format, add the normalize_cpu_flag helper to the CPUFlags module, which returns the alias QEMU has for a given flag value. The list is sourced from x86_cpu_initfn() in qemu/target/i386/cpu.c. Suggested-by: Fiona Ebner Signed-off-by: Arthur Bied-Charreton --- src/PVE/QemuServer.pm | 7 ++--- src/PVE/QemuServer/CPUFlags.pm | 53 ++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm index 57123e56..af55c322 100644 --- a/src/PVE/QemuServer.pm +++ b/src/PVE/QemuServer.pm @@ -69,6 +69,7 @@ use PVE::QemuServer::CPUConfig qw( get_intel_tdx_object get_cvm_type ); +use PVE::QemuServer::CPUFlags; use PVE::QemuServer::Drive qw( is_valid_drivename checked_volume_format @@ -2992,10 +2993,8 @@ sub query_supported_cpu_flags { my $props = $cmd_result->{model}->{props}; foreach my $prop (keys %$props) { next if $props->{$prop} ne JSON::true; - # QEMU returns some flags multiple times, with '_', '.' or '-' - # (e.g. lahf_lm and lahf-lm; sse4.2, sse4-2 and sse4_2; ...). - # We only keep those with underscores, to match /proc/cpuinfo - $prop =~ s/\.|-/_/g; + $prop = PVE::QemuServer::CPUFlags::normalize_cpu_flag($prop); + $flags->{$prop} = 1; } }; diff --git a/src/PVE/QemuServer/CPUFlags.pm b/src/PVE/QemuServer/CPUFlags.pm index a681eb75..e17ed00c 100644 --- a/src/PVE/QemuServer/CPUFlags.pm +++ b/src/PVE/QemuServer/CPUFlags.pm @@ -14,6 +14,7 @@ our @EXPORT_OK = qw( supported_cpu_flags_names get_supported_cpu_flags query_understood_cpu_flags + normalize_cpu_flag ); my $supported_vm_specific_cpu_flags_by_arch = { @@ -93,6 +94,58 @@ for my $arch ($supported_vm_specific_cpu_flags_by_arch->%*) { my @supported_cpu_flags_name_sorted = sort keys $all_supported_vm_specific_cpu_flags->%*; +# qemu/target/i386/cpu.c, x86_cpu_initfn() +my $qemu_cpu_flag_alias_map = { + sse3 => 'pni', + pclmuldq => 'pclmulqdq', + 'sse4-1' => 'sse4.1', + 'sse4-2' => 'sse4.2', + xd => 'nx', + ffxsr => 'fxsr-opt', + i64 => 'lm', + ds_cpl => 'ds-cpl', + tsc_adjust => 'tsc-adjust', + fxsr_opt => 'fxsr-opt', + lahf_lm => 'lahf-lm', + cmp_legacy => 'cmp-legacy', + nodeid_msr => 'nodeid-msr', + perfctr_core => 'perfctr-core', + perfctr_nb => 'perfctr-nb', + kvm_nopiodelay => 'kvm-nopiodelay', + kvm_mmu => 'kvm-mmu', + kvm_asyncpf => 'kvm-asyncpf', + kvm_asyncpf_int => 'kvm-asyncpf-int', + kvm_steal_time => 'kvm-steal-time', + kvm_pv_eoi => 'kvm-pv-eoi', + kvm_pv_unhalt => 'kvm-pv-unhalt', + kvm_poll_control => 'kvm-poll-control', + svm_lock => 'svm-lock', + nrip_save => 'nrip-save', + tsc_scale => 'tsc-scale', + vmcb_clean => 'vmcb-clean', + pause_filter => 'pause-filter', + sse4_1 => 'sse4.1', + sse4_2 => 'sse4.2', + 'hv-apicv' => 'hv-avic', + lbr_fmt => 'lbr-fmt', +}; + +=head3 normalize_cpu_flag($flag) + +Normalize a CPU flag to its QEMU form. + +QEMU defines aliases for some CPU flags (see C in +C). For example, C and C are both aliases for +C. + +If C<$flag> has a known alias, return that, otherwise return C<$flag> unchanged. + +=cut + +sub normalize_cpu_flag($flag) { + return $qemu_cpu_flag_alias_map->{$flag} // $flag; +} + # Understood CPU flags are written to a file at 'pve-qemu' compile time and # shipped below this directory by the pve-qemu-kvm package. my $understood_cpu_flag_dir = "/usr/share/kvm"; -- 2.47.3