all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH qemu-server] Properly identify the CPU architecture of 32-bit VMs
@ 2023-12-11 14:12 Filip Schauer
  2023-12-11 14:37 ` Fiona Ebner
  0 siblings, 1 reply; 6+ messages in thread
From: Filip Schauer @ 2023-12-11 14:12 UTC (permalink / raw)
  To: pve-devel

Add an i386 CPU architecture which is used when a 32 bit CPU type is
detected.

This now prevents starting a 32-bit VM using a 64-bit OVMF BIOS. Instead
it throws the error, "no OVMF images known for architecture 'i386'",
triggered in get_ovmf_file. This behaviour is intended since we do not
support 32 bit OVMF images.

Signed-off-by: Filip Schauer <f.schauer@proxmox.com>
---
 PVE/QemuServer.pm           |  8 +++++---
 PVE/QemuServer/CPUConfig.pm | 28 ++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 2063e66..54590df 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 cpu_type_to_arch);
 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);
@@ -649,7 +649,7 @@ EODESCR
 	description => "Virtual processor architecture. Defaults to the host.",
 	optional => 1,
 	type => 'string',
-	enum => [qw(x86_64 aarch64)],
+	enum => [qw(x86_64 i386 aarch64)],
     },
     smbios1 => {
 	description => "Specify SMBIOS type 1 fields.",
@@ -3293,11 +3293,12 @@ sub is_native($) {
 
 sub get_vm_arch {
     my ($conf) = @_;
-    return $conf->{arch} // get_host_arch();
+    return $conf->{arch} // cpu_type_to_arch($conf->{cpu}) // get_host_arch();
 }
 
 my $default_machines = {
     x86_64 => 'pc',
+    i386 => 'pc',
     aarch64 => 'virt',
 };
 
@@ -3390,6 +3391,7 @@ sub get_ovmf_files($$$) {
 
 my $Arch2Qemu = {
     aarch64 => '/usr/bin/qemu-system-aarch64',
+    i386 => '/usr/bin/qemu-system-i386',
     x86_64 => '/usr/bin/qemu-system-x86_64',
 };
 sub get_command_for_arch($) {
diff --git a/PVE/QemuServer/CPUConfig.pm b/PVE/QemuServer/CPUConfig.pm
index 750d3b6..cc71298 100644
--- a/PVE/QemuServer/CPUConfig.pm
+++ b/PVE/QemuServer/CPUConfig.pm
@@ -3,6 +3,8 @@ package PVE::QemuServer::CPUConfig;
 use strict;
 use warnings;
 
+use List::Util qw(first);
+
 use PVE::JSONSchema;
 use PVE::Cluster qw(cfs_register_file cfs_read_file);
 use PVE::QemuServer::Helpers qw(min_version);
@@ -12,6 +14,7 @@ use base qw(PVE::SectionConfig Exporter);
 our @EXPORT_OK = qw(
 print_cpu_device
 get_cpu_options
+cpu_type_to_arch
 );
 
 # under certain race-conditions, this module might be loaded before pve-cluster
@@ -57,6 +60,17 @@ my $depreacated_cpu_map = {
     'Icelake-Client-noTSX' => 'Icelake-Server-noTSX',
 };
 
+my @cpu_32bit_list = (
+    '486',
+    'pentium',
+    'pentium2',
+    'pentium3',
+    'coreduo',
+    'athlon',
+    'kvm32',
+    'qemu32',
+);
+
 my $cpu_vendor_list = {
     # Intel CPUs
     486 => 'GenuineIntel',
@@ -646,6 +660,20 @@ sub get_pve_cpu_flags {
     return $pve_flags;
 }
 
+sub cpu_type_to_arch {
+    my ($cputype) = @_;
+
+    if ($cputype) {
+	if (first {$_ eq $cputype} @cpu_32bit_list) {
+	    return 'i386';
+	} elsif ($cpu_vendor_list->{$cputype}) {
+	    return 'x86_64';
+	}
+    }
+
+    return undef;
+}
+
 sub get_hyperv_enlightenments {
     my ($winversion, $machine_version, $bios, $gpu_passthrough, $hv_vendor_id) = @_;
 
-- 
2.39.2





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-12-14  9:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-11 14:12 [pve-devel] [PATCH qemu-server] Properly identify the CPU architecture of 32-bit VMs Filip Schauer
2023-12-11 14:37 ` Fiona Ebner
2023-12-12 10:39   ` Filip Schauer
2023-12-12 11:48     ` Fiona Ebner
2023-12-13 17:31       ` Filip Schauer
2023-12-14  9:13         ` Fiona Ebner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal