From ac43825f79806a3262f6490dcf8d018e118e831c Mon Sep 17 00:00:00 2001 From: Jinank Jain Date: Thu, 19 Oct 2023 10:43:57 +0000 Subject: [PATCH] hypervisor: Add support MMIO read VMGEXIT MMIO emulation is also performed via VMGEXIT in case of SEV-SNP guest. Emulation is done in a very similar way like a regular guest. Just need to make sure that guest memory is access via read/write GPA hypercall instead of directly accessing it. 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 f6fb1d83e..9a7439989 100644 --- a/hypervisor/src/mshv/mod.rs +++ b/hypervisor/src/mshv/mod.rs @@ -920,6 +920,34 @@ impl cpu::Vcpu for MshvVcpu { .gpa_write(&mut swei1_rw_gpa_arg) .map_err(|e| cpu::HypervisorCpuError::GpaWrite(e.into()))?; } + SVM_EXITCODE_MMIO_READ => { + let src_gpa = + info.__bindgen_anon_2.__bindgen_anon_1.sw_exit_info1; + let dst_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 data: Vec = vec![0; data_len]; + if let Some(vm_ops) = &self.vm_ops { + vm_ops.mmio_read(src_gpa, &mut data[0..data_len]).map_err( + |e| cpu::HypervisorCpuError::RunVcpu(e.into()), + )?; + } + let mut arg: mshv_read_write_gpa = + mshv_bindings::mshv_read_write_gpa { + base_gpa: dst_gpa, + byte_count: data_len as u32, + ..Default::default() + }; + arg.data[0..data_len].copy_from_slice(&data); + + self.fd + .gpa_write(&mut arg) + .map_err(|e| cpu::HypervisorCpuError::GpaWrite(e.into()))?; + } _ => panic!( "GHCB_INFO_NORMAL: Unhandled exit code: {:0x}", exit_code