Skip to content

Commit 2e840b3

Browse files
committed
Remove mshv internal feature and use only mshv3
Signed-off-by: Doru Blânzeanu <[email protected]>
1 parent ddc1edb commit 2e840b3

File tree

13 files changed

+64
-75
lines changed

13 files changed

+64
-75
lines changed

Justfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ test-integration guest target=default-target features="":
172172

173173
# tests compilation with no default features on different platforms
174174
test-compilation-no-default-features target=default-target:
175-
@# Linux should fail without a hypervisor feature (kvm, mshv, or mshv3)
175+
@# Linux should fail without a hypervisor feature (kvm or mshv3)
176176
{{ if os() == "linux" { "! " + cargo-cmd + " check -p hyperlight-host --no-default-features "+target-triple-flag+" 2> /dev/null" } else { "" } }}
177177
@# Windows should succeed even without default features
178178
{{ if os() == "windows" { cargo-cmd + " check -p hyperlight-host --no-default-features" } else { "" } }}
@@ -307,7 +307,7 @@ tar-static-lib: (build-rust-capi "release") (build-rust-capi "debug")
307307
# Downloads the benchmarks result from the given release tag.
308308
# If tag is not given, defaults to latest release
309309
# Options for os: "Windows", or "Linux"
310-
# Options for Linux hypervisor: "kvm", "mshv", "mshv3"
310+
# Options for Linux hypervisor: "kvm", "mshv3"
311311
# Options for Windows hypervisor: "hyperv"
312312
# Options for cpu: "amd", "intel"
313313
bench-download os hypervisor cpu tag="":

src/hyperlight_host/build.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,15 @@ fn main() -> Result<()> {
8686
}
8787

8888
// Makes #[cfg(kvm)] == #[cfg(all(feature = "kvm", target_os = "linux"))]
89-
// and #[cfg(mshv)] == #[cfg(all(feature = "mshv3", target_os = "linux"))].
90-
// Essentially the kvm and mshv features are ignored on windows as long as you use #[cfg(kvm)] and not #[cfg(feature = "kvm")].
91-
// You should never use #[cfg(feature = "kvm")] or #[cfg(feature = "mshv")] in the codebase.
89+
// Essentially the kvm and mshv3 features are ignored on windows as long as you use #[cfg(kvm)] and not #[cfg(feature = "kvm")].
90+
// You should never use #[cfg(feature = "kvm")] or #[cfg(feature = "mshv3")] in the codebase.
9291
cfg_aliases::cfg_aliases! {
9392
gdb: { all(feature = "gdb", debug_assertions) },
9493
kvm: { all(feature = "kvm", target_os = "linux") },
95-
mshv: { all(feature = "mshv3", target_os = "linux") },
94+
mshv3: { all(feature = "mshv3", target_os = "linux") },
9695
crashdump: { all(feature = "crashdump") },
9796
// print_debug feature is aliased with debug_assertions to make it only available in debug-builds.
9897
print_debug: { all(feature = "print_debug", debug_assertions) },
99-
mshv3: { all(feature = "mshv3", target_os = "linux") },
10098
}
10199

102100
#[cfg(feature = "build-metadata")]

src/hyperlight_host/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ pub enum HyperlightError {
169169

170170
/// mshv Error Occurred
171171
#[error("mshv Error {0:?}")]
172-
#[cfg(mshv)]
172+
#[cfg(mshv3)]
173173
MSHVError(#[from] mshv_ioctls::MshvError),
174174

175175
/// No Hypervisor was found for Sandbox.

src/hyperlight_host/src/hypervisor/gdb/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ mod event_loop;
2020
mod hyperv_debug;
2121
#[cfg(kvm)]
2222
mod kvm_debug;
23-
#[cfg(mshv)]
23+
#[cfg(mshv3)]
2424
mod mshv_debug;
2525
mod x86_64_target;
2626

@@ -40,7 +40,7 @@ use hyperlight_common::mem::PAGE_SIZE;
4040
pub(crate) use hyperv_debug::HypervDebug;
4141
#[cfg(kvm)]
4242
pub(crate) use kvm_debug::KvmDebug;
43-
#[cfg(mshv)]
43+
#[cfg(mshv3)]
4444
pub(crate) use mshv_debug::MshvDebug;
4545
use thiserror::Error;
4646
use x86_64_target::HyperlightSandboxTarget;

src/hyperlight_host/src/hypervisor/hyperv_linux.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
#[cfg(mshv3)]
1817
extern crate mshv_bindings3 as mshv_bindings;
19-
#[cfg(mshv3)]
2018
extern crate mshv_ioctls3 as mshv_ioctls;
2119

2220
use std::fmt::{Debug, Formatter};
@@ -27,7 +25,9 @@ use log::{LevelFilter, error};
2725
use mshv_bindings::{
2826
FloatingPointUnit, SpecialRegisters, StandardRegisters, hv_message_type,
2927
hv_message_type_HVMSG_GPA_INTERCEPT, hv_message_type_HVMSG_UNMAPPED_GPA,
30-
hv_message_type_HVMSG_X64_HALT, hv_message_type_HVMSG_X64_IO_PORT_INTERCEPT, hv_register_assoc,
28+
hv_message_type_HVMSG_X64_HALT, hv_message_type_HVMSG_X64_IO_PORT_INTERCEPT,
29+
hv_partition_property_code_HV_PARTITION_PROPERTY_SYNTHETIC_PROC_FEATURES,
30+
hv_partition_synthetic_processor_features, hv_register_assoc,
3131
hv_register_name_HV_X64_REGISTER_RIP, hv_register_value, mshv_user_mem_region,
3232
};
3333
#[cfg(gdb)]
@@ -36,11 +36,6 @@ use mshv_bindings::{
3636
hv_intercept_type_HV_INTERCEPT_TYPE_EXCEPTION, hv_message_type_HVMSG_X64_EXCEPTION_INTERCEPT,
3737
mshv_install_intercept,
3838
};
39-
#[cfg(mshv3)]
40-
use mshv_bindings::{
41-
hv_partition_property_code_HV_PARTITION_PROPERTY_SYNTHETIC_PROC_FEATURES,
42-
hv_partition_synthetic_processor_features,
43-
};
4439
use mshv_ioctls::{Mshv, VcpuFd, VmFd};
4540
use tracing::{Span, instrument};
4641
#[cfg(feature = "trace_guest")]
@@ -319,7 +314,7 @@ impl HypervLinuxDriver {
319314
) -> Result<Self> {
320315
let mshv = Mshv::new()?;
321316
let pr = Default::default();
322-
#[cfg(mshv3)]
317+
323318
let vm_fd = {
324319
// It's important to avoid create_vm() and explicitly use
325320
// create_vm_with_args() with an empty arguments structure
@@ -688,7 +683,6 @@ impl Hypervisor for HypervLinuxDriver {
688683
// to interrupt it until `running` is set to false. The `vcpu_fd::run()` call will
689684
// return either normally with an exit reason, or from being "kicked" by out signal handler, with an EINTR error,
690685
// both of which are fine.
691-
#[cfg(mshv3)]
692686
self.vcpu_fd.run()
693687
};
694688
// Note: if a `InterruptHandle::kill()` called while this thread is **here**

src/hyperlight_host/src/hypervisor/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::sandbox::trace::MemTraceInfo;
2929
use crate::{HyperlightError, Result, log_then_return};
3030

3131
/// HyperV-on-linux functionality
32-
#[cfg(mshv)]
32+
#[cfg(mshv3)]
3333
pub mod hyperv_linux;
3434
#[cfg(target_os = "windows")]
3535
/// Hyperv-on-windows functionality
@@ -63,10 +63,10 @@ pub(crate) mod crashdump;
6363

6464
use std::fmt::Debug;
6565
use std::str::FromStr;
66-
#[cfg(any(kvm, mshv))]
66+
#[cfg(any(kvm, mshv3))]
6767
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
6868
use std::sync::{Arc, Mutex};
69-
#[cfg(any(kvm, mshv))]
69+
#[cfg(any(kvm, mshv3))]
7070
use std::time::Duration;
7171

7272
#[cfg(gdb)]
@@ -486,7 +486,7 @@ pub trait InterruptHandle: Debug + Send + Sync {
486486
fn dropped(&self) -> bool;
487487
}
488488

489-
#[cfg(any(kvm, mshv))]
489+
#[cfg(any(kvm, mshv3))]
490490
#[derive(Debug)]
491491
pub(super) struct LinuxInterruptHandle {
492492
/// Invariant: vcpu is running => most significant bit (63) of `running` is set. (Neither converse nor inverse is true)
@@ -531,7 +531,7 @@ pub(super) struct LinuxInterruptHandle {
531531
sig_rt_min_offset: u8,
532532
}
533533

534-
#[cfg(any(kvm, mshv))]
534+
#[cfg(any(kvm, mshv3))]
535535
impl LinuxInterruptHandle {
536536
const RUNNING_BIT: u64 = 1 << 63;
537537
const MAX_GENERATION: u64 = Self::RUNNING_BIT - 1;
@@ -593,7 +593,7 @@ impl LinuxInterruptHandle {
593593
}
594594
}
595595

596-
#[cfg(any(kvm, mshv))]
596+
#[cfg(any(kvm, mshv3))]
597597
impl InterruptHandle for LinuxInterruptHandle {
598598
fn kill(&self) -> bool {
599599
self.cancel_requested.store(true, Ordering::Relaxed);

src/hyperlight_host/src/hypervisor/regs/fpu.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::collections::HashSet;
2323

2424
#[cfg(kvm)]
2525
use kvm_bindings::kvm_fpu;
26-
#[cfg(mshv)]
26+
#[cfg(mshv3)]
2727
use mshv_bindings::FloatingPointUnit;
2828

2929
#[cfg(target_os = "windows")]
@@ -86,7 +86,7 @@ impl From<&CommonFpu> for kvm_fpu {
8686
}
8787
}
8888

89-
#[cfg(mshv)]
89+
#[cfg(mshv3)]
9090
impl From<&CommonFpu> for FloatingPointUnit {
9191
fn from(common_fpu: &CommonFpu) -> FloatingPointUnit {
9292
FloatingPointUnit {
@@ -124,7 +124,7 @@ impl From<&kvm_fpu> for CommonFpu {
124124
}
125125
}
126126

127-
#[cfg(mshv)]
127+
#[cfg(mshv3)]
128128
impl From<&FloatingPointUnit> for CommonFpu {
129129
fn from(mshv_fpu: &FloatingPointUnit) -> Self {
130130
Self {
@@ -385,7 +385,7 @@ mod tests {
385385
assert_eq!(original, round_tripped);
386386
}
387387

388-
#[cfg(mshv)]
388+
#[cfg(mshv3)]
389389
#[test]
390390
fn round_trip_mshv_fpu() {
391391
use mshv_bindings::FloatingPointUnit;

src/hyperlight_host/src/hypervisor/regs/special_regs.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use std::collections::HashSet;
2424

2525
#[cfg(kvm)]
2626
use kvm_bindings::{kvm_dtable, kvm_segment, kvm_sregs};
27-
#[cfg(mshv)]
27+
#[cfg(mshv3)]
2828
use mshv_bindings::{SegmentRegister, SpecialRegisters, TableRegister};
2929
#[cfg(target_os = "windows")]
3030
use windows::Win32::System::Hypervisor::*;
@@ -54,7 +54,7 @@ pub(crate) struct CommonSpecialRegisters {
5454
pub interrupt_bitmap: [u64; 4],
5555
}
5656

57-
#[cfg(mshv)]
57+
#[cfg(mshv3)]
5858
impl From<&SpecialRegisters> for CommonSpecialRegisters {
5959
fn from(value: &SpecialRegisters) -> Self {
6060
CommonSpecialRegisters {
@@ -80,7 +80,7 @@ impl From<&SpecialRegisters> for CommonSpecialRegisters {
8080
}
8181
}
8282

83-
#[cfg(mshv)]
83+
#[cfg(mshv3)]
8484
impl From<&CommonSpecialRegisters> for SpecialRegisters {
8585
fn from(other: &CommonSpecialRegisters) -> Self {
8686
SpecialRegisters {
@@ -340,7 +340,7 @@ pub(crate) struct CommonSegmentRegister {
340340
pub padding: u8,
341341
}
342342

343-
#[cfg(mshv)]
343+
#[cfg(mshv3)]
344344
impl From<SegmentRegister> for CommonSegmentRegister {
345345
fn from(other: SegmentRegister) -> Self {
346346
CommonSegmentRegister {
@@ -361,7 +361,7 @@ impl From<SegmentRegister> for CommonSegmentRegister {
361361
}
362362
}
363363

364-
#[cfg(mshv)]
364+
#[cfg(mshv3)]
365365
impl From<CommonSegmentRegister> for SegmentRegister {
366366
fn from(other: CommonSegmentRegister) -> Self {
367367
SegmentRegister {
@@ -493,7 +493,7 @@ pub(crate) struct CommonTableRegister {
493493
pub limit: u16,
494494
}
495495

496-
#[cfg(mshv)]
496+
#[cfg(mshv3)]
497497
impl From<TableRegister> for CommonTableRegister {
498498
fn from(other: TableRegister) -> Self {
499499
CommonTableRegister {
@@ -503,7 +503,7 @@ impl From<TableRegister> for CommonTableRegister {
503503
}
504504
}
505505

506-
#[cfg(mshv)]
506+
#[cfg(mshv3)]
507507
impl From<CommonTableRegister> for TableRegister {
508508
fn from(other: CommonTableRegister) -> Self {
509509
TableRegister {
@@ -618,7 +618,7 @@ mod tests {
618618
assert_eq!(original, roundtrip);
619619
}
620620

621-
#[cfg(mshv)]
621+
#[cfg(mshv3)]
622622
#[test]
623623
fn round_trip_mshv_sregs() {
624624
let original = sample_common_special_registers();

src/hyperlight_host/src/hypervisor/regs/standard_regs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extern crate mshv_ioctls3 as mshv_ioctls;
2121

2222
#[cfg(kvm)]
2323
use kvm_bindings::kvm_regs;
24-
#[cfg(mshv)]
24+
#[cfg(mshv3)]
2525
use mshv_bindings::StandardRegisters;
2626

2727
#[derive(Debug, Default, Copy, Clone, PartialEq)]
@@ -101,7 +101,7 @@ impl From<&CommonRegisters> for kvm_regs {
101101

102102
// --- MSHV ---
103103

104-
#[cfg(mshv)]
104+
#[cfg(mshv3)]
105105
impl From<&StandardRegisters> for CommonRegisters {
106106
fn from(mshv_regs: &StandardRegisters) -> Self {
107107
CommonRegisters {
@@ -127,7 +127,7 @@ impl From<&StandardRegisters> for CommonRegisters {
127127
}
128128
}
129129

130-
#[cfg(mshv)]
130+
#[cfg(mshv3)]
131131
impl From<&CommonRegisters> for StandardRegisters {
132132
fn from(regs: &CommonRegisters) -> Self {
133133
StandardRegisters {
@@ -375,7 +375,7 @@ mod tests {
375375
assert_eq!(original, converted);
376376
}
377377

378-
#[cfg(mshv)]
378+
#[cfg(mshv3)]
379379
#[test]
380380
fn round_trip_mshv_regs() {
381381
let original = common_regs();

src/hyperlight_host/src/mem/memory_region.rs

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ extern crate mshv_ioctls3 as mshv_ioctls;
2222
use std::ops::Range;
2323

2424
use bitflags::bitflags;
25-
#[cfg(mshv)]
25+
#[cfg(mshv3)]
2626
use hyperlight_common::mem::PAGE_SHIFT;
2727
use hyperlight_common::mem::PAGE_SIZE_USIZE;
2828
#[cfg(kvm)]
@@ -31,7 +31,7 @@ use kvm_bindings::{KVM_MEM_READONLY, kvm_userspace_memory_region};
3131
use mshv_bindings::{
3232
MSHV_SET_MEM_BIT_EXECUTABLE, MSHV_SET_MEM_BIT_UNMAP, MSHV_SET_MEM_BIT_WRITABLE,
3333
};
34-
#[cfg(mshv)]
34+
#[cfg(mshv3)]
3535
use mshv_bindings::{hv_x64_memory_intercept_message, mshv_user_mem_region};
3636
#[cfg(target_os = "windows")]
3737
use windows::Win32::System::Hypervisor::{self, WHV_MEMORY_ACCESS_TYPE};
@@ -127,7 +127,7 @@ impl TryFrom<WHV_MEMORY_ACCESS_TYPE> for MemoryRegionFlags {
127127
}
128128
}
129129

130-
#[cfg(mshv)]
130+
#[cfg(mshv3)]
131131
impl TryFrom<hv_x64_memory_intercept_message> for MemoryRegionFlags {
132132
type Error = crate::HyperlightError;
133133

@@ -252,33 +252,30 @@ impl MemoryRegionVecBuilder {
252252
}
253253
}
254254

255-
#[cfg(mshv)]
255+
#[cfg(mshv3)]
256256
impl From<MemoryRegion> for mshv_user_mem_region {
257257
fn from(region: MemoryRegion) -> Self {
258258
let size = (region.guest_region.end - region.guest_region.start) as u64;
259259
let guest_pfn = region.guest_region.start as u64 >> PAGE_SHIFT;
260260
let userspace_addr = region.host_region.start as u64;
261261

262-
#[cfg(mshv3)]
263-
{
264-
let flags: u8 = region.flags.iter().fold(0, |acc, flag| {
265-
let flag_value = match flag {
266-
MemoryRegionFlags::NONE => 1 << MSHV_SET_MEM_BIT_UNMAP,
267-
MemoryRegionFlags::READ => 0,
268-
MemoryRegionFlags::WRITE => 1 << MSHV_SET_MEM_BIT_WRITABLE,
269-
MemoryRegionFlags::EXECUTE => 1 << MSHV_SET_MEM_BIT_EXECUTABLE,
270-
_ => 0, // ignore any unknown flags
271-
};
272-
acc | flag_value
273-
});
274-
275-
mshv_user_mem_region {
276-
guest_pfn,
277-
size,
278-
userspace_addr,
279-
flags,
280-
..Default::default()
281-
}
262+
let flags: u8 = region.flags.iter().fold(0, |acc, flag| {
263+
let flag_value = match flag {
264+
MemoryRegionFlags::NONE => 1 << MSHV_SET_MEM_BIT_UNMAP,
265+
MemoryRegionFlags::READ => 0,
266+
MemoryRegionFlags::WRITE => 1 << MSHV_SET_MEM_BIT_WRITABLE,
267+
MemoryRegionFlags::EXECUTE => 1 << MSHV_SET_MEM_BIT_EXECUTABLE,
268+
_ => 0, // ignore any unknown flags
269+
};
270+
acc | flag_value
271+
});
272+
273+
mshv_user_mem_region {
274+
guest_pfn,
275+
size,
276+
userspace_addr,
277+
flags,
278+
..Default::default()
282279
}
283280
}
284281
}

0 commit comments

Comments
 (0)