From: Filip Schauer <f.schauer@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH qemu-server] Properly identify the CPU architecture of 32-bit VMs
Date: Mon, 11 Dec 2023 15:12:56 +0100 [thread overview]
Message-ID: <20231211141256.27565-1-f.schauer@proxmox.com> (raw)
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
next reply other threads:[~2023-12-11 14:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-11 14:12 Filip Schauer [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231211141256.27565-1-f.schauer@proxmox.com \
--to=f.schauer@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.