Skip to content

Commit 3d74f59

Browse files
committed
Move kvm,hyperv_linux/hyperv_windows into vm module
Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com> Clean up import paths after file move Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com> Rename hyperv_linux to mshv, hyperv_windows to whp Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
1 parent 89ce6eb commit 3d74f59

File tree

7 files changed

+42
-41
lines changed

7 files changed

+42
-41
lines changed

src/hyperlight_host/src/hypervisor/hyperlight_vm.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ use crate::hypervisor::Hypervisor;
4242
use crate::hypervisor::LinuxInterruptHandle;
4343
#[cfg(crashdump)]
4444
use crate::hypervisor::crashdump;
45+
use crate::hypervisor::regs::CommonSpecialRegisters;
46+
#[cfg(kvm)]
47+
use crate::hypervisor::vm::kvm::KvmVm;
4548
#[cfg(mshv3)]
46-
use crate::hypervisor::hyperv_linux::MshvVm;
49+
use crate::hypervisor::vm::mshv::MshvVm;
4750
#[cfg(target_os = "windows")]
48-
use crate::hypervisor::hyperv_windows::WhpVm;
49-
#[cfg(kvm)]
50-
use crate::hypervisor::kvm::KvmVm;
51-
use crate::hypervisor::regs::CommonSpecialRegisters;
51+
use crate::hypervisor::vm::whp::WhpVm;
5252
#[cfg(target_os = "windows")]
5353
use crate::hypervisor::wrappers::HandleWrapper;
5454
use crate::hypervisor::{HyperlightExit, InterruptHandle, InterruptHandleImpl, get_max_log_level};

src/hyperlight_host/src/hypervisor/mod.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,14 @@ use crate::Result;
2020
use crate::hypervisor::regs::{CommonFpu, CommonRegisters, CommonSpecialRegisters};
2121
use crate::mem::memory_region::MemoryRegion;
2222

23-
/// HyperV-on-linux functionality
24-
#[cfg(mshv3)]
25-
pub(crate) mod hyperv_linux;
26-
#[cfg(target_os = "windows")]
27-
pub(crate) mod hyperv_windows;
28-
2923
/// GDB debugging support
3024
#[cfg(gdb)]
3125
pub(crate) mod gdb;
3226

3327
/// Abstracts over different hypervisor register representations
3428
pub(crate) mod regs;
3529

36-
#[cfg(kvm)]
37-
/// Functionality to manipulate KVM-based virtual machines
38-
pub(crate) mod kvm;
30+
pub(crate) mod vm;
3931

4032
#[cfg(target_os = "windows")]
4133
/// Hyperlight Surrogate Process

src/hyperlight_host/src/hypervisor/kvm.rs renamed to src/hyperlight_host/src/hypervisor/vm/kvm.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use tracing::{Span, instrument};
2525

2626
#[cfg(gdb)]
2727
use crate::hypervisor::gdb::DebuggableVm;
28+
use crate::hypervisor::regs::{CommonFpu, CommonRegisters, CommonSpecialRegisters};
2829
use crate::hypervisor::{HyperlightExit, Hypervisor};
2930
use crate::mem::memory_region::MemoryRegion;
3031
use crate::{Result, new_error};
@@ -130,34 +131,34 @@ impl Hypervisor for KvmVm {
130131
}
131132
}
132133

133-
fn regs(&self) -> Result<super::regs::CommonRegisters> {
134+
fn regs(&self) -> Result<CommonRegisters> {
134135
let kvm_regs = self.vcpu_fd.get_regs()?;
135136
Ok((&kvm_regs).into())
136137
}
137138

138-
fn set_regs(&self, regs: &super::regs::CommonRegisters) -> Result<()> {
139+
fn set_regs(&self, regs: &CommonRegisters) -> Result<()> {
139140
let kvm_regs: kvm_regs = regs.into();
140141
self.vcpu_fd.set_regs(&kvm_regs)?;
141142
Ok(())
142143
}
143144

144-
fn fpu(&self) -> Result<super::regs::CommonFpu> {
145+
fn fpu(&self) -> Result<CommonFpu> {
145146
let kvm_fpu = self.vcpu_fd.get_fpu()?;
146147
Ok((&kvm_fpu).into())
147148
}
148149

149-
fn set_fpu(&self, fpu: &super::regs::CommonFpu) -> Result<()> {
150+
fn set_fpu(&self, fpu: &CommonFpu) -> Result<()> {
150151
let kvm_fpu: kvm_fpu = fpu.into();
151152
self.vcpu_fd.set_fpu(&kvm_fpu)?;
152153
Ok(())
153154
}
154155

155-
fn sregs(&self) -> Result<super::regs::CommonSpecialRegisters> {
156+
fn sregs(&self) -> Result<CommonSpecialRegisters> {
156157
let kvm_sregs = self.vcpu_fd.get_sregs()?;
157158
Ok((&kvm_sregs).into())
158159
}
159160

160-
fn set_sregs(&self, sregs: &super::regs::CommonSpecialRegisters) -> Result<()> {
161+
fn set_sregs(&self, sregs: &CommonSpecialRegisters) -> Result<()> {
161162
let kvm_sregs: kvm_sregs = sregs.into();
162163
self.vcpu_fd.set_sregs(&kvm_sregs)?;
163164
Ok(())
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#[cfg(kvm)]
2+
/// Functionality to manipulate KVM-based virtual machines
3+
pub(crate) mod kvm;
4+
/// HyperV-on-linux functionality
5+
#[cfg(mshv3)]
6+
pub(crate) mod mshv;
7+
#[cfg(target_os = "windows")]
8+
pub(crate) mod whp;

src/hyperlight_host/src/hypervisor/hyperv_linux.rs renamed to src/hyperlight_host/src/hypervisor/vm/mshv.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use tracing::{Span, instrument};
3333

3434
#[cfg(gdb)]
3535
use crate::hypervisor::gdb::DebuggableVm;
36+
use crate::hypervisor::regs::{CommonFpu, CommonRegisters, CommonSpecialRegisters};
3637
use crate::hypervisor::{HyperlightExit, Hypervisor};
3738
use crate::mem::memory_region::{MemoryRegion, MemoryRegionFlags};
3839
use crate::{Result, new_error};
@@ -175,34 +176,34 @@ impl Hypervisor for MshvVm {
175176
Ok(result)
176177
}
177178

178-
fn regs(&self) -> Result<super::regs::CommonRegisters> {
179+
fn regs(&self) -> Result<CommonRegisters> {
179180
let mshv_regs = self.vcpu_fd.get_regs()?;
180181
Ok((&mshv_regs).into())
181182
}
182183

183-
fn set_regs(&self, regs: &super::regs::CommonRegisters) -> Result<()> {
184+
fn set_regs(&self, regs: &CommonRegisters) -> Result<()> {
184185
let mshv_regs: StandardRegisters = regs.into();
185186
self.vcpu_fd.set_regs(&mshv_regs)?;
186187
Ok(())
187188
}
188189

189-
fn fpu(&self) -> Result<super::regs::CommonFpu> {
190+
fn fpu(&self) -> Result<CommonFpu> {
190191
let mshv_fpu = self.vcpu_fd.get_fpu()?;
191192
Ok((&mshv_fpu).into())
192193
}
193194

194-
fn set_fpu(&self, fpu: &super::regs::CommonFpu) -> Result<()> {
195+
fn set_fpu(&self, fpu: &CommonFpu) -> Result<()> {
195196
let mshv_fpu: FloatingPointUnit = fpu.into();
196197
self.vcpu_fd.set_fpu(&mshv_fpu)?;
197198
Ok(())
198199
}
199200

200-
fn sregs(&self) -> Result<super::regs::CommonSpecialRegisters> {
201+
fn sregs(&self) -> Result<CommonSpecialRegisters> {
201202
let mshv_sregs = self.vcpu_fd.get_sregs()?;
202203
Ok((&mshv_sregs).into())
203204
}
204205

205-
fn set_sregs(&self, sregs: &super::regs::CommonSpecialRegisters) -> Result<()> {
206+
fn set_sregs(&self, sregs: &CommonSpecialRegisters) -> Result<()> {
206207
let mshv_sregs: SpecialRegisters = sregs.into();
207208
self.vcpu_fd.set_sregs(&mshv_sregs)?;
208209
Ok(())

src/hyperlight_host/src/hypervisor/hyperv_windows.rs renamed to src/hyperlight_host/src/hypervisor/vm/whp.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,15 @@ use windows::Win32::System::LibraryLoader::*;
2323
use windows::core::s;
2424
use windows_result::HRESULT;
2525

26-
use super::regs::{
27-
Align16, WHP_FPU_NAMES, WHP_FPU_NAMES_LEN, WHP_REGS_NAMES, WHP_REGS_NAMES_LEN, WHP_SREGS_NAMES,
28-
WHP_SREGS_NAMES_LEN,
29-
};
30-
use super::surrogate_process::SurrogateProcess;
31-
use super::surrogate_process_manager::get_surrogate_process_manager;
32-
use super::wrappers::HandleWrapper;
3326
#[cfg(gdb)]
3427
use crate::hypervisor::gdb::DebuggableVm;
35-
use crate::hypervisor::regs::{CommonFpu, CommonRegisters, CommonSpecialRegisters};
28+
use crate::hypervisor::regs::{
29+
Align16, CommonFpu, CommonRegisters, CommonSpecialRegisters, WHP_FPU_NAMES, WHP_FPU_NAMES_LEN,
30+
WHP_REGS_NAMES, WHP_REGS_NAMES_LEN, WHP_SREGS_NAMES, WHP_SREGS_NAMES_LEN,
31+
};
32+
use crate::hypervisor::surrogate_process::SurrogateProcess;
33+
use crate::hypervisor::surrogate_process_manager::get_surrogate_process_manager;
34+
use crate::hypervisor::wrappers::HandleWrapper;
3635
use crate::hypervisor::{HyperlightExit, Hypervisor};
3736
use crate::mem::memory_region::{MemoryRegion, MemoryRegionFlags};
3837
use crate::{Result, log_then_return, new_error};

src/hyperlight_host/src/sandbox/hypervisor.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ limitations under the License.
1717
use std::fmt::Debug;
1818
use std::sync::OnceLock;
1919

20-
#[cfg(mshv3)]
21-
use crate::hypervisor::hyperv_linux;
2220
#[cfg(kvm)]
23-
use crate::hypervisor::kvm;
21+
use crate::hypervisor::vm::kvm;
22+
#[cfg(mshv3)]
23+
use crate::hypervisor::vm::mshv;
2424

2525
static AVAILABLE_HYPERVISOR: OnceLock<Option<HypervisorType>> = OnceLock::new();
2626

@@ -31,7 +31,7 @@ pub fn get_available_hypervisor() -> &'static Option<HypervisorType> {
3131
// If both features are enabled, we need to determine hypervisor at runtime.
3232
// Currently /dev/kvm and /dev/mshv cannot exist on the same machine, so the first one
3333
// that works is guaranteed to be correct.
34-
if hyperv_linux::is_hypervisor_present() {
34+
if mshv::is_hypervisor_present() {
3535
Some(HypervisorType::Mshv)
3636
} else if kvm::is_hypervisor_present() {
3737
Some(HypervisorType::Kvm)
@@ -45,15 +45,15 @@ pub fn get_available_hypervisor() -> &'static Option<HypervisorType> {
4545
None
4646
}
4747
} else if #[cfg(mshv3)] {
48-
if hyperv_linux::is_hypervisor_present() {
48+
if mshv::is_hypervisor_present() {
4949
Some(HypervisorType::Mshv)
5050
} else {
5151
None
5252
}
5353
} else if #[cfg(target_os = "windows")] {
54-
use crate::hypervisor::hyperv_windows;
54+
use crate::hypervisor::vm::whp;
5555

56-
if hyperv_windows::is_hypervisor_present() {
56+
if whp::is_hypervisor_present() {
5757
Some(HypervisorType::Whp)
5858
} else {
5959
None

0 commit comments

Comments
 (0)