From 9af477e9647a0c1c315957b413b9d04f446dd67d Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Wed, 10 Feb 2021 14:38:47 +0100 Subject: [PATCH] pci: vfio: Check VFIO device interrupt's support In case the VFIO device does not support MSI or MSI-X, the capabilities should not be parsed, avoiding the exposure of unsupported capabilities. Signed-off-by: Sebastien Boeuf --- pci/src/vfio.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pci/src/vfio.rs b/pci/src/vfio.rs index 5f499be9c..7d5b373fe 100644 --- a/pci/src/vfio.rs +++ b/pci/src/vfio.rs @@ -537,10 +537,22 @@ impl VfioPciDevice { match PciCapabilityID::from(cap_id) { PciCapabilityID::MessageSignalledInterrupts => { - self.parse_msi_capabilities(cap_next, interrupt_manager); + if let Some(irq_info) = self.device.get_irq_info(VFIO_PCI_MSI_IRQ_INDEX) { + if irq_info.count > 0 { + // Parse capability only if the VFIO device + // supports MSI. + self.parse_msi_capabilities(cap_next, interrupt_manager); + } + } } PciCapabilityID::MSIX => { - self.parse_msix_capabilities(cap_next, interrupt_manager); + if let Some(irq_info) = self.device.get_irq_info(VFIO_PCI_MSIX_IRQ_INDEX) { + if irq_info.count > 0 { + // Parse capability only if the VFIO device + // supports MSI-X. + self.parse_msix_capabilities(cap_next, interrupt_manager); + } + } } _ => {} };