devices: virtio: convert Interrupt to use IrqLevelEvent

Instead of using a separate pair of events in Interrupt structure
convert it to use IrqLevelEvent.

BUG=None
TEST=./tools/presubmit

Change-Id: Ibf0fa69b96de4686fc58a1a431c3a983b7ed4de1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3546575
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Dmitry Torokhov <dtor@chromium.org>
This commit is contained in:
Dmitry Torokhov 2022-03-19 15:12:02 -07:00 committed by Chromeos LUCI
parent bcc5368cc1
commit 7a8ce70bae
5 changed files with 17 additions and 21 deletions

View file

@ -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
),

View file

@ -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<AtomicUsize>,
interrupt_evt: Event,
interrupt_resample_evt: Event,
interrupt_evt: IrqLevelEvent,
msix_config: Option<Arc<Mutex<MsixConfig>>>,
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<I: SignalableInterrupt> SignalableInterrupt for Arc<Mutex<I>> {
impl Interrupt {
pub fn new(
interrupt_status: Arc<AtomicUsize>,
interrupt_evt: Event,
interrupt_resample_evt: Event,
interrupt_evt: IrqLevelEvent,
msix_config: Option<Arc<Mutex<MsixConfig>>>,
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();
}

View file

@ -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,
);

View file

@ -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,
),

View file

@ -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,
);