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 46E6B3BB110 for ; Mon, 31 Aug 2026 22:44:21 +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=1788216262; cv=none; b=KcnPqAkkzdvWSak87uqZ2xDVMdAWc4p6kgD7Jyn5ehv4IvTouPGlZejvS/3EdwBnMwuOW06hfzp0Tp6zadgSbE8udh3Nx0fYVfhUBOcVGgBkuwiHDxSQQt7+cYdSqgKJ+eTntxu+nPVEy8sicad8X2KPpc6iInWmV1t+183qx2Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788216262; c=relaxed/simple; bh=qPL3H5ZasTVEP4r0onqzTPTymQARnOcF3Ju5Za0zk8A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bqOYbqSRIrsksruRNaXGAVh8+v+ge6zd9CtPXJDXMDyKThhrJ5Q3/QboKPnzy5+vtVyJxKoDsFzn2sKujxHCfwTmTM+L2gmr28uga467/CJ5DDWoBiEmWhfswj4IcIG4ZgFYTy7F9OuteAAqPZYSNP/Jiu26z/E7HjPsuHZPqGw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bXRdzHHF; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bXRdzHHF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75F381F00A3F; Mon, 31 Aug 2026 22:44:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788216261; bh=dEKAVlhDWYb0t9ZdqBSHJJ9tUnom19guSbXItbkx1p4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=bXRdzHHF+r3zVGf83YOmraN1QhpAqEFs05SqUqoezWxtgtdZ1GcnbcgFVU27pPJP7 +rYWNv+exe2uZr36BvYBCVtV5yxpTdVKRp0/LUn4Cj/d7fn21OEY8Gsn49aZzlrpmi qmI+T1Pe/DWKf7DVniuyYmoGuhX5Ikpbpdppvm9LmxoYpyG7w89UQ9a6Xl+e5VmQhh bdxfA1Q3iwwKvL/V2vU8r37oNRIFPpc64kGYtJcbQN7GTMFwDserH56QWmHwuzlOg8 Kf38NmC6tn6Hxv+Tj2OM2Aavw/zWJDHqMfQnZBvenhEdrZert5mmzjkWi2dHdyXRYQ m7zJK7LoBPVLw== From: Sasha Levin To: stable@vger.kernel.org Cc: Sean Christopherson , Michael Roth , Sasha Levin Subject: [PATCH 7.1.y 2/8] KVM: SEV: Extract loading of guest-provided VMSA to a separate helper Date: Mon, 31 Aug 2026 18:44:11 -0400 Message-ID: <20260831224417.1903154-2-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260831224417.1903154-1-sashal@kernel.org> References: <2026083159-request-customs-f573@gregkh> <20260831224417.1903154-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Sean Christopherson [ Upstream commit 0060569e4f18a7dee2dd8728595e909f19a23c24 ] 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 Stable-dep-of: d1a3c2162334 ("KVM: SEV: Forcefully invalidate SNP VMSA if its backing gmem page is zapped") Signed-off-by: Sasha Levin --- arch/x86/kvm/svm/sev.c | 52 +++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 63ed3da1fb4e2..d9683d584f712 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -4081,29 +4081,17 @@ static int snp_begin_psc(struct vcpu_svm *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; - - /* Mark the vCPU as offline and not runnable */ - vcpu->arch.pv.pv_unhalted = false; - kvm_set_mp_state(vcpu, KVM_MP_STATE_HALTED); + lockdep_assert_held(&svm->sev_es.snp_vmsa_mutex); - /* 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; @@ -4113,12 +4101,9 @@ static void sev_snp_init_protected_guest_state(struct kvm_vcpu *vcpu) */ 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; @@ -4142,7 +4127,7 @@ static void sev_snp_init_protected_guest_state(struct kvm_vcpu *vcpu) 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 */ @@ -4156,6 +4141,31 @@ static void sev_snp_init_protected_guest_state(struct kvm_vcpu *vcpu) 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); -- 2.53.0