vfio: Update memory slot index to support multiple VFIO devices

In order to correctly support multiple VFIO devices, we need to
increment the memory slot index every time it is being used to set some
user memory region through KVM. That's why the mem_slot parameter is
made mutable.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf
2019-07-24 21:36:53 -07:00
committed by Rob Bradford
parent b9f677c46c
commit d92d797896
2 changed files with 17 additions and 7 deletions

View File

@@ -969,6 +969,7 @@ impl DeviceManager {
buses: &mut BusInfo,
mem_slots: u32,
) -> DeviceManagerResult<()> {
let mut mem_slot = mem_slots;
if let Some(device_list_cfg) = &vm_cfg.devices {
// Create the KVM VFIO device
let device_fd = DeviceManager::create_kvm_device(vm_fd)?;
@@ -986,8 +987,8 @@ impl DeviceManager {
.allocate_bars(allocator)
.map_err(DeviceManagerError::AllocateBars)?;
vfio_pci_device
.map_mmio_regions(vm_fd, mem_slots)
mem_slot = vfio_pci_device
.map_mmio_regions(vm_fd, mem_slot)
.map_err(DeviceManagerError::VfioMapRegion)?;
let vfio_pci_device = Arc::new(Mutex::new(vfio_pci_device));