msix: Perform interrupt enabling/disabling

In order to factorize one step further, we let MsixConfig perform the
interrupt enabling/disabling. This is done by registering/unregistering
the KVM irq_fds of all GSI routes related to this device.

And now that MsixConfig is in charge of the irq_fds, vfio-pci must rely
on it to retrieve them and provide them to the vfio driver.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf
2020-01-09 23:40:04 +01:00
committed by Samuel Ortiz
parent 19aeac40c9
commit 1e5e02801f
2 changed files with 21 additions and 8 deletions
+12
View File
@@ -113,6 +113,12 @@ impl MsixConfig {
let mut gsi_msi_routes = self.gsi_msi_routes.lock().unwrap(); let mut gsi_msi_routes = self.gsi_msi_routes.lock().unwrap();
if self.enabled && !self.masked { if self.enabled && !self.masked {
for (idx, table_entry) in self.table_entries.iter().enumerate() { 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. // Ignore MSI-X vector if masked.
if table_entry.masked() { if table_entry.masked() {
continue; continue;
@@ -134,6 +140,12 @@ impl MsixConfig {
} }
} else { } else {
for route in self.irq_routes.iter() { 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); gsi_msi_routes.remove(&route.gsi);
} }
} }
+9 -8
View File
@@ -550,21 +550,22 @@ impl VfioPciDevice {
fn update_msix_capabilities(&mut self, offset: u64, data: &[u8]) -> Result<()> { fn update_msix_capabilities(&mut self, offset: u64, data: &[u8]) -> Result<()> {
match self.interrupt.update_msix(offset, data) { match self.interrupt.update_msix(offset, data) {
Some(InterruptUpdateAction::EnableMsix) => match self.enable_irq_fds() { Some(InterruptUpdateAction::EnableMsix) => {
Ok(fds) => { if let Some(msix) = &self.interrupt.msix {
if let Err(e) = self.device.enable_msix(fds) { 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); warn!("Could not enable MSI-X: {}", e);
} }
} }
Err(e) => warn!("Could not get IRQ fds: {}", e), }
},
Some(InterruptUpdateAction::DisableMsix) => { Some(InterruptUpdateAction::DisableMsix) => {
if let Err(e) = self.device.disable_msix() { if let Err(e) = self.device.disable_msix() {
warn!("Could not disable MSI-X: {}", e); warn!("Could not disable MSI-X: {}", e);
} }
if let Err(e) = self.disable_irq_fds() {
warn!("Could not disable MSI: {}", e);
}
} }
_ => {} _ => {}
} }