Skip to content

Conversation

@ludfjig
Copy link
Contributor

@ludfjig ludfjig commented Dec 16, 2025

MSRs will be added in another PR.

  • Add debug register abstraction over hv implementation
  • Removed padding fields from fpu register to simplify comparisons. Not sure why I added them to begin with, we don't need C repr on these. It could possibly allow more efficient into() implementation for kvm/mshv due to single memcyp, but that seems like premature optimization to me
  • Reset vcpu state on snapshot::restore
  • Added bunch of tests

@ludfjig ludfjig added the kind/enhancement For PRs adding features, improving functionality, docs, tests, etc. label Dec 16, 2025
@ludfjig ludfjig force-pushed the reset_vcpu branch 3 times, most recently from 9cfcc9c to 8507c7a Compare December 16, 2025 19:52
}

#[cfg(test)]
#[cfg(feature = "init-paging")]
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be valid for more than just init paging feature?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes will fix before publishing pr

xsave
}

fn hyperlight_vm(code: &[u8]) -> Result<HyperlightVm> {
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't this duplicating alot of the configuration code we do during VM setup in the test? how will we maintain this with the actual setup? What if there is a difference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is calling HyperlightVm::new so they should be the same

@ludfjig ludfjig force-pushed the reset_vcpu branch 2 times, most recently from b522e52 to b9dfb2a Compare December 16, 2025 21:46
Signed-off-by: Ludvig Liljenberg <[email protected]>
Signed-off-by: Ludvig Liljenberg <[email protected]>
@ludfjig ludfjig force-pushed the reset_vcpu branch 8 times, most recently from f7c0224 to d09b1fc Compare December 17, 2025 04:51
Signed-off-by: Ludvig Liljenberg <[email protected]>
Copy link
Contributor

Copilot AI left a comment

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 enhances vCPU state management during snapshot restoration by adding debug register abstraction and ensuring all vCPU state is properly reset. The changes follow the established Common* struct pattern for hypervisor abstraction and include comprehensive test coverage across KVM, MSHV, and WHP hypervisors.

Key changes:

  • Added CommonDebugRegs abstraction with implementations for all supported hypervisors (KVM, MSHV, WHP)
  • Removed padding fields from CommonFpu to simplify comparisons while maintaining correct conversions to hypervisor-specific types
  • Implemented reset_vcpu() to reset general purpose registers, debug registers, FPU/XSAVE state, and special registers
  • Added reset_vcpu() call in MultiUseSandbox::restore() to ensure clean state after snapshot restoration
  • Added extensive tests covering all reset scenarios with both direct state setting and actual code execution

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/hyperlight_host/src/hypervisor/regs/debug_regs.rs New file implementing CommonDebugRegs abstraction with conversions for KVM, MSHV, and WHP
src/hyperlight_host/src/hypervisor/regs/fpu.rs Removed pad1 and pad2 fields from CommonFpu; updated all conversions to use literal 0 for padding
src/hyperlight_host/src/hypervisor/regs.rs Added debug_regs module export
src/hyperlight_host/src/hypervisor/mod.rs Added debug_regs, set_debug_regs, reset_xsave, and set_xsave methods to Hypervisor trait
src/hyperlight_host/src/hypervisor/kvm.rs Implemented debug register and xsave methods for KVM hypervisor
src/hyperlight_host/src/hypervisor/hyperv_linux.rs Implemented debug register and xsave methods for MSHV hypervisor
src/hyperlight_host/src/hypervisor/hyperv_windows.rs Implemented debug register and xsave methods for WHP; refactored gdb breakpoint code to use new abstractions
src/hyperlight_host/src/hypervisor/hyperlight_vm.rs Added reset_vcpu() method and comprehensive test suite covering all vCPU state reset scenarios
src/hyperlight_host/src/sandbox/initialized_multi_use.rs Added reset_vcpu() call in restore() and test to verify debug registers are reset
src/hyperlight_host/src/sandbox/hypervisor.rs Added Copy and Clone derives to HypervisorType enum
src/hyperlight_host/src/mem/layout.rs Changed visibility from pub(super) to pub(crate) for methods used by tests
src/tests/rust_guests/simpleguest/src/main.rs Added SetDr0 and GetDr0 guest functions for testing debug register reset
.github/workflows/ValidatePullRequest.yml Changed fail-fast from true to false for build-test job to allow all matrix combinations to complete

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.

2 participants