diff --git a/pci/src/msix.rs b/pci/src/msix.rs index 106bbae92..39530bb37 100644 --- a/pci/src/msix.rs +++ b/pci/src/msix.rs @@ -113,6 +113,12 @@ impl MsixConfig { let mut gsi_msi_routes = self.gsi_msi_routes.lock().unwrap(); if self.enabled && !self.masked { for (idx, table_entry) in self.table_entries.iter().enumerate() { + if !old_enabled || old_masked { + if let Err(e) = self.irq_routes[idx].enable(&self.vm_fd) { + error!("Failed enabling irq_fd: {:?}", e); + } + } + // Ignore MSI-X vector if masked. if table_entry.masked() { continue; @@ -134,6 +140,12 @@ impl MsixConfig { } } else { for route in self.irq_routes.iter() { + if old_enabled || !old_masked { + if let Err(e) = route.disable(&self.vm_fd) { + error!("Failed disabling irq_fd: {:?}", e); + } + } + gsi_msi_routes.remove(&route.gsi); } } diff --git a/vfio/src/vfio_pci.rs b/vfio/src/vfio_pci.rs index 3f7c5c001..ed9d0dc2c 100644 --- a/vfio/src/vfio_pci.rs +++ b/vfio/src/vfio_pci.rs @@ -550,21 +550,22 @@ impl VfioPciDevice { fn update_msix_capabilities(&mut self, offset: u64, data: &[u8]) -> Result<()> { match self.interrupt.update_msix(offset, data) { - Some(InterruptUpdateAction::EnableMsix) => match self.enable_irq_fds() { - Ok(fds) => { - if let Err(e) = self.device.enable_msix(fds) { + Some(InterruptUpdateAction::EnableMsix) => { + if let Some(msix) = &self.interrupt.msix { + let mut irq_fds: Vec<&EventFd> = Vec::new(); + for r in msix.bar.irq_routes.iter() { + irq_fds.push(&r.irq_fd); + } + + if let Err(e) = self.device.enable_msix(irq_fds) { warn!("Could not enable MSI-X: {}", e); } } - Err(e) => warn!("Could not get IRQ fds: {}", e), - }, + } Some(InterruptUpdateAction::DisableMsix) => { if let Err(e) = self.device.disable_msix() { warn!("Could not disable MSI-X: {}", e); } - if let Err(e) = self.disable_irq_fds() { - warn!("Could not disable MSI: {}", e); - } } _ => {} }