summary refs log tree commit diff
path: root/devices/src/virtio/vhost/vsock.rs
diff options
context:
space:
mode:
Diffstat (limited to 'devices/src/virtio/vhost/vsock.rs')
-rw-r--r--devices/src/virtio/vhost/vsock.rs29
1 files changed, 21 insertions, 8 deletions
diff --git a/devices/src/virtio/vhost/vsock.rs b/devices/src/virtio/vhost/vsock.rs
index b39c368..b4101eb 100644
--- a/devices/src/virtio/vhost/vsock.rs
+++ b/devices/src/virtio/vhost/vsock.rs
@@ -21,13 +21,14 @@ use crate::virtio::{copy_config, Queue, VirtioDevice, TYPE_VSOCK};
 const QUEUE_SIZE: u16 = 256;
 const NUM_QUEUES: usize = 3;
 const QUEUE_SIZES: &[u16] = &[QUEUE_SIZE; NUM_QUEUES];
+const NUM_MSIX_VECTORS: u16 = NUM_QUEUES as u16;
 
 pub struct Vsock {
     worker_kill_evt: Option<EventFd>,
     kill_evt: Option<EventFd>,
     vhost_handle: Option<VhostVsockHandle>,
     cid: u64,
-    interrupt: Option<EventFd>,
+    interrupts: Option<Vec<EventFd>>,
     avail_features: u64,
     acked_features: u64,
 }
@@ -45,12 +46,17 @@ impl Vsock {
             | 1 << virtio_sys::vhost::VIRTIO_F_ANY_LAYOUT
             | 1 << virtio_sys::vhost::VIRTIO_F_VERSION_1;
 
+        let mut interrupts = Vec::new();
+        for _ in 0..NUM_MSIX_VECTORS {
+            interrupts.push(EventFd::new().map_err(Error::VhostIrqCreate)?);
+        }
+
         Ok(Vsock {
             worker_kill_evt: Some(kill_evt.try_clone().map_err(Error::CloneKillEventFd)?),
             kill_evt: Some(kill_evt),
             vhost_handle: Some(handle),
             cid,
-            interrupt: Some(EventFd::new().map_err(Error::VhostIrqCreate)?),
+            interrupts: Some(interrupts),
             avail_features,
             acked_features: 0,
         })
@@ -62,7 +68,7 @@ impl Vsock {
             kill_evt: None,
             vhost_handle: None,
             cid,
-            interrupt: None,
+            interrupts: None,
             avail_features: features,
             acked_features: 0,
         }
@@ -93,8 +99,10 @@ impl VirtioDevice for Vsock {
             keep_fds.push(handle.as_raw_fd());
         }
 
-        if let Some(interrupt) = &self.interrupt {
-            keep_fds.push(interrupt.as_raw_fd());
+        if let Some(interrupt) = &self.interrupts {
+            for vhost_int in interrupt.iter() {
+                keep_fds.push(vhost_int.as_raw_fd());
+            }
         }
 
         if let Some(worker_kill_evt) = &self.worker_kill_evt {
@@ -108,6 +116,10 @@ impl VirtioDevice for Vsock {
         TYPE_VSOCK
     }
 
+    fn msix_vectors(&self) -> u16 {
+        NUM_MSIX_VECTORS
+    }
+
     fn queue_max_sizes(&self) -> &[u16] {
         QUEUE_SIZES
     }
@@ -140,7 +152,7 @@ impl VirtioDevice for Vsock {
         _: GuestMemory,
         interrupt_evt: EventFd,
         interrupt_resample_evt: EventFd,
-        _msix_config: Option<Arc<Mutex<MsixConfig>>>,
+        msix_config: Option<Arc<Mutex<MsixConfig>>>,
         status: Arc<AtomicUsize>,
         queues: Vec<Queue>,
         queue_evts: Vec<EventFd>,
@@ -151,7 +163,7 @@ impl VirtioDevice for Vsock {
         }
 
         if let Some(vhost_handle) = self.vhost_handle.take() {
-            if let Some(interrupt) = self.interrupt.take() {
+            if let Some(interrupts) = self.interrupts.take() {
                 if let Some(kill_evt) = self.worker_kill_evt.take() {
                     let acked_features = self.acked_features;
                     let cid = self.cid;
@@ -164,10 +176,11 @@ impl VirtioDevice for Vsock {
                             let mut worker = Worker::new(
                                 vhost_queues,
                                 vhost_handle,
-                                interrupt,
+                                interrupts,
                                 status,
                                 interrupt_evt,
                                 interrupt_resample_evt,
+                                msix_config,
                                 acked_features,
                             );
                             let activate_vqs = |handle: &VhostVsockHandle| -> Result<()> {