From: "Jörg Rödel" <joro@8bytes.org>
To: Paolo Bonzini <pbonzini@redhat.com>,
Sean Christopherson <seanjc@google.com>
Cc: Michael Roth <michael.roth@amd.com>,
Liam Merwick <liam.merwick@oracle.com>,
Vishal Annapurve <vannapurve@google.com>,
Ninad Naik <ninadnaik07@gmail.com>,
Joerg Roedel <joerg.roedel@amd.com>,
Tom Lendacky <thomas.lendacky@amd.com>,
James Bottomley <James.Bottomley@HansenPartnership.com>,
kvm@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
coconut-svsm@lists.linux.dev
Subject: [PATCH v2 3/8] KVM: SVM: Hold SRCU while reloading guest-owned VMSAs
Date: Tue, 8 Sep 2026 12:33:33 +0200 [thread overview]
Message-ID: <20260908103338.427254-4-joro@8bytes.org> (raw)
In-Reply-To: <20260908103338.427254-1-joro@8bytes.org>
From: Joerg Roedel <joerg.roedel@amd.com>
Take a dedicated KVM SRCU read lock around the guest-owned VMSA memslot
and guest_memfd lookup. This makes the reload path self-contained and
prevents it from racing a userspace memslot replacement.
Keep the lock through VMCB installation, and release it on all lookup
failure paths.
Assisted-by: LLM
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
arch/x86/kvm/svm/sev.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index c16eca9983f3..ee1bf9b4cc53 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -4037,6 +4037,7 @@ static void __sev_snp_reload_vmsa(struct kvm_vcpu *vcpu, gpa_t gpa)
unsigned long mmu_seq;
struct page *page;
kvm_pfn_t pfn;
+ int idx;
lockdep_assert_held(&svm->sev_es.snp_vmsa_mutex);
@@ -4068,9 +4069,10 @@ static void __sev_snp_reload_vmsa(struct kvm_vcpu *vcpu, gpa_t gpa)
if (!VALID_PAGE(gpa))
return;
- slot = gfn_to_memslot(vcpu->kvm, gfn);
+ idx = srcu_read_lock(&kvm->srcu);
+ slot = gfn_to_memslot(kvm, gfn);
if (!slot)
- return;
+ goto out_unlock;
mmu_seq = kvm->mmu_invalidate_seq;
smp_rmb();
@@ -4079,8 +4081,8 @@ static void __sev_snp_reload_vmsa(struct kvm_vcpu *vcpu, gpa_t gpa)
* The new VMSA will be private memory guest memory, so retrieve the
* PFN from the gmem backend.
*/
- if (kvm_gmem_get_pfn(vcpu->kvm, slot, gfn, &pfn, &page, NULL))
- return;
+ if (kvm_gmem_get_pfn(kvm, slot, gfn, &pfn, &page, NULL))
+ goto out_unlock;
read_lock(&kvm->mmu_lock);
/*
@@ -4097,6 +4099,8 @@ static void __sev_snp_reload_vmsa(struct kvm_vcpu *vcpu, gpa_t gpa)
read_unlock(&kvm->mmu_lock);
kvm_release_page_clean(page);
+out_unlock:
+ srcu_read_unlock(&kvm->srcu, idx);
}
/*
--
2.53.0
next prev parent reply other threads:[~2026-09-08 10:33 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-08 10:33 [PATCH v2 0/8] KVM: SVM: Support direct setting of VMSA for SEV-SNP guests Jörg Rödel
2026-09-08 10:33 ` [PATCH v2 1/8] KVM: SEV: Document SNP direct VMSA userspace ABI Jörg Rödel
2026-09-08 10:33 ` [PATCH v2 2/8] KVM: SVM: Implement GET_AP_APIC_IDS NAE event Jörg Rödel
2026-09-08 10:33 ` Jörg Rödel [this message]
2026-09-08 10:33 ` [PATCH v2 4/8] KVM: SEV: Add direct VMSA capability Jörg Rödel
2026-09-08 10:33 ` [PATCH v2 5/8] KVM: SEV: Allow VMSA pages in SNP launch updates Jörg Rödel
2026-09-08 10:33 ` [PATCH v2 6/8] KVM: SEV: Add SNP vCPU state get and set commands Jörg Rödel
2026-09-08 10:33 ` [PATCH v2 7/8] KVM: selftests: Test the SNP APIC-ID-list GHCB request Jörg Rödel
2026-09-08 10:33 ` [PATCH v2 8/8] KVM: selftests: Test SNP vCPU state and direct VMSA launch Jörg Rödel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260908103338.427254-4-joro@8bytes.org \
--to=joro@8bytes.org \
--cc=James.Bottomley@HansenPartnership.com \
--cc=coconut-svsm@lists.linux.dev \
--cc=joerg.roedel@amd.com \
--cc=kvm@vger.kernel.org \
--cc=liam.merwick@oracle.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=michael.roth@amd.com \
--cc=ninadnaik07@gmail.com \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=thomas.lendacky@amd.com \
--cc=vannapurve@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox