From d7d6054b8c473f80f74674279d54bde704797294 Mon Sep 17 00:00:00 2001 From: Jinank Jain Date: Fri, 10 Nov 2023 07:24:14 +0000 Subject: [PATCH] hypervisor: Add support for handling SNP guest request SEV-SNP guest can request AMD's secure co-processor i.e., PSP to generate an runtime attesation report. During this process guest needs to inform PSP about the request and response GPAs where that report would be generated by the PSP. This is handled via a VMGEXIT request. Thus, extend the current GHCB handling to add support for it. Signed-off-by: Jinank Jain --- hypervisor/src/mshv/mod.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/hypervisor/src/mshv/mod.rs b/hypervisor/src/mshv/mod.rs index 3ace10531..f05605f04 100644 --- a/hypervisor/src/mshv/mod.rs +++ b/hypervisor/src/mshv/mod.rs @@ -978,6 +978,32 @@ impl cpu::Vcpu for MshvVcpu { })?; } } + SVM_EXITCODE_SNP_GUEST_REQUEST => { + let req_gpa = + info.__bindgen_anon_2.__bindgen_anon_1.sw_exit_info1; + let rsp_gpa = + info.__bindgen_anon_2.__bindgen_anon_1.sw_exit_info2; + + let mshv_psp_req = + mshv_issue_psp_guest_request { req_gpa, rsp_gpa }; + self.vm_fd + .psp_issue_guest_request(&mshv_psp_req) + .map_err(|e| cpu::HypervisorCpuError::RunVcpu(e.into()))?; + + debug!( + "SNP guest request: req_gpa {:0x} rsp_gpa {:0x}", + req_gpa, rsp_gpa + ); + + let mut swei2_rw_gpa_arg = mshv_bindings::mshv_read_write_gpa { + base_gpa: ghcb_gpa + GHCB_SW_EXITINFO2_OFFSET, + byte_count: std::mem::size_of::() as u32, + ..Default::default() + }; + self.fd + .gpa_write(&mut swei2_rw_gpa_arg) + .map_err(|e| cpu::HypervisorCpuError::GpaWrite(e.into()))?; + } _ => panic!( "GHCB_INFO_NORMAL: Unhandled exit code: {:0x}", exit_code