summary refs log tree commit diff
path: root/vm_control
diff options
context:
space:
mode:
authorChirantan Ekbote <chirantan@chromium.org>2020-04-24 19:37:04 +0900
committerCommit Bot <commit-bot@chromium.org>2020-04-29 07:36:36 +0000
commit2d9dde9ee7ac78a9831d1e019e40107b5691f895 (patch)
tree6b055f267adfebdf828cbe680dce0e06c870cdfb /vm_control
parent887289e5d455d2cd026a2b178002ed009ea8bdd4 (diff)
downloadcrosvm-2d9dde9ee7ac78a9831d1e019e40107b5691f895.tar
crosvm-2d9dde9ee7ac78a9831d1e019e40107b5691f895.tar.gz
crosvm-2d9dde9ee7ac78a9831d1e019e40107b5691f895.tar.bz2
crosvm-2d9dde9ee7ac78a9831d1e019e40107b5691f895.tar.lz
crosvm-2d9dde9ee7ac78a9831d1e019e40107b5691f895.tar.xz
crosvm-2d9dde9ee7ac78a9831d1e019e40107b5691f895.tar.zst
crosvm-2d9dde9ee7ac78a9831d1e019e40107b5691f895.zip
Stop tracking sub-mappings in MemoryMappingArena
The kernel already takes care of tracking all our memory mappings.
Doing it again ourselves doesn't provide any benefit and also adds
additional restrictions (like not being able to overlap with existing
mappings or partially remove mappings).  Additionally, the
`MemoryMappingArena` will already unmap the entire memory mapped region
so there is no need to individually unmap the sub-mappings.

The kernel's mmap api doesn't have these restrictions and as far as I
can tell there are no safety concerns with allowing this behavior so
just stop tracking the sub-mappings.

Safe use of MAP_FIXED only requires that the address is part of a
previously mmaped region so allow any MemoryMapping to be converted into
a MemoryMappedArena.

BUG=b:147341783
TEST=unit tests

Change-Id: Iaf944a971b8ba9333802aab73c1d184fe388af89
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2162542
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Diffstat (limited to 'vm_control')
-rw-r--r--vm_control/src/lib.rs14
1 files changed, 9 insertions, 5 deletions
diff --git a/vm_control/src/lib.rs b/vm_control/src/lib.rs
index 585b162..9e78be2 100644
--- a/vm_control/src/lib.rs
+++ b/vm_control/src/lib.rs
@@ -450,7 +450,12 @@ pub enum VmMsyncRequest {
     /// Flush the content of a memory mapping to its backing file.
     /// `slot` selects the arena (as returned by `Vm::add_mmap_arena`).
     /// `offset` is the offset of the mapping to sync within the arena.
-    MsyncArena { slot: u32, offset: usize },
+    /// `size` is the size of the mapping to sync within the arena.
+    MsyncArena {
+        slot: u32,
+        offset: usize,
+        size: usize,
+    },
 }
 
 #[derive(MsgOnSocket, Debug)]
@@ -471,11 +476,10 @@ impl VmMsyncRequest {
     pub fn execute(&self, vm: &mut Vm) -> VmMsyncResponse {
         use self::VmMsyncRequest::*;
         match *self {
-            MsyncArena { slot, offset } => {
+            MsyncArena { slot, offset, size } => {
                 if let Some(arena) = vm.get_mmap_arena(slot) {
-                    match arena.msync(offset) {
-                        Ok(true) => VmMsyncResponse::Ok,
-                        Ok(false) => VmMsyncResponse::Err(SysError::new(EINVAL)),
+                    match arena.msync(offset, size) {
+                        Ok(()) => VmMsyncResponse::Ok,
                         Err(e) => match e {
                             MmapError::SystemCallFailed(errno) => VmMsyncResponse::Err(errno),
                             _ => VmMsyncResponse::Err(SysError::new(EINVAL)),