crosvm: Extend VmMemoryRequest to support read_only map

Extend with read_only support so that the user can create a
read-only map for some read-only memory region, like read-only
memory backed MMIO bar.

BUG=None
TEST=Boot a VM

Change-Id: Ia6c1fd365808991f02298f7bbfaac0be8c801f8b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3292929
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Stevens <stevensd@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
This commit is contained in:
Chuanxiao Dong 2021-11-22 08:15:11 +08:00 committed by Commit Bot
parent a0638451f1
commit c41ee08e99
3 changed files with 5 additions and 1 deletions

View file

@ -782,6 +782,7 @@ impl VfioPciDevice {
size: mmap_size as usize,
offset,
gpa: guest_map_start,
read_only: false,
})
.is_err()
{

View file

@ -173,6 +173,7 @@ impl VfioPlatformDevice {
size: mmap_size.try_into().unwrap(),
offset,
gpa: guest_map_start,
read_only: false,
})
.is_err()
{

View file

@ -288,6 +288,7 @@ pub enum VmMemoryRequest {
size: usize,
offset: u64,
gpa: u64,
read_only: bool,
},
}
@ -439,6 +440,7 @@ impl VmMemoryRequest {
size,
offset,
gpa,
read_only,
} => {
let mmap = match MemoryMappingBuilder::new(size)
.from_descriptor(descriptor)
@ -448,7 +450,7 @@ impl VmMemoryRequest {
Ok(v) => v,
Err(_e) => return VmMemoryResponse::Err(SysError::new(EINVAL)),
};
match vm.add_memory_region(GuestAddress(gpa), Box::new(mmap), false, false) {
match vm.add_memory_region(GuestAddress(gpa), Box::new(mmap), read_only, false) {
Ok(slot) => VmMemoryResponse::RegisterMemory { pfn: 0, slot },
Err(e) => VmMemoryResponse::Err(e),
}