[pve-devel] [PATCH qemu-server 3/3] fix #7014: fix regression starting aarch64 VMs with machine type >= 10.1

Fiona Ebner f.ebner at proxmox.com
Wed Nov 12 12:29:40 CET 2025


The 'virt' machine type used for 'aarch64' does not support the 'hpet'
machine flag. Change add_machine_flag() to only add the flag when the
current machine type supports it and rename the method to
add_machine_flag_if_supported() to make the behavior obvious from the
name. If a future caller really depends on adding a specific flag and
would rather die when the machine type does not support it, it can
check the return value whether the flag was successfully added or not.

Fixes: 3a4e0144 ("cfg2cmd: turn off hpet for Linux VMs running at least kernel 2.6 and machine type >= 10.1")
Signed-off-by: Fiona Ebner <f.ebner at proxmox.com>
---
 src/PVE/QemuServer.pm               |  3 ++-
 src/PVE/QemuServer/Cfg2Cmd.pm       | 26 ++++++++++++++++++++++----
 src/PVE/QemuServer/Cfg2Cmd/Timer.pm |  4 ++--
 3 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index cf195ccc..9abcd5bf 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -3388,7 +3388,8 @@ sub config_to_command {
     }
 
     # For now, handles only specific parts, but the final goal is to cover everything.
-    my $cfg2cmd = PVE::QemuServer::Cfg2Cmd->new($conf, $defaults, $version_guard);
+    my $cfg2cmd_opts = { forcemachine => $forcemachine };
+    my $cfg2cmd = PVE::QemuServer::Cfg2Cmd->new($conf, $defaults, $version_guard, $cfg2cmd_opts);
     my $generated = $cfg2cmd->generate();
     push $cmd->@*, '-global', $_ for ($generated->global_flags() // [])->@*;
     push $machineFlags->@*, ($generated->machine_flags() // [])->@*;
diff --git a/src/PVE/QemuServer/Cfg2Cmd.pm b/src/PVE/QemuServer/Cfg2Cmd.pm
index c7ee0165..36149aba 100644
--- a/src/PVE/QemuServer/Cfg2Cmd.pm
+++ b/src/PVE/QemuServer/Cfg2Cmd.pm
@@ -5,9 +5,10 @@ use strict;
 
 use PVE::QemuServer::Cfg2Cmd::Timer;
 use PVE::QemuServer::Helpers;
+use PVE::QemuServer::Machine;
 
 sub new {
-    my ($class, $conf, $defaults, $version_guard) = @_;
+    my ($class, $conf, $defaults, $version_guard, $opts) = @_;
 
     my $self = bless {
         conf => $conf,
@@ -18,6 +19,10 @@ sub new {
     $self->{ostype} = $self->get_prop('ostype');
     $self->{'windows-version'} = PVE::QemuServer::Helpers::windows_version($self->{ostype});
 
+    my $arch = PVE::QemuServer::Helpers::get_vm_arch($conf);
+    $self->{'machine-type'} =
+        PVE::QemuServer::Machine::get_vm_machine($conf, $opts->{forcemachine}, $arch);
+
     return $self;
 }
 
@@ -51,10 +56,23 @@ sub global_flags {
     return $self->{'global-flags'};
 }
 
-sub add_machine_flag {
-    my ($self, $flag) = @_;
+=head3 add_machine_flag_if_supported
 
-    push $self->{'machine-flags'}->@*, $flag;
+    my $success = $self->add_machine_flag_if_supported($flag_name, $value);
+
+Add flag C<$flag_name> with value C<$value> to the machine flags if the current machine type
+supports it. Returns whether the flag was added or not.
+
+=cut
+
+sub add_machine_flag_if_supported {
+    my ($self, $flag_name, $value) = @_;
+
+    return if !PVE::QemuServer::Machine::machine_supports_flag($self->{'machine-type'}, $flag_name);
+
+    push $self->{'machine-flags'}->@*, "${flag_name}=${value}";
+
+    return 1;
 }
 
 sub machine_flags {
diff --git a/src/PVE/QemuServer/Cfg2Cmd/Timer.pm b/src/PVE/QemuServer/Cfg2Cmd/Timer.pm
index 452c15b2..d03715a0 100644
--- a/src/PVE/QemuServer/Cfg2Cmd/Timer.pm
+++ b/src/PVE/QemuServer/Cfg2Cmd/Timer.pm
@@ -20,9 +20,9 @@ sub generate {
 
     if ($cfg2cmd->windows_version() >= 6) {
         $cfg2cmd->add_global_flag('kvm-pit.lost_tick_policy=discard');
-        $cfg2cmd->add_machine_flag('hpet=off');
+        $cfg2cmd->add_machine_flag_if_supported('hpet', 'off');
     } elsif ($cfg2cmd->is_linux() && $cfg2cmd->version_guard(10, 1, 0)) {
-        $cfg2cmd->add_machine_flag('hpet=off');
+        $cfg2cmd->add_machine_flag_if_supported('hpet', 'off');
     }
 
     $cfg2cmd->add_rtc_flag('driftfix=slew') if $time_drift_fix;
-- 
2.47.3





More information about the pve-devel mailing list