From 7fe399598d4eac01d8a01953f4578cf62d93c09f Mon Sep 17 00:00:00 2001 From: Bo Chen Date: Thu, 28 Apr 2022 15:20:24 -0700 Subject: [PATCH] vmm: device_manager: Map MMIO regions to the guest correctly To correctly map MMIO regions to the guest, we will need to wait for valid MMIO region information which is generated from 'PciDevice::allocate_bars()' (as a part of 'DeviceManager::add_pci_device()'). Signed-off-by: Bo Chen --- vmm/src/device_manager.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 82c246665..67b6935a6 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -3354,12 +3354,6 @@ impl DeviceManager { ) .map_err(DeviceManagerError::VfioUserCreate)?; - vfio_user_pci_device - .map_mmio_regions(&self.address_manager.vm, || { - self.memory_manager.lock().unwrap().allocate_memory_slot() - }) - .map_err(DeviceManagerError::VfioUserMapRegion)?; - let memory = self.memory_manager.lock().unwrap().guest_memory(); let vfio_user_mapping = Arc::new(VfioUserDmaMapping::new(client, Arc::new(memory))); for virtio_mem_device in self.virtio_mem_devices.iter() { @@ -3391,6 +3385,16 @@ impl DeviceManager { resources, )?; + // Note it is required to call 'add_pci_device()' in advance to have the list of + // mmio regions provisioned correctly + vfio_user_pci_device + .lock() + .unwrap() + .map_mmio_regions(&self.address_manager.vm, || { + self.memory_manager.lock().unwrap().allocate_memory_slot() + }) + .map_err(DeviceManagerError::VfioUserMapRegion)?; + let mut node = device_node!(vfio_user_name); // Update the device tree with correct resource information.