diff --git a/pci/src/vfio.rs b/pci/src/vfio.rs index ab775ba99..85b3d75dc 100644 --- a/pci/src/vfio.rs +++ b/pci/src/vfio.rs @@ -23,7 +23,7 @@ use vfio_ioctls::{ use vm_allocator::page_size::{ align_page_size_down, align_page_size_up, is_4k_aligned, is_4k_multiple, is_page_size_aligned, }; -use vm_allocator::{AddressAllocator, SystemAllocator}; +use vm_allocator::{AddressAllocator, MemorySlotAllocator, SystemAllocator}; use vm_device::dma_mapping::ExternalDmaMapping; use vm_device::interrupt::{ InterruptIndex, InterruptManager, InterruptSourceGroup, MsiIrqGroupConfig, @@ -1416,7 +1416,7 @@ pub struct VfioPciDevice { container: Arc, common: VfioCommon, iommu_attached: bool, - memory_slot: Arc u32 + Send + Sync>, + memory_slot_allocator: MemorySlotAllocator, } impl VfioPciDevice { @@ -1431,7 +1431,7 @@ impl VfioPciDevice { legacy_interrupt_group: Option>, iommu_attached: bool, bdf: PciBdf, - memory_slot: Arc u32 + Send + Sync>, + memory_slot_allocator: MemorySlotAllocator, snapshot: Option, x_nv_gpudirect_clique: Option, ) -> Result { @@ -1457,7 +1457,7 @@ impl VfioPciDevice { container, common, iommu_attached, - memory_slot, + memory_slot_allocator, }; Ok(vfio_pci_device) @@ -1635,7 +1635,7 @@ impl VfioPciDevice { } let user_memory_region = UserMemoryRegion { - slot: (self.memory_slot)(), + slot: self.memory_slot_allocator.next_memory_slot(), start: region.start.0 + area.offset, size: area.size, host_addr: host_addr as u64, diff --git a/pci/src/vfio_user.rs b/pci/src/vfio_user.rs index 63aff1af6..ce3e70f9e 100644 --- a/pci/src/vfio_user.rs +++ b/pci/src/vfio_user.rs @@ -13,7 +13,7 @@ use thiserror::Error; use vfio_bindings::bindings::vfio::*; use vfio_ioctls::VfioIrq; use vfio_user::{Client, Error as VfioUserError}; -use vm_allocator::{AddressAllocator, SystemAllocator}; +use vm_allocator::{AddressAllocator, MemorySlotAllocator, SystemAllocator}; use vm_device::dma_mapping::ExternalDmaMapping; use vm_device::interrupt::{InterruptManager, InterruptSourceGroup, MsiIrqGroupConfig}; use vm_device::{BusDevice, Resource}; @@ -35,7 +35,7 @@ pub struct VfioUserPciDevice { vm: Arc, client: Arc>, common: VfioCommon, - memory_slot: Arc u32 + Send + Sync>, + memory_slot_allocator: MemorySlotAllocator, } #[derive(Error, Debug)] @@ -74,7 +74,7 @@ impl VfioUserPciDevice { msi_interrupt_manager: Arc>, legacy_interrupt_group: Option>, bdf: PciBdf, - memory_slot: Arc u32 + Send + Sync>, + memory_slot_allocator: MemorySlotAllocator, snapshot: Option, ) -> Result { let resettable = client.lock().unwrap().resettable(); @@ -106,7 +106,7 @@ impl VfioUserPciDevice { vm: vm.clone(), client, common, - memory_slot, + memory_slot_allocator, }) } @@ -178,7 +178,7 @@ impl VfioUserPciDevice { } let user_memory_region = UserMemoryRegion { - slot: (self.memory_slot)(), + slot: self.memory_slot_allocator.next_memory_slot(), start: mmio_region.start.0 + s.offset, size: s.size, host_addr: host_addr as u64, diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 4c9b65fd3..03ab7c244 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -3432,7 +3432,7 @@ impl DeviceManager { legacy_interrupt_group, device_cfg.iommu, pci_device_bdf, - Arc::new(move || memory_manager.lock().unwrap().allocate_memory_slot()), + memory_manager.lock().unwrap().memory_slot_allocator(), vm_migration::snapshot_from_id(self.snapshot.as_ref(), vfio_name.as_str()), device_cfg.x_nv_gpudirect_clique, ) @@ -3596,7 +3596,7 @@ impl DeviceManager { self.msi_interrupt_manager.clone(), legacy_interrupt_group, pci_device_bdf, - Arc::new(move || memory_manager.lock().unwrap().allocate_memory_slot()), + memory_manager.lock().unwrap().memory_slot_allocator(), vm_migration::snapshot_from_id(self.snapshot.as_ref(), vfio_user_name.as_str()), ) .map_err(DeviceManagerError::VfioUserCreate)?;