vmm: Ensure that allocate_bars() is called before mmio_regions()

The allocate_bars method has a side effect which collates the BARs used
for the device and stores them internally. Ensure that any use of this
internal state is after the state is created otherwise no MMIO regions
will be seen and so none will be mapped.

Fixes: #3237

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2021-10-14 16:31:03 +01:00 committed by Bo Chen
parent d00eb4aa25
commit c25bd447a1

View File

@ -2886,7 +2886,7 @@ impl DeviceManager {
None None
}; };
let mut vfio_pci_device = VfioPciDevice::new( let vfio_pci_device = VfioPciDevice::new(
&self.address_manager.vm, &self.address_manager.vm,
vfio_device, vfio_device,
vfio_container, vfio_container,
@ -2908,21 +2908,6 @@ impl DeviceManager {
id id
}; };
vfio_pci_device
.map_mmio_regions(&self.address_manager.vm, || {
self.memory_manager.lock().unwrap().allocate_memory_slot()
})
.map_err(DeviceManagerError::VfioMapRegion)?;
let mut node = device_node!(vfio_name);
for region in vfio_pci_device.mmio_regions() {
node.resources.push(Resource::MmioAddressRange {
base: region.start.0,
size: region.length as u64,
});
}
let vfio_pci_device = Arc::new(Mutex::new(vfio_pci_device)); let vfio_pci_device = Arc::new(Mutex::new(vfio_pci_device));
self.add_pci_device( self.add_pci_device(
@ -2931,6 +2916,23 @@ impl DeviceManager {
pci_device_bdf, pci_device_bdf,
)?; )?;
vfio_pci_device
.lock()
.unwrap()
.map_mmio_regions(&self.address_manager.vm, || {
self.memory_manager.lock().unwrap().allocate_memory_slot()
})
.map_err(DeviceManagerError::VfioMapRegion)?;
let mut node = device_node!(vfio_name);
for region in vfio_pci_device.lock().unwrap().mmio_regions() {
node.resources.push(Resource::MmioAddressRange {
base: region.start.0,
size: region.length as u64,
});
}
node.pci_bdf = Some(pci_device_bdf); node.pci_bdf = Some(pci_device_bdf);
node.pci_device_handle = Some(PciDeviceHandle::Vfio(vfio_pci_device)); node.pci_device_handle = Some(PciDeviceHandle::Vfio(vfio_pci_device));