summary refs log tree commit diff
path: root/x86_64
diff options
context:
space:
mode:
authorDaniel Prilik <prilik@google.com>2019-02-27 12:24:25 -0800
committerchrome-bot <chrome-bot@chromium.org>2019-03-25 17:43:50 -0700
commitdb4721d8709a7d139f9b6cb405b22e2a405072ff (patch)
treeff21f5766937b8b8333d894adc19c9a5faf08293 /x86_64
parent33e8ef061d4a0d263edd6542728ac4bec3ebf42f (diff)
downloadcrosvm-db4721d8709a7d139f9b6cb405b22e2a405072ff.tar
crosvm-db4721d8709a7d139f9b6cb405b22e2a405072ff.tar.gz
crosvm-db4721d8709a7d139f9b6cb405b22e2a405072ff.tar.bz2
crosvm-db4721d8709a7d139f9b6cb405b22e2a405072ff.tar.lz
crosvm-db4721d8709a7d139f9b6cb405b22e2a405072ff.tar.xz
crosvm-db4721d8709a7d139f9b6cb405b22e2a405072ff.tar.zst
crosvm-db4721d8709a7d139f9b6cb405b22e2a405072ff.zip
crosvm: add memfd for GuestMemory
Building off CL:1290293

Instead of having a seperate GuestMemoryManager, this adds SharedMemory
as a Arc'd member of GuestMemory. This is nice since it removes the need
to plumb the Manager struct throughout the codebase.

BUG=chromium:936567
TEST=cargo test -p sys_util

Change-Id: I6fa5d73f7e0db495c2803a040479818445660345
Reviewed-on: https://chromium-review.googlesource.com/1493013
Commit-Ready: Daniel Prilik <prilik@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Diffstat (limited to 'x86_64')
-rw-r--r--x86_64/src/mptable.rs23
1 files changed, 13 insertions, 10 deletions
diff --git a/x86_64/src/mptable.rs b/x86_64/src/mptable.rs
index 7d5d622..9277840 100644
--- a/x86_64/src/mptable.rs
+++ b/x86_64/src/mptable.rs
@@ -330,6 +330,13 @@ pub fn setup_mptable(
 #[cfg(test)]
 mod tests {
     use super::*;
+    use sys_util::pagesize;
+
+    fn compute_page_aligned_mp_size(num_cpus: u8) -> u64 {
+        let mp_size = compute_mp_size(num_cpus);
+        let pg_size = pagesize();
+        (mp_size + pg_size - (mp_size % pg_size)) as u64
+    }
 
     fn table_entry_size(type_: u8) -> usize {
         match type_ as u32 {
@@ -347,7 +354,7 @@ mod tests {
         let num_cpus = 4;
         let mem = GuestMemory::new(&[(
             GuestAddress(MPTABLE_START),
-            compute_mp_size(num_cpus) as u64,
+            compute_page_aligned_mp_size(num_cpus),
         )])
         .unwrap();
 
@@ -356,12 +363,8 @@ mod tests {
 
     #[test]
     fn bounds_check_fails() {
-        let num_cpus = 4;
-        let mem = GuestMemory::new(&[(
-            GuestAddress(MPTABLE_START),
-            (compute_mp_size(num_cpus) - 1) as u64,
-        )])
-        .unwrap();
+        let num_cpus = 255;
+        let mem = GuestMemory::new(&[(GuestAddress(MPTABLE_START), 0x1000)]).unwrap();
 
         assert!(setup_mptable(&mem, num_cpus, Vec::new()).is_err());
     }
@@ -371,7 +374,7 @@ mod tests {
         let num_cpus = 1;
         let mem = GuestMemory::new(&[(
             GuestAddress(MPTABLE_START),
-            compute_mp_size(num_cpus) as u64,
+            compute_page_aligned_mp_size(num_cpus),
         )])
         .unwrap();
 
@@ -387,7 +390,7 @@ mod tests {
         let num_cpus = 4;
         let mem = GuestMemory::new(&[(
             GuestAddress(MPTABLE_START),
-            compute_mp_size(num_cpus) as u64,
+            compute_page_aligned_mp_size(num_cpus),
         )])
         .unwrap();
 
@@ -421,7 +424,7 @@ mod tests {
         const MAX_CPUS: u8 = 0xff;
         let mem = GuestMemory::new(&[(
             GuestAddress(MPTABLE_START),
-            compute_mp_size(MAX_CPUS) as u64,
+            compute_page_aligned_mp_size(MAX_CPUS),
         )])
         .unwrap();