From db4c70d2151d054b6b4df58be432e500aeafecbe Mon Sep 17 00:00:00 2001 From: Zhuocheng Ding Date: Mon, 2 Dec 2019 15:50:24 +0800 Subject: 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 Tested-by: kokoro Commit-Queue: Zhuocheng Ding --- kvm/src/lib.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'kvm') 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 { -- cgit 1.4.1