-
Notifications
You must be signed in to change notification settings - Fork 155
Trim Hypervisor trait
#924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
81f0d54 to
62fad87
Compare
1562f26 to
edc7f00
Compare
f6337f9 to
350b8e0
Compare
fa21515 to
0a033d6
Compare
5a116e5 to
ee7545e
Compare
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { |
There was a problem hiding this comment.
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
c07d874 to
11db597
Compare
Signed-off-by: Ludvig Liljenberg <[email protected]>
Signed-off-by: Ludvig Liljenberg <[email protected]>
trait Signed-off-by: Ludvig Liljenberg <[email protected]>
Signed-off-by: Ludvig Liljenberg <[email protected]>
There was a problem hiding this 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
-
New
HyperlightVmstruct: Contains hypervisor-agnostic logic previously duplicated across KVM/MSHV/WHP implementations, including memory management, guest initialization, debugging support, and crashdump generation. -
Trimmed
Hypervisortrait: Now focuses only on core VM operations (run_vcpu,map_memory,unmap_memory, register operations), with platform-specific details abstracted away. -
Consolidated Windows implementation: Merged
windows_hypervisor_platform.rsintohyperv_windows.rsand 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 |
This PR
Hypervisortrait. 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.HyperlightVmstruct. This is a new struct that contains thedyn Hypervisorabove, 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, whichHypervisortrait doesn't. All code that was previously duplicated in kvm/mshv/whp now lives in HyperlightVm.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:
Closes #465, #904