Skip to content

Commit

Permalink
Add method to query KVM_CAP_X86_DISABLE_EXITS
Browse files Browse the repository at this point in the history
Add method to query KVM_CAP_X86_DISABLE_EXITS for x86 platforms.

Signed-off-by: Liu Jiang <[email protected]>
  • Loading branch information
jiangliu committed Jun 5, 2021
1 parent 808dd4b commit fde84ee
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/cap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
27 changes: 27 additions & 0 deletions src/ioctls/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CpuId> {
if num_entries > KVM_MAX_CPUID_ENTRIES {
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit fde84ee

Please sign in to comment.