diff --git a/src/cap.rs b/src/cap.rs index 40714256..9d0e7c1f 100644 --- a/src/cap.rs +++ b/src/cap.rs @@ -140,6 +140,8 @@ pub enum Cap { S390UserSigp = KVM_CAP_S390_USER_SIGP, #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] SplitIrqchip = KVM_CAP_SPLIT_IRQCHIP, + #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] + DisableExits = KVM_CAP_X86_DISABLE_EXITS, ImmediateExit = KVM_CAP_IMMEDIATE_EXIT, ArmVmIPASize = KVM_CAP_ARM_VM_IPA_SIZE, MsiDevid = KVM_CAP_MSI_DEVID, diff --git a/src/ioctls/system.rs b/src/ioctls/system.rs index 1875f12c..07949466 100644 --- a/src/ioctls/system.rs +++ b/src/ioctls/system.rs @@ -248,6 +248,26 @@ impl Kvm { } } + /// Gets the `KVM_CAP_X86_DISABLE_EXITS` capability. + /// + /// # Example + /// + /// ``` + /// # use kvm_ioctls::Kvm; + /// let kvm = Kvm::new().unwrap(); + /// assert!(kvm.get_disable_exits_cap() >= 0); + /// ``` + /// + #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] + pub fn get_disable_exits_cap(&self) -> usize { + let x = self.check_extension_int(Cap::DisableExits); + if x > 0 { + x as usize + } else { + 0 + } + } + #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] fn get_cpuid(&self, kind: u64, num_entries: usize) -> Result { if num_entries > KVM_MAX_CPUID_ENTRIES { @@ -615,6 +635,13 @@ mod tests { assert!(kvm.get_nr_memslots() >= 32); } + #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] + #[test] + fn test_kvm_get_disable_exits() { + let kvm = Kvm::new().unwrap(); + let _disable_exits = kvm.get_disable_exits_cap(); + } + #[test] fn test_create_vm() { let kvm = Kvm::new().unwrap();