From 1db7718589551aa348c4acd53ac40e0d7f5df668 Mon Sep 17 00:00:00 2001 From: Michael Zhao Date: Tue, 18 Jan 2022 19:52:56 +0800 Subject: [PATCH] pci, vmm: Pass PCI BDF to vfio and vfio_user On AArch64, PCI BDF is used for devId in MSI-X routing entry. Signed-off-by: Michael Zhao --- pci/src/vfio.rs | 20 ++++++++++++++++---- pci/src/vfio_user.rs | 5 +++-- vmm/src/device_manager.rs | 2 ++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/pci/src/vfio.rs b/pci/src/vfio.rs index 7f942ba10..07e20cb89 100644 --- a/pci/src/vfio.rs +++ b/pci/src/vfio.rs @@ -5,7 +5,7 @@ use crate::{ msi_num_enabled_vectors, BarReprogrammingParams, MsiConfig, MsixCap, MsixConfig, - PciBarConfiguration, PciBarRegionType, PciCapabilityId, PciClassCode, PciConfiguration, + PciBarConfiguration, PciBarRegionType, PciBdf, PciCapabilityId, PciClassCode, PciConfiguration, PciDevice, PciDeviceError, PciHeaderType, PciSubclass, MSIX_TABLE_ENTRY_SIZE, }; use byteorder::{ByteOrder, LittleEndian}; @@ -557,6 +557,7 @@ impl VfioCommon { cap: u8, interrupt_manager: &Arc>, vfio_wrapper: &dyn Vfio, + bdf: PciBdf, ) { let msg_ctl = vfio_wrapper.read_config_word((cap + 2).into()); @@ -577,7 +578,11 @@ impl VfioCommon { }) .unwrap(); - let msix_config = MsixConfig::new(msix_cap.table_size(), interrupt_source_group.clone(), 0); + let msix_config = MsixConfig::new( + msix_cap.table_size(), + interrupt_source_group.clone(), + bdf.into(), + ); self.interrupt.msix = Some(VfioMsix { bar: msix_config, @@ -615,6 +620,7 @@ impl VfioCommon { &mut self, interrupt_manager: &Arc>, vfio_wrapper: &dyn Vfio, + bdf: PciBdf, ) { let mut cap_next = vfio_wrapper.read_config_byte(PCI_CONFIG_CAPABILITY_OFFSET); @@ -636,7 +642,12 @@ impl VfioCommon { if irq_info.count > 0 { // Parse capability only if the VFIO device // supports MSI-X. - self.parse_msix_capabilities(cap_next, interrupt_manager, vfio_wrapper); + self.parse_msix_capabilities( + cap_next, + interrupt_manager, + vfio_wrapper, + bdf, + ); } } } @@ -968,6 +979,7 @@ impl VfioPciDevice { msi_interrupt_manager: &Arc>, legacy_interrupt_group: Option>, iommu_attached: bool, + bdf: PciBdf, ) -> Result { let device = Arc::new(device); device.reset(); @@ -997,7 +1009,7 @@ impl VfioPciDevice { }, }; - common.parse_capabilities(msi_interrupt_manager, &vfio_wrapper); + common.parse_capabilities(msi_interrupt_manager, &vfio_wrapper, bdf); common.initialize_legacy_interrupt(legacy_interrupt_group, &vfio_wrapper)?; let vfio_pci_device = VfioPciDevice { diff --git a/pci/src/vfio_user.rs b/pci/src/vfio_user.rs index cf619ec0a..82a25b931 100644 --- a/pci/src/vfio_user.rs +++ b/pci/src/vfio_user.rs @@ -6,7 +6,7 @@ use crate::vfio::{Interrupt, Vfio, VfioCommon, VfioError}; use crate::{BarReprogrammingParams, PciBarRegionType, VfioPciError}; use crate::{ - PciClassCode, PciConfiguration, PciDevice, PciDeviceError, PciHeaderType, PciSubclass, + PciBdf, PciClassCode, PciConfiguration, PciDevice, PciDeviceError, PciHeaderType, PciSubclass, }; use hypervisor::HypervisorVmError; use std::any::Any; @@ -67,6 +67,7 @@ impl VfioUserPciDevice { client: Arc>, msi_interrupt_manager: &Arc>, legacy_interrupt_group: Option>, + bdf: PciBdf, ) -> Result { // This is used for the BAR and capabilities only let configuration = PciConfiguration::new( @@ -104,7 +105,7 @@ impl VfioUserPciDevice { }, }; - common.parse_capabilities(msi_interrupt_manager, &vfio_wrapper); + common.parse_capabilities(msi_interrupt_manager, &vfio_wrapper, bdf); common .initialize_legacy_interrupt(legacy_interrupt_group, &vfio_wrapper) .map_err(VfioUserPciDeviceError::InitializeLegacyInterrupts)?; diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 8113af100..cbd99e595 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -3025,6 +3025,7 @@ impl DeviceManager { &self.msi_interrupt_manager, legacy_interrupt_group, device_cfg.iommu, + pci_device_bdf, ) .map_err(DeviceManagerError::VfioPciCreate)?; @@ -3171,6 +3172,7 @@ impl DeviceManager { client.clone(), &self.msi_interrupt_manager, legacy_interrupt_group, + pci_device_bdf, ) .map_err(DeviceManagerError::VfioUserCreate)?;