Skip to content

Commit fde84ee

Browse files
committed
Add method to query KVM_CAP_X86_DISABLE_EXITS
Add method to query KVM_CAP_X86_DISABLE_EXITS for x86 platforms. Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
1 parent 808dd4b commit fde84ee

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/cap.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ pub enum Cap {
140140
S390UserSigp = KVM_CAP_S390_USER_SIGP,
141141
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
142142
SplitIrqchip = KVM_CAP_SPLIT_IRQCHIP,
143+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
144+
DisableExits = KVM_CAP_X86_DISABLE_EXITS,
143145
ImmediateExit = KVM_CAP_IMMEDIATE_EXIT,
144146
ArmVmIPASize = KVM_CAP_ARM_VM_IPA_SIZE,
145147
MsiDevid = KVM_CAP_MSI_DEVID,

src/ioctls/system.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,26 @@ impl Kvm {
248248
}
249249
}
250250

251+
/// Gets the `KVM_CAP_X86_DISABLE_EXITS` capability.
252+
///
253+
/// # Example
254+
///
255+
/// ```
256+
/// # use kvm_ioctls::Kvm;
257+
/// let kvm = Kvm::new().unwrap();
258+
/// assert!(kvm.get_disable_exits_cap() >= 0);
259+
/// ```
260+
///
261+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
262+
pub fn get_disable_exits_cap(&self) -> usize {
263+
let x = self.check_extension_int(Cap::DisableExits);
264+
if x > 0 {
265+
x as usize
266+
} else {
267+
0
268+
}
269+
}
270+
251271
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
252272
fn get_cpuid(&self, kind: u64, num_entries: usize) -> Result<CpuId> {
253273
if num_entries > KVM_MAX_CPUID_ENTRIES {
@@ -615,6 +635,13 @@ mod tests {
615635
assert!(kvm.get_nr_memslots() >= 32);
616636
}
617637

638+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
639+
#[test]
640+
fn test_kvm_get_disable_exits() {
641+
let kvm = Kvm::new().unwrap();
642+
let _disable_exits = kvm.get_disable_exits_cap();
643+
}
644+
618645
#[test]
619646
fn test_create_vm() {
620647
let kvm = Kvm::new().unwrap();

0 commit comments

Comments
 (0)