all lists on 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 v2 09/20] cpu flags: report invtsc support of nodes
Date: Tue, 24 Nov 2026 17:30:33 +0100	[thread overview]
Message-ID: <20261124163136.320992-10-j.theisen@proxmox.com> (raw)
In-Reply-To: <20261124163136.320992-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                     | 14 ++++
 src/test/MigrationTest/QemuMigrateMock.pm |  2 +-
 src/test/run_qemu_migrate_tests.pl        | 81 +++++++++++++++++++++++
 4 files changed, 101 insertions(+), 3 deletions(-)

diff --git a/src/PVE/QemuMigrate/Helpers.pm b/src/PVE/QemuMigrate/Helpers.pm
index 48e4da5e..817bd923 100644
--- a/src/PVE/QemuMigrate/Helpers.pm
+++ b/src/PVE/QemuMigrate/Helpers.pm
@@ -271,11 +271,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->{$_}
-                    && ($cpu->{props}->{$_} // '') ne 'off'
+                    && ($props->{$_} // '') ne 'off'
             } @flags;
             return if !scalar(@missing);
 
diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index ecbaa27f..166b02a0 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -3045,6 +3045,20 @@ sub query_supported_cpu_flags {
 
                 $flags->{$prop} = 1;
             }
+
+            # '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 ($unmigratable->{model}->{props}->{invtsc} // '') eq JSON::true;
+            }
         };
         my $err = $@;
 
diff --git a/src/test/MigrationTest/QemuMigrateMock.pm b/src/test/MigrationTest/QemuMigrateMock.pm
index 6295736f..a27788dc 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 9cd85990..90e42f2e 100755
--- a/src/test/run_qemu_migrate_tests.pl
+++ b/src/test/run_qemu_migrate_tests.pl
@@ -1872,6 +1872,87 @@ my $tests = [
             },
         },
     },
+    {
+        # 'host' only has invtsc if enabled explicitly, older nodes do not broadcast it
+        name => '1033_running_host_cpu_invtsc_not_enabled',
+        target => 'pve1',
+        vmid => 1033,
+        vm_status => {
+            running => 1,
+            runningmachine => 'pc-q35-5.0+pve0',
+            runningcpu => 'host,+kvm_pv_eoi,+kvm_pv_unhalt',
+        },
+        cpu_info => {
+            source => { vendor => 'GenuineIntel' },
+            nodes => {
+                pve1 => { vendor => 'GenuineIntel' },
+            },
+            'kvm-flags' => {
+                pve0 => 'fpu invtsc sse',
+                pve1 => 'fpu sse',
+            },
+        },
+        opts => {
+            online => 1,
+        },
+        config_patch => {
+            cpu => 'host',
+        },
+        expected_calls => $default_expected_calls_online,
+        expected => {
+            source_volids => {},
+            target_volids => {},
+            vm_config => get_patched_config(1033, {
+                    cpu => 'host',
+            }),
+            vm_status => {
+                running => 1,
+                runningmachine => 'pc-q35-5.0+pve0',
+            },
+        },
+    },
+    {
+        name => '1033_running_host_cpu_invtsc_enabled',
+        target => 'pve1',
+        vmid => 1033,
+        vm_status => {
+            running => 1,
+            runningmachine => 'pc-q35-5.0+pve0',
+            runningcpu => 'host,+invtsc,+kvm_pv_eoi,+kvm_pv_unhalt',
+        },
+        cpu_info => {
+            source => { vendor => 'GenuineIntel' },
+            nodes => {
+                pve1 => { vendor => 'GenuineIntel' },
+            },
+            'kvm-flags' => {
+                pve0 => 'fpu invtsc sse',
+                pve1 => 'fpu sse',
+            },
+        },
+        opts => {
+            online => 1,
+        },
+        config_patch => {
+            cpu => 'host',
+        },
+        expected_calls => {},
+        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",
+        expected => {
+            source_volids => {},
+            target_volids => {},
+            vm_config => get_patched_config(1033, {
+                    cpu => 'host',
+            }),
+            vm_status => {
+                running => 1,
+                runningmachine => 'pc-q35-5.0+pve0',
+                runningcpu => 'host,+invtsc,+kvm_pv_eoi,+kvm_pv_unhalt',
+            },
+        },
+    },
     {
         name => '1033_running_host_cpu_other_model',
         target => 'pve1',
-- 
2.47.3





  parent reply	other threads:[~2026-11-24 16:33 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 16:30 [PATCH docs/manager/qemu-server v2 00/20] check the target node's CPU before live migrating a VM Jonas Theisen
2026-11-24 16:30 ` [PATCH qemu-server v2 01/20] test: migration: allow checking for warnings and errors in the log Jonas Theisen
2026-11-24 16:30 ` [PATCH qemu-server v2 02/20] migrate: block live migration of host CPU VMs between CPU vendors Jonas Theisen
2026-11-24 16:30 ` [PATCH qemu-server v2 03/20] fix #6535: migrate: warn about live migration " Jonas Theisen
2026-11-24 16:30 ` [PATCH qemu-server v2 04/20] cpu flags: factor out parsing the broadcast CPU flags of a node Jonas Theisen
2026-11-24 16:30 ` [PATCH qemu-server v2 05/20] fix #2924: migrate: block live migration of host CPU VMs to nodes lacking flags Jonas Theisen
2026-11-24 16:30 ` [PATCH qemu-server v2 06/20] migrate: warn about live migration of host CPU VMs between CPU models Jonas Theisen
2026-11-24 16:30 ` [PATCH qemu-server v2 07/20] migrate: factor out whether the running virtual CPU is kept Jonas Theisen
2026-11-24 16:30 ` [PATCH qemu-server v2 08/20] migrate: block migration if the target cannot run the virtual CPU Jonas Theisen
2026-11-24 16:30 ` Jonas Theisen [this message]
2026-11-24 16:30 ` [PATCH qemu-server v2 10/20] helpers: add helper to query the host's TSC frequency and scaling support Jonas Theisen
2026-11-24 16:30 ` [PATCH qemu-server v2 11/20] cpu config: add hv-reenlightenment flag and set TSC frequency for it Jonas Theisen
2026-11-24 16:30 ` [PATCH qemu-server v2 12/20] migrate: block migration to nodes with incompatible TSC for re-enlightenment Jonas Theisen
2026-11-24 16:30 ` [PATCH qemu-server v2 13/20] cpu config: set TSC frequency for invtsc to allow live migration Jonas Theisen
2026-11-24 16:30 ` [PATCH qemu-server v2 14/20] migrate: factor out asserting the CPU compatibility of the target Jonas Theisen
2026-11-24 16:30 ` [PATCH qemu-server v2 15/20] api: migrate: check the CPU of the target before requesting HA migration Jonas Theisen
2026-11-24 16:30 ` [PATCH manager v2 16/20] pvestatd: broadcast host CPU information relevant for live migration Jonas Theisen
2026-11-24 16:30 ` [PATCH manager v2 17/20] ui: migrate: show why the CPU of the target node is incompatible Jonas Theisen
2026-11-24 16:30 ` [PATCH manager v2 18/20] fix #6535: ui: migrate: show CPU warnings for the target node Jonas Theisen
2026-11-24 16:30 ` [PATCH manager v2 19/20] api: nodes: migrateall: skip VMs whose CPU is incompatible with the target Jonas Theisen
2026-11-24 16:30 ` [PATCH docs v2 20/20] qm: document hv-reenlightenment, invtsc and CPU checks for migration 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=20261124163136.320992-10-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal