Re: [PATCH] KVM: SEV: Track SNP launch state and disallow invalid userspace interactions
From: Sean Christopherson
Date: Wed Feb 25 2026 - 15:22:54 EST
On Wed, Feb 25, 2026, Jethro Beekman wrote:
> On 2026-02-25 12:05, Sean Christopherson wrote:
> > On Mon, Jan 19, 2026, Jethro Beekman wrote:
> >> Calling any of the SNP_LAUNCH_ ioctls after SNP_LAUNCH_FINISH results in a
> >> kernel page fault due to RMP violation. Track SNP launch state and exit early.
> >
> > What exactly trips the RMP #PF? A backtrace would be especially helpful for
> > posterity.
>
> Here's a backtrace for calling ioctl(KVM_SEV_SNP_LAUNCH_FINISH) twice. Note this is with a modified version of QEMU.
> RIP: 0010:sev_es_sync_vmsa+0x54/0x4c0 [kvm_amd]
> snp_launch_update_vmsa+0x19d/0x290 [kvm_amd]
> snp_launch_finish+0xb6/0x380 [kvm_amd]
> sev_mem_enc_ioctl+0x14e/0x720 [kvm_amd]
> kvm_arch_vm_ioctl+0x837/0xcf0 [kvm]
Ah, it's the VMSA that's being accessed. Can't we just do?
diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 723f4452302a..1e40ae592c93 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -882,6 +882,9 @@ static int sev_es_sync_vmsa(struct vcpu_svm *svm)
u8 *d;
int i;
+ if (vcpu->arch.guest_state_protected)
+ return -EINVAL;
+
/* Check some debug related fields before encrypting the VMSA */
if (svm->vcpu.guest_debug || (svm->vmcb->save.dr7 & ~DR7_FIXED_1))
return -EINVAL;