From 1f029dd2dc946fcc6d3c05fc153045dda0cd5276 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Mon, 13 Jan 2020 20:43:53 +0100 Subject: [PATCH] vm-virtio: Add notifier to VirtioInterrupt trait The point is to be able to retrieve directly the event fd related to the interrupt, as this might optimize the way VirtioDevice devices are implemented. For instance, this can be used by vhost-user devices to provide vhost-user backends directly with the event fd triggering the interrupt related to a virtqueue. Signed-off-by: Sebastien Boeuf --- vm-virtio/src/device.rs | 3 +++ vm-virtio/src/transport/pci_device.rs | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/vm-virtio/src/device.rs b/vm-virtio/src/device.rs index da9ba1c6b..bf1bc1196 100644 --- a/vm-virtio/src/device.rs +++ b/vm-virtio/src/device.rs @@ -23,6 +23,9 @@ pub trait VirtioInterrupt: Send + Sync { int_type: &VirtioInterruptType, queue: Option<&Queue>, ) -> std::result::Result<(), std::io::Error>; + fn notifier(&self, _int_type: &VirtioInterruptType, _queue: Option<&Queue>) -> Option { + None + } } pub type VirtioIommuRemapping = diff --git a/vm-virtio/src/transport/pci_device.rs b/vm-virtio/src/transport/pci_device.rs index 8d7f5eb55..90196ce52 100755 --- a/vm-virtio/src/transport/pci_device.rs +++ b/vm-virtio/src/transport/pci_device.rs @@ -517,6 +517,26 @@ impl VirtioInterrupt for VirtioInterruptMsix { config.irq_routes[vector as usize].irq_fd.write(1) } + + fn notifier(&self, int_type: &VirtioInterruptType, queue: Option<&Queue>) -> Option { + let vector = match int_type { + VirtioInterruptType::Config => self.config_vector.load(Ordering::SeqCst), + VirtioInterruptType::Queue => { + if let Some(q) = queue { + q.vector + } else { + 0 + } + } + }; + + Some( + self.msix_config.lock().unwrap().irq_routes[vector as usize] + .irq_fd + .try_clone() + .unwrap(), + ) + } } impl PciDevice for VirtioPciDevice {