vmm: Increase memory slot from virtio-pmem

Since virtio-pmem uses a KVM user memory region, it needs to increment
the slot index in use to prevent from any conflict with further VFIO
allocations (used for mapping mappable memory BARs).

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2019-08-01 09:00:08 -07:00 committed by Rob Bradford
parent 8c4c162109
commit c0756c429d

View File

@ -527,7 +527,7 @@ impl DeviceManager {
vm_cfg: &VmConfig, vm_cfg: &VmConfig,
msi_capable: bool, msi_capable: bool,
userspace_ioapic: bool, userspace_ioapic: bool,
mem_slots: u32, mut mem_slots: u32,
) -> DeviceManagerResult<Self> { ) -> DeviceManagerResult<Self> {
let mut io_bus = devices::Bus::new(); let mut io_bus = devices::Bus::new();
let mut mmio_bus = devices::Bus::new(); let mut mmio_bus = devices::Bus::new();
@ -621,6 +621,7 @@ impl DeviceManager {
&mut pci, &mut pci,
&mut buses, &mut buses,
&interrupt_info, &interrupt_info,
&mut mem_slots,
)?; )?;
DeviceManager::add_vfio_devices( DeviceManager::add_vfio_devices(
@ -655,6 +656,7 @@ impl DeviceManager {
pci: &mut PciConfigIo, pci: &mut PciConfigIo,
buses: &mut BusInfo, buses: &mut BusInfo,
interrupt_info: &InterruptInfo, interrupt_info: &InterruptInfo,
mut mem_slots: &mut u32,
) -> DeviceManagerResult<()> { ) -> DeviceManagerResult<()> {
// Add virtio-blk if required // Add virtio-blk if required
DeviceManager::add_virtio_block_devices( DeviceManager::add_virtio_block_devices(
@ -709,6 +711,7 @@ impl DeviceManager {
pci, pci,
buses, buses,
&interrupt_info, &interrupt_info,
&mut mem_slots,
)?; )?;
Ok(()) Ok(())
@ -879,6 +882,7 @@ impl DeviceManager {
pci: &mut PciConfigIo, pci: &mut PciConfigIo,
buses: &mut BusInfo, buses: &mut BusInfo,
interrupt_info: &InterruptInfo, interrupt_info: &InterruptInfo,
mem_slots: &mut u32,
) -> DeviceManagerResult<()> { ) -> DeviceManagerResult<()> {
// Add virtio-pmem if required // Add virtio-pmem if required
if let Some(pmem_list_cfg) = &vm_cfg.pmem { if let Some(pmem_list_cfg) = &vm_cfg.pmem {
@ -921,7 +925,7 @@ impl DeviceManager {
}; };
let mem_region = kvm_userspace_memory_region { let mem_region = kvm_userspace_memory_region {
slot: memory.num_regions() as u32, slot: *mem_slots as u32,
guest_phys_addr: pmem_guest_addr.raw_value(), guest_phys_addr: pmem_guest_addr.raw_value(),
memory_size: size, memory_size: size,
userspace_addr: addr as u64, userspace_addr: addr as u64,
@ -930,6 +934,9 @@ impl DeviceManager {
// Safe because the guest regions are guaranteed not to overlap. // Safe because the guest regions are guaranteed not to overlap.
let _ = unsafe { vm_fd.set_user_memory_region(mem_region) }; let _ = unsafe { vm_fd.set_user_memory_region(mem_region) };
// Increment the KVM slot number
*mem_slots += 1;
let virtio_pmem_device = let virtio_pmem_device =
vm_virtio::Pmem::new(file, pmem_guest_addr, size as GuestUsize) vm_virtio::Pmem::new(file, pmem_guest_addr, size as GuestUsize)
.map_err(DeviceManagerError::CreateVirtioPmem)?; .map_err(DeviceManagerError::CreateVirtioPmem)?;