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 435E1B9C2B for ; Tue, 12 Dec 2023 11:37:14 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 248C832A10 for ; Tue, 12 Dec 2023 11:37:14 +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 ; Tue, 12 Dec 2023 11:37:13 +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 2D0DD4606B for ; Tue, 12 Dec 2023 11:37:13 +0100 (CET) From: Filip Schauer To: pve-devel@lists.proxmox.com Date: Tue, 12 Dec 2023 11:37:08 +0100 Message-Id: <20231212103708.35372-1-f.schauer@proxmox.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.181 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: [pve-devel] [PATCH v2 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: Tue, 12 Dec 2023 10:37:14 -0000 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. Signed-off-by: Filip Schauer --- PVE/API2/Qemu.pm | 2 +- PVE/QemuServer.pm | 27 ++++++++++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index f26adf5..c4f87c9 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -419,7 +419,7 @@ my $create_disks = sub { if ($ds eq 'efidisk0') { my $smm = PVE::QemuServer::Machine::machine_type_is_q35($conf); ($volid, $size) = PVE::QemuServer::create_efidisk( - $storecfg, $storeid, $vmid, $fmt, $arch, $disk, $smm); + $storecfg, $storeid, $vmid, $fmt, $arch, $conf->{cpu}, $disk, $smm); } elsif ($ds eq 'tpmstate0') { # swtpm can only use raw volumes, and uses a fixed size $size = PVE::Tools::convert_size(PVE::QemuServer::Drive::TPMSTATE_DISK_SIZE, 'b' => 'kb'); diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 2063e66..94a8795 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -3365,12 +3365,25 @@ sub get_vm_machine { return $machine; } -sub get_ovmf_files($$$) { - my ($arch, $efidisk, $smm) = @_; +my @cputypes_32bit = ( + '486', + 'pentium', + 'pentium2', + 'pentium3', + 'coreduo', + 'athlon', + 'kvm32', + 'qemu32', +); +sub get_ovmf_files($$$$) { + my ($arch, $cputype, $efidisk, $smm) = @_; my $types = $OVMF->{$arch} or die "no OVMF images known for architecture '$arch'\n"; + die "OVMF (UEFI) BIOS is not supported on 32-bit CPU types\n" + if ($cputype && first {$_ eq $cputype} @cputypes_32bit); + my $type = 'default'; if ($arch eq 'x86_64') { if (defined($efidisk->{efitype}) && $efidisk->{efitype} eq '4m') { @@ -3535,7 +3548,7 @@ my sub print_ovmf_drive_commandlines { my $d = $conf->{efidisk0} ? parse_drive('efidisk0', $conf->{efidisk0}) : undef; - my ($ovmf_code, $ovmf_vars) = get_ovmf_files($arch, $d, $q35); + my ($ovmf_code, $ovmf_vars) = get_ovmf_files($arch, $conf->{cpu}, $d, $q35); my $var_drive_str = "if=pflash,unit=1,id=drive-efidisk0"; if ($d) { @@ -8239,7 +8252,7 @@ sub get_efivars_size { my $arch = get_vm_arch($conf); $efidisk //= $conf->{efidisk0} ? parse_drive('efidisk0', $conf->{efidisk0}) : undef; my $smm = PVE::QemuServer::Machine::machine_type_is_q35($conf); - my (undef, $ovmf_vars) = get_ovmf_files($arch, $efidisk, $smm); + my (undef, $ovmf_vars) = get_ovmf_files($arch, $conf->{cpu}, $efidisk, $smm); return -s $ovmf_vars; } @@ -8263,10 +8276,10 @@ sub update_tpmstate_size { $conf->{tpmstate0} = print_drive($disk); } -sub create_efidisk($$$$$$$) { - my ($storecfg, $storeid, $vmid, $fmt, $arch, $efidisk, $smm) = @_; +sub create_efidisk($$$$$$$$) { + my ($storecfg, $storeid, $vmid, $fmt, $arch, $cputype, $efidisk, $smm) = @_; - my (undef, $ovmf_vars) = get_ovmf_files($arch, $efidisk, $smm); + my (undef, $ovmf_vars) = get_ovmf_files($arch, $cputype, $efidisk, $smm); my $vars_size_b = -s $ovmf_vars; my $vars_size = PVE::Tools::convert_size($vars_size_b, 'b' => 'kb'); -- 2.39.2