Skip to content

vmm: Synchronize vCPU TSC on restore#8437

Open
rbradford wants to merge 2 commits into
cloud-hypervisor:mainfrom
rbradford:202606/tsc-synch-restore
Open

vmm: Synchronize vCPU TSC on restore#8437
rbradford wants to merge 2 commits into
cloud-hypervisor:mainfrom
rbradford:202606/tsc-synch-restore

Conversation

@rbradford

Copy link
Copy Markdown
Member
  • hypervisor: kvm: Reduce fully qualified paths
  • vmm: cpu: Re-sync vCPU TSC offsets after restore

Reduce, but don't fully eliminate the fully qualified std:: paths.

Signed-off-by: Rob Bradford <rbradford@meta.com>
@rbradford rbradford requested a review from a team as a code owner June 19, 2026 08:41
Restoring a snapshot (snapshot restore or live-migration receive) sets
each vCPU's TSC by writing MSR_IA32_TSC as the vCPU is created.

However because CpuManager creates and restores vCPUs one at a time, the
host TSC advances between the per-vCPU writes and KVM derives a slightly
different TSC offset for each vCPU.

KVM only engages its masterclock when every offset matches. This has a
side effect of breaking the HyperV TSC reference clock page resulting in
significantly reduced performance on Windows.

After restore synchronise all vCPU's TSC offset to the boot vCPU's via
the KVM_VCPU_TSC_CTRL device attribute group (Linux 5.16+) this allows
the KVM TSC masterclock to engage and mitigates performance issues with
the KVM HyperV emulation.

See: cloud-hypervisor#8383

Signed-off-by: Rob Bradford <rbradford@meta.com>
Assisted-by: Claude <claude-opus-4-8>
@rbradford rbradford force-pushed the 202606/tsc-synch-restore branch from aa36397 to eac6f77 Compare June 19, 2026 08:42
@rbradford

Copy link
Copy Markdown
Member Author

@tonicmuroq I think this should also mitigate the issue that you were trying to fix in #8383

Comment thread hypervisor/src/kvm/mod.rs

#[cfg(target_arch = "x86_64")]
ioctl_io_nr!(KVM_NMI, kvm_bindings::KVMIO, 0x9a);
// kvm-ioctls only exposes the vCPU device-attribute ioctls for aarch64.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we fix this in kvm-ioctls?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants