public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Filip Schauer <f.schauer@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: Re: [pve-devel] [PATCH v2 qemu-server] Prevent starting a 32-bit VM using a 64-bit OVMF BIOS
Date: Tue, 12 Dec 2023 12:00:38 +0100	[thread overview]
Message-ID: <5f000968-b643-470e-9e04-fb379bb7ddbf@proxmox.com> (raw)
In-Reply-To: <20231212103708.35372-1-f.schauer@proxmox.com>

A much simpler patch v3 is available:
https://lists.proxmox.com/pipermail/pve-devel/2023-December/061036.html

On 12/12/2023 11:37, 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.
>
> Signed-off-by: Filip Schauer <f.schauer@proxmox.com>
> ---
>   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');




      reply	other threads:[~2023-12-12 11:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-12 10:37 Filip Schauer
2023-12-12 11:00 ` Filip Schauer [this message]

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=5f000968-b643-470e-9e04-fb379bb7ddbf@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal