KVM: SVM: Convert plain error code numbers to defines
authorMelody Wang <huibo.wang@amd.com>
Tue, 25 Feb 2025 21:39:36 +0000 (21:39 +0000)
committerSean Christopherson <seanjc@google.com>
Wed, 26 Feb 2025 00:29:59 +0000 (16:29 -0800)
Convert VMGEXIT SW_EXITINFO1 codes from plain numbers to proper defines.

Opportunistically update the comment for the malformed input "sub-error"
codes to state that they are defined by the GHCB, and to capure the
relationship to the malformed input response.

No functional change intended.

Signed-off-by: Melody Wang <huibo.wang@amd.com>
Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
Reviewed-by: Pavan Kumar Paluri <papaluri@amd.com>
Link: https://lore.kernel.org/r/20250225213937.2471419-2-huibo.wang@amd.com
[sean: update comments]
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/include/asm/sev-common.h
arch/x86/kvm/svm/sev.c
arch/x86/kvm/svm/svm.c

index dcbccdb280f9e89c59aa899601751d4e0e62c2f1..acb85b9346d84b9d68f9e1faac477c4dff547231 100644 (file)
@@ -212,8 +212,16 @@ struct snp_psc_desc {
 #define GHCB_RESP_CODE(v)              ((v) & GHCB_MSR_INFO_MASK)
 
 /*
- * Error codes related to GHCB input that can be communicated back to the guest
- * by setting the lower 32-bits of the GHCB SW_EXITINFO1 field to 2.
+ * GHCB-defined return codes that are communicated back to the guest via
+ * SW_EXITINFO1.
+ */
+#define GHCB_HV_RESP_NO_ACTION         0
+#define GHCB_HV_RESP_ISSUE_EXCEPTION   1
+#define GHCB_HV_RESP_MALFORMED_INPUT   2
+
+/*
+ * GHCB-defined sub-error codes for malformed input (see above) that are
+ * communicated back to the guest via SW_EXITINFO2[31:0].
  */
 #define GHCB_ERR_NOT_REGISTERED                1
 #define GHCB_ERR_INVALID_USAGE         2
index 602cb51f95fe46783e560e8f24cc18b8eb7290eb..818e66404fa01ccf2484cf697e1f822bf6a92122 100644 (file)
@@ -3410,7 +3410,7 @@ vmgexit_err:
                dump_ghcb(svm);
        }
 
-       ghcb_set_sw_exit_info_1(svm->sev_es.ghcb, 2);
+       ghcb_set_sw_exit_info_1(svm->sev_es.ghcb, GHCB_HV_RESP_MALFORMED_INPUT);
        ghcb_set_sw_exit_info_2(svm->sev_es.ghcb, reason);
 
        /* Resume the guest to "return" the error code. */
@@ -3554,7 +3554,7 @@ static int setup_vmgexit_scratch(struct vcpu_svm *svm, bool sync, u64 len)
        return 0;
 
 e_scratch:
-       ghcb_set_sw_exit_info_1(svm->sev_es.ghcb, 2);
+       ghcb_set_sw_exit_info_1(svm->sev_es.ghcb, GHCB_HV_RESP_MALFORMED_INPUT);
        ghcb_set_sw_exit_info_2(svm->sev_es.ghcb, GHCB_ERR_INVALID_SCRATCH_AREA);
 
        return 1;
@@ -4114,7 +4114,7 @@ static int snp_handle_ext_guest_req(struct vcpu_svm *svm, gpa_t req_gpa, gpa_t r
        return snp_handle_guest_req(svm, req_gpa, resp_gpa);
 
 request_invalid:
-       ghcb_set_sw_exit_info_1(svm->sev_es.ghcb, 2);
+       ghcb_set_sw_exit_info_1(svm->sev_es.ghcb, GHCB_HV_RESP_MALFORMED_INPUT);
        ghcb_set_sw_exit_info_2(svm->sev_es.ghcb, GHCB_ERR_INVALID_INPUT);
        return 1; /* resume guest */
 }
@@ -4307,7 +4307,7 @@ int sev_handle_vmgexit(struct kvm_vcpu *vcpu)
        if (ret)
                return ret;
 
-       ghcb_set_sw_exit_info_1(svm->sev_es.ghcb, 0);
+       ghcb_set_sw_exit_info_1(svm->sev_es.ghcb, GHCB_HV_RESP_NO_ACTION);
        ghcb_set_sw_exit_info_2(svm->sev_es.ghcb, 0);
 
        exit_code = kvm_ghcb_get_sw_exit_code(control);
@@ -4357,7 +4357,7 @@ int sev_handle_vmgexit(struct kvm_vcpu *vcpu)
                default:
                        pr_err("svm: vmgexit: unsupported AP jump table request - exit_info_1=%#llx\n",
                               control->exit_info_1);
-                       ghcb_set_sw_exit_info_1(svm->sev_es.ghcb, 2);
+                       ghcb_set_sw_exit_info_1(svm->sev_es.ghcb, GHCB_HV_RESP_MALFORMED_INPUT);
                        ghcb_set_sw_exit_info_2(svm->sev_es.ghcb, GHCB_ERR_INVALID_INPUT);
                }
 
@@ -4387,7 +4387,7 @@ int sev_handle_vmgexit(struct kvm_vcpu *vcpu)
        case SVM_VMGEXIT_AP_CREATION:
                ret = sev_snp_ap_creation(svm);
                if (ret) {
-                       ghcb_set_sw_exit_info_1(svm->sev_es.ghcb, 2);
+                       ghcb_set_sw_exit_info_1(svm->sev_es.ghcb, GHCB_HV_RESP_MALFORMED_INPUT);
                        ghcb_set_sw_exit_info_2(svm->sev_es.ghcb, GHCB_ERR_INVALID_INPUT);
                }
 
index 7640a84e554a6a7b256a582fd107f2944ad67015..a115f219809c45ab6d026b86870b934d5ea1b46e 100644 (file)
@@ -2973,7 +2973,7 @@ static int svm_complete_emulated_msr(struct kvm_vcpu *vcpu, int err)
        if (!err || !sev_es_guest(vcpu->kvm) || WARN_ON_ONCE(!svm->sev_es.ghcb))
                return kvm_complete_insn_gp(vcpu, err);
 
-       ghcb_set_sw_exit_info_1(svm->sev_es.ghcb, 1);
+       ghcb_set_sw_exit_info_1(svm->sev_es.ghcb, GHCB_HV_RESP_ISSUE_EXCEPTION);
        ghcb_set_sw_exit_info_2(svm->sev_es.ghcb,
                                X86_TRAP_GP |
                                SVM_EVTINJ_TYPE_EXEPT |