]> git.hungrycats.org Git - linux/commitdiff
KVM: SEV: Mark vCPU RUNNABLE after AP_CREATE, even if VMSA is unusable
authorSean Christopherson <seanjc@google.com>
Thu, 9 Jul 2026 20:49:33 +0000 (13:49 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 2 Sep 2026 12:31:48 +0000 (14:31 +0200)
commit 98ade8c48c28c227fe2e80e545ff0c57cd4712a3 upstream.

Always mark the vCPU as RUNNABLE after responding to AP_CREATE, even if the
guest-specified VMSA is unusable, e.g. isn't backed by a memslot or doesn't
have a backing guest_memfd page.  If the VMSA is unusable, leaving the vCPU
in a non-running state will effectively hang the vCPU instead of reporting
an error to userspace.  This will also allow retrying the VMSA load in the
future, to fix a bug where KVM doesn't honor guest_memfd invalidation
events, e.g. if AP_CREATION races with PUNCH_HOLE.

Cc: stable@vger.kernel.org # 6.12.x
Reviewed-by: Michael Roth <michael.roth@amd.com>
Link: https://patch.msgid.link/20260709204948.1988414-4-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/x86/kvm/svm/sev.c

index 8fda50829c2865108de666635764f7c2b937d394..c32c38520a34e41603d0eeee702250c5db992bc8 100644 (file)
@@ -4062,9 +4062,6 @@ static void sev_snp_reload_vmsa(struct kvm_vcpu *vcpu, gpa_t gpa)
        svm->sev_es.snp_guest_vmsa_gpa = gpa;
        svm->vmcb->control.vmsa_pa = pfn_to_hpa(pfn);
 
-       /* Mark the vCPU as runnable */
-       kvm_set_mp_state(vcpu, KVM_MP_STATE_RUNNABLE);
-
        /*
         * gmem pages aren't currently migratable, but if this ever changes
         * then care should be taken to ensure svm->sev_es.vmsa is pinned
@@ -4096,6 +4093,15 @@ static void sev_snp_init_protected_guest_state(struct kvm_vcpu *vcpu)
        svm->sev_es.snp_pending_vmsa_gpa = INVALID_PAGE;
 
        sev_snp_reload_vmsa(vcpu, gpa);
+
+       /*
+        * Mark the vCPU as runnable for CREATE requests, indicated by a valid
+        * VMSA GPA, even if installing the VMSA failed, so that KVM_RUN will
+        * fail instead of blocking indefinitely and hanging the vCPU, e.g. if
+        * the backing guest_memfd page is unavailable.
+        */
+       if (VALID_PAGE(gpa))
+               kvm_set_mp_state(vcpu, KVM_MP_STATE_RUNNABLE);
 }
 
 static int sev_snp_ap_creation(struct vcpu_svm *svm)