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 docs/qemu-server v3 0/6] live migrate VMs with an invariant TSC or re-enlightenment
Date: Mon, 30 Nov 2026 19:34:07 +0100	[thread overview]
Message-ID: <20261130183418.617530-1-j.theisen@proxmox.com> (raw)

This series sets an explicit TSC frequency for VMs whose guest relies on
a TSC frequency that does not change, so that they can be live
migrated, and checks upfront whether the target node can provide it.
It builds on the series "check the target node's CPU before live
migrating a VM" [0], from which it was split out in v3, and needs to
be applied on top of it.

The invariant TSC flag 'invtsc' can be enabled with custom CPU models.
Without an explicit TSC frequency, QEMU blocks live migration,
snapshots with RAM and hibernation of such VMs. Guests need the flag to
rely on the TSC as clock source, for example for applications reading
it directly or for nested hypervisors. In benchmarks of Windows guests
with virtualization-based security (VBS) and the 'host' CPU type, it
considerably reduced the performance cost of VBS, for example for
context switches and thread creation. Nodes now also report whether
they support invtsc.
Previously, they never reported it, as QEMU omits it from the
migratable 'host' CPU model, so the "Supported On" column of the flag
selector of the custom CPU model editor was always empty for it.

The 'hv-reenlightenment' flag is added as well. It notifies nested
Hyper-V guests, for example Windows with WSL2 or VBS, about TSC
frequency changes from live migrations. Together with 'hv-frequencies',
which custom CPU models can enable, this lets them keep a stable clock
source for their own guests. Without it, guests do not use the
notifications. 'hv-frequencies' is not enabled by this series. The flag
is added in preparation for 'hv-frequencies' to become usable.

For both flags, the TSC frequency is set explicitly to the host's,
which is queried via KVM_GET_TSC_KHZ on a temporary VM, as upstream
Linux does not export it otherwise. The 'host-cpu-info' entry each
node broadcasts additionally includes the TSC frequency and whether KVM
can scale the TSC, so the migration checks block:

- 'hv-reenlightenment' or 'invtsc', target can neither scale the TSC
  nor match the VM's TSC frequency within 250 ppm
- 'invtsc' on a VM that was started without an explicit TSC frequency,
  for example before the update: QEMU blocks its migration anyway, but
  only after the target instance was started and local disks were
  copied. It is refused upfront for every target, until the VM is
  restarted.

The precondition API reports both with the new 'tsc-frequency' type in
'incompatible-cpu'. pve-manager needs no changes, as pvestatd
broadcasts whatever qemu-server provides.

[0] cover letter of "[PATCH docs/manager/qemu-server v3 00/18] check
    the target node's CPU before live migrating a VM"

Testing:

Upgrading the packages reloads pvestatd, so that it broadcasts the TSC
information and the 'cpuflags-kvm' entry including invtsc. Only when
deploying the code without the packages, restart pvestatd manually.
Start the test VMs only afterwards, as only VMs started with this
series get an explicit TSC frequency, without which the TSC check does
not apply.

The TSC check can be tested on a cluster with identical CPUs by making
the target node broadcast a different TSC frequency. pvestatd
broadcasts 'host-cpu-info' again whenever it differs, so stop it first.
The following only changes the TSC information, to a 'tsc-khz' clearly
different from the real one, as the check tolerates 250 ppm:

  systemctl stop pvestatd
  perl -MPVE::Cluster -MPVE::INotify -MJSON -e '
      PVE::Cluster::cfs_update();
      my $node = PVE::INotify::nodename();
      my $info = decode_json(PVE::Cluster::get_node_kv("host-cpu-info", $node)->{$node});
      $info->{"tsc-khz"} = 1000000;
      $info->{"tsc-scaling"} = 0;
      PVE::Cluster::broadcast_node_kv("host-cpu-info", encode_json($info));
  '

Restarting pvestatd broadcasts the real values again:

  systemctl restart pvestatd

What to expect for a running VM:

- 'tsc-scaling' 0 and a 'tsc-khz' more than 250 ppm off: blocked for
  VMs with 'flags=+hv-reenlightenment' or a custom CPU model with
  '+invtsc'
- 'invtsc' removed from 'cpuflags-kvm' on the target for a VM with
  a custom CPU model with '+invtsc' and a reported model other than
  'host', for example the default 'kvm64': blocked, without override.
  With reported model 'host', it is blocked like other flags missing
  for 'host', so it can be overridden. VMs with CPU type 'host' do not
  have invtsc unless enabled explicitly, so they are not blocked.
- a VM with a custom CPU model with '+invtsc' that was started without
  an explicit TSC frequency, for example with
  'args: -cpu kvm64,enforce,+invtsc' on a node with an invariant TSC:
  blocked for every target, until it is restarted without 'args'

The invtsc support of a node requires a host CPU with an invariant TSC,
which nested nodes only have if their own CPU has 'invtsc' enabled.
After the upgrade, the "Supported On" column of the flag selector of
the custom CPU model editor lists such nodes for invtsc.

Changes since v2 (as part of the series "check the target node's CPU
before live migrating a VM"):
* split out into this series
* new: refuse the live migration of VMs with invtsc that were started
  without an explicit TSC frequency, for example before the update,
  upfront. QEMU blocks their migration anyway, but only after the
  target instance was started and local disks were copied. Whether the
  vCPUs have invtsc is queried from QEMU, as 'host' and 'max' drop it
  if the host lacks it.
* describe in the flag description, the commit message and the docs that
  guests only use 'hv-reenlightenment' together with 'hv-frequencies'
* tests: use the helper for the migration tests of the CPU checks, and
  add tests for the edge of the TSC tolerance and invtsc with TCG
* new: cfg2cmd test for a disabled 'hv-reenlightenment' flag
* docs: mention that VMs started without an explicit TSC frequency need
  a restart before they can be live migrated
* fix the trailing newline of the invtsc cfg2cmd test
* rebased onto current master

Changes since v1 (as part of the series "check the target node's CPU
before live migrating a VM"):
* new: report the invtsc support of nodes
* new: set the TSC frequency for invtsc, as for 'hv-reenlightenment',
  so that such VMs can be live migrated, and extend the TSC check of
  the target node to it
* new: docs for 'hv-reenlightenment' and invtsc


qemu-server:

Jonas Theisen (5):
  cpu flags: report invtsc support of nodes
  helpers: add helper to query the host's TSC frequency and scaling
    support
  cpu config: add hv-reenlightenment flag and set TSC frequency for it
  migrate: block migration to nodes with incompatible TSC for
    re-enlightenment
  cpu config: set TSC frequency for invtsc to allow live migration

 src/PVE/API2/Qemu.pm                          |   8 +-
 src/PVE/QemuMigrate/Helpers.pm                |  82 +++++++++-
 src/PVE/QemuServer.pm                         |  15 ++
 src/PVE/QemuServer/CPUConfig.pm               |  35 +++++
 src/PVE/QemuServer/CPUFlags.pm                |   8 +
 src/PVE/QemuServer/Helpers.pm                 |  65 ++++++++
 src/test/MigrationTest/QemuMigrateMock.pm     |  12 +-
 src/test/QemuServerTest/CommandLineMocks.pm   |   7 +
 .../cpu-hv-reenlightenment-disabled.conf      |   6 +
 .../cpu-hv-reenlightenment-disabled.conf.cmd  |  26 ++++
 src/test/cfg2cmd/cpu-hv-reenlightenment.conf  |   6 +
 .../cfg2cmd/cpu-hv-reenlightenment.conf.cmd   |  26 ++++
 src/test/cfg2cmd/cpu-invtsc.conf              |   6 +
 src/test/cfg2cmd/cpu-invtsc.conf.cmd          |  27 ++++
 src/test/run_api_tests.pl                     |  23 ++-
 src/test/run_qemu_migrate_tests.pl            | 144 +++++++++++++++++-
 16 files changed, 488 insertions(+), 8 deletions(-)
 create mode 100644 src/test/cfg2cmd/cpu-hv-reenlightenment-disabled.conf
 create mode 100644 src/test/cfg2cmd/cpu-hv-reenlightenment-disabled.conf.cmd
 create mode 100644 src/test/cfg2cmd/cpu-hv-reenlightenment.conf
 create mode 100644 src/test/cfg2cmd/cpu-hv-reenlightenment.conf.cmd
 create mode 100644 src/test/cfg2cmd/cpu-invtsc.conf
 create mode 100644 src/test/cfg2cmd/cpu-invtsc.conf.cmd


docs:

Jonas Theisen (1):
  qm: document hv-reenlightenment and invtsc

 qm.adoc | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)


Summary over all repositories:
  17 files changed, 512 insertions(+), 8 deletions(-)

-- 
Generated by murpp 0.12.1




             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 Jonas Theisen [this message]
2026-11-30 18:34 ` [PATCH qemu-server v3 1/6] cpu flags: report invtsc support of nodes Jonas Theisen
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-1-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