vmm: Add "readonly" parameter MemoryManager::create_userspace_mapping

Use this boolean to turn on the KVM_MEM_READONLY flag to indicate that
this memory mapping should not be writable by the VM.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2020-03-19 10:00:09 +00:00 committed by Sebastien Boeuf
parent 03cb26cc70
commit 7257e890ef
2 changed files with 7 additions and 2 deletions

View File

@ -1320,6 +1320,7 @@ impl DeviceManager {
fs_cache, fs_cache,
addr, addr,
false, false,
false,
) )
.map_err(DeviceManagerError::MemoryManager)?; .map_err(DeviceManagerError::MemoryManager)?;
@ -1417,6 +1418,7 @@ impl DeviceManager {
size, size,
addr, addr,
pmem_cfg.mergeable, pmem_cfg.mergeable,
false,
) )
.map_err(DeviceManagerError::MemoryManager)?; .map_err(DeviceManagerError::MemoryManager)?;

View File

@ -7,7 +7,7 @@
use acpi_tables::{aml, aml::Aml}; use acpi_tables::{aml, aml::Aml};
use arch::RegionType; use arch::RegionType;
use devices::BusDevice; use devices::BusDevice;
use kvm_bindings::kvm_userspace_memory_region; use kvm_bindings::{kvm_userspace_memory_region, KVM_MEM_READONLY};
use kvm_ioctls::*; use kvm_ioctls::*;
use std::convert::TryInto; use std::convert::TryInto;
use std::fs::{File, OpenOptions}; use std::fs::{File, OpenOptions};
@ -258,6 +258,7 @@ impl MemoryManager {
region.len() as u64, region.len() as u64,
region.as_ptr() as u64, region.as_ptr() as u64,
mergeable, mergeable,
false,
)?; )?;
Ok(()) Ok(())
})?; })?;
@ -350,6 +351,7 @@ impl MemoryManager {
region.len() as u64, region.len() as u64,
region.as_ptr() as u64, region.as_ptr() as u64,
self.mergeable, self.mergeable,
false,
)?; )?;
// Tell the allocator // Tell the allocator
@ -403,6 +405,7 @@ impl MemoryManager {
memory_size: u64, memory_size: u64,
userspace_addr: u64, userspace_addr: u64,
mergeable: bool, mergeable: bool,
readonly: bool,
) -> Result<u32, Error> { ) -> Result<u32, Error> {
let slot = self.allocate_kvm_memory_slot(); let slot = self.allocate_kvm_memory_slot();
let mem_region = kvm_userspace_memory_region { let mem_region = kvm_userspace_memory_region {
@ -410,7 +413,7 @@ impl MemoryManager {
guest_phys_addr, guest_phys_addr,
memory_size, memory_size,
userspace_addr, userspace_addr,
flags: 0, flags: if readonly { KVM_MEM_READONLY } else { 0 },
}; };
// Safe because the guest regions are guaranteed not to overlap. // Safe because the guest regions are guaranteed not to overlap.