diff --git a/arch/Cargo.toml b/arch/Cargo.toml index 74e6409c1..70bc61fbb 100644 --- a/arch/Cargo.toml +++ b/arch/Cargo.toml @@ -6,6 +6,7 @@ version = "0.1.0" [features] default = [] +kvm = [] sev_snp = [] tdx = [] diff --git a/arch/src/x86_64/mod.rs b/arch/src/x86_64/mod.rs index a4bbe4a73..a412663e2 100644 --- a/arch/src/x86_64/mod.rs +++ b/arch/src/x86_64/mod.rs @@ -34,6 +34,7 @@ use std::arch::x86_64; pub mod tdx; // CPUID feature bits +#[cfg(feature = "kvm")] const TSC_DEADLINE_TIMER_ECX_BIT: u8 = 24; // tsc deadline timer ecx bit. const HYPERVISOR_ECX_BIT: u8 = 31; // Hypervisor ecx bit. const MTRR_EDX_BIT: u8 = 12; // Hypervisor ecx bit. @@ -619,17 +620,8 @@ pub fn generate_common_cpuid( "Generating guest CPUID for with physical address size: {}", config.phys_bits ); - let cpuid_patches = vec![ - // Patch tsc deadline timer bit - CpuidPatch { - function: 1, - index: 0, - flags_bit: None, - eax_bit: None, - ebx_bit: None, - ecx_bit: Some(TSC_DEADLINE_TIMER_ECX_BIT), - edx_bit: None, - }, + #[allow(unused_mut)] + let mut cpuid_patches = vec![ // Patch hypervisor bit CpuidPatch { function: 1, @@ -652,6 +644,23 @@ pub fn generate_common_cpuid( }, ]; + #[cfg(feature = "kvm")] + if matches!( + hypervisor.hypervisor_type(), + hypervisor::HypervisorType::Kvm + ) { + // Patch tsc deadline timer bit + cpuid_patches.push(CpuidPatch { + function: 1, + index: 0, + flags_bit: None, + eax_bit: None, + ebx_bit: None, + ecx_bit: Some(TSC_DEADLINE_TIMER_ECX_BIT), + edx_bit: None, + }); + } + // Supported CPUID let mut cpuid = hypervisor .get_supported_cpuid() diff --git a/vmm/Cargo.toml b/vmm/Cargo.toml index 492540f90..9e9773c61 100644 --- a/vmm/Cargo.toml +++ b/vmm/Cargo.toml @@ -7,11 +7,17 @@ version = "0.1.0" [features] dbus_api = ["blocking", "futures", "zbus"] default = [] -dhat-heap = ["dhat"] # For heap profiling +dhat-heap = ["dhat"] # For heap profiling guest_debug = ["gdbstub", "gdbstub_arch", "kvm"] igvm = ["dep:igvm", "hex", "igvm_defs", "mshv-bindings", "range_map_vec"] io_uring = ["block/io_uring"] -kvm = ["hypervisor/kvm", "pci/kvm", "vfio-ioctls/kvm", "vm-device/kvm"] +kvm = [ + "arch/kvm", + "hypervisor/kvm", + "pci/kvm", + "vfio-ioctls/kvm", + "vm-device/kvm", +] mshv = ["hypervisor/mshv", "pci/mshv", "vfio-ioctls/mshv", "vm-device/mshv"] sev_snp = ["arch/sev_snp", "hypervisor/sev_snp", "virtio-devices/sev_snp"] tdx = ["arch/tdx", "hypervisor/tdx"]