interrupt: Add a notifier method to the InterruptController

Both GIC and IOAPIC must implement a new method notifier() in order to
provide the caller with an EventFd corresponding to the IRQ it refers
to.

This is needed in anticipation for supporting INTx with VFIO PCI
devices.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2021-02-09 08:28:24 +01:00 committed by Rob Bradford
parent acfbee5b7a
commit 3bd47ffdc1
6 changed files with 20 additions and 5 deletions

View File

@ -8,6 +8,7 @@ use std::sync::Arc;
use vm_device::interrupt::{
InterruptIndex, InterruptManager, InterruptSourceGroup, MsiIrqGroupConfig,
};
use vmm_sys_util::eventfd::EventFd;
type Result<T> = result::Result<T, Error>;
@ -61,4 +62,8 @@ impl InterruptController for Gic {
Ok(())
}
fn notifier(&self, irq: usize) -> Option<EventFd> {
self.interrupt_source_group.notifier(irq as InterruptIndex)
}
}

View File

@ -4,6 +4,7 @@
use std::io;
use std::result;
use vmm_sys_util::eventfd::EventFd;
#[derive(Debug)]
pub enum Error {
@ -56,4 +57,5 @@ pub trait InterruptController: Send {
fn enable(&self) -> Result<()>;
#[cfg(target_arch = "x86_64")]
fn end_of_interrupt(&mut self, vec: u8);
fn notifier(&self, irq: usize) -> Option<EventFd>;
}

View File

@ -24,6 +24,7 @@ use vm_migration::{
Migratable, MigratableError, Pausable, Snapshot, SnapshotDataSection, Snapshottable,
Transportable,
};
use vmm_sys_util::eventfd::EventFd;
#[derive(Serialize, Deserialize)]
#[serde(remote = "GuestAddress")]
@ -405,6 +406,10 @@ impl InterruptController for Ioapic {
Ok(())
}
fn notifier(&self, irq: usize) -> Option<EventFd> {
self.interrupt_source_group.notifier(irq as InterruptIndex)
}
}
impl Snapshottable for Ioapic {

View File

@ -356,6 +356,9 @@ mod tests {
) -> result::Result<(), std::io::Error> {
Ok(())
}
fn notifier(&self, _index: InterruptIndex) -> Option<EventFd> {
Some(self.event_fd.try_clone().unwrap())
}
}
impl TestInterrupt {

View File

@ -169,11 +169,7 @@ pub trait InterruptSourceGroup: Send + Sync {
/// to inject interrupts into a guest, by writing to the file returned
/// by this method.
#[allow(unused_variables)]
fn notifier(&self, index: InterruptIndex) -> Option<EventFd> {
// One use case of the notifier is to implement vhost user backends.
// For all other implementations we can just return None here.
None
}
fn notifier(&self, index: InterruptIndex) -> Option<EventFd>;
/// Update the interrupt source group configuration.
///

View File

@ -246,6 +246,10 @@ impl InterruptSourceGroup for LegacyUserspaceInterruptGroup {
fn update(&self, _index: InterruptIndex, _config: InterruptSourceConfig) -> Result<()> {
Ok(())
}
fn notifier(&self, _index: InterruptIndex) -> Option<EventFd> {
self.ioapic.lock().unwrap().notifier(self.irq as usize)
}
}
pub struct LegacyUserspaceInterruptManager {