summary refs log tree commit diff
path: root/hypervisor/src/kvm/mod.rs
diff options
context:
space:
mode:
authorColin Downs-Razouk <colindr@google.com>2020-05-26 08:43:18 -0700
committerCommit Bot <commit-bot@chromium.org>2020-06-10 16:33:35 +0000
commit2a0ce34f31533b8e6e8c7b7ed1a55990702958ac (patch)
tree62aead8a36749319ce206d479a16b909a5e164d8 /hypervisor/src/kvm/mod.rs
parent55f21f743481dc44da6457757358262940b81286 (diff)
downloadcrosvm-2a0ce34f31533b8e6e8c7b7ed1a55990702958ac.tar
crosvm-2a0ce34f31533b8e6e8c7b7ed1a55990702958ac.tar.gz
crosvm-2a0ce34f31533b8e6e8c7b7ed1a55990702958ac.tar.bz2
crosvm-2a0ce34f31533b8e6e8c7b7ed1a55990702958ac.tar.lz
crosvm-2a0ce34f31533b8e6e8c7b7ed1a55990702958ac.tar.xz
crosvm-2a0ce34f31533b8e6e8c7b7ed1a55990702958ac.tar.zst
crosvm-2a0ce34f31533b8e6e8c7b7ed1a55990702958ac.zip
devices: irqchip: KvmKernelIrqchip x86_64 impl
Implemented get/set_pic/ioapic/pit functions for the KvmKernelIrqchip.
Added respective functions on KvmVm for interacting with the underlying
KVM API.

Added associated tests for get/set functions.

BUG=chromium:1077058
TEST=ran devices tests and added get/set function tests

Change-Id: I66a29828fe2f1fbdf54d7325656a003ac09e36d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2219422
Reviewed-by: Udam Saini <udam@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
Diffstat (limited to 'hypervisor/src/kvm/mod.rs')
-rw-r--r--hypervisor/src/kvm/mod.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/hypervisor/src/kvm/mod.rs b/hypervisor/src/kvm/mod.rs
index 5fdf124..bf87e3d 100644
--- a/hypervisor/src/kvm/mod.rs
+++ b/hypervisor/src/kvm/mod.rs
@@ -171,6 +171,34 @@ impl KvmVm {
     fn create_kvm_vcpu(&self, _id: usize) -> Result<KvmVcpu> {
         Ok(KvmVcpu {})
     }
+
+    /// Crates an in kernel interrupt controller.
+    ///
+    /// See the documentation on the KVM_CREATE_IRQCHIP ioctl.
+    pub fn create_irq_chip(&self) -> Result<()> {
+        // Safe because we know that our file is a VM fd and we verify the return result.
+        let ret = unsafe { ioctl(self, KVM_CREATE_IRQCHIP()) };
+        if ret == 0 {
+            Ok(())
+        } else {
+            errno_result()
+        }
+    }
+    /// Sets the level on the given irq to 1 if `active` is true, and 0 otherwise.
+    pub fn set_irq_line(&self, irq: u32, active: bool) -> Result<()> {
+        let mut irq_level = kvm_irq_level::default();
+        irq_level.__bindgen_anon_1.irq = irq;
+        irq_level.level = if active { 1 } else { 0 };
+
+        // Safe because we know that our file is a VM fd, we know the kernel will only read the
+        // correct amount of memory from our pointer, and we verify the return result.
+        let ret = unsafe { ioctl_with_ref(self, KVM_IRQ_LINE(), &irq_level) };
+        if ret == 0 {
+            Ok(())
+        } else {
+            errno_result()
+        }
+    }
 }
 
 impl Vm for KvmVm {