From 0287e6a603bbd92b56f7251a4782b5f6d0ec797c Mon Sep 17 00:00:00 2001 From: Jinank Jain Date: Thu, 19 Oct 2023 10:51:38 +0000 Subject: [PATCH] hypervisor: Add support for MMIO write emulation This is very similar MMIO read emulation for SEV-SNP guest. Signed-off-by: Jinank Jain Signed-off-by: Muminul Islam --- hypervisor/src/mshv/mod.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/hypervisor/src/mshv/mod.rs b/hypervisor/src/mshv/mod.rs index 9a7439989..e41f8fa76 100644 --- a/hypervisor/src/mshv/mod.rs +++ b/hypervisor/src/mshv/mod.rs @@ -948,6 +948,34 @@ impl cpu::Vcpu for MshvVcpu { .gpa_write(&mut arg) .map_err(|e| cpu::HypervisorCpuError::GpaWrite(e.into()))?; } + SVM_EXITCODE_MMIO_WRITE => { + let dst_gpa = + info.__bindgen_anon_2.__bindgen_anon_1.sw_exit_info1; + let src_gpa = info.__bindgen_anon_2.__bindgen_anon_1.sw_scratch; + let data_len = + info.__bindgen_anon_2.__bindgen_anon_1.sw_exit_info2 + as usize; + // Sanity check to make sure data len is within supported range. + assert!(data_len <= 0x8); + let mut arg: mshv_read_write_gpa = + mshv_bindings::mshv_read_write_gpa { + base_gpa: src_gpa, + byte_count: data_len as u32, + ..Default::default() + }; + + self.fd + .gpa_read(&mut arg) + .map_err(|e| cpu::HypervisorCpuError::GpaRead(e.into()))?; + + if let Some(vm_ops) = &self.vm_ops { + vm_ops + .mmio_write(dst_gpa, &arg.data[0..data_len]) + .map_err(|e| { + cpu::HypervisorCpuError::RunVcpu(e.into()) + })?; + } + } _ => panic!( "GHCB_INFO_NORMAL: Unhandled exit code: {:0x}", exit_code