From b59243f6cfc02f97b12d300a42fc4831e4f15208 Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Mon, 11 Jan 2021 15:04:18 +0000 Subject: [PATCH] hypervisor: mshv: support reading and writing guest memory in emulator We don't have an easy way to figure out if a GPA points to normal memory or device memory, but the guest's normal memory regions shouldn't overlap with device regions. We can simply try to do a normal memory read / write, and proceed to do device memory read / write if that fails. Signed-off-by: Wei Liu --- hypervisor/src/mshv/mod.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/hypervisor/src/mshv/mod.rs b/hypervisor/src/mshv/mod.rs index a2cbb6160..ffc77b3c5 100644 --- a/hypervisor/src/mshv/mod.rs +++ b/hypervisor/src/mshv/mod.rs @@ -586,9 +586,11 @@ impl<'a> PlatformEmulator for MshvEmulatorContext<'a> { ); if let Some(vmmops) = &self.vcpu.vmmops { - vmmops - .mmio_read(gpa, data) - .map_err(|e| PlatformError::MemoryReadFailure(e.into()))?; + if vmmops.guest_mem_read(gpa, data).is_err() { + vmmops + .mmio_read(gpa, data) + .map_err(|e| PlatformError::MemoryReadFailure(e.into()))?; + } } Ok(()) @@ -604,9 +606,11 @@ impl<'a> PlatformEmulator for MshvEmulatorContext<'a> { ); if let Some(vmmops) = &self.vcpu.vmmops { - vmmops - .mmio_write(gpa, data) - .map_err(|e| PlatformError::MemoryWriteFailure(e.into()))?; + if vmmops.guest_mem_write(gpa, data).is_err() { + vmmops + .mmio_write(gpa, data) + .map_err(|e| PlatformError::MemoryWriteFailure(e.into()))?; + } } Ok(())