From d11a67b0fef70561a32cacf18a9c379916ede19c Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Thu, 19 Mar 2020 10:10:41 +0000 Subject: [PATCH] vmm: Use more generic MmapRegion constructor Switch to MmapRegion::build() and fill in the fields appropriately. Signed-off-by: Rob Bradford --- vmm/src/device_manager.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 9186078bd..bb6b26c53 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -26,8 +26,8 @@ use arch::layout; use arch::layout::{APIC_START, IOAPIC_SIZE, IOAPIC_START}; use devices::{ioapic, BusDevice, HotPlugNotificationFlags}; use kvm_ioctls::*; -use libc::O_TMPFILE; use libc::TIOCGWINSZ; +use libc::{MAP_NORESERVE, MAP_SHARED, O_RDONLY, O_TMPFILE, PROT_READ, PROT_WRITE}; #[cfg(feature = "pci_support")] use pci::{ DeviceRelocation, PciBarRegionType, PciBus, PciConfigIo, PciConfigMmio, PciDevice, PciRoot, @@ -1403,9 +1403,17 @@ impl DeviceManager { } let cloned_file = file.try_clone().map_err(DeviceManagerError::CloneFile)?; - let mmap_region = - MmapRegion::from_file(FileOffset::new(cloned_file, 0), size as usize) - .map_err(DeviceManagerError::NewMmapRegion)?; + let mmap_region = MmapRegion::build( + Some(FileOffset::new(cloned_file, 0)), + size as usize, + if pmem_cfg.readonly { + PROT_READ + } else { + PROT_READ | PROT_WRITE + }, + MAP_NORESERVE | MAP_SHARED, + ) + .map_err(DeviceManagerError::NewMmapRegion)?; let addr: u64 = mmap_region.as_ptr() as u64; self._mmap_regions.push(mmap_region);