Re: [PATCH 2/5] KVM: TDX: Exit with MEMORY_FAULT on unexpected pending S-EPT Violation

From: Sean Christopherson
Date: Tue Jul 29 2025 - 18:55:04 EST


On Tue, Jul 29, 2025, Rick P Edgecombe wrote:
> On Tue, 2025-07-29 at 12:33 -0700, Sean Christopherson wrote:
> > diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c
> > index 3e0d4edee849..c2ef03f39c32 100644
> > --- a/arch/x86/kvm/vmx/tdx.c
> > +++ b/arch/x86/kvm/vmx/tdx.c
> > @@ -1937,10 +1937,8 @@ static int tdx_handle_ept_violation(struct kvm_vcpu *vcpu)
> >  
> >   if (vt_is_tdx_private_gpa(vcpu->kvm, gpa)) {
> >   if (tdx_is_sept_violation_unexpected_pending(vcpu)) {
> > - pr_warn("Guest access before accepting 0x%llx on vCPU %d\n",
> > - gpa, vcpu->vcpu_id);
> > - kvm_vm_dead(vcpu->kvm);
> > - return -EIO;
> > + kvm_prepare_memory_fault_exit(vcpu, gpa, 0, true, false, true);
> > + return -EFAULT;
> >   }
> >   /*
> >   * Always treat SEPT violations as write faults.  Ignore the
>
> The vm_dead was added because mirror EPT will KVM_BUG_ON() if there is an
> attempt to set the mirror EPT entry when it is already present. And the
> unaccepted memory access will trigger an EPT violation for a mirror PTE that is
> already set. I think this is a better solution irrespective of the vm_dead
> changes.

In that case, this change will expose KVM to the KVM_BUG_ON(), because nothing
prevents userspace from re-running the vCPU. Which KVM_BUG_ON() exactly gets
hit?