From e07bd96ea90edd8a12dcf163f3211cc1ddbe9691 Mon Sep 17 00:00:00 2001 From: Zach Reizner Date: Tue, 30 Jan 2018 10:09:21 -0800 Subject: [PATCH] kvm: fix and test set_identity_map_addr The kernel expects a pointer to a physical address, not a physical address directly in the ioctl argument. TEST=cargo test -p kvm BUG=chromium:800626 Change-Id: I4a7298149373c00b5b9c634cd1dead7053d053c3 Reviewed-on: https://chromium-review.googlesource.com/893215 Commit-Ready: Zach Reizner Tested-by: Zach Reizner Reviewed-by: Stephen Barber --- kvm/src/lib.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/kvm/src/lib.rs b/kvm/src/lib.rs index be1feecdd0..ef382ef292 100644 --- a/kvm/src/lib.rs +++ b/kvm/src/lib.rs @@ -342,7 +342,7 @@ impl Vm { pub fn set_identity_map_addr(&self, addr: GuestAddress) -> Result<()> { // Safe because we know that our file is a VM fd and we verify the return result. let ret = unsafe { - ioctl_with_val(self, KVM_SET_IDENTITY_MAP_ADDR(), addr.offset() as u64) + ioctl_with_ref(self, KVM_SET_IDENTITY_MAP_ADDR(), &(addr.offset() as u64)) }; if ret == 0 { Ok(()) @@ -1097,4 +1097,12 @@ mod tests { assert!(mmap_size >= page_size); assert!(mmap_size % page_size == 0); } + + #[test] + fn set_identity_map_addr() { + let kvm = Kvm::new().unwrap(); + let gm = GuestMemory::new(&vec![(GuestAddress(0), 0x10000)]).unwrap(); + let vm = Vm::new(&kvm, gm).unwrap(); + vm.set_identity_map_addr(GuestAddress(0x20000)).unwrap(); + } }