From 310dafb4d7aa9bf98d4b0d5d2b7f192d3f279071 Mon Sep 17 00:00:00 2001 From: Muminul Islam Date: Thu, 7 Nov 2024 10:24:45 -0800 Subject: [PATCH] hypervisor: mshv: modify doorbell page handling for CVM VMM needs to handle VMG exit for doorbell page. 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 --- hypervisor/src/mshv/mod.rs | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/hypervisor/src/mshv/mod.rs b/hypervisor/src/mshv/mod.rs index 83a8d0361..170d60906 100644 --- a/hypervisor/src/mshv/mod.rs +++ b/hypervisor/src/mshv/mod.rs @@ -805,6 +805,10 @@ impl cpu::Vcpu for MshvVcpu { let ghcb_msr = svm_ghcb_msr { as_uint64: info.ghcb_msr, }; + // Safe to use unwrap, for sev_snp guest we already have the + // GHCB pointer wrapped in the option, otherwise this place is not reached. + let ghcb = self.ghcb.as_ref().unwrap().0; + // SAFETY: Accessing a union element from bindgen generated bindings. let ghcb_op = unsafe { ghcb_msr.__bindgen_anon_2.ghcb_info() as u32 }; // Sanity check on the header fields before handling other operations. @@ -914,10 +918,11 @@ impl cpu::Vcpu for MshvVcpu { SVM_NAE_HV_DOORBELL_PAGE_GET_PREFERRED => { // Hypervisor does not have any preference for doorbell GPA. let preferred_doorbell_gpa: u64 = 0xFFFFFFFFFFFFFFFF; - self.gpa_write( - ghcb_gpa + GHCB_SW_EXITINFO2_OFFSET, - &preferred_doorbell_gpa.to_le_bytes(), - )?; + set_svm_field_u64_ptr!( + ghcb, + exit_info2, + preferred_doorbell_gpa + ); } SVM_NAE_HV_DOORBELL_PAGE_SET => { let exit_info2 = info @@ -944,10 +949,7 @@ impl cpu::Vcpu for MshvVcpu { cpu::HypervisorCpuError::SetRegister(e.into()) })?; - self.gpa_write( - ghcb_gpa + GHCB_SW_EXITINFO2_OFFSET, - &exit_info2.to_le_bytes(), - )?; + set_svm_field_u64_ptr!(ghcb, exit_info2, exit_info2); // Clear the SW_EXIT_INFO1 register to indicate no error self.clear_swexit_info1()?; @@ -961,19 +963,13 @@ impl cpu::Vcpu for MshvVcpu { // SAFETY: Accessing a union element from bindgen generated bindings. let doorbell_gpa = unsafe { reg_assocs[0].value.reg64 }; - self.gpa_write( - ghcb_gpa + GHCB_SW_EXITINFO2_OFFSET, - &doorbell_gpa.to_le_bytes(), - )?; + set_svm_field_u64_ptr!(ghcb, exit_info2, doorbell_gpa); // Clear the SW_EXIT_INFO1 register to indicate no error self.clear_swexit_info1()?; } SVM_NAE_HV_DOORBELL_PAGE_CLEAR => { - self.gpa_write( - ghcb_gpa + GHCB_SW_EXITINFO2_OFFSET, - &[0; 8], - )?; + set_svm_field_u64_ptr!(ghcb, exit_info2, 0); } _ => { panic!(