Skip to content

Conversation

@ludfjig
Copy link
Contributor

@ludfjig ludfjig commented Sep 30, 2025

This PR

  • refactors Hypervisor trait. It's now a minimal trait for common functionality of a minimal Vm. It abstracts over differences in kvm, mshv, whp. This traits only knows things like set/get registers, run, but nothing about guest functions or hyperlight specifics.
  • Introduces HyperlightVm struct. This is a new struct that contains the dyn Hypervisor above, as well as things like guest_ptr, rsp, memory-regions, gdb connections, etc. HyperlightVm knows about initialization, dispatching guest calls, gdb-debugging etc, guest-tracing, which Hypervisor trait doesn't. All code that was previously duplicated in kvm/mshv/whp now lives in HyperlightVm.
  • Slighty cleans up the windows whp implementation, unifying files and removing windows_hypervisor_platform.rs

When reviewing, new file hyperlight_vm.rs should be compared against old kvm.rs, hyperv_linux.rs, hyperv_windows.rs. Note: this PR should not modify/introduce new code (as best as possible). It primarily just moves code around and factors out duplicate code.

Most files changed in this PR are minimally changed. The following files are the important files to review:

  • src/hyperlight_host/src/hypervisor/hyperlight_vm.rs
  • src/hyperlight_host/src/hypervisor/hyperv_linux.rs
  • src/hyperlight_host/src/hypervisor/hyperv_windows.rs
  • src/hyperlight_host/src/hypervisor/windows_hypervisor_platform.rs
  • src/hyperlight_host/src/hypervisor/kvm.rs
  • src/hyperlight_host/src/hypervisor/mod.rs

Closes #465, #904

@ludfjig ludfjig force-pushed the vm_trait_new branch 3 times, most recently from 81f0d54 to 62fad87 Compare October 22, 2025 19:44
@ludfjig ludfjig added the kind/refactor For PRs that restructure or remove code without adding new functionality. label Oct 22, 2025
@ludfjig ludfjig force-pushed the vm_trait_new branch 17 times, most recently from 1562f26 to edc7f00 Compare October 24, 2025 20:15
@ludfjig ludfjig force-pushed the vm_trait_new branch 4 times, most recently from f6337f9 to 350b8e0 Compare October 28, 2025 18:05
@ludfjig ludfjig marked this pull request as ready for review October 28, 2025 18:39
@ludfjig ludfjig force-pushed the vm_trait_new branch 15 times, most recently from fa21515 to 0a033d6 Compare November 25, 2025 22:43
@ludfjig ludfjig changed the title Introduce new Vm trait Trim Hypervisor trait Nov 25, 2025
@ludfjig ludfjig force-pushed the vm_trait_new branch 2 times, most recently from 5a116e5 to ee7545e Compare November 26, 2025 19:09
}

#[cfg(test)]
mod tests {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed these tests are removed (on purpose). Turns out it does not even run the CODE below... I am planning on re-adding some unit tests in next PR

@ludfjig ludfjig marked this pull request as ready for review December 1, 2025 20:18
@ludfjig ludfjig requested a review from Copilot December 1, 2025 20:24
Copilot finished reviewing on behalf of ludfjig December 1, 2025 20:25
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 refactors the hypervisor architecture to improve code organization and reduce duplication. It introduces a minimal Hypervisor trait that abstracts only the essential differences between KVM, MSHV, and WHP implementations, while consolidating shared logic into a new HyperlightVm struct. The refactoring successfully eliminates duplicate code from platform-specific implementations and creates a clearer separation of concerns.

Key Changes

  1. New HyperlightVm struct: Contains hypervisor-agnostic logic previously duplicated across KVM/MSHV/WHP implementations, including memory management, guest initialization, debugging support, and crashdump generation.

  2. Trimmed Hypervisor trait: Now focuses only on core VM operations (run_vcpu, map_memory, unmap_memory, register operations), with platform-specific details abstracted away.

  3. Consolidated Windows implementation: Merged windows_hypervisor_platform.rs into hyperv_windows.rs and simplified the WHP implementation to match the new trait design.

Reviewed changes

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

Show a summary per file
File Description
hypervisor/hyperlight_vm.rs New file containing consolidated VM logic, memory management, initialization, and debugging support
hypervisor/mod.rs Refactored Hypervisor trait to minimal interface; moved helper functions
hypervisor/kvm.rs Simplified to implement only core Hypervisor trait methods
hypervisor/hyperv_linux.rs Simplified MSHV implementation following new trait pattern
hypervisor/hyperv_windows.rs Merged WHP implementation with cleaner structure
hypervisor/wrappers.rs Removed unused WHvDebugRegisters struct
hypervisor/gdb/* Updated debugging traits and removed platform-specific debug modules
mem/memory_region.rs Changed From trait to take references instead of owned values
sandbox/*.rs Updated to use HyperlightVm instead of Box<dyn Hypervisor>
crashdump.rs Updated to work with HyperlightVm directly

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

Labels

kind/refactor For PRs that restructure or remove code without adding new functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rethink driver API

3 participants