diff --git a/crosvm-fuzz/block_fuzzer.rs b/crosvm-fuzz/block_fuzzer.rs index b944d1fc5d..de0f79892c 100644 --- a/crosvm-fuzz/block_fuzzer.rs +++ b/crosvm-fuzz/block_fuzzer.rs @@ -12,6 +12,7 @@ use std::sync::Arc; use base::Event; use cros_fuzz::fuzz_target; use devices::virtio::{base_features, Block, Interrupt, Queue, VirtioDevice}; +use devices::IrqLevelEvent; use hypervisor::ProtectionType; use vm_memory::{GuestAddress, GuestMemory}; @@ -87,8 +88,7 @@ fuzz_target!(|bytes| { mem, Interrupt::new( Arc::new(AtomicUsize::new(0)), - Event::new().unwrap(), - Event::new().unwrap(), + IrqLevelEvent::new().unwrap(), None, // msix_config 0xFFFF, // VIRTIO_MSI_NO_VECTOR ), diff --git a/devices/src/virtio/interrupt.rs b/devices/src/virtio/interrupt.rs index ba210547ce..ba98a51db5 100644 --- a/devices/src/virtio/interrupt.rs +++ b/devices/src/virtio/interrupt.rs @@ -3,6 +3,7 @@ // found in the LICENSE file. use super::{INTERRUPT_STATUS_CONFIG_CHANGED, INTERRUPT_STATUS_USED_RING, VIRTIO_MSI_NO_VECTOR}; +use crate::irq_event::IrqLevelEvent; use crate::pci::MsixConfig; use base::Event; use std::sync::atomic::{AtomicUsize, Ordering}; @@ -31,8 +32,7 @@ pub trait SignalableInterrupt { pub struct Interrupt { interrupt_status: Arc, - interrupt_evt: Event, - interrupt_resample_evt: Event, + interrupt_evt: IrqLevelEvent, msix_config: Option>>, config_msix_vector: u16, } @@ -62,7 +62,7 @@ impl SignalableInterrupt for Interrupt { == 0 { // Write to irqfd to inject INTx interrupt - self.interrupt_evt.write(1).unwrap(); + self.interrupt_evt.trigger().unwrap(); } } @@ -71,12 +71,12 @@ impl SignalableInterrupt for Interrupt { } fn get_resample_evt(&self) -> Option<&Event> { - Some(&self.interrupt_resample_evt) + Some(self.interrupt_evt.get_resample()) } fn do_interrupt_resample(&self) { if self.interrupt_status.load(Ordering::SeqCst) != 0 { - self.interrupt_evt.write(1).unwrap(); + self.interrupt_evt.trigger().unwrap(); } } } @@ -105,15 +105,13 @@ impl SignalableInterrupt for Arc> { impl Interrupt { pub fn new( interrupt_status: Arc, - interrupt_evt: Event, - interrupt_resample_evt: Event, + interrupt_evt: IrqLevelEvent, msix_config: Option>>, config_msix_vector: u16, ) -> Interrupt { Interrupt { interrupt_status, interrupt_evt, - interrupt_resample_evt, msix_config, config_msix_vector, } @@ -121,12 +119,12 @@ impl Interrupt { /// Get a reference to the interrupt event. pub fn get_interrupt_evt(&self) -> &Event { - &self.interrupt_evt + self.interrupt_evt.get_trigger() } /// Handle interrupt resampling event, reading the value from the event and doing the resample. pub fn interrupt_resample(&self) { - let _ = self.interrupt_resample_evt.read(); + self.interrupt_evt.clear_resample(); self.do_interrupt_resample(); } diff --git a/devices/src/virtio/queue.rs b/devices/src/virtio/queue.rs index 7b47d3d70d..a436f748f6 100644 --- a/devices/src/virtio/queue.rs +++ b/devices/src/virtio/queue.rs @@ -621,7 +621,7 @@ impl Queue { mod tests { use super::super::Interrupt; use super::*; - use base::Event; + use crate::IrqLevelEvent; use std::convert::TryInto; use std::sync::atomic::AtomicUsize; use std::sync::Arc; @@ -723,8 +723,7 @@ mod tests { let interrupt = Interrupt::new( Arc::new(AtomicUsize::new(0)), - Event::new().unwrap(), - Event::new().unwrap(), + IrqLevelEvent::new().unwrap(), None, 10, ); @@ -800,8 +799,7 @@ mod tests { let interrupt = Interrupt::new( Arc::new(AtomicUsize::new(0)), - Event::new().unwrap(), - Event::new().unwrap(), + IrqLevelEvent::new().unwrap(), None, 10, ); diff --git a/devices/src/virtio/vhost/net.rs b/devices/src/virtio/vhost/net.rs index 78af0f5aaf..9fbdde554a 100644 --- a/devices/src/virtio/vhost/net.rs +++ b/devices/src/virtio/vhost/net.rs @@ -355,6 +355,7 @@ pub mod tests { use super::*; use crate::virtio::base_features; use crate::virtio::VIRTIO_MSI_NO_VECTOR; + use crate::IrqLevelEvent; use hypervisor::ProtectionType; use net_util::fakes::FakeTap; use std::path::PathBuf; @@ -417,8 +418,7 @@ pub mod tests { guest_memory, Interrupt::new( Arc::new(AtomicUsize::new(0)), - Event::new().unwrap(), - Event::new().unwrap(), + IrqLevelEvent::new().unwrap(), None, VIRTIO_MSI_NO_VECTOR, ), diff --git a/devices/src/virtio/virtio_pci_device.rs b/devices/src/virtio/virtio_pci_device.rs index 45e77c4319..811ece8636 100644 --- a/devices/src/virtio/virtio_pci_device.rs +++ b/devices/src/virtio/virtio_pci_device.rs @@ -23,6 +23,7 @@ use crate::pci::{ PciDeviceError, PciDisplaySubclass, PciHeaderType, PciId, PciInterruptPin, PciSubclass, }; use crate::virtio::ipc_memory_mapper::IpcMemoryMapper; +use crate::IrqLevelEvent; use self::virtio_pci_common_config::VirtioPciCommonConfig; @@ -451,8 +452,7 @@ impl VirtioPciDevice { let interrupt = Interrupt::new( self.interrupt_status.clone(), - interrupt_evt, - interrupt_resample_evt, + IrqLevelEvent::from_event_pair(interrupt_evt, interrupt_resample_evt), Some(self.msix_config.clone()), self.common_config.msix_config, );