From 84b643f80b64237cd67c2281b4855ddc3217e6d3 Mon Sep 17 00:00:00 2001 From: Jinank Jain Date: Fri, 10 Nov 2023 07:33:34 +0000 Subject: [PATCH] hypervisor: Add support to bringup AP threads for SEV-SNP guest As part SMP bringup for a SEV-SNP guest, BSP sets up the VMSA page for each AP threads and informs hypervisor about the same using a VMGEXIT. Thus, extend the current GHCB interface to handle this scenario. Signed-off-by: Jinank Jain --- hypervisor/src/mshv/mod.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/hypervisor/src/mshv/mod.rs b/hypervisor/src/mshv/mod.rs index f05605f04..acd20713b 100644 --- a/hypervisor/src/mshv/mod.rs +++ b/hypervisor/src/mshv/mod.rs @@ -1004,6 +1004,33 @@ impl cpu::Vcpu for MshvVcpu { .gpa_write(&mut swei2_rw_gpa_arg) .map_err(|e| cpu::HypervisorCpuError::GpaWrite(e.into()))?; } + SVM_EXITCODE_SNP_AP_CREATION => { + let vmsa_gpa = + info.__bindgen_anon_2.__bindgen_anon_1.sw_exit_info2; + let apic_id = + info.__bindgen_anon_2.__bindgen_anon_1.sw_exit_info1 >> 32; + debug!( + "SNP AP CREATE REQUEST with VMSA GPA {:0x}, and APIC ID {:?}", + vmsa_gpa, apic_id + ); + + let mshv_ap_create_req = mshv_sev_snp_ap_create { + vp_id: apic_id, + vmsa_gpa, + }; + self.vm_fd + .sev_snp_ap_create(&mshv_ap_create_req) + .map_err(|e| cpu::HypervisorCpuError::RunVcpu(e.into()))?; + + 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