summary refs log tree commit diff
path: root/vm_control
diff options
context:
space:
mode:
authorXiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>2019-04-23 17:15:24 +0800
committerCommit Bot <commit-bot@chromium.org>2019-12-06 08:47:29 +0000
commit85abeff27f6256725621c4db749d4401078236d8 (patch)
treef0e911c1b8dcd3348d1b80ae4f04bf262a6a21b2 /vm_control
parentc0385a09161fc2570354a071af4a945d81528c08 (diff)
downloadcrosvm-85abeff27f6256725621c4db749d4401078236d8.tar
crosvm-85abeff27f6256725621c4db749d4401078236d8.tar.gz
crosvm-85abeff27f6256725621c4db749d4401078236d8.tar.bz2
crosvm-85abeff27f6256725621c4db749d4401078236d8.tar.lz
crosvm-85abeff27f6256725621c4db749d4401078236d8.tar.xz
crosvm-85abeff27f6256725621c4db749d4401078236d8.tar.zst
crosvm-85abeff27f6256725621c4db749d4401078236d8.zip
vfio: Implement bar mappable
if device bar is mappable, map bar's gpa to hpa in EPT, guest vcpu
could access this bar directly through EPT without trapping. This
could improve performance.

vm.add_mmio_memory could help do this, here vfio_pci send
RegisterMmapMemory request through vm_control socket to do this.

BUG=chromium:992270
TEST=none

Change-Id: I3b4274372f7dcd32e18084d55f037b6fe45ed422
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1581147
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Diffstat (limited to 'vm_control')
-rw-r--r--vm_control/src/lib.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/vm_control/src/lib.rs b/vm_control/src/lib.rs
index eccee10..7e5faf5 100644
--- a/vm_control/src/lib.rs
+++ b/vm_control/src/lib.rs
@@ -201,6 +201,13 @@ pub enum VmMemoryRequest {
         height: u32,
         format: u32,
     },
+    /// Register mmaped memory into kvm's EPT.
+    RegisterMmapMemory {
+        fd: MaybeOwnedFd,
+        size: usize,
+        offset: usize,
+        gpa: u64,
+    },
 }
 
 impl VmMemoryRequest {
@@ -260,6 +267,21 @@ impl VmMemoryRequest {
                     Err(e) => VmMemoryResponse::Err(e),
                 }
             }
+            RegisterMmapMemory {
+                ref fd,
+                size,
+                offset,
+                gpa,
+            } => {
+                let mmap = match MemoryMapping::from_fd_offset(fd, size, offset) {
+                    Ok(v) => v,
+                    Err(_e) => return VmMemoryResponse::Err(SysError::new(EINVAL)),
+                };
+                match vm.add_mmio_memory(GuestAddress(gpa), mmap, false, false) {
+                    Ok(_) => VmMemoryResponse::Ok,
+                    Err(e) => VmMemoryResponse::Err(e),
+                }
+            }
         }
     }
 }