Skip to content

Commit ea4c2f2

Browse files
MelodyHuibosean-jc
authored andcommitted
KVM: SVM: Convert plain error code numbers to defines
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>
1 parent 7e066cb commit ea4c2f2

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

arch/x86/include/asm/sev-common.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,16 @@ struct snp_psc_desc {
212212
#define GHCB_RESP_CODE(v) ((v) & GHCB_MSR_INFO_MASK)
213213

214214
/*
215-
* Error codes related to GHCB input that can be communicated back to the guest
216-
* by setting the lower 32-bits of the GHCB SW_EXITINFO1 field to 2.
215+
* GHCB-defined return codes that are communicated back to the guest via
216+
* SW_EXITINFO1.
217+
*/
218+
#define GHCB_HV_RESP_NO_ACTION 0
219+
#define GHCB_HV_RESP_ISSUE_EXCEPTION 1
220+
#define GHCB_HV_RESP_MALFORMED_INPUT 2
221+
222+
/*
223+
* GHCB-defined sub-error codes for malformed input (see above) that are
224+
* communicated back to the guest via SW_EXITINFO2[31:0].
217225
*/
218226
#define GHCB_ERR_NOT_REGISTERED 1
219227
#define GHCB_ERR_INVALID_USAGE 2

arch/x86/kvm/svm/sev.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3410,7 +3410,7 @@ static int sev_es_validate_vmgexit(struct vcpu_svm *svm)
34103410
dump_ghcb(svm);
34113411
}
34123412

3413-
ghcb_set_sw_exit_info_1(svm->sev_es.ghcb, 2);
3413+
ghcb_set_sw_exit_info_1(svm->sev_es.ghcb, GHCB_HV_RESP_MALFORMED_INPUT);
34143414
ghcb_set_sw_exit_info_2(svm->sev_es.ghcb, reason);
34153415

34163416
/* 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)
35543554
return 0;
35553555

35563556
e_scratch:
3557-
ghcb_set_sw_exit_info_1(svm->sev_es.ghcb, 2);
3557+
ghcb_set_sw_exit_info_1(svm->sev_es.ghcb, GHCB_HV_RESP_MALFORMED_INPUT);
35583558
ghcb_set_sw_exit_info_2(svm->sev_es.ghcb, GHCB_ERR_INVALID_SCRATCH_AREA);
35593559

35603560
return 1;
@@ -4114,7 +4114,7 @@ static int snp_handle_ext_guest_req(struct vcpu_svm *svm, gpa_t req_gpa, gpa_t r
41144114
return snp_handle_guest_req(svm, req_gpa, resp_gpa);
41154115

41164116
request_invalid:
4117-
ghcb_set_sw_exit_info_1(svm->sev_es.ghcb, 2);
4117+
ghcb_set_sw_exit_info_1(svm->sev_es.ghcb, GHCB_HV_RESP_MALFORMED_INPUT);
41184118
ghcb_set_sw_exit_info_2(svm->sev_es.ghcb, GHCB_ERR_INVALID_INPUT);
41194119
return 1; /* resume guest */
41204120
}
@@ -4307,7 +4307,7 @@ int sev_handle_vmgexit(struct kvm_vcpu *vcpu)
43074307
if (ret)
43084308
return ret;
43094309

4310-
ghcb_set_sw_exit_info_1(svm->sev_es.ghcb, 0);
4310+
ghcb_set_sw_exit_info_1(svm->sev_es.ghcb, GHCB_HV_RESP_NO_ACTION);
43114311
ghcb_set_sw_exit_info_2(svm->sev_es.ghcb, 0);
43124312

43134313
exit_code = kvm_ghcb_get_sw_exit_code(control);
@@ -4357,7 +4357,7 @@ int sev_handle_vmgexit(struct kvm_vcpu *vcpu)
43574357
default:
43584358
pr_err("svm: vmgexit: unsupported AP jump table request - exit_info_1=%#llx\n",
43594359
control->exit_info_1);
4360-
ghcb_set_sw_exit_info_1(svm->sev_es.ghcb, 2);
4360+
ghcb_set_sw_exit_info_1(svm->sev_es.ghcb, GHCB_HV_RESP_MALFORMED_INPUT);
43614361
ghcb_set_sw_exit_info_2(svm->sev_es.ghcb, GHCB_ERR_INVALID_INPUT);
43624362
}
43634363

@@ -4387,7 +4387,7 @@ int sev_handle_vmgexit(struct kvm_vcpu *vcpu)
43874387
case SVM_VMGEXIT_AP_CREATION:
43884388
ret = sev_snp_ap_creation(svm);
43894389
if (ret) {
4390-
ghcb_set_sw_exit_info_1(svm->sev_es.ghcb, 2);
4390+
ghcb_set_sw_exit_info_1(svm->sev_es.ghcb, GHCB_HV_RESP_MALFORMED_INPUT);
43914391
ghcb_set_sw_exit_info_2(svm->sev_es.ghcb, GHCB_ERR_INVALID_INPUT);
43924392
}
43934393

arch/x86/kvm/svm/svm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2973,7 +2973,7 @@ static int svm_complete_emulated_msr(struct kvm_vcpu *vcpu, int err)
29732973
if (!err || !sev_es_guest(vcpu->kvm) || WARN_ON_ONCE(!svm->sev_es.ghcb))
29742974
return kvm_complete_insn_gp(vcpu, err);
29752975

2976-
ghcb_set_sw_exit_info_1(svm->sev_es.ghcb, 1);
2976+
ghcb_set_sw_exit_info_1(svm->sev_es.ghcb, GHCB_HV_RESP_ISSUE_EXCEPTION);
29772977
ghcb_set_sw_exit_info_2(svm->sev_es.ghcb,
29782978
X86_TRAP_GP |
29792979
SVM_EVTINJ_TYPE_EXEPT |

0 commit comments

Comments
 (0)