public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Jonas Theisen <j.theisen@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH qemu-server v3 1/6] cpu flags: report invtsc support of nodes
Date: Mon, 30 Nov 2026 19:34:08 +0100	[thread overview]
Message-ID: <20261130183418.617530-2-j.theisen@proxmox.com> (raw)
In-Reply-To: <20261130183418.617530-1-j.theisen@proxmox.com>

QEMU only considers the invariant TSC flag migratable if the TSC
frequency is set explicitly. As the 'host' CPU model is migratable by
default, its expansion never includes invtsc. So no node is reported to
support it, for example in the 'Supported On' column of the CPU flag
selector.

Query the expansion once more with 'migratable' disabled and report
invtsc if the host supports it. Only invtsc is taken from it, as other
features QEMU considers unmigratable must not be reported for the
migratable 'host' model.

The live migration check for the 'host' CPU model must not require
invtsc on the target if it was not enabled explicitly, as the VM does
not have it then, and nodes with an older version do not report it.

Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
 src/PVE/QemuMigrate/Helpers.pm            |  7 +++++--
 src/PVE/QemuServer.pm                     | 15 +++++++++++++++
 src/test/MigrationTest/QemuMigrateMock.pm |  2 +-
 src/test/run_qemu_migrate_tests.pl        | 20 ++++++++++++++++++++
 4 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/src/PVE/QemuMigrate/Helpers.pm b/src/PVE/QemuMigrate/Helpers.pm
index 8d255716..8d086d72 100644
--- a/src/PVE/QemuMigrate/Helpers.pm
+++ b/src/PVE/QemuMigrate/Helpers.pm
@@ -272,11 +272,14 @@ my $target_cpu_checks = [
             my $understood = $source->{'understood-flags'};
             my @flags = grep { !$understood || $understood->{$_} } keys $source_flags->%*;
 
+            my $props = $cpu->{props};
             my @missing = sort grep {
-                # Hyper-V enlightenments are not passed through, but set explicitly
+                # Hyper-V enlightenments are not passed through, but set explicitly. As
+                # 'host' is migratable by default, invtsc is only enabled explicitly, too.
                 !m/^hv-/
+                    && ($_ ne 'invtsc' || $cpu->{flags}->{invtsc})
                     && !$target_flags->{$_}
-                    && (PVE::JSONSchema::parse_boolean($cpu->{props}->{$_} // 'on') // 1)
+                    && (PVE::JSONSchema::parse_boolean($props->{$_} // 'on') // 1)
             } @flags;
             return if !scalar(@missing);
 
diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index f8b3094f..ce281b26 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -3040,6 +3040,21 @@ sub query_supported_cpu_flags {
 
             $flags->{$_} = 1
                 for PVE::QemuServer::CPUFlags::get_cpu_expansion_flags($cmd_result);
+
+            # 'host' omits invtsc while it is migratable, as QEMU only considers invtsc
+            # migratable with an explicit TSC frequency. It can still be enabled explicitly.
+            if ($kvm && $arch eq 'x86_64') {
+                $model->{props}->{migratable} = JSON::false;
+                my $unmigratable = mon_cmd(
+                    $fakevmid,
+                    'query-cpu-model-expansion',
+                    type => 'full',
+                    model => $model,
+                );
+                $flags->{invtsc} = 1
+                    if grep { $_ eq 'invtsc' }
+                    PVE::QemuServer::CPUFlags::get_cpu_expansion_flags($unmigratable);
+            }
         };
         my $err = $@;
 
diff --git a/src/test/MigrationTest/QemuMigrateMock.pm b/src/test/MigrationTest/QemuMigrateMock.pm
index 6f351375..21a85d40 100644
--- a/src/test/MigrationTest/QemuMigrateMock.pm
+++ b/src/test/MigrationTest/QemuMigrateMock.pm
@@ -270,7 +270,7 @@ $MigrationTest::Shared::cluster_module->mock(
 my $qemu_server_cpuflags_module = Test::MockModule->new("PVE::QemuServer::CPUFlags");
 $qemu_server_cpuflags_module->mock(
     query_understood_cpu_flags => sub {
-        return [qw(avx512f avx512vl fpu hv-relaxed lahf-lm sse sse4.2)];
+        return [qw(avx512f avx512vl fpu hv-relaxed invtsc lahf-lm sse sse4.2)];
     },
 );
 
diff --git a/src/test/run_qemu_migrate_tests.pl b/src/test/run_qemu_migrate_tests.pl
index a08cac19..92b96d8e 100755
--- a/src/test/run_qemu_migrate_tests.pl
+++ b/src/test/run_qemu_migrate_tests.pl
@@ -1824,6 +1824,26 @@ my $tests = [
             },
         },
     ),
+    cpu_migration_test(
+        # 'host' only has invtsc if enabled explicitly, older nodes do not broadcast it
+        name => '1033_running_host_cpu_invtsc_not_enabled',
+        cpu => 'host',
+        runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+        cpu_info => {
+            'kvm-flags' => { pve0 => 'fpu invtsc sse' },
+        },
+    ),
+    cpu_migration_test(
+        name => '1033_running_host_cpu_invtsc_enabled',
+        cpu => 'host',
+        runningcpu => 'host,+invtsc,+kvm_pv_eoi,+kvm_pv_unhalt',
+        cpu_info => {
+            'kvm-flags' => { pve0 => 'fpu invtsc sse' },
+        },
+        expect_die => "can't migrate VM to 'pve1' - incompatible CPU: CPU model 'host' passes"
+            . " through the flags of the host CPU, but the node lacks: invtsc - use"
+            . " 'allow-missing-cpu-flags' to override",
+    ),
     {
         name => '105_replicated_to_non_replication_target',
         target => 'pve1',
-- 
2.47.3





  reply	other threads:[~2026-11-30 18:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 18:34 [PATCH docs/qemu-server v3 0/6] live migrate VMs with an invariant TSC or re-enlightenment Jonas Theisen
2026-11-30 18:34 ` Jonas Theisen [this message]
2026-11-30 18:34 ` [PATCH qemu-server v3 2/6] helpers: add helper to query the host's TSC frequency and scaling support Jonas Theisen
2026-11-30 18:34 ` [PATCH qemu-server v3 3/6] cpu config: add hv-reenlightenment flag and set TSC frequency for it Jonas Theisen
2026-11-30 18:34 ` [PATCH qemu-server v3 4/6] migrate: block migration to nodes with incompatible TSC for re-enlightenment Jonas Theisen
2026-11-30 18:34 ` [PATCH qemu-server v3 5/6] cpu config: set TSC frequency for invtsc to allow live migration Jonas Theisen
2026-11-30 18:34 ` [PATCH docs v3 6/6] qm: document hv-reenlightenment and invtsc Jonas Theisen
2026-11-30 18:36 ` [PATCH docs/qemu-server v3 0/6] live migrate VMs with an invariant TSC or re-enlightenment Jonas Theisen

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=20261130183418.617530-2-j.theisen@proxmox.com \
    --to=j.theisen@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