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,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(())