summary refs log tree commit diff
path: root/kvm
diff options
context:
space:
mode:
authorZhuocheng Ding <zhuocheng.ding@intel.corp-partner.google.com>2019-12-02 15:50:24 +0800
committerCommit Bot <commit-bot@chromium.org>2020-03-05 01:02:49 +0000
commitdb4c70d2151d054b6b4df58be432e500aeafecbe (patch)
tree20c86cafe4e8ca664f90a853518075d204c49173 /kvm
parentf2e90bf0b0ca101d2925e91ca50d3e9e5ea2fdb7 (diff)
downloadcrosvm-db4c70d2151d054b6b4df58be432e500aeafecbe.tar
crosvm-db4c70d2151d054b6b4df58be432e500aeafecbe.tar.gz
crosvm-db4c70d2151d054b6b4df58be432e500aeafecbe.tar.bz2
crosvm-db4c70d2151d054b6b4df58be432e500aeafecbe.tar.lz
crosvm-db4c70d2151d054b6b4df58be432e500aeafecbe.tar.xz
crosvm-db4c70d2151d054b6b4df58be432e500aeafecbe.tar.zst
crosvm-db4c70d2151d054b6b4df58be432e500aeafecbe.zip
devices: PIC: implement interrupt injection
TODO: Route irqfd to PIC, and use signal to kick vCPU thread when
interrupt is triggered.

BUG=chromium:908689
TEST=Unit tests in file.

Change-Id: I9a87502da57e725d3bb26d746a337d0ba44ef337
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1945797
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Zhuocheng Ding <zhuocheng.ding@intel.corp-partner.google.com>
Diffstat (limited to 'kvm')
-rw-r--r--kvm/src/lib.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/kvm/src/lib.rs b/kvm/src/lib.rs
index 66ebd20..2d951f2 100644
--- a/kvm/src/lib.rs
+++ b/kvm/src/lib.rs
@@ -1313,6 +1313,26 @@ impl Vcpu {
         });
     }
 
+    /// Request the VCPU to exit when it becomes possible to inject interrupts into the guest.
+    #[allow(clippy::cast_ptr_alignment)]
+    pub fn request_interrupt_window(&self) {
+        // Safe because we know we mapped enough memory to hold the kvm_run struct because the
+        // kernel told us how large it was. The pointer is page aligned so casting to a different
+        // type is well defined, hence the clippy allow attribute.
+        let run = unsafe { &mut *(self.run_mmap.as_ptr() as *mut kvm_run) };
+        run.request_interrupt_window = 1;
+    }
+
+    /// Checks if we can inject an interrupt into the VCPU.
+    #[allow(clippy::cast_ptr_alignment)]
+    pub fn ready_for_interrupt(&self) -> bool {
+        // Safe because we know we mapped enough memory to hold the kvm_run struct because the
+        // kernel told us how large it was. The pointer is page aligned so casting to a different
+        // type is well defined, hence the clippy allow attribute.
+        let run = unsafe { &mut *(self.run_mmap.as_ptr() as *mut kvm_run) };
+        run.ready_for_interrupt_injection != 0 && run.if_flag != 0
+    }
+
     /// Gets the VCPU registers.
     #[cfg(not(any(target_arch = "arm", target_arch = "aarch64")))]
     pub fn get_regs(&self) -> Result<kvm_regs> {