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 249F81FF066 for ; Tue, 24 Nov 2026 17:33:15 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 2D2A221691; Tue, 24 Nov 2026 17:32:44 +0100 (CET) From: Jonas Theisen 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 Message-ID: <20261124163136.320992-10-j.theisen@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261124163136.320992-1-j.theisen@proxmox.com> References: <20261124163136.320992-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: 1795537926181 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.077 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: JN2YRUKJRZ7L67VZVM73Z3L56UWPRT7C X-Message-ID-Hash: JN2YRUKJRZ7L67VZVM73Z3L56UWPRT7C 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 | 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