From 85abeff27f6256725621c4db749d4401078236d8 Mon Sep 17 00:00:00 2001 From: Xiong Zhang Date: Tue, 23 Apr 2019 17:15:24 +0800 Subject: 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 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1581147 Tested-by: kokoro Reviewed-by: Daniel Verkamp --- vm_control/src/lib.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'vm_control') 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), + } + } } } } -- cgit 1.4.1