From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id D49ABBA416 for ; Wed, 13 Dec 2023 18:01:45 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B3EA5E480 for ; Wed, 13 Dec 2023 18:01:15 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Wed, 13 Dec 2023 18:01:15 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id D6970471B2 for ; Wed, 13 Dec 2023 18:01:14 +0100 (CET) Message-ID: <632a4c52-a26b-4e77-84a8-4cd1d90aa055@proxmox.com> Date: Wed, 13 Dec 2023 18:01:13 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: pve-devel@lists.proxmox.com References: <20231213165331.106297-1-f.schauer@proxmox.com> From: Filip Schauer In-Reply-To: <20231213165331.106297-1-f.schauer@proxmox.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.168 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 SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: Re: [pve-devel] [PATCH v4 qemu-server] Prevent starting a 32-bit VM using a 64-bit OVMF BIOS X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Dec 2023 17:01:45 -0000 Patch v5 is available: https://lists.proxmox.com/pipermail/pve-devel/2023-December/061079.html On 13/12/2023 17:53, Filip Schauer wrote: > Instead of starting a VM with a 32-bit CPU type and a 64-bit OVMF image, > throw an error before starting the VM telling the user that OVMF is not > supported on 32-bit CPU types. > > To obtain a list of 32-bit CPU types, refer to builtin_x86_defs in > target/i386/cpu.c of QEMU. Exclude any entries that have the long mode > feature (CPUID_EXT2_LM). > > Signed-off-by: Filip Schauer > --- > Changes since v2: > * Simplify the check whether a 32-bit CPU type is used in combination > with OVMF > > Changes since v3: > * Move the cputypes_32bit list from QemuServer.pm to CPUConfig.pm > * Turn cputypes_32bit into a hash for lookup > * Create a helper get_cpu_bitness function in CPUConfig.pm > * Describe how the list of 32-bit CPU types was obtained > > PVE/QemuServer.pm | 5 ++++- > PVE/QemuServer/CPUConfig.pm | 32 ++++++++++++++++++++++++++++++++ > 2 files changed, 36 insertions(+), 1 deletion(-) > > diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm > index 2063e66..5bfa11f 100644 > --- a/PVE/QemuServer.pm > +++ b/PVE/QemuServer.pm > @@ -52,7 +52,7 @@ use PVE::QemuConfig; > use PVE::QemuServer::Helpers qw(config_aware_timeout min_version windows_version); > use PVE::QemuServer::Cloudinit; > use PVE::QemuServer::CGroup; > -use PVE::QemuServer::CPUConfig qw(print_cpu_device get_cpu_options); > +use PVE::QemuServer::CPUConfig qw(print_cpu_device get_cpu_options get_cpu_bitness); > use PVE::QemuServer::Drive qw(is_valid_drivename drive_is_cloudinit drive_is_cdrom drive_is_read_only parse_drive print_drive); > use PVE::QemuServer::Machine; > use PVE::QemuServer::Memory qw(get_current_memory); > @@ -3689,6 +3689,9 @@ sub config_to_command { > } > > if ($conf->{bios} && $conf->{bios} eq 'ovmf') { > + die "OVMF (UEFI) BIOS is not supported on 32-bit CPU types\n" > + if get_cpu_bitness($conf, $arch) == 32; > + > my ($code_drive_str, $var_drive_str) = > print_ovmf_drive_commandlines($conf, $storecfg, $vmid, $arch, $q35, $version_guard); > push $cmd->@*, '-drive', $code_drive_str; > diff --git a/PVE/QemuServer/CPUConfig.pm b/PVE/QemuServer/CPUConfig.pm > index ca2946b..c04e749 100644 > --- a/PVE/QemuServer/CPUConfig.pm > +++ b/PVE/QemuServer/CPUConfig.pm > @@ -12,6 +12,7 @@ use base qw(PVE::SectionConfig Exporter); > our @EXPORT_OK = qw( > print_cpu_device > get_cpu_options > +get_cpu_bitness > ); > > # under certain race-conditions, this module might be loaded before pve-cluster > @@ -57,6 +58,17 @@ my $depreacated_cpu_map = { > 'Icelake-Client-noTSX' => 'Icelake-Server-noTSX', > }; > > +my $cputypes_32bit = { > + '486' => 1, > + 'pentium' => 1, > + 'pentium2' => 1, > + 'pentium3' => 1, > + 'coreduo' => 1, > + 'athlon' => 1, > + 'kvm32' => 1, > + 'qemu32' => 1, > +}; > + > my $cpu_vendor_list = { > # Intel CPUs > 486 => 'GenuineIntel', > @@ -719,6 +731,26 @@ sub get_cpu_from_running_vm { > return $1; > } > > +sub get_cpu_bitness { > + my ($conf, $arch) = @_; > + > + return if !$conf or !$arch; > + > + if ($arch eq 'x86_64') { > + if (my $cpu_prop_str = $conf->{cpu}) { > + my $cpu = PVE::JSONSchema::parse_property_string('pve-vm-cpu-conf', $cpu_prop_str) > + or die "Cannot parse cpu description: $cpu_prop_str\n"; > + > + my $cputype = $cpu->{cputype}; > + return 32 if $cputypes_32bit->{$cputype}; > + } > + > + return 64; > + } > + > + return 64 if ($arch eq 'aarch64'); > +} > + > __PACKAGE__->register(); > __PACKAGE__->init(); >