Repository navigation
Restore the guest TSC exactly on WHP - #2022
Conversation
There was a problem hiding this comment.
🔵 Needs a closer look
The hard-coded SDK bit controlling WHP partition feature exposure remains unverified because authoritative header retrieval failed and independent runtime validation requires a Windows host with TscAdjustSupport.
No open issues 🎉
What changed in this PR
This PR makes snapshot restore rewind the guest time-stamp counter (TSC) on WHP hosts with TscAdjustSupport. It also includes the KVM restore fix from #2015, aligning guest-time behavior across Hyperlight’s backends.
Changes:
- Disable
TscAdjustSupportduring WHP partition creation. - Include KVM’s decoy TSC write and regression tests for rewind and zero-value restore.
- Document TSC restore behavior and record both fixes in the changelog.
| File | Description |
|---|---|
src/tests/rust_guests/simpleguest/src/main.rs |
Add a guest function for reading the TSC. |
src/hyperlight_host/src/sandbox/initialized.rs |
Test TSC rewind and KVM zero-value restore. |
src/hyperlight_host/src/hypervisor/virtual_machine/whp/x86_64.rs |
Disable TSC adjustment support during partition creation. |
src/hyperlight_host/src/hypervisor/virtual_machine/kvm/x86_64.rs |
Prepend a decoy write to force TSC restoration. |
src/hyperlight_host/src/hypervisor/regs/x86_64/msrs.rs |
Remove an inaccurate comment about Hyper-V TSC storage. |
docs/msr.md |
Explain TSC rewind behavior and disabled adjustment support. |
CHANGELOG.md |
Record the KVM and WHP TSC restore fixes. |
Review effort: Balanced
7fa6952 to
f9412e1
Compare
This comment has been minimized.
This comment has been minimized.
On WHP hosts with TscAdjustSupport, restore does not rewind the guest TSC. Writing TSC shifts TSC_ADJUST by the same amount, and writing TSC_ADJUST shifts TSC back, so restoring both keeps the time since the snapshot. Clear TscAdjustSupport in the partition's processor feature banks, as the MSHV driver does. The probe then drops TSC_ADJUST from the reset set, and restore_rewinds_tsc runs on WHP too. Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
f9412e1 to
3245e42
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 |
On WHP hosts with
TscAdjustSupport, restore does not rewind the guest TSC. WritingTSCshiftsTSC_ADJUSTby the same amount, and writingTSC_ADJUSTshiftsTSCback, so restoring both keeps the time since the snapshot.This clears
TscAdjustSupportwhen creating the partition, as the MSHV driver does.restore_rewinds_tscnow runs on WHP. CI hosts lack the feature, so I tested on a host that has it. The test fails without the fix and passes with it.Fixes #2021