Skip to content

Batch register restore on MSHV and WHP - #1774

Merged
ludfjig merged 3 commits into
hyperlight-dev:mainfrom
ludfjig:batch_register
Aug 27, 2026
Merged

Batch register restore on MSHV and WHP#1774
ludfjig merged 3 commits into
hyperlight-dev:mainfrom
ludfjig:batch_register

Conversation

@ludfjig

@ludfjig ludfjig commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Batch general, debug, special, XCR0, and MSR writes during x86_64 vCPU restore on MSHV and WHP.

benchmarks (vs main branch):

MSHV:

snapshots/restore/default
time: [83.550 µs 84.031 µs 84.443 µs]
change: [−29.780% −28.618% −27.365%] (p = 0.00 < 0.05)
Performance has improved.

snapshots/restore/small time: [91.355 µs 92.208 µs 93.294 µs]
change: [−24.927% −22.241% −19.535%] (p = 0.00 < 0.05)
Performance has improved.

snapshots/restore/medium
time: [105.37 µs 105.78 µs 106.27 µs]
change: [−28.331% −21.040% −12.627%] (p = 0.00 < 0.05)
Performance has improved.

snapshots/restore/large time: [167.54 µs 169.86 µs 172.89 µs]
change: [−31.405% −9.3155% +20.327%] (p = 0.53 > 0.05)
No change in performance detected.

WHP:

my windows machine is too noisy to measure

KVM:

no difference

@ludfjig
ludfjig force-pushed the batch_register branch 2 times, most recently from a1f08a2 to 11799f4 Compare August 26, 2026 22:50
@ludfjig ludfjig added the kind/enhancement For PRs adding features, improving functionality, docs, tests, etc. label Aug 26, 2026
@ludfjig
ludfjig marked this pull request as ready for review August 27, 2026 00:20
@ludfjig
ludfjig requested a review from danbugs as a code owner August 27, 2026 00:20
Copilot AI lite review requested due to automatic review settings August 27, 2026 00:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR reduces x86_64 snapshot-restore overhead by batching general/debug/special/XCR0/MSR register writes into a single backend call when running on MSHV or WHP, avoiding multiple hypercalls during vCPU reset.

Changes:

  • Extend the VirtualMachine trait with a batched-register write API and plumb new RegisterError variants for it.
  • Implement batched register restore for WHP and MSHV, with KVM/HVF reporting the capability as unsupported.
  • Fold MSR restore into HyperlightVm::reset_vcpu and update sandbox restore to pass snapshot MSRs into the reset path.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/hyperlight_host/src/sandbox/initialized_multi_use.rs Pass snapshot MSRs into reset_vcpu so restore can batch state updates.
src/hyperlight_host/src/hypervisor/virtual_machine/whp.rs Add WHP batched register write implementation via set_registers.
src/hyperlight_host/src/hypervisor/virtual_machine/mshv/x86_64.rs Add MSHV batched register write implementation via set_reg.
src/hyperlight_host/src/hypervisor/virtual_machine/mod.rs Define the batched-register capability + API on the backend trait and add new error variants.
src/hyperlight_host/src/hypervisor/virtual_machine/kvm/x86_64.rs Explicitly mark batching as unsupported on KVM.
src/hyperlight_host/src/hypervisor/virtual_machine/hvf/mod.rs Explicitly mark batching as unsupported on HVF.
src/hyperlight_host/src/hypervisor/hyperlight_vm/x86_64.rs Use the new capability to batch reset writes and incorporate MSR restore into reset.
src/hyperlight_host/src/hypervisor/hyperlight_vm/test_support.rs Forward the new trait methods through the fault-injecting VM wrapper.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/hyperlight_host/src/hypervisor/virtual_machine/mod.rs Outdated
Comment thread src/hyperlight_host/src/hypervisor/virtual_machine/whp.rs
Comment thread src/hyperlight_host/src/hypervisor/hyperlight_vm/x86_64.rs Outdated
Comment thread src/hyperlight_host/src/hypervisor/hyperlight_vm/x86_64.rs
Comment thread src/hyperlight_host/src/hypervisor/hyperlight_vm/x86_64.rs
Comment thread src/hyperlight_host/src/hypervisor/hyperlight_vm/test_support.rs
Comment thread src/hyperlight_host/src/hypervisor/hyperlight_vm/test_support.rs
Comment thread src/hyperlight_host/src/hypervisor/hyperlight_vm/x86_64.rs Outdated
Comment thread src/hyperlight_host/src/hypervisor/virtual_machine/kvm/x86_64.rs Outdated
Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
@ludfjig
ludfjig merged commit 1d0deec into hyperlight-dev:main Aug 27, 2026
56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement For PRs adding features, improving functionality, docs, tests, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants