[PATCH v2 2/2] kvm: sev: If ccp is busy, report throttled to guest

From: Dionna Glaze
Date: Thu Nov 17 2022 - 13:12:40 EST


The ccp driver can be overloaded even with 1 HZ throttling. The return
value of -EBUSY means that there is no firmware error to report back to
user space, so the guest VM would see this as exitinfo2 = 0. The false
success can trick the guest to update its the message sequence number
when it shouldn't have.

Instead, when ccp returns -EBUSY, we report that to userspace as the
throttling return value.

Cc: Thomas Lendacky <Thomas.Lendacky@xxxxxxx>
Cc: Paolo Bonzini <pbonzini@xxxxxxxxxx>
Cc: Joerg Roedel <jroedel@xxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Andy Lutomirsky <luto@xxxxxxxxxx>
Cc: John Allen <john.allen@xxxxxxx>
Cc: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Cc: "David S. Miller" <davem@xxxxxxxxxxxxx>
Cc: Peter Gonda <pgonda@xxxxxxxxxx>

Signed-off-by: Dionna Glaze <dionnaglaze@xxxxxxxxxx>
---
arch/x86/kvm/svm/sev.c | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 3ced06c6e07a..81e4862126fb 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -3335,7 +3335,13 @@ static void snp_handle_guest_request(struct vcpu_svm *svm, gpa_t req_gpa, gpa_t
goto unlock;

rc = sev_issue_cmd(kvm, SEV_CMD_SNP_GUEST_REQUEST, &data, &err);
- if (rc)
+ /*
+ * The ccp driver can return -EBUSY if the PSP is overloaded, so
+ * we offer that as a throttling signal too.
+ */
+ if (rc == -EBUSY)
+ rc = SNP_GUEST_REQ_THROTTLED;
+ else if (rc)
/* use the firmware error code */
rc = err;

@@ -3368,7 +3374,7 @@ static void snp_handle_ext_guest_request(struct vcpu_svm *svm, gpa_t req_gpa, gp
if (snp_throttle_guest_request(sev)) {
rc = SNP_GUEST_REQ_THROTTLED;
goto e_fail;
- }
+ }

data_gpa = vcpu->arch.regs[VCPU_REGS_RAX];
data_npages = vcpu->arch.regs[VCPU_REGS_RBX];
@@ -3392,7 +3398,14 @@ static void snp_handle_ext_guest_request(struct vcpu_svm *svm, gpa_t req_gpa, gp

rc = snp_guest_ext_guest_request(&req, (unsigned long)sev->snp_certs_data,
&data_npages, &err);
- if (rc) {
+ /*
+ * The ccp driver can return -EBUSY if the PSP is overloaded, so
+ * we offer that as a throttling signal too.
+ */
+ if (rc == -EBUSY) {
+ rc = SNP_GUEST_REQ_THROTTLED;
+ goto cleanup;
+ } else if (rc) {
/*
* If buffer length is small then return the expected
* length in rbx.
--
2.38.1.584.g0f3c55d4c2-goog