@@ -1045,18 +1045,21 @@ int __init sev_es_setup_ap_jump_table(struct real_mode_header *rmh)
10451045 * This is needed by the OVMF UEFI firmware which will use whatever it finds in
10461046 * the GHCB MSR as its GHCB to talk to the hypervisor. So make sure the per-cpu
10471047 * runtime GHCBs used by the kernel are also mapped in the EFI page-table.
1048+ *
1049+ * When running under SVSM the CA page is needed too, so map it as well.
10481050 */
1049- int __init sev_es_efi_map_ghcbs (pgd_t * pgd )
1051+ int __init sev_es_efi_map_ghcbs_cas (pgd_t * pgd )
10501052{
1053+ unsigned long address , pflags , pflags_enc ;
10511054 struct sev_es_runtime_data * data ;
1052- unsigned long address , pflags ;
10531055 int cpu ;
10541056 u64 pfn ;
10551057
10561058 if (!cc_platform_has (CC_ATTR_GUEST_STATE_ENCRYPT ))
10571059 return 0 ;
10581060
10591061 pflags = _PAGE_NX | _PAGE_RW ;
1062+ pflags_enc = cc_mkenc (pflags );
10601063
10611064 for_each_possible_cpu (cpu ) {
10621065 data = per_cpu (runtime_data , cpu );
@@ -1066,6 +1069,16 @@ int __init sev_es_efi_map_ghcbs(pgd_t *pgd)
10661069
10671070 if (kernel_map_pages_in_pgd (pgd , pfn , address , 1 , pflags ))
10681071 return 1 ;
1072+
1073+ if (snp_vmpl ) {
1074+ address = per_cpu (svsm_caa_pa , cpu );
1075+ if (!address )
1076+ return 1 ;
1077+
1078+ pfn = address >> PAGE_SHIFT ;
1079+ if (kernel_map_pages_in_pgd (pgd , pfn , address , 1 , pflags_enc ))
1080+ return 1 ;
1081+ }
10691082 }
10701083
10711084 return 0 ;
@@ -1389,16 +1402,16 @@ int snp_issue_svsm_attest_req(u64 call_id, struct svsm_call *call,
13891402}
13901403EXPORT_SYMBOL_GPL (snp_issue_svsm_attest_req );
13911404
1392- static int snp_issue_guest_request (struct snp_guest_req * req , struct snp_req_data * input ,
1393- struct snp_guest_request_ioctl * rio )
1405+ static int snp_issue_guest_request (struct snp_guest_req * req )
13941406{
1407+ struct snp_req_data * input = & req -> input ;
13951408 struct ghcb_state state ;
13961409 struct es_em_ctxt ctxt ;
13971410 unsigned long flags ;
13981411 struct ghcb * ghcb ;
13991412 int ret ;
14001413
1401- rio -> exitinfo2 = SEV_RET_NO_FW_CALL ;
1414+ req -> exitinfo2 = SEV_RET_NO_FW_CALL ;
14021415
14031416 /*
14041417 * __sev_get_ghcb() needs to run with IRQs disabled because it is using
@@ -1423,8 +1436,8 @@ static int snp_issue_guest_request(struct snp_guest_req *req, struct snp_req_dat
14231436 if (ret )
14241437 goto e_put ;
14251438
1426- rio -> exitinfo2 = ghcb -> save .sw_exit_info_2 ;
1427- switch (rio -> exitinfo2 ) {
1439+ req -> exitinfo2 = ghcb -> save .sw_exit_info_2 ;
1440+ switch (req -> exitinfo2 ) {
14281441 case 0 :
14291442 break ;
14301443
@@ -1919,8 +1932,7 @@ static int enc_payload(struct snp_msg_desc *mdesc, u64 seqno, struct snp_guest_r
19191932 return 0 ;
19201933}
19211934
1922- static int __handle_guest_request (struct snp_msg_desc * mdesc , struct snp_guest_req * req ,
1923- struct snp_guest_request_ioctl * rio )
1935+ static int __handle_guest_request (struct snp_msg_desc * mdesc , struct snp_guest_req * req )
19241936{
19251937 unsigned long req_start = jiffies ;
19261938 unsigned int override_npages = 0 ;
@@ -1934,7 +1946,7 @@ static int __handle_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_r
19341946 * sequence number must be incremented or the VMPCK must be deleted to
19351947 * prevent reuse of the IV.
19361948 */
1937- rc = snp_issue_guest_request (req , & req -> input , rio );
1949+ rc = snp_issue_guest_request (req );
19381950 switch (rc ) {
19391951 case - ENOSPC :
19401952 /*
@@ -1987,7 +1999,7 @@ static int __handle_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_r
19871999 snp_inc_msg_seqno (mdesc );
19882000
19892001 if (override_err ) {
1990- rio -> exitinfo2 = override_err ;
2002+ req -> exitinfo2 = override_err ;
19912003
19922004 /*
19932005 * If an extended guest request was issued and the supplied certificate
@@ -2005,12 +2017,20 @@ static int __handle_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_r
20052017 return rc ;
20062018}
20072019
2008- int snp_send_guest_request (struct snp_msg_desc * mdesc , struct snp_guest_req * req ,
2009- struct snp_guest_request_ioctl * rio )
2020+ int snp_send_guest_request (struct snp_msg_desc * mdesc , struct snp_guest_req * req )
20102021{
20112022 u64 seqno ;
20122023 int rc ;
20132024
2025+ /*
2026+ * enc_payload() calls aesgcm_encrypt(), which can potentially offload to HW.
2027+ * The offload's DMA SG list of data to encrypt has to be in linear mapping.
2028+ */
2029+ if (!virt_addr_valid (req -> req_buf ) || !virt_addr_valid (req -> resp_buf )) {
2030+ pr_warn ("AES-GSM buffers must be in linear mapping" );
2031+ return - EINVAL ;
2032+ }
2033+
20142034 guard (mutex )(& snp_cmd_mutex );
20152035
20162036 /* Check if the VMPCK is not empty */
@@ -2043,14 +2063,14 @@ int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req
20432063 req -> input .resp_gpa = __pa (mdesc -> response );
20442064 req -> input .data_gpa = req -> certs_data ? __pa (req -> certs_data ) : 0 ;
20452065
2046- rc = __handle_guest_request (mdesc , req , rio );
2066+ rc = __handle_guest_request (mdesc , req );
20472067 if (rc ) {
20482068 if (rc == - EIO &&
2049- rio -> exitinfo2 == SNP_GUEST_VMM_ERR (SNP_GUEST_VMM_ERR_INVALID_LEN ))
2069+ req -> exitinfo2 == SNP_GUEST_VMM_ERR (SNP_GUEST_VMM_ERR_INVALID_LEN ))
20502070 return rc ;
20512071
20522072 pr_alert ("Detected error from ASP request. rc: %d, exitinfo2: 0x%llx\n" ,
2053- rc , rio -> exitinfo2 );
2073+ rc , req -> exitinfo2 );
20542074
20552075 snp_disable_vmpck (mdesc );
20562076 return rc ;
@@ -2069,11 +2089,10 @@ EXPORT_SYMBOL_GPL(snp_send_guest_request);
20692089
20702090static int __init snp_get_tsc_info (void )
20712091{
2072- struct snp_guest_request_ioctl * rio ;
20732092 struct snp_tsc_info_resp * tsc_resp ;
20742093 struct snp_tsc_info_req * tsc_req ;
20752094 struct snp_msg_desc * mdesc ;
2076- struct snp_guest_req * req ;
2095+ struct snp_guest_req req = {} ;
20772096 int rc = - ENOMEM ;
20782097
20792098 tsc_req = kzalloc (sizeof (* tsc_req ), GFP_KERNEL );
@@ -2089,32 +2108,24 @@ static int __init snp_get_tsc_info(void)
20892108 if (!tsc_resp )
20902109 goto e_free_tsc_req ;
20912110
2092- req = kzalloc (sizeof (* req ), GFP_KERNEL );
2093- if (!req )
2094- goto e_free_tsc_resp ;
2095-
2096- rio = kzalloc (sizeof (* rio ), GFP_KERNEL );
2097- if (!rio )
2098- goto e_free_req ;
2099-
21002111 mdesc = snp_msg_alloc ();
21012112 if (IS_ERR_OR_NULL (mdesc ))
2102- goto e_free_rio ;
2113+ goto e_free_tsc_resp ;
21032114
21042115 rc = snp_msg_init (mdesc , snp_vmpl );
21052116 if (rc )
21062117 goto e_free_mdesc ;
21072118
2108- req -> msg_version = MSG_HDR_VER ;
2109- req -> msg_type = SNP_MSG_TSC_INFO_REQ ;
2110- req -> vmpck_id = snp_vmpl ;
2111- req -> req_buf = tsc_req ;
2112- req -> req_sz = sizeof (* tsc_req );
2113- req -> resp_buf = (void * )tsc_resp ;
2114- req -> resp_sz = sizeof (* tsc_resp ) + AUTHTAG_LEN ;
2115- req -> exit_code = SVM_VMGEXIT_GUEST_REQUEST ;
2119+ req . msg_version = MSG_HDR_VER ;
2120+ req . msg_type = SNP_MSG_TSC_INFO_REQ ;
2121+ req . vmpck_id = snp_vmpl ;
2122+ req . req_buf = tsc_req ;
2123+ req . req_sz = sizeof (* tsc_req );
2124+ req . resp_buf = (void * )tsc_resp ;
2125+ req . resp_sz = sizeof (* tsc_resp ) + AUTHTAG_LEN ;
2126+ req . exit_code = SVM_VMGEXIT_GUEST_REQUEST ;
21162127
2117- rc = snp_send_guest_request (mdesc , req , rio );
2128+ rc = snp_send_guest_request (mdesc , & req );
21182129 if (rc )
21192130 goto e_request ;
21202131
@@ -2135,11 +2146,7 @@ static int __init snp_get_tsc_info(void)
21352146 memzero_explicit (tsc_resp , sizeof (* tsc_resp ) + AUTHTAG_LEN );
21362147e_free_mdesc :
21372148 snp_msg_free (mdesc );
2138- e_free_rio :
2139- kfree (rio );
2140- e_free_req :
2141- kfree (req );
2142- e_free_tsc_resp :
2149+ e_free_tsc_resp :
21432150 kfree (tsc_resp );
21442151e_free_tsc_req :
21452152 kfree (tsc_req );
0 commit comments