Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proof of concept for GHCB spec addition for throttling #4

Open
wants to merge 2 commits into
base: sev-snp-v12
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions arch/x86/include/asm/sev-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ struct snp_psc_desc {
#define GHCB_SEV_ES_PROT_UNSUPPORTED 1
#define GHCB_SNP_UNSUPPORTED 2

/* Error codes from hypervisor in EXITINFO[31:0] after VMGEXIT */
#define VMGEXIT_RESULT_OK 0
#define VMGEXIT_RESULT_EXCEPTION 1
#define VMGEXIT_RESULT_BAD_INPUT 2
#define VMGEXIT_RESULT_THROTTLED 3

/* Linux-specific reason codes (used with reason set 1) */
#define SEV_TERM_SET_LINUX 1
#define GHCB_TERM_REGISTER 0 /* GHCB GPA registration failure */
Expand Down
4 changes: 3 additions & 1 deletion arch/x86/kernel/sev-shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ static enum es_result verify_exception_info(struct ghcb *ghcb, struct es_em_ctxt
if (!ret)
return ES_OK;

if (ret == 1) {
if (ret == VMGEXIT_RESULT_EXCEPTION) {
u64 info = ghcb->save.sw_exit_info_2;
unsigned long v;

Expand All @@ -217,6 +217,8 @@ static enum es_result verify_exception_info(struct ghcb *ghcb, struct es_em_ctxt

return ES_EXCEPTION;
}
} else if (ret == VMGEXIT_RESULT_THROTTLED) {
return ES_RETRY;
}

return ES_VMM_ERROR;
Expand Down
6 changes: 5 additions & 1 deletion arch/x86/kernel/sev.c
Original file line number Diff line number Diff line change
Expand Up @@ -2161,8 +2161,12 @@ int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, unsigned
}

ret = sev_es_ghcb_hv_call(ghcb, true, &ctxt, exit_code, input->req_gpa, input->resp_gpa);
if (ret)
/* ret is an es_result at this point */
if (ret) {
if (ret == ES_RETRY)
ret = -EAGAIN;
goto e_put;
}

if (ghcb->save.sw_exit_info_2) {
/* Number of expected pages are returned in RBX */
Expand Down
2 changes: 1 addition & 1 deletion drivers/virt/coco/sevguest/sevguest.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, in
u8 type, void *req_buf, size_t req_sz, void *resp_buf,
u32 resp_sz, __u64 *fw_err)
{
unsigned long err;
unsigned long err = 0;
u64 seqno;
int rc;

Expand Down