From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 93F2F1FF138 for ; Mon, 01 Jun 2026 09:16:59 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id C48F11078C; Mon, 1 Jun 2026 09:16:40 +0200 (CEST) From: Arthur Bied-Charreton To: pve-devel@lists.proxmox.com Subject: [PATCH v2 1/2] build: include Hyper-V enlightenments in CPUID flags list Date: Mon, 1 Jun 2026 09:08:09 +0200 Message-ID: <20260601071633.442590-2-a.bied-charreton@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260601071633.442590-1-a.bied-charreton@proxmox.com> References: <20260601071633.442590-1-a.bied-charreton@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.139 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: TRCHVAHWCJNEP3JJTNSM5GCCM66JFWGM X-Message-ID-Hash: TRCHVAHWCJNEP3JJTNSM5GCCM66JFWGM 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: ... by sourcing CPU flags from qom-list-properties. The recognized-CPUID-flags-x86_64 list is generated from QEMU's '-cpu help' output, which does not advertise Hyper-V enlightenments. Source the flags from the qom-list-properties QMP command instead to include them. Keep only boolean properties, since the custom CPU models config only supports enable/disable. qom-list-properties also exposes boolean properties that are neither CPUID flags nor 'hv-*' enlightenments, exclude those with a static blacklist that must be reviewed on QEMU bumps. Also add a trailing newline to the generated output. Suggested-by: Fiona Ebner Signed-off-by: Arthur Bied-Charreton --- debian/parse-cpu-flags.pl | 125 ++++++++++++++++++++++++++++++++++---- debian/rules | 2 +- 2 files changed, 113 insertions(+), 14 deletions(-) diff --git a/debian/parse-cpu-flags.pl b/debian/parse-cpu-flags.pl index 1847b3e..517ee0a 100755 --- a/debian/parse-cpu-flags.pl +++ b/debian/parse-cpu-flags.pl @@ -1,23 +1,122 @@ #!/usr/bin/perl -use warnings; -use strict; +use v5.36; -my @flags = (); -my $got_flags_section; +use IPC::Open2; +use JSON; -while () { - if (/^\s*Recognized CPUID flags:/) { - $got_flags_section = 1; - next; +my ($qemu_bin) = @ARGV; + +my $pid = open2( + my $out, + my $in, + $qemu_bin, + '-machine', + 'none', + '-display', + 'none', + '-S', + '-qmp', + 'stdio', + '-nodefaults', +); + +sub qmp($cmd, %args) { + print $in encode_json({ execute => $cmd, %args ? (arguments => \%args) : () }), "\n"; + while (my $line = <$out>) { + my $msg = decode_json($line); + next if $msg->{event}; + return $msg->{return} if exists($msg->{return}); + die "QMP error: " . encode_json($msg->{error}) if $msg->{error}; } - next if !$got_flags_section; +} + +# 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', +}; + +# Static blacklist to be reviewed on QEMU bumps. +# Currently includes boolean properties from qom-list-properties that are neither CPUID +# flags ('-cpu help') nor Hyper-V enlightenments ('hv-*'). +my $blacklist = { + check => 1, + 'cpuid-0xb' => 1, + enforce => 1, + 'fill-mtrr-mask' => 1, + 'host-cache-info' => 1, + 'host-phys-bits' => 1, + hotpluggable => 1, + hotplugged => 1, + kvm => 1, + 'kvm-pv-enforce-cpuid' => 1, + 'l3-cache' => 1, + 'legacy-cache' => 1, + 'legacy-multi-node' => 1, + lmce => 1, + migratable => 1, + pmu => 1, + realized => 1, + 'start-powered-off' => 1, + 'tcg-cpuid' => 1, + 'vmware-cpuid-freq' => 1, + 'x-amd-topoext-features-only' => 1, + 'x-arch-cap-always-on' => 1, + 'x-consistent-cache' => 1, + 'x-force-cpuid-0x1f' => 1, + 'x-force-features' => 1, + 'x-l1-cache-per-thread' => 1, + 'x-migrate-error-code' => 1, + 'x-migrate-smi-count' => 1, + 'x-pdcm-on-even-without-pmu' => 1, + 'x-vendor-cpuid-only' => 1, + 'x-vendor-cpuid-only-v2' => 1, + 'xen-vapic' => 1, +}; - s/^\s+//; +my $flags = {}; - push @flags, split(/\s+/); +<$out>; +qmp('qmp_capabilities'); +my $props = qmp('qom-list-properties', typename => 'host-x86_64-cpu'); +for my $qo ($props->@*) { + next if $qo->{type} ne 'bool' || defined($blacklist->{$qo->{name}}); + $flags->{$qemu_cpu_flag_alias_map->{$qo->{name}} // $qo->{name}} = 1; } +qmp('quit'); +waitpid($pid, 0); -die "no QEMU/KVM CPU flags detected from STDIN input" if scalar (@flags) <= 0; +my @flags = sort keys $flags->%*; -print join("\n", @flags) or die "$!\n"; +print join("\n", @flags) . "\n" or die "$!\n"; diff --git a/debian/rules b/debian/rules index c90db29..b2eed71 100755 --- a/debian/rules +++ b/debian/rules @@ -123,7 +123,7 @@ install: build rm -f $(destdir)/usr/lib/kvm/virtfs-proxy-helper # CPU flags are static for QEMU version, allows avoiding more costly checks - $(destdir)/usr/bin/qemu-system-x86_64 -cpu help | ./debian/parse-cpu-flags.pl > $(flagfile) + ./debian/parse-cpu-flags.pl $(destdir)/usr/bin/qemu-system-x86_64 > $(flagfile) # Supported machine versions are static for a given QEMU binary. $(destdir)/usr/bin/qemu-system-x86_64 -machine help | ./debian/parse-machines.pl > $(machine_file_x86_64) -- 2.47.3