From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 97D821FF0B7 for ; Mon, 30 Nov 2026 19:34:36 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id B47F8216F2; Mon, 30 Nov 2026 19:34:25 +0100 (CET) From: Jonas Theisen 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 Message-ID: <20261130183418.617530-2-j.theisen@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261130183418.617530-1-j.theisen@proxmox.com> References: <20261130183418.617530-1-j.theisen@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1796063660687 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.059 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: JOJI6M3NRY3INULGAGTHJX4FTYPNC4B4 X-Message-ID-Hash: JOJI6M3NRY3INULGAGTHJX4FTYPNC4B4 X-MailFrom: j.theisen@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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