[pve-devel] [PATCH v2 qemu-server] Prevent starting a 32-bit VM using a 64-bit OVMF BIOS

Filip Schauer f.schauer at proxmox.com
Tue Dec 12 12:00:38 CET 2023


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 at 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');




More information about the pve-devel mailing list