hypervisor: mshv: modify IoPort handling for CVM

VMM needs to handle VMG exit for IO Port. This patch
removes the old method that uses gpa_read/write(IOCTL and hypercall),
which is expensive and update the GHCB page using
mapped(root partition) struct.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
This commit is contained in:
Muminul Islam 2024-11-07 10:42:09 -08:00 committed by Wei Liu
parent 310dafb4d7
commit 5a27bf878c

View File

@ -1003,9 +1003,8 @@ impl cpu::Vcpu for MshvVcpu {
let is_write = let is_write =
// SAFETY: Accessing a union element from bindgen generated bindings. // SAFETY: Accessing a union element from bindgen generated bindings.
unsafe { port_info.__bindgen_anon_1.access_type() == 0 }; unsafe { port_info.__bindgen_anon_1.access_type() == 0 };
// SAFETY: Accessing the field from a mapped address
let mut data = [0; 8]; let mut data = unsafe { (*ghcb).rax.to_le_bytes() };
self.gpa_read(ghcb_gpa + GHCB_RAX_OFFSET, &mut data)?;
if is_write { if is_write {
if let Some(vm_ops) = &self.vm_ops { if let Some(vm_ops) = &self.vm_ops {
@ -1021,8 +1020,7 @@ impl cpu::Vcpu for MshvVcpu {
cpu::HypervisorCpuError::RunVcpu(e.into()) cpu::HypervisorCpuError::RunVcpu(e.into())
})?; })?;
} }
set_svm_field_u64_ptr!(ghcb, rax, u64::from_le_bytes(data));
self.gpa_write(ghcb_gpa + GHCB_RAX_OFFSET, &data)?;
} }
// Clear the SW_EXIT_INFO1 register to indicate no error // Clear the SW_EXIT_INFO1 register to indicate no error