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 <liuwe@microsoft.com>
This commit is contained in:
Wei Liu 2021-01-11 15:04:18 +00:00 committed by Samuel Ortiz
parent 07a09eda27
commit b59243f6cf

View File

@ -586,10 +586,12 @@ impl<'a> PlatformEmulator for MshvEmulatorContext<'a> {
); );
if let Some(vmmops) = &self.vcpu.vmmops { if let Some(vmmops) = &self.vcpu.vmmops {
if vmmops.guest_mem_read(gpa, data).is_err() {
vmmops vmmops
.mmio_read(gpa, data) .mmio_read(gpa, data)
.map_err(|e| PlatformError::MemoryReadFailure(e.into()))?; .map_err(|e| PlatformError::MemoryReadFailure(e.into()))?;
} }
}
Ok(()) Ok(())
} }
@ -604,10 +606,12 @@ impl<'a> PlatformEmulator for MshvEmulatorContext<'a> {
); );
if let Some(vmmops) = &self.vcpu.vmmops { if let Some(vmmops) = &self.vcpu.vmmops {
if vmmops.guest_mem_write(gpa, data).is_err() {
vmmops vmmops
.mmio_write(gpa, data) .mmio_write(gpa, data)
.map_err(|e| PlatformError::MemoryWriteFailure(e.into()))?; .map_err(|e| PlatformError::MemoryWriteFailure(e.into()))?;
} }
}
Ok(()) Ok(())
} }