]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: SEV: Don't terminate SNP VMs on #VMGEXIT without a registered GHCB
authorSean Christopherson <seanjc@google.com>
Fri, 29 May 2026 18:35:43 +0000 (20:35 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 3 Jun 2026 14:59:19 +0000 (16:59 +0200)
If the guest attempts a non-MSR #VMGEXIT without the registered GHCB,
return a GHCB_HV_RESP_MALFORMED_INPUT+GHCB_ERR_NOT_REGISTERED error to the
guest instead of exiting KVM_RUN with -EINVAL (and in likelihood killing
the VM).  KVM has already mapped the requested GHCB, i.e. can cleanly
report an error, and so exiting with -EINVAL is completely unjustified.

Fixes: 0c76b1d08280 ("KVM: SEV: Add support to handle GHCB GPA register VMGEXIT")
Cc: stable@vger.kernel.org
Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
Reviewed-by: Michael Roth <michael.roth@amd.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-ID: <20260501202250.2115252-19-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-ID: <20260529183549.1104619-19-pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/svm/sev.c

index 6c6a6d663e29638ac8cd0f5da64fc1a3b1e221f4..7c2ebc81306f2547c8f269028bacbba316035a80 100644 (file)
@@ -4520,9 +4520,12 @@ int sev_handle_vmgexit(struct kvm_vcpu *vcpu)
        sev_es_sync_from_ghcb(svm);
 
        /* SEV-SNP guest requires that the GHCB GPA must be registered */
-       if (is_sev_snp_guest(vcpu) && !ghcb_gpa_is_registered(svm, ghcb_gpa)) {
-               vcpu_unimpl(&svm->vcpu, "vmgexit: GHCB GPA [%#llx] is not registered.\n", ghcb_gpa);
-               return -EINVAL;
+       if (is_sev_snp_guest(vcpu) &&
+           !ghcb_gpa_is_registered(svm, control->ghcb_gpa)) {
+               vcpu_unimpl(vcpu, "vmgexit: GHCB GPA [%#llx] is not registered.\n",
+                           control->ghcb_gpa);
+               svm_vmgexit_bad_input(svm, GHCB_ERR_NOT_REGISTERED);
+               return 1;
        }
 
        ret = sev_es_validate_vmgexit(svm);