Repository navigation
Conversation
ludfjig
requested review from
andreiltd,
danbugs,
dblnz,
devigned,
jprendes,
jsturtevant,
simongdavies,
squillace and
syntactically
as code owners
November 2, 2026 23:54
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The regression test can falsely fail due to scheduling delays and Hyper-V TSC_ADJUST behavior, while the documentation incorrectly guarantees rewind behavior across all backends.
3 open issues
What changed in this PR
This PR addresses #2014 by making KVM restore the guest TSC reliably during closely spaced sandbox restores, without an extra ioctl.
Changes:
- Write a decoy TSC before the snapshot value in the same
KVM_SET_MSRScall, with special handling for zero. - Add guest counter reads and regression tests for repeated restores and zero values.
- Document guest-time behavior and record the fix in the changelog.
| File | Description |
|---|---|
src/tests/rust_guests/simpleguest/src/main.rs |
Exposes ReadTsc for host tests. |
src/hyperlight_host/src/sandbox/initialized.rs |
Tests TSC rewind and zero-value restore. |
src/hyperlight_host/src/hypervisor/virtual_machine/kvm/x86_64.rs |
Adds paired TSC writes to bypass KVM synchronization. |
docs/msr.md |
Describes guest timing and the KVM restore mechanism. |
CHANGELOG.md |
Records the KVM TSC restore fix. |
Review effort: Balanced
ludfjig
marked this pull request as draft
November 3, 2026 00:08
ludfjig
force-pushed
the
kvm-tsc-restore
branch
from
November 3, 2026 00:36
e02c90e to
9d8531c
Compare
Restore did not rewind the guest TSC on KVM when restores were less than a second apart. KVM ignores a host TSC write within one second of the value it expects and treats it as a vCPU sync. Write a decoy TSC value half the counter range away immediately before the restored value, in the same KVM_SET_MSRS call. KVM then applies the restored value exactly, with no extra ioctl. KVM also syncs a zero write, so write a restored value of 0 as 1. Add tests that restore repeatedly and that restore a zero TSC. Fixes hyperlight-dev#2014 Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
ludfjig
force-pushed
the
kvm-tsc-restore
branch
from
November 3, 2026 01:42
c334b69 to
7591df8
Compare
Benchmark ResultsMeasured commit: kvm / amd (Linux) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
kvm / intel (Linux) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
mshv3 / amd (Linux) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
mshv3 / intel (Linux) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
hyperv-ws2025 / amd (Windows) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
hyperv-ws2025 / intel (Windows) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
Reported by |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Restore does not rewind the guest TSC on KVM when it comes less than about a second after the previous restore. Restore now writes a decoy TSC value half the counter range away just before the snapshot value, in the same
KVM_SET_MSRScall. KVM then applies the snapshot value exactly, with no extra ioctl.Fixes #2014