public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH qemu-server 3/3] fix #7014: fix regression starting aarch64 VMs with machine type >= 10.1
Date: Wed, 12 Nov 2025 12:29:40 +0100	[thread overview]
Message-ID: <20251112112959.237909-4-f.ebner@proxmox.com> (raw)
In-Reply-To: <20251112112959.237909-1-f.ebner@proxmox.com>

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@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



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


  parent reply	other threads:[~2025-11-12 11:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-12 11:29 [pve-devel] [PATCH-SERIES qemu-server 0/3] " Fiona Ebner
2025-11-12 11:29 ` [pve-devel] [PATCH qemu-server 1/3] machine: add machine_base_type() helper Fiona Ebner
2025-11-12 11:29 ` [pve-devel] [PATCH qemu-server 2/3] machine: add machine_supports_flag() helper Fiona Ebner
2025-11-12 11:29 ` Fiona Ebner [this message]
2025-11-12 11:52   ` [pve-devel] [PATCH qemu-server 3/3] fix #7014: fix regression starting aarch64 VMs with machine type >= 10.1 Fiona Ebner
2025-11-13 22:13 ` [pve-devel] applied: [PATCH-SERIES qemu-server 0/3] " Thomas Lamprecht

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=20251112112959.237909-4-f.ebner@proxmox.com \
    --to=f.ebner@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