diff --git a/.github/workflows/Benchmarks.yml b/.github/workflows/Benchmarks.yml index 8739f0a28..9e69f71b6 100644 --- a/.github/workflows/Benchmarks.yml +++ b/.github/workflows/Benchmarks.yml @@ -18,7 +18,7 @@ jobs: strategy: fail-fast: true matrix: - hypervisor: [hyperv, 'hyperv-ws2025', mshv, mshv3, kvm] # hyperv,hyperv-ws2025 are windows, mshv, mshv3 and kvm are linux + hypervisor: [hyperv, 'hyperv-ws2025', mshv3, kvm] # hyperv,hyperv-ws2025 are windows, mshv3 and kvm are linux cpu: [amd, intel] config: [release] runs-on: ${{ fromJson( @@ -66,7 +66,7 @@ jobs: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Run Benchmarks - run: just bench-ci main ${{ matrix.hypervisor == 'mshv' && 'mshv2' || ''}} + run: just bench-ci main - uses: actions/upload-artifact@v5 with: diff --git a/.github/workflows/CreateRelease.yml b/.github/workflows/CreateRelease.yml index b2082d91e..14d23ddcf 100644 --- a/.github/workflows/CreateRelease.yml +++ b/.github/workflows/CreateRelease.yml @@ -146,9 +146,6 @@ jobs: # kvm tar -zcvf benchmarks_Linux_kvm_amd.tar.gz benchmarks_Linux_kvm_amd tar -zcvf benchmarks_Linux_kvm_intel.tar.gz benchmarks_Linux_kvm_intel - # mshv2 - tar -zcvf benchmarks_Linux_mshv_intel.tar.gz benchmarks_Linux_mshv_intel - tar -zcvf benchmarks_Linux_mshv_amd.tar.gz benchmarks_Linux_mshv_amd # mshv3 tar -zcvf benchmarks_Linux_mshv3_amd.tar.gz benchmarks_Linux_mshv3_amd tar -zcvf benchmarks_Linux_mshv3_intel.tar.gz benchmarks_Linux_mshv3_intel @@ -173,8 +170,6 @@ jobs: benchmarks_Windows_hyperv_intel.tar.gz \ benchmarks_Linux_kvm_amd.tar.gz \ benchmarks_Linux_kvm_intel.tar.gz \ - benchmarks_Linux_mshv_intel.tar.gz \ - benchmarks_Linux_mshv_amd.tar.gz \ benchmarks_Linux_mshv3_amd.tar.gz \ benchmarks_Linux_mshv3_intel.tar.gz \ hyperlight-guest-c-api-linux.tar.gz \ @@ -191,8 +186,6 @@ jobs: benchmarks_Windows_hyperv_intel.tar.gz \ benchmarks_Linux_kvm_amd.tar.gz \ benchmarks_Linux_kvm_intel.tar.gz \ - benchmarks_Linux_mshv_intel.tar.gz \ - benchmarks_Linux_mshv_amd.tar.gz \ benchmarks_Linux_mshv3_amd.tar.gz \ benchmarks_Linux_mshv3_intel.tar.gz \ hyperlight-guest-c-api-linux.tar.gz \ diff --git a/.github/workflows/ValidatePullRequest.yml b/.github/workflows/ValidatePullRequest.yml index f5e8b1157..65b387cac 100644 --- a/.github/workflows/ValidatePullRequest.yml +++ b/.github/workflows/ValidatePullRequest.yml @@ -47,7 +47,7 @@ jobs: strategy: fail-fast: true matrix: - hypervisor: [hyperv, 'hyperv-ws2025', mshv, mshv3, kvm] + hypervisor: [hyperv, 'hyperv-ws2025', mshv3, kvm] cpu: [amd, intel] config: [debug, release] uses: ./.github/workflows/dep_rust.yml diff --git a/.github/workflows/dep_rust.yml b/.github/workflows/dep_rust.yml index c9a94f7ea..ac89b3e4d 100644 --- a/.github/workflows/dep_rust.yml +++ b/.github/workflows/dep_rust.yml @@ -132,7 +132,7 @@ jobs: # use these commands in favor of build-and-move-c-guests to avoid building both configs just build-c-guests ${{ inputs.config }} just move-c-guests ${{ inputs.config }} - + - name: Build run: just build ${{ inputs.config }} env: @@ -144,10 +144,10 @@ jobs: TARGET_TRIPLE: ${{ inputs.target_triple }} run: | # with default features - just test ${{ inputs.config }} ${{ inputs.hypervisor == 'mshv' && 'mshv2' || '""'}} + just test ${{ inputs.config }} # with only one driver enabled (driver mshv/kvm feature is ignored on windows) - just test ${{ inputs.config }} ${{ inputs.hypervisor == 'mshv' && 'mshv2' || inputs.hypervisor == 'mshv3' && 'mshv3' || 'kvm' }} + just test ${{ inputs.config }} ${{ inputs.hypervisor == 'mshv3' && 'mshv3' || 'kvm' }} # make sure certain cargo features compile just check @@ -171,21 +171,21 @@ jobs: CARGO_TERM_COLOR: always RUST_LOG: debug TARGET_TRIPLE: ${{ inputs.target_triple }} - run: just run-rust-examples-linux ${{ inputs.config }} ${{ inputs.hypervisor == 'mshv' && 'mshv2' || '""'}} + run: just run-rust-examples-linux ${{ inputs.config }} - name: Run Rust Gdb tests env: CARGO_TERM_COLOR: always RUST_LOG: debug TARGET_TRIPLE: ${{ inputs.target_triple }} - run: just test-rust-gdb-debugging ${{ inputs.config }} ${{ inputs.hypervisor == 'mshv' && 'mshv2' || '""'}} + run: just test-rust-gdb-debugging ${{ inputs.config }} - name: Run Rust Crashdump tests env: CARGO_TERM_COLOR: always RUST_LOG: debug TARGET_TRIPLE: ${{ inputs.target_triple }} - run: just test-rust-crashdump ${{ inputs.config }} ${{ inputs.hypervisor == 'mshv' && 'mshv2' || '""'}} + run: just test-rust-crashdump ${{ inputs.config }} - name: Run Rust Tracing tests - linux if: runner.os == 'Linux' @@ -193,7 +193,7 @@ jobs: CARGO_TERM_COLOR: always RUST_LOG: debug TARGET_TRIPLE: ${{ inputs.target_triple }} - run: just test-rust-tracing ${{ inputs.config }} ${{ inputs.hypervisor == 'mshv' && 'mshv2' || '""'}} + run: just test-rust-tracing ${{ inputs.config }} - name: Download benchmarks from "latest" run: just bench-download ${{ runner.os }} ${{ inputs.hypervisor }} ${{ inputs.cpu}} dev-latest # compare to prerelease @@ -204,5 +204,5 @@ jobs: - name: Run benchmarks run: | - just bench-ci main ${{ inputs.hypervisor == 'mshv' && 'mshv2' || ''}} + just bench-ci main if: ${{ inputs.config == 'release' && inputs.target_triple == '' }} diff --git a/Cargo.lock b/Cargo.lock index a9526f543..259963405 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1495,10 +1495,8 @@ dependencies = [ "metrics", "metrics-exporter-prometheus", "metrics-util", - "mshv-bindings 0.2.1", - "mshv-bindings 0.6.1", - "mshv-ioctls 0.2.1", - "mshv-ioctls 0.6.1", + "mshv-bindings", + "mshv-ioctls", "opentelemetry", "opentelemetry-otlp", "opentelemetry-semantic-conventions", @@ -2071,18 +2069,6 @@ dependencies = [ "windows-sys 0.59.0", ] -[[package]] -name = "mshv-bindings" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f416b4432174e5a3f956a7887f4c1a4acea9511d81def67fcb8473293630ab9e" -dependencies = [ - "libc", - "num_enum", - "vmm-sys-util", - "zerocopy 0.7.35", -] - [[package]] name = "mshv-bindings" version = "0.6.1" @@ -2095,18 +2081,6 @@ dependencies = [ "zerocopy 0.8.26", ] -[[package]] -name = "mshv-ioctls" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d57586da719aacc905042eea71ff2efb52d16c7228a94af155c9ea45fe09c1c7" -dependencies = [ - "libc", - "mshv-bindings 0.2.1", - "thiserror 1.0.69", - "vmm-sys-util", -] - [[package]] name = "mshv-ioctls" version = "0.6.1" @@ -2114,7 +2088,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fdbb879d6a9ca5359ae020c17ebf8587e0be309bf32beae636030e4408c2e481" dependencies = [ "libc", - "mshv-bindings 0.6.1", + "mshv-bindings", "thiserror 2.0.17", "vmm-sys-util", ] diff --git a/Justfile b/Justfile index 67925f662..42400b86b 100644 --- a/Justfile +++ b/Justfile @@ -78,10 +78,10 @@ clean-rust: # convenience recipe to run all tests with the given target and features (similar to CI) test-like-ci config=default-target hypervisor="kvm": @# with default features - just test {{config}} {{ if hypervisor == "mshv" {"mshv2"} else {""} }} + just test {{config}} @# with only one driver enabled + build-metadata + init-paging - just test {{config}} build-metadata,init-paging,{{ if hypervisor == "mshv" {"mshv2"} else if hypervisor == "mshv3" {"mshv3"} else {"kvm"} }} + just test {{config}} build-metadata,init-paging,{{ if hypervisor == "mshv3" {"mshv3"} else {"kvm"} }} @# make sure certain cargo features compile just check @@ -93,7 +93,7 @@ test-like-ci config=default-target hypervisor="kvm": just test-rust-crashdump {{config}} @# test the tracing related features - {{ if os() == "linux" { "just test-rust-tracing " + config + " " + if hypervisor == "mshv" { "mshv2" } else if hypervisor == "mshv3" { "mshv3" } else { "kvm" } } else { "" } }} + {{ if os() == "linux" { "just test-rust-tracing " + config + " " + if hypervisor == "mshv3" { "mshv3" } else { "kvm" } } else { "" } }} like-ci config=default-target hypervisor="kvm": @# Ensure up-to-date Cargo.lock @@ -130,19 +130,19 @@ like-ci config=default-target hypervisor="kvm": {{ if os() == "windows" { "just run-rust-examples " + config } else { "" } }} @# Run Rust examples - linux - {{ if os() == "linux" { "just run-rust-examples-linux " + config + " " + if hypervisor == "mshv" { "mshv2" } else if hypervisor == "mshv3" { "mshv3" } else { "kvm" } } else { "" } }} + {{ if os() == "linux" { "just run-rust-examples-linux " + config + " " + if hypervisor == "mshv3" { "mshv3" } else { "kvm" } } else { "" } }} @# Run Rust Gdb tests - just test-rust-gdb-debugging {{ config }} {{ if hypervisor == "mshv" { "mshv2" } else if hypervisor == "mshv3" { "mshv3" } else { "kvm" } }} + just test-rust-gdb-debugging {{ config }} {{ if hypervisor == "mshv3" { "mshv3" } else { "kvm" } }} @# Run Rust Crashdump tests - just test-rust-crashdump {{config}} {{ if hypervisor == "mshv" { "mshv2" } else if hypervisor == "mshv3" { "mshv3" } else { "kvm" } }} + just test-rust-crashdump {{config}} {{ if hypervisor == "mshv3" { "mshv3" } else { "kvm" } }} @# Run Rust Tracing tests - linux - {{ if os() == "linux" { "just test-rust-tracing " + config + " " + if hypervisor == "mshv" { "mshv2" } else if hypervisor == "mshv3" { "mshv3" } else { "kvm" } } else { "" } }} + {{ if os() == "linux" { "just test-rust-tracing " + config + " " + if hypervisor == "mshv3" { "mshv3" } else { "kvm" } } else { "" } }} @# Run benchmarks - {{ if config == "release" { "just bench-ci main " + if hypervisor == "mshv" { "mshv2" } else if hypervisor == "mshv3" { "mshv3" } else { "kvm" } } else { "" } }} + {{ if config == "release" { "just bench-ci main " + if hypervisor == "mshv3" { "mshv3" } else { "kvm" } } else { "" } }} # runs all tests test target=default-target features="": (test-unit target features) (test-isolated target features) (test-integration "rust" target features) (test-integration "c" target features) (test-doc target features) @@ -172,13 +172,12 @@ test-integration guest target=default-target features="": # tests compilation with no default features on different platforms test-compilation-no-default-features target=default-target: - @# Linux should fail without a hypervisor feature (kvm, mshv, or mshv3) + @# Linux should fail without a hypervisor feature (kvm or mshv3) {{ if os() == "linux" { "! " + cargo-cmd + " check -p hyperlight-host --no-default-features "+target-triple-flag+" 2> /dev/null" } else { "" } }} @# Windows should succeed even without default features {{ if os() == "windows" { cargo-cmd + " check -p hyperlight-host --no-default-features" } else { "" } }} @# Linux should succeed with a hypervisor driver but without init-paging {{ if os() == "linux" { cargo-cmd + " check -p hyperlight-host --no-default-features --features kvm" } else { "" } }} {{ target-triple-flag }} - {{ if os() == "linux" { cargo-cmd + " check -p hyperlight-host --no-default-features --features mshv2" } else { "" } }} {{ target-triple-flag }} {{ if os() == "linux" { cargo-cmd + " check -p hyperlight-host --no-default-features --features mshv3" } else { "" } }} {{ target-triple-flag }} # runs tests that exercise gdb debugging @@ -308,7 +307,7 @@ tar-static-lib: (build-rust-capi "release") (build-rust-capi "debug") # Downloads the benchmarks result from the given release tag. # If tag is not given, defaults to latest release # Options for os: "Windows", or "Linux" -# Options for Linux hypervisor: "kvm", "mshv", "mshv3" +# Options for Linux hypervisor: "kvm", "mshv3" # Options for Windows hypervisor: "hyperv" # Options for cpu: "amd", "intel" bench-download os hypervisor cpu tag="": diff --git a/src/hyperlight_host/Cargo.toml b/src/hyperlight_host/Cargo.toml index 0c7bf1372..afa9a4c2c 100644 --- a/src/hyperlight_host/Cargo.toml +++ b/src/hyperlight_host/Cargo.toml @@ -77,10 +77,8 @@ lazy_static = "1.4.0" [target.'cfg(unix)'.dependencies] kvm-bindings = { version = "0.14", features = ["fam-wrappers"], optional = true } kvm-ioctls = { version = "0.24", optional = true } -mshv-bindings2 = { package="mshv-bindings", version = "=0.2.1", optional = true } -mshv-ioctls2 = { package="mshv-ioctls", version = "=0.2.1", optional = true} -mshv-bindings3 = { package="mshv-bindings", version = "0.6.1", optional = true } -mshv-ioctls3 = { package="mshv-ioctls", version = "0.6.1", optional = true} +mshv-bindings = { version = "0.6.1", optional = true } +mshv-ioctls = { version = "0.6.1", optional = true} [dev-dependencies] uuid = { version = "1.18.1", features = ["v4"] } @@ -135,9 +133,7 @@ crashdump = ["dep:chrono"] trace_guest = ["dep:opentelemetry", "dep:tracing-opentelemetry", "dep:hyperlight-guest-tracing", "hyperlight-common/trace_guest"] mem_profile = [ "trace_guest", "dep:framehop", "dep:fallible-iterator", "hyperlight-common/mem_profile" ] kvm = ["dep:kvm-bindings", "dep:kvm-ioctls"] -# This feature is deprecated in favor of mshv3 -mshv2 = ["dep:mshv-bindings2", "dep:mshv-ioctls2"] -mshv3 = ["dep:mshv-bindings3", "dep:mshv-ioctls3"] +mshv3 = ["dep:mshv-bindings", "dep:mshv-ioctls"] # This enables easy debug in the guest gdb = ["dep:gdbstub", "dep:gdbstub_arch"] fuzzing = ["hyperlight-common/fuzzing"] diff --git a/src/hyperlight_host/build.rs b/src/hyperlight_host/build.rs index 6c90a485f..414f784b4 100644 --- a/src/hyperlight_host/build.rs +++ b/src/hyperlight_host/build.rs @@ -86,21 +86,15 @@ fn main() -> Result<()> { } // Makes #[cfg(kvm)] == #[cfg(all(feature = "kvm", target_os = "linux"))] - // and #[cfg(mshv)] == #[cfg(all(any(feature = "mshv2", feature = "mshv3"), target_os = "linux"))]. - // Essentially the kvm and mshv features are ignored on windows as long as you use #[cfg(kvm)] and not #[cfg(feature = "kvm")]. - // You should never use #[cfg(feature = "kvm")] or #[cfg(feature = "mshv")] in the codebase. + // Essentially the kvm and mshv3 features are ignored on windows as long as you use #[cfg(kvm)] and not #[cfg(feature = "kvm")]. + // You should never use #[cfg(feature = "kvm")] or #[cfg(feature = "mshv3")] in the codebase. cfg_aliases::cfg_aliases! { gdb: { all(feature = "gdb", debug_assertions) }, kvm: { all(feature = "kvm", target_os = "linux") }, - mshv: { all(any(feature = "mshv2", feature = "mshv3"), target_os = "linux") }, + mshv3: { all(feature = "mshv3", target_os = "linux") }, crashdump: { all(feature = "crashdump") }, // print_debug feature is aliased with debug_assertions to make it only available in debug-builds. print_debug: { all(feature = "print_debug", debug_assertions) }, - // the following features are mutually exclusive but rather than enforcing that here we are enabling mshv2 to override mshv3 when both are enabled - // because mshv3 is in the default feature set we want to allow users to enable mshv2 without having to set --no-default-features and the re-enable - // the other features they want. - mshv2: { all(feature = "mshv2", target_os = "linux") }, - mshv3: { all(feature = "mshv3", not(feature="mshv2"), target_os = "linux") }, } #[cfg(feature = "build-metadata")] diff --git a/src/hyperlight_host/examples/guest-debugging/main.rs b/src/hyperlight_host/examples/guest-debugging/main.rs index 9d9ac230e..a9675e421 100644 --- a/src/hyperlight_host/examples/guest-debugging/main.rs +++ b/src/hyperlight_host/examples/guest-debugging/main.rs @@ -136,9 +136,6 @@ mod tests { write_cmds_file(&cmd_file_path, cmd).expect("Failed to write gdb commands to file"); - #[cfg(mshv2)] // mshv3 is a default feature is mutually exclusive with the mshv2 feature - let features = "gdb,mshv2"; - #[cfg(not(mshv2))] let features = "gdb"; // build it before running to avoid a race condition below diff --git a/src/hyperlight_host/src/error.rs b/src/hyperlight_host/src/error.rs index 9851b9f61..b46dd5a6c 100644 --- a/src/hyperlight_host/src/error.rs +++ b/src/hyperlight_host/src/error.rs @@ -14,11 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ -#[cfg(mshv2)] -extern crate mshv_ioctls2 as mshv_ioctls; - #[cfg(mshv3)] -extern crate mshv_ioctls3 as mshv_ioctls; +extern crate mshv_ioctls; use std::array::TryFromSliceError; use std::cell::{BorrowError, BorrowMutError}; @@ -172,7 +169,7 @@ pub enum HyperlightError { /// mshv Error Occurred #[error("mshv Error {0:?}")] - #[cfg(mshv)] + #[cfg(mshv3)] MSHVError(#[from] mshv_ioctls::MshvError), /// No Hypervisor was found for Sandbox. @@ -382,7 +379,7 @@ impl HyperlightError { HyperlightError::VmmSysError(_) => false, #[cfg(kvm)] HyperlightError::KVMError(_) => false, - #[cfg(mshv)] + #[cfg(mshv3)] HyperlightError::MSHVError(_) => false, #[cfg(gdb)] HyperlightError::TranslateGuestAddress(_) => false, diff --git a/src/hyperlight_host/src/hypervisor/gdb/mod.rs b/src/hyperlight_host/src/hypervisor/gdb/mod.rs index 4c57958e5..fb4829ef0 100644 --- a/src/hyperlight_host/src/hypervisor/gdb/mod.rs +++ b/src/hyperlight_host/src/hypervisor/gdb/mod.rs @@ -20,7 +20,7 @@ mod event_loop; mod hyperv_debug; #[cfg(kvm)] mod kvm_debug; -#[cfg(mshv)] +#[cfg(mshv3)] mod mshv_debug; mod x86_64_target; @@ -40,7 +40,7 @@ use hyperlight_common::mem::PAGE_SIZE; pub(crate) use hyperv_debug::HypervDebug; #[cfg(kvm)] pub(crate) use kvm_debug::KvmDebug; -#[cfg(mshv)] +#[cfg(mshv3)] pub(crate) use mshv_debug::MshvDebug; use thiserror::Error; use x86_64_target::HyperlightSandboxTarget; diff --git a/src/hyperlight_host/src/hypervisor/gdb/mshv_debug.rs b/src/hyperlight_host/src/hypervisor/gdb/mshv_debug.rs index 92569a2fd..0b5aba47c 100644 --- a/src/hyperlight_host/src/hypervisor/gdb/mshv_debug.rs +++ b/src/hyperlight_host/src/hypervisor/gdb/mshv_debug.rs @@ -14,15 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -#[cfg(mshv2)] -extern crate mshv_bindings2 as mshv_bindings; -#[cfg(mshv2)] -extern crate mshv_ioctls2 as mshv_ioctls; - #[cfg(mshv3)] -extern crate mshv_bindings3 as mshv_bindings; +extern crate mshv_bindings; #[cfg(mshv3)] -extern crate mshv_ioctls3 as mshv_ioctls; +extern crate mshv_ioctls; use std::collections::HashMap; diff --git a/src/hyperlight_host/src/hypervisor/hyperv_linux.rs b/src/hyperlight_host/src/hypervisor/hyperv_linux.rs index 801f361a7..758e7a14e 100644 --- a/src/hyperlight_host/src/hypervisor/hyperv_linux.rs +++ b/src/hyperlight_host/src/hypervisor/hyperv_linux.rs @@ -14,27 +14,20 @@ See the License for the specific language governing permissions and limitations under the License. */ -#[cfg(mshv2)] -extern crate mshv_bindings2 as mshv_bindings; -#[cfg(mshv2)] -extern crate mshv_ioctls2 as mshv_ioctls; - -#[cfg(mshv3)] -extern crate mshv_bindings3 as mshv_bindings; -#[cfg(mshv3)] -extern crate mshv_ioctls3 as mshv_ioctls; +extern crate mshv_bindings; +extern crate mshv_ioctls; use std::fmt::{Debug, Formatter}; use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; use std::sync::{Arc, Mutex}; use log::{LevelFilter, error}; -#[cfg(mshv2)] -use mshv_bindings::hv_message; use mshv_bindings::{ FloatingPointUnit, SpecialRegisters, StandardRegisters, hv_message_type, hv_message_type_HVMSG_GPA_INTERCEPT, hv_message_type_HVMSG_UNMAPPED_GPA, - hv_message_type_HVMSG_X64_HALT, hv_message_type_HVMSG_X64_IO_PORT_INTERCEPT, hv_register_assoc, + hv_message_type_HVMSG_X64_HALT, hv_message_type_HVMSG_X64_IO_PORT_INTERCEPT, + hv_partition_property_code_HV_PARTITION_PROPERTY_SYNTHETIC_PROC_FEATURES, + hv_partition_synthetic_processor_features, hv_register_assoc, hv_register_name_HV_X64_REGISTER_RIP, hv_register_value, mshv_user_mem_region, }; #[cfg(gdb)] @@ -43,11 +36,6 @@ use mshv_bindings::{ hv_intercept_type_HV_INTERCEPT_TYPE_EXCEPTION, hv_message_type_HVMSG_X64_EXCEPTION_INTERCEPT, mshv_install_intercept, }; -#[cfg(mshv3)] -use mshv_bindings::{ - hv_partition_property_code_HV_PARTITION_PROPERTY_SYNTHETIC_PROC_FEATURES, - hv_partition_synthetic_processor_features, -}; use mshv_ioctls::{Mshv, VcpuFd, VmFd}; use tracing::{Span, instrument}; #[cfg(feature = "trace_guest")] @@ -326,9 +314,7 @@ impl HypervLinuxDriver { ) -> Result { let mshv = Mshv::new()?; let pr = Default::default(); - #[cfg(mshv2)] - let vm_fd = mshv.create_vm_with_config(&pr)?; - #[cfg(mshv3)] + let vm_fd = { // It's important to avoid create_vm() and explicitly use // create_vm_with_args() with an empty arguments structure @@ -697,12 +683,6 @@ impl Hypervisor for HypervLinuxDriver { // to interrupt it until `running` is set to false. The `vcpu_fd::run()` call will // return either normally with an exit reason, or from being "kicked" by out signal handler, with an EINTR error, // both of which are fine. - #[cfg(mshv2)] - { - let hv_message: hv_message = Default::default(); - self.vcpu_fd.run(hv_message) - } - #[cfg(mshv3)] self.vcpu_fd.run() }; // Note: if a `InterruptHandle::kill()` called while this thread is **here** diff --git a/src/hyperlight_host/src/hypervisor/mod.rs b/src/hyperlight_host/src/hypervisor/mod.rs index e5592509a..8f2298059 100644 --- a/src/hyperlight_host/src/hypervisor/mod.rs +++ b/src/hyperlight_host/src/hypervisor/mod.rs @@ -29,7 +29,7 @@ use crate::sandbox::trace::MemTraceInfo; use crate::{HyperlightError, Result, log_then_return}; /// HyperV-on-linux functionality -#[cfg(mshv)] +#[cfg(mshv3)] pub mod hyperv_linux; #[cfg(target_os = "windows")] /// Hyperv-on-windows functionality @@ -63,10 +63,10 @@ pub(crate) mod crashdump; use std::fmt::Debug; use std::str::FromStr; -#[cfg(any(kvm, mshv))] +#[cfg(any(kvm, mshv3))] use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; use std::sync::{Arc, Mutex}; -#[cfg(any(kvm, mshv))] +#[cfg(any(kvm, mshv3))] use std::time::Duration; #[cfg(gdb)] @@ -486,7 +486,7 @@ pub trait InterruptHandle: Debug + Send + Sync { fn dropped(&self) -> bool; } -#[cfg(any(kvm, mshv))] +#[cfg(any(kvm, mshv3))] #[derive(Debug)] pub(super) struct LinuxInterruptHandle { /// 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 { sig_rt_min_offset: u8, } -#[cfg(any(kvm, mshv))] +#[cfg(any(kvm, mshv3))] impl LinuxInterruptHandle { const RUNNING_BIT: u64 = 1 << 63; const MAX_GENERATION: u64 = Self::RUNNING_BIT - 1; @@ -593,7 +593,7 @@ impl LinuxInterruptHandle { } } -#[cfg(any(kvm, mshv))] +#[cfg(any(kvm, mshv3))] impl InterruptHandle for LinuxInterruptHandle { fn kill(&self) -> bool { self.cancel_requested.store(true, Ordering::Relaxed); diff --git a/src/hyperlight_host/src/hypervisor/regs/fpu.rs b/src/hyperlight_host/src/hypervisor/regs/fpu.rs index 0ccd080ab..0fdbde31d 100644 --- a/src/hyperlight_host/src/hypervisor/regs/fpu.rs +++ b/src/hyperlight_host/src/hypervisor/regs/fpu.rs @@ -13,22 +13,17 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -#[cfg(mshv2)] -extern crate mshv_bindings2 as mshv_bindings; -#[cfg(mshv2)] -extern crate mshv_ioctls2 as mshv_ioctls; - #[cfg(mshv3)] -extern crate mshv_bindings3 as mshv_bindings; +extern crate mshv_bindings; #[cfg(mshv3)] -extern crate mshv_ioctls3 as mshv_ioctls; +extern crate mshv_ioctls; #[cfg(target_os = "windows")] use std::collections::HashSet; #[cfg(kvm)] use kvm_bindings::kvm_fpu; -#[cfg(mshv)] +#[cfg(mshv3)] use mshv_bindings::FloatingPointUnit; #[cfg(target_os = "windows")] @@ -91,7 +86,7 @@ impl From<&CommonFpu> for kvm_fpu { } } -#[cfg(mshv)] +#[cfg(mshv3)] impl From<&CommonFpu> for FloatingPointUnit { fn from(common_fpu: &CommonFpu) -> FloatingPointUnit { FloatingPointUnit { @@ -129,7 +124,7 @@ impl From<&kvm_fpu> for CommonFpu { } } -#[cfg(mshv)] +#[cfg(mshv3)] impl From<&FloatingPointUnit> for CommonFpu { fn from(mshv_fpu: &FloatingPointUnit) -> Self { Self { @@ -390,7 +385,7 @@ mod tests { assert_eq!(original, round_tripped); } - #[cfg(mshv)] + #[cfg(mshv3)] #[test] fn round_trip_mshv_fpu() { use mshv_bindings::FloatingPointUnit; diff --git a/src/hyperlight_host/src/hypervisor/regs/special_regs.rs b/src/hyperlight_host/src/hypervisor/regs/special_regs.rs index b20291d16..7d4267c2d 100644 --- a/src/hyperlight_host/src/hypervisor/regs/special_regs.rs +++ b/src/hyperlight_host/src/hypervisor/regs/special_regs.rs @@ -14,22 +14,17 @@ See the License for the specific language governing permissions and limitations under the License. */ -#[cfg(mshv2)] -extern crate mshv_bindings2 as mshv_bindings; -#[cfg(mshv2)] -extern crate mshv_ioctls2 as mshv_ioctls; - #[cfg(mshv3)] -extern crate mshv_bindings3 as mshv_bindings; +extern crate mshv_bindings; #[cfg(mshv3)] -extern crate mshv_ioctls3 as mshv_ioctls; +extern crate mshv_ioctls; #[cfg(target_os = "windows")] use std::collections::HashSet; #[cfg(kvm)] use kvm_bindings::{kvm_dtable, kvm_segment, kvm_sregs}; -#[cfg(mshv)] +#[cfg(mshv3)] use mshv_bindings::{SegmentRegister, SpecialRegisters, TableRegister}; #[cfg(target_os = "windows")] use windows::Win32::System::Hypervisor::*; @@ -59,7 +54,7 @@ pub(crate) struct CommonSpecialRegisters { pub interrupt_bitmap: [u64; 4], } -#[cfg(mshv)] +#[cfg(mshv3)] impl From<&SpecialRegisters> for CommonSpecialRegisters { fn from(value: &SpecialRegisters) -> Self { CommonSpecialRegisters { @@ -85,7 +80,7 @@ impl From<&SpecialRegisters> for CommonSpecialRegisters { } } -#[cfg(mshv)] +#[cfg(mshv3)] impl From<&CommonSpecialRegisters> for SpecialRegisters { fn from(other: &CommonSpecialRegisters) -> Self { SpecialRegisters { @@ -345,7 +340,7 @@ pub(crate) struct CommonSegmentRegister { pub padding: u8, } -#[cfg(mshv)] +#[cfg(mshv3)] impl From for CommonSegmentRegister { fn from(other: SegmentRegister) -> Self { CommonSegmentRegister { @@ -366,7 +361,7 @@ impl From for CommonSegmentRegister { } } -#[cfg(mshv)] +#[cfg(mshv3)] impl From for SegmentRegister { fn from(other: CommonSegmentRegister) -> Self { SegmentRegister { @@ -498,7 +493,7 @@ pub(crate) struct CommonTableRegister { pub limit: u16, } -#[cfg(mshv)] +#[cfg(mshv3)] impl From for CommonTableRegister { fn from(other: TableRegister) -> Self { CommonTableRegister { @@ -508,7 +503,7 @@ impl From for CommonTableRegister { } } -#[cfg(mshv)] +#[cfg(mshv3)] impl From for TableRegister { fn from(other: CommonTableRegister) -> Self { TableRegister { @@ -623,7 +618,7 @@ mod tests { assert_eq!(original, roundtrip); } - #[cfg(mshv)] + #[cfg(mshv3)] #[test] fn round_trip_mshv_sregs() { let original = sample_common_special_registers(); diff --git a/src/hyperlight_host/src/hypervisor/regs/standard_regs.rs b/src/hyperlight_host/src/hypervisor/regs/standard_regs.rs index cc39b3247..d97f4cb68 100644 --- a/src/hyperlight_host/src/hypervisor/regs/standard_regs.rs +++ b/src/hyperlight_host/src/hypervisor/regs/standard_regs.rs @@ -14,19 +14,14 @@ See the License for the specific language governing permissions and limitations under the License. */ -#[cfg(mshv2)] -extern crate mshv_bindings2 as mshv_bindings; -#[cfg(mshv2)] -extern crate mshv_ioctls2 as mshv_ioctls; - #[cfg(mshv3)] -extern crate mshv_bindings3 as mshv_bindings; +extern crate mshv_bindings; #[cfg(mshv3)] -extern crate mshv_ioctls3 as mshv_ioctls; +extern crate mshv_ioctls; #[cfg(kvm)] use kvm_bindings::kvm_regs; -#[cfg(mshv)] +#[cfg(mshv3)] use mshv_bindings::StandardRegisters; #[derive(Debug, Default, Copy, Clone, PartialEq)] @@ -106,7 +101,7 @@ impl From<&CommonRegisters> for kvm_regs { // --- MSHV --- -#[cfg(mshv)] +#[cfg(mshv3)] impl From<&StandardRegisters> for CommonRegisters { fn from(mshv_regs: &StandardRegisters) -> Self { CommonRegisters { @@ -132,7 +127,7 @@ impl From<&StandardRegisters> for CommonRegisters { } } -#[cfg(mshv)] +#[cfg(mshv3)] impl From<&CommonRegisters> for StandardRegisters { fn from(regs: &CommonRegisters) -> Self { StandardRegisters { @@ -380,7 +375,7 @@ mod tests { assert_eq!(original, converted); } - #[cfg(mshv)] + #[cfg(mshv3)] #[test] fn round_trip_mshv_regs() { let original = common_regs(); diff --git a/src/hyperlight_host/src/mem/memory_region.rs b/src/hyperlight_host/src/mem/memory_region.rs index 22f71d65b..192298aaa 100644 --- a/src/hyperlight_host/src/mem/memory_region.rs +++ b/src/hyperlight_host/src/mem/memory_region.rs @@ -14,33 +14,24 @@ See the License for the specific language governing permissions and limitations under the License. */ -#[cfg(mshv2)] -extern crate mshv_bindings2 as mshv_bindings; -#[cfg(mshv2)] -extern crate mshv_ioctls2 as mshv_ioctls; - #[cfg(mshv3)] -extern crate mshv_bindings3 as mshv_bindings; +extern crate mshv_bindings; #[cfg(mshv3)] -extern crate mshv_ioctls3 as mshv_ioctls; +extern crate mshv_ioctls; use std::ops::Range; use bitflags::bitflags; -#[cfg(mshv)] +#[cfg(mshv3)] use hyperlight_common::mem::PAGE_SHIFT; use hyperlight_common::mem::PAGE_SIZE_USIZE; #[cfg(kvm)] use kvm_bindings::{KVM_MEM_READONLY, kvm_userspace_memory_region}; -#[cfg(mshv2)] -use mshv_bindings::{ - HV_MAP_GPA_EXECUTABLE, HV_MAP_GPA_PERMISSIONS_NONE, HV_MAP_GPA_READABLE, HV_MAP_GPA_WRITABLE, -}; #[cfg(mshv3)] use mshv_bindings::{ MSHV_SET_MEM_BIT_EXECUTABLE, MSHV_SET_MEM_BIT_UNMAP, MSHV_SET_MEM_BIT_WRITABLE, }; -#[cfg(mshv)] +#[cfg(mshv3)] use mshv_bindings::{hv_x64_memory_intercept_message, mshv_user_mem_region}; #[cfg(target_os = "windows")] use windows::Win32::System::Hypervisor::{self, WHV_MEMORY_ACCESS_TYPE}; @@ -136,7 +127,7 @@ impl TryFrom for MemoryRegionFlags { } } -#[cfg(mshv)] +#[cfg(mshv3)] impl TryFrom for MemoryRegionFlags { type Error = crate::HyperlightError; @@ -261,52 +252,30 @@ impl MemoryRegionVecBuilder { } } -#[cfg(mshv)] +#[cfg(mshv3)] impl From for mshv_user_mem_region { fn from(region: MemoryRegion) -> Self { let size = (region.guest_region.end - region.guest_region.start) as u64; let guest_pfn = region.guest_region.start as u64 >> PAGE_SHIFT; let userspace_addr = region.host_region.start as u64; - #[cfg(mshv2)] - { - let flags = region.flags.iter().fold(0, |acc, flag| { - let flag_value = match flag { - MemoryRegionFlags::NONE => HV_MAP_GPA_PERMISSIONS_NONE, - MemoryRegionFlags::READ => HV_MAP_GPA_READABLE, - MemoryRegionFlags::WRITE => HV_MAP_GPA_WRITABLE, - MemoryRegionFlags::EXECUTE => HV_MAP_GPA_EXECUTABLE, - _ => 0, // ignore any unknown flags - }; - acc | flag_value - }); - mshv_user_mem_region { - guest_pfn, - size, - userspace_addr, - flags, - } - } - #[cfg(mshv3)] - { - let flags: u8 = region.flags.iter().fold(0, |acc, flag| { - let flag_value = match flag { - MemoryRegionFlags::NONE => 1 << MSHV_SET_MEM_BIT_UNMAP, - MemoryRegionFlags::READ => 0, - MemoryRegionFlags::WRITE => 1 << MSHV_SET_MEM_BIT_WRITABLE, - MemoryRegionFlags::EXECUTE => 1 << MSHV_SET_MEM_BIT_EXECUTABLE, - _ => 0, // ignore any unknown flags - }; - acc | flag_value - }); - - mshv_user_mem_region { - guest_pfn, - size, - userspace_addr, - flags, - ..Default::default() - } + let flags: u8 = region.flags.iter().fold(0, |acc, flag| { + let flag_value = match flag { + MemoryRegionFlags::NONE => 1 << MSHV_SET_MEM_BIT_UNMAP, + MemoryRegionFlags::READ => 0, + MemoryRegionFlags::WRITE => 1 << MSHV_SET_MEM_BIT_WRITABLE, + MemoryRegionFlags::EXECUTE => 1 << MSHV_SET_MEM_BIT_EXECUTABLE, + _ => 0, // ignore any unknown flags + }; + acc | flag_value + }); + + mshv_user_mem_region { + guest_pfn, + size, + userspace_addr, + flags, + ..Default::default() } } } diff --git a/src/hyperlight_host/src/sandbox/hypervisor.rs b/src/hyperlight_host/src/sandbox/hypervisor.rs index 114083c78..412f55000 100644 --- a/src/hyperlight_host/src/sandbox/hypervisor.rs +++ b/src/hyperlight_host/src/sandbox/hypervisor.rs @@ -17,7 +17,7 @@ limitations under the License. use std::fmt::Debug; use std::sync::OnceLock; -#[cfg(mshv)] +#[cfg(mshv3)] use crate::hypervisor::hyperv_linux; #[cfg(kvm)] use crate::hypervisor::kvm; @@ -27,7 +27,7 @@ static AVAILABLE_HYPERVISOR: OnceLock> = OnceLock::new(); pub fn get_available_hypervisor() -> &'static Option { AVAILABLE_HYPERVISOR.get_or_init(|| { cfg_if::cfg_if! { - if #[cfg(all(kvm, mshv))] { + if #[cfg(all(kvm, mshv3))] { // If both features are enabled, we need to determine hypervisor at runtime. // Currently /dev/kvm and /dev/mshv cannot exist on the same machine, so the first one // that works is guaranteed to be correct. @@ -44,7 +44,7 @@ pub fn get_available_hypervisor() -> &'static Option { } else { None } - } else if #[cfg(mshv)] { + } else if #[cfg(mshv3)] { if hyperv_linux::is_hypervisor_present() { Some(HypervisorType::Mshv) } else { @@ -71,7 +71,7 @@ pub(crate) enum HypervisorType { #[cfg(kvm)] Kvm, - #[cfg(mshv)] + #[cfg(mshv3)] Mshv, #[cfg(target_os = "windows")] @@ -79,7 +79,7 @@ pub(crate) enum HypervisorType { } // Compiler error if no hypervisor type is available -#[cfg(not(any(kvm, mshv, target_os = "windows")))] +#[cfg(not(any(kvm, mshv3, target_os = "windows")))] compile_error!( - "No hypervisor type is available for the current platform. Please enable either the `kvm` or `mshv` cargo feature." + "No hypervisor type is available for the current platform. Please enable either the `kvm` or `mshv3` cargo feature." ); diff --git a/src/hyperlight_host/src/sandbox/mod.rs b/src/hyperlight_host/src/sandbox/mod.rs index 381b6a89e..7ff940a23 100644 --- a/src/hyperlight_host/src/sandbox/mod.rs +++ b/src/hyperlight_host/src/sandbox/mod.rs @@ -103,11 +103,11 @@ mod tests { use std::path::Path; cfg_if::cfg_if! { - if #[cfg(all(kvm, mshv))] { + if #[cfg(all(kvm, mshv3))] { assert_eq!(Path::new("/dev/kvm").exists() || Path::new("/dev/mshv").exists(), super::is_hypervisor_present()); } else if #[cfg(kvm)] { assert_eq!(Path::new("/dev/kvm").exists(), super::is_hypervisor_present()); - } else if #[cfg(mshv)] { + } else if #[cfg(mshv3)] { assert_eq!(Path::new("/dev/mshv").exists(), super::is_hypervisor_present()); } else { assert!(!super::is_hypervisor_present()); diff --git a/src/hyperlight_host/src/sandbox/uninitialized_evolve.rs b/src/hyperlight_host/src/sandbox/uninitialized_evolve.rs index d1ba71ef9..a2f9edffb 100644 --- a/src/hyperlight_host/src/sandbox/uninitialized_evolve.rs +++ b/src/hyperlight_host/src/sandbox/uninitialized_evolve.rs @@ -168,7 +168,7 @@ pub(crate) fn set_up_hypervisor_partition( let trace_info = MemTraceInfo::new(_load_info)?; match *get_available_hypervisor() { - #[cfg(mshv)] + #[cfg(mshv3)] Some(HypervisorType::Mshv) => { let hv = crate::hypervisor::hyperv_linux::HypervLinuxDriver::new( regions,