Skip to content

Commit c5961f6

Browse files
sean-jcgregkh
authored andcommitted
KVM: SVM: Don't change target vCPU state on AP Creation VMGEXIT error
commit d26638b upstream. If KVM rejects an AP Creation event, leave the target vCPU state as-is. Nothing in the GHCB suggests the hypervisor is *allowed* to muck with vCPU state on failure, let alone required to do so. Furthermore, kicking only in the !ON_INIT case leads to divergent behavior, and even the "kick" case is non-deterministic. E.g. if an ON_INIT request fails, the guest can successfully retry if the fixed AP Creation request is made prior to sending INIT. And if a !ON_INIT fails, the guest can successfully retry if the fixed AP Creation request is handled before the target vCPU processes KVM's KVM_REQ_UPDATE_PROTECTED_GUEST_STATE. Fixes: e366f92 ("KVM: SEV: Support SEV-SNP AP Creation NAE event") Cc: stable@vger.kernel.org Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com> Reviewed-by: Pankaj Gupta <pankaj.gupta@amd.com> Link: https://lore.kernel.org/r/20250227012541.3234589-5-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 8bc4675 commit c5961f6

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

arch/x86/kvm/svm/sev.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3969,16 +3969,12 @@ static int sev_snp_ap_creation(struct vcpu_svm *svm)
39693969

39703970
/*
39713971
* The target vCPU is valid, so the vCPU will be kicked unless the
3972-
* request is for CREATE_ON_INIT. For any errors at this stage, the
3973-
* kick will place the vCPU in an non-runnable state.
3972+
* request is for CREATE_ON_INIT.
39743973
*/
39753974
kick = true;
39763975

39773976
mutex_lock(&target_svm->sev_es.snp_vmsa_mutex);
39783977

3979-
target_svm->sev_es.snp_vmsa_gpa = INVALID_PAGE;
3980-
target_svm->sev_es.snp_ap_waiting_for_reset = true;
3981-
39823978
/* Interrupt injection mode shouldn't change for AP creation */
39833979
if (request < SVM_VMGEXIT_AP_DESTROY) {
39843980
u64 sev_features;
@@ -4024,20 +4020,23 @@ static int sev_snp_ap_creation(struct vcpu_svm *svm)
40244020
target_svm->sev_es.snp_vmsa_gpa = svm->vmcb->control.exit_info_2;
40254021
break;
40264022
case SVM_VMGEXIT_AP_DESTROY:
4023+
target_svm->sev_es.snp_vmsa_gpa = INVALID_PAGE;
40274024
break;
40284025
default:
40294026
vcpu_unimpl(vcpu, "vmgexit: invalid AP creation request [%#x] from guest\n",
40304027
request);
40314028
ret = -EINVAL;
4032-
break;
4029+
goto out;
40334030
}
40344031

4035-
out:
4032+
target_svm->sev_es.snp_ap_waiting_for_reset = true;
4033+
40364034
if (kick) {
40374035
kvm_make_request(KVM_REQ_UPDATE_PROTECTED_GUEST_STATE, target_vcpu);
40384036
kvm_vcpu_kick(target_vcpu);
40394037
}
40404038

4039+
out:
40414040
mutex_unlock(&target_svm->sev_es.snp_vmsa_mutex);
40424041

40434042
return ret;

0 commit comments

Comments
 (0)