diff --git a/hypervisor/src/cpu.rs b/hypervisor/src/cpu.rs index 96b8cfabf..90254a0a2 100644 --- a/hypervisor/src/cpu.rs +++ b/hypervisor/src/cpu.rs @@ -12,6 +12,12 @@ use crate::aarch64::VcpuInit; #[cfg(target_arch = "aarch64")] use crate::aarch64::{RegList, Register, StandardRegisters}; +#[cfg(feature = "tdx")] +use crate::kvm::{TdxExitDetails, TdxExitStatus}; +#[cfg(all(feature = "mshv", target_arch = "x86_64"))] +use crate::x86_64::SuspendRegisters; +#[cfg(target_arch = "x86_64")] +use crate::x86_64::Xsave; #[cfg(target_arch = "x86_64")] use crate::x86_64::{CpuId, LapicState}; #[cfg(target_arch = "x86_64")] @@ -23,12 +29,6 @@ use crate::CpuState; use crate::DeviceAttr; #[cfg(feature = "kvm")] use crate::MpState; -#[cfg(all(feature = "mshv", target_arch = "x86_64"))] -use crate::SuspendRegisters; -#[cfg(target_arch = "x86_64")] -use crate::Xsave; -#[cfg(feature = "tdx")] -use crate::{TdxExitDetails, TdxExitStatus}; use thiserror::Error; #[cfg(all(feature = "kvm", target_arch = "x86_64"))] use vm_memory::GuestAddress; diff --git a/hypervisor/src/hypervisor.rs b/hypervisor/src/hypervisor.rs index 9612836b8..84839dca8 100644 --- a/hypervisor/src/hypervisor.rs +++ b/hypervisor/src/hypervisor.rs @@ -7,13 +7,13 @@ // Copyright 2018-2019 CrowdStrike, Inc. // // +#[cfg(feature = "tdx")] +use crate::kvm::TdxCapabilities; use crate::vm::Vm; #[cfg(target_arch = "x86_64")] use crate::x86_64::CpuId; #[cfg(target_arch = "x86_64")] use crate::x86_64::MsrList; -#[cfg(feature = "tdx")] -use crate::TdxCapabilities; use std::sync::Arc; use thiserror::Error; diff --git a/hypervisor/src/kvm/mod.rs b/hypervisor/src/kvm/mod.rs index ab217acc0..fcd4f0d5a 100644 --- a/hypervisor/src/kvm/mod.rs +++ b/hypervisor/src/kvm/mod.rs @@ -305,7 +305,7 @@ impl vm::Vm for KvmVm { kvm_route.u.msi.address_hi = cfg.high_addr; kvm_route.u.msi.data = cfg.data; - if self.check_extension(crate::Cap::MsiDevid) { + if self.check_extension(crate::kvm::Cap::MsiDevid) { // On AArch64, there is limitation on the range of the 'devid', // it can not be greater than 65536 (the max of u16). // diff --git a/hypervisor/src/lib.rs b/hypervisor/src/lib.rs index 2e9043466..1e557a2e9 100644 --- a/hypervisor/src/lib.rs +++ b/hypervisor/src/lib.rs @@ -51,19 +51,30 @@ mod device; pub use cpu::{HypervisorCpuError, Vcpu, VmExit}; pub use device::{Device, HypervisorDeviceError}; pub use hypervisor::{Hypervisor, HypervisorError}; -#[cfg(feature = "tdx")] -pub use kvm::TdxCapabilities; +#[cfg(all(feature = "kvm", target_arch = "aarch64"))] +pub use kvm::aarch64; +#[cfg(all(feature = "kvm", target_arch = "x86_64"))] +pub use kvm::x86_64; +// Aliased types exposed from both hypervisors #[cfg(feature = "kvm")] -pub use kvm::*; +pub use kvm::{ + ClockData, CpuState, CreateDevice, DeviceAttr, DeviceFd, IoEventAddress, IrqRoutingEntry, + MemoryRegion, MpState, VcpuEvents, VcpuExit, VmState, +}; #[cfg(all(feature = "mshv", target_arch = "x86_64"))] -pub use mshv::*; +pub use mshv::x86_64; +// Aliased types exposed from both hypervisors +#[cfg(all(feature = "mshv", target_arch = "x86_64"))] +pub use mshv::{ + CpuState, CreateDevice, DeviceAttr, DeviceFd, IoEventAddress, IrqRoutingEntry, MemoryRegion, + MpState, VcpuEvents, VcpuExit, VmState, +}; +use std::sync::Arc; pub use vm::{ DataMatch, HypervisorVmError, InterruptSourceConfig, LegacyIrqSourceConfig, MsiIrqSourceConfig, Vm, VmOps, }; -use std::sync::Arc; - pub fn new() -> std::result::Result, HypervisorError> { #[cfg(feature = "kvm")] let hv = kvm::KvmHypervisor::new()?; diff --git a/hypervisor/src/vm.rs b/hypervisor/src/vm.rs index 20ea84f4f..cf3c49b69 100644 --- a/hypervisor/src/vm.rs +++ b/hypervisor/src/vm.rs @@ -12,15 +12,15 @@ use crate::aarch64::VcpuInit; use crate::cpu::Vcpu; use crate::device::Device; +#[cfg(feature = "kvm")] +use crate::kvm::KvmVmState as VmState; +#[cfg(feature = "mshv")] +use crate::mshv::HvState as VmState; #[cfg(feature = "tdx")] use crate::x86_64::CpuId; #[cfg(all(feature = "kvm", target_arch = "x86_64"))] use crate::ClockData; use crate::CreateDevice; -#[cfg(feature = "mshv")] -use crate::HvState as VmState; -#[cfg(feature = "kvm")] -use crate::KvmVmState as VmState; use crate::{IoEventAddress, IrqRoutingEntry, MemoryRegion}; #[cfg(feature = "kvm")] use kvm_ioctls::Cap; diff --git a/vmm/src/cpu.rs b/vmm/src/cpu.rs index f4a8a037c..174c322b3 100644 --- a/vmm/src/cpu.rs +++ b/vmm/src/cpu.rs @@ -30,13 +30,13 @@ use devices::interrupt_controller::InterruptController; use gdbstub_arch::x86::reg::{X86SegmentRegs, X86_64CoreRegs}; #[cfg(target_arch = "aarch64")] use hypervisor::kvm::kvm_bindings; +#[cfg(feature = "tdx")] +use hypervisor::kvm::{TdxExitDetails, TdxExitStatus}; #[cfg(target_arch = "x86_64")] use hypervisor::x86_64::CpuId; #[cfg(all(target_arch = "x86_64", feature = "gdb"))] use hypervisor::x86_64::{SpecialRegisters, StandardRegisters}; use hypervisor::{CpuState, HypervisorCpuError, VmExit, VmOps}; -#[cfg(feature = "tdx")] -use hypervisor::{TdxExitDetails, TdxExitStatus}; use libc::{c_void, siginfo_t}; use seccompiler::{apply_filter, SeccompAction}; use std::collections::BTreeMap;