Skip to content

Commit 3f83ab6

Browse files
aikbp3tk0v
authored andcommitted
virt: sev-guest: Contain snp_guest_request_ioctl in sev-guest
SNP Guest Request uses only exitinfo2 which is a return value from GHCB, has meaning beyond ioctl and therefore belongs to struct snp_guest_req. Move exitinfo2 there and remove snp_guest_request_ioctl from the SEV platform code. No functional change intended. Signed-off-by: Alexey Kardashevskiy <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Tom Lendacky <[email protected]> Reviewed-by: Dionna Glaze <[email protected]> Link: https://lore.kernel.org/[email protected]
1 parent e04c78d commit 3f83ab6

File tree

3 files changed

+23
-32
lines changed

3 files changed

+23
-32
lines changed

arch/x86/coco/sev/core.c

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,16 +1389,15 @@ int snp_issue_svsm_attest_req(u64 call_id, struct svsm_call *call,
13891389
}
13901390
EXPORT_SYMBOL_GPL(snp_issue_svsm_attest_req);
13911391

1392-
static int snp_issue_guest_request(struct snp_guest_req *req, struct snp_req_data *input,
1393-
struct snp_guest_request_ioctl *rio)
1392+
static int snp_issue_guest_request(struct snp_guest_req *req, struct snp_req_data *input)
13941393
{
13951394
struct ghcb_state state;
13961395
struct es_em_ctxt ctxt;
13971396
unsigned long flags;
13981397
struct ghcb *ghcb;
13991398
int ret;
14001399

1401-
rio->exitinfo2 = SEV_RET_NO_FW_CALL;
1400+
req->exitinfo2 = SEV_RET_NO_FW_CALL;
14021401

14031402
/*
14041403
* __sev_get_ghcb() needs to run with IRQs disabled because it is using
@@ -1423,8 +1422,8 @@ static int snp_issue_guest_request(struct snp_guest_req *req, struct snp_req_dat
14231422
if (ret)
14241423
goto e_put;
14251424

1426-
rio->exitinfo2 = ghcb->save.sw_exit_info_2;
1427-
switch (rio->exitinfo2) {
1425+
req->exitinfo2 = ghcb->save.sw_exit_info_2;
1426+
switch (req->exitinfo2) {
14281427
case 0:
14291428
break;
14301429

@@ -1919,8 +1918,7 @@ static int enc_payload(struct snp_msg_desc *mdesc, u64 seqno, struct snp_guest_r
19191918
return 0;
19201919
}
19211920

1922-
static int __handle_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req,
1923-
struct snp_guest_request_ioctl *rio)
1921+
static int __handle_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req)
19241922
{
19251923
unsigned long req_start = jiffies;
19261924
unsigned int override_npages = 0;
@@ -1934,7 +1932,7 @@ static int __handle_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_r
19341932
* sequence number must be incremented or the VMPCK must be deleted to
19351933
* prevent reuse of the IV.
19361934
*/
1937-
rc = snp_issue_guest_request(req, &req->input, rio);
1935+
rc = snp_issue_guest_request(req, &req->input);
19381936
switch (rc) {
19391937
case -ENOSPC:
19401938
/*
@@ -1987,7 +1985,7 @@ static int __handle_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_r
19871985
snp_inc_msg_seqno(mdesc);
19881986

19891987
if (override_err) {
1990-
rio->exitinfo2 = override_err;
1988+
req->exitinfo2 = override_err;
19911989

19921990
/*
19931991
* If an extended guest request was issued and the supplied certificate
@@ -2005,8 +2003,7 @@ static int __handle_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_r
20052003
return rc;
20062004
}
20072005

2008-
int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req,
2009-
struct snp_guest_request_ioctl *rio)
2006+
int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req)
20102007
{
20112008
u64 seqno;
20122009
int rc;
@@ -2043,14 +2040,14 @@ int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req
20432040
req->input.resp_gpa = __pa(mdesc->response);
20442041
req->input.data_gpa = req->certs_data ? __pa(req->certs_data) : 0;
20452042

2046-
rc = __handle_guest_request(mdesc, req, rio);
2043+
rc = __handle_guest_request(mdesc, req);
20472044
if (rc) {
20482045
if (rc == -EIO &&
2049-
rio->exitinfo2 == SNP_GUEST_VMM_ERR(SNP_GUEST_VMM_ERR_INVALID_LEN))
2046+
req->exitinfo2 == SNP_GUEST_VMM_ERR(SNP_GUEST_VMM_ERR_INVALID_LEN))
20502047
return rc;
20512048

20522049
pr_alert("Detected error from ASP request. rc: %d, exitinfo2: 0x%llx\n",
2053-
rc, rio->exitinfo2);
2050+
rc, req->exitinfo2);
20542051

20552052
snp_disable_vmpck(mdesc);
20562053
return rc;
@@ -2069,7 +2066,6 @@ EXPORT_SYMBOL_GPL(snp_send_guest_request);
20692066

20702067
static int __init snp_get_tsc_info(void)
20712068
{
2072-
struct snp_guest_request_ioctl *rio;
20732069
struct snp_tsc_info_resp *tsc_resp;
20742070
struct snp_tsc_info_req *tsc_req;
20752071
struct snp_msg_desc *mdesc;
@@ -2093,13 +2089,9 @@ static int __init snp_get_tsc_info(void)
20932089
if (!req)
20942090
goto e_free_tsc_resp;
20952091

2096-
rio = kzalloc(sizeof(*rio), GFP_KERNEL);
2097-
if (!rio)
2098-
goto e_free_req;
2099-
21002092
mdesc = snp_msg_alloc();
21012093
if (IS_ERR_OR_NULL(mdesc))
2102-
goto e_free_rio;
2094+
goto e_free_req;
21032095

21042096
rc = snp_msg_init(mdesc, snp_vmpl);
21052097
if (rc)
@@ -2114,7 +2106,7 @@ static int __init snp_get_tsc_info(void)
21142106
req->resp_sz = sizeof(*tsc_resp) + AUTHTAG_LEN;
21152107
req->exit_code = SVM_VMGEXIT_GUEST_REQUEST;
21162108

2117-
rc = snp_send_guest_request(mdesc, req, rio);
2109+
rc = snp_send_guest_request(mdesc, req);
21182110
if (rc)
21192111
goto e_request;
21202112

@@ -2135,8 +2127,6 @@ static int __init snp_get_tsc_info(void)
21352127
memzero_explicit(tsc_resp, sizeof(*tsc_resp) + AUTHTAG_LEN);
21362128
e_free_mdesc:
21372129
snp_msg_free(mdesc);
2138-
e_free_rio:
2139-
kfree(rio);
21402130
e_free_req:
21412131
kfree(req);
21422132
e_free_tsc_resp:

arch/x86/include/asm/sev.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ struct snp_guest_req {
231231
size_t resp_sz;
232232

233233
u64 exit_code;
234+
u64 exitinfo2;
234235
unsigned int vmpck_id;
235236
u8 msg_version;
236237
u8 msg_type;
@@ -486,8 +487,6 @@ static inline int pvalidate(unsigned long vaddr, bool rmp_psize, bool validate)
486487
return rc;
487488
}
488489

489-
struct snp_guest_request_ioctl;
490-
491490
void setup_ghcb(void);
492491
void early_snp_set_memory_private(unsigned long vaddr, unsigned long paddr,
493492
unsigned long npages);
@@ -513,8 +512,7 @@ void snp_kexec_begin(void);
513512
int snp_msg_init(struct snp_msg_desc *mdesc, int vmpck_id);
514513
struct snp_msg_desc *snp_msg_alloc(void);
515514
void snp_msg_free(struct snp_msg_desc *mdesc);
516-
int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req,
517-
struct snp_guest_request_ioctl *rio);
515+
int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req);
518516

519517
int snp_svsm_vtpm_send_command(u8 *buffer);
520518

@@ -587,8 +585,8 @@ static inline void snp_kexec_begin(void) { }
587585
static inline int snp_msg_init(struct snp_msg_desc *mdesc, int vmpck_id) { return -1; }
588586
static inline struct snp_msg_desc *snp_msg_alloc(void) { return NULL; }
589587
static inline void snp_msg_free(struct snp_msg_desc *mdesc) { }
590-
static inline int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *req,
591-
struct snp_guest_request_ioctl *rio) { return -ENODEV; }
588+
static inline int snp_send_guest_request(struct snp_msg_desc *mdesc,
589+
struct snp_guest_req *req) { return -ENODEV; }
592590
static inline int snp_svsm_vtpm_send_command(u8 *buffer) { return -ENODEV; }
593591
static inline void __init snp_secure_tsc_prepare(void) { }
594592
static inline void __init snp_secure_tsc_init(void) { }

drivers/virt/coco/sev-guest/sev-guest.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ static int get_report(struct snp_guest_dev *snp_dev, struct snp_guest_request_io
101101
req.resp_sz = resp_len;
102102
req.exit_code = SVM_VMGEXIT_GUEST_REQUEST;
103103

104-
rc = snp_send_guest_request(mdesc, &req, arg);
104+
rc = snp_send_guest_request(mdesc, &req);
105+
arg->exitinfo2 = req.exitinfo2;
105106
if (rc)
106107
goto e_free;
107108

@@ -152,7 +153,8 @@ static int get_derived_key(struct snp_guest_dev *snp_dev, struct snp_guest_reque
152153
req.resp_sz = resp_len;
153154
req.exit_code = SVM_VMGEXIT_GUEST_REQUEST;
154155

155-
rc = snp_send_guest_request(mdesc, &req, arg);
156+
rc = snp_send_guest_request(mdesc, &req);
157+
arg->exitinfo2 = req.exitinfo2;
156158
if (rc)
157159
return rc;
158160

@@ -249,7 +251,8 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques
249251
req.resp_sz = resp_len;
250252
req.exit_code = SVM_VMGEXIT_EXT_GUEST_REQUEST;
251253

252-
ret = snp_send_guest_request(mdesc, &req, arg);
254+
ret = snp_send_guest_request(mdesc, &req);
255+
arg->exitinfo2 = req.exitinfo2;
253256

254257
/* If certs length is invalid then copy the returned length */
255258
if (arg->vmm_error == SNP_GUEST_VMM_ERR_INVALID_LEN) {

0 commit comments

Comments
 (0)