From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB84850AC0F; Mon, 31 Aug 2026 13:42:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788183755; cv=none; b=BLpKPZ6rd2A4HzLtx0jJKeKtyrTQDhMZfFpN7DUYhaimIkK3yFmYnXbodClSeBq6BjaDSg3ouxaEsgtNQJxGeBXTF6cF8YQNz9BLHLjbdl8XTtF0/oBHSQqAHuCEj1dIJ7WAeEeZ6dAcHxRETGuiYkfSD9pyoaaK1FuCgb2agNE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788183755; c=relaxed/simple; bh=nRkzAka5UUgTGLJuFxvpOJ0P1BWmqVmbpIu2cOvWR7w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JUQjv1wA/n4TZDJlvr1o2NUblVmbkXOdiUrl6hqNkgGARZBBXSekKbqAKvQXFwKhLdz7z+Mj+GRL02Te0nERZmjHtgjKKJ6L2aYdRje65JZ2o2zUNqnYnYCpw28iu18UDj08blHmOvOe3WM8QQqSrcNE+r/GgyFtQDRTDFz594A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=MhSWW4xj; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="MhSWW4xj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 438BA1F00ACF; Mon, 31 Aug 2026 13:42:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1788183753; bh=bi9g9MJMVIK7XWRxKdgrka0glX2BheXfXGmRSrktjb8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=MhSWW4xjkaUchTTF+3yogjlxC80KiyQFM2LRzRnqY2iBx6DJlRthkAkN+EzJqJqcc q9N0oVpiHBS/4akWjpxIlPEMbtCgZIUDWB/9wKvhiC6oW/0l7qH3CVVzBTZ0mK2YNI zFzaZXSIu75Gnw7+A/ABvj/7Vq/Hy0T7QcJEEd1A= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Michael Roth , Sean Christopherson Subject: [PATCH 7.1 31/76] KVM: SEV: Extract loading of guest-provided VMSA to a separate helper Date: Mon, 31 Aug 2026 15:34:03 +0200 Message-ID: <20260831133400.932526143@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260831133359.185608553@linuxfoundation.org> References: <20260831133359.185608553@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sean Christopherson commit 0060569e4f18a7dee2dd8728595e909f19a23c24 upstream. Extract the loading/retrieval of a guest-provided VMSA to a separate helper so that KVM can reuse the core logic when refreshing the VMSA after an MMU invalidation from guest_memfd. No functional change intended. Cc: stable@vger.kernel.org # 6.12.x Reviewed-by: Michael Roth Link: https://patch.msgid.link/20260709204948.1988414-3-seanjc@google.com Signed-off-by: Sean Christopherson Signed-off-by: Greg Kroah-Hartman --- arch/x86/kvm/svm/sev.c | 52 +++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 21 deletions(-) --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -4085,29 +4085,17 @@ static int snp_begin_psc(struct vcpu_svm return snp_do_psc(svm); } -/* - * Invoked as part of svm_vcpu_reset() processing of an init event. - */ -static void sev_snp_init_protected_guest_state(struct kvm_vcpu *vcpu) +static void sev_snp_reload_vmsa(struct kvm_vcpu *vcpu, gpa_t gpa) { struct vcpu_svm *svm = to_svm(vcpu); struct kvm_memory_slot *slot; + gfn_t gfn = gpa_to_gfn(gpa); struct page *page; kvm_pfn_t pfn; - gfn_t gfn; - - guard(mutex)(&svm->sev_es.snp_vmsa_mutex); - if (!svm->sev_es.snp_ap_waiting_for_reset) - return; - - svm->sev_es.snp_ap_waiting_for_reset = false; + lockdep_assert_held(&svm->sev_es.snp_vmsa_mutex); - /* Mark the vCPU as offline and not runnable */ - vcpu->arch.pv.pv_unhalted = false; - kvm_set_mp_state(vcpu, KVM_MP_STATE_HALTED); - - /* Clear use of the VMSA */ + /* Clear use of the VMSA. */ svm->vmcb->control.vmsa_pa = INVALID_PAGE; svm->sev_es.snp_guest_vmsa_gpa = INVALID_PAGE; @@ -4117,12 +4105,9 @@ static void sev_snp_init_protected_guest */ vmcb_mark_all_dirty(svm->vmcb); - if (!VALID_PAGE(svm->sev_es.snp_pending_vmsa_gpa)) + if (!VALID_PAGE(gpa)) return; - gfn = gpa_to_gfn(svm->sev_es.snp_pending_vmsa_gpa); - svm->sev_es.snp_pending_vmsa_gpa = INVALID_PAGE; - slot = gfn_to_memslot(vcpu->kvm, gfn); if (!slot) return; @@ -4146,7 +4131,7 @@ static void sev_snp_init_protected_guest svm->sev_es.snp_has_guest_vmsa = true; /* Use the new VMSA */ - svm->sev_es.snp_guest_vmsa_gpa = gfn_to_gpa(gfn); + svm->sev_es.snp_guest_vmsa_gpa = gpa; svm->vmcb->control.vmsa_pa = pfn_to_hpa(pfn); /* Mark the vCPU as runnable */ @@ -4160,6 +4145,31 @@ static void sev_snp_init_protected_guest kvm_release_page_clean(page); } +/* + * Invoked as part of svm_vcpu_reset() processing of an init event. + */ +static void sev_snp_init_protected_guest_state(struct kvm_vcpu *vcpu) +{ + struct vcpu_svm *svm = to_svm(vcpu); + gpa_t gpa; + + guard(mutex)(&svm->sev_es.snp_vmsa_mutex); + + if (!svm->sev_es.snp_ap_waiting_for_reset) + return; + + svm->sev_es.snp_ap_waiting_for_reset = false; + + /* Mark the vCPU as offline and not runnable */ + vcpu->arch.pv.pv_unhalted = false; + kvm_set_mp_state(vcpu, KVM_MP_STATE_HALTED); + + gpa = svm->sev_es.snp_pending_vmsa_gpa; + svm->sev_es.snp_pending_vmsa_gpa = INVALID_PAGE; + + sev_snp_reload_vmsa(vcpu, gpa); +} + static int sev_snp_ap_creation(struct vcpu_svm *svm) { struct kvm_sev_info *sev = to_kvm_sev_info(svm->vcpu.kvm);