Re: [PATCH v4 11/17] KVM: TDX: Honor the guest's accept level contained in an EPT violation
From: Edgecombe, Rick P
Date: Mon Oct 12 2026 - 12:16:42 EST
On Sat, 2026-10-10 at 13:42 +0800, Yan Zhao wrote:
> On Sat, Oct 10, 2026 at 06:00:01AM +0800, Edgecombe, Rick P wrote:
> > On Fri, 2026-10-09 at 17:33 +0800, Yan Zhao wrote:
> > > On Thu, Oct 08, 2026 at 09:05:32AM +0800, Edgecombe, Rick P wrote:
> > > > On Mon, 2026-09-28 at 17:11 +0800, Yan Zhao wrote:
> > >
> > > @@ -2183,7 +2172,13 @@ static int
> > > tdx_handle_guest_accept_ept_violation(struct kvm_vcpu *vcpu, gfn_t gf
> > > return 0;
> > >
> > > level = tdx_get_ept_violation_level(vcpu);
> > > - if (level > PG_LEVEL_2M)
> > > + KVM_BUG_ON(level != PG_LEVEL_2M && level != PG_LEVEL_4K, kvm);
> > > +
> > > + /*
> > > + * No need to inhibit 1GB mappings since they are unsupported with
> > > + * the initial huge page implementation.
> >
> > This also implies 1GB is coming...
> What about simply commenting as
> "No need to inhibit 1GB mappings since they are unsupported." ?
Seems reasonable.
>
> > > + */
> > > + if (level == PG_LEVEL_2M)
> > > return 0;
> > >
> > > if (hugepage_test_guest_inhibit(slot, gfn, level + 1))
> > > @@ -2203,8 +2198,6 @@ static int
> > > tdx_handle_guest_accept_ept_violation(struct kvm_vcpu *vcpu, gfn_t gf
> > > * sequence required by the TDX-Module includes a TLB flush.
> > > */
> > > hugepage_set_guest_inhibit(slot, gfn, level + 1);
> > > - if (level == PG_LEVEL_4K)
> > > - hugepage_set_guest_inhibit(slot, gfn, level + 2);
> > >
> > > return 0;
> > > }
> > >
> >
> > There are a lot of possible things that are not handled if a 1GB mapping
> > sneaks
> > through.
> >
> > Why not KVM_BUG_ON() if something tries to map 1GB in the appropriate
> > tdx_sept_set_private_spte() sub functions. tdx_sept_split_leaf_spte() should
> > be
> > covered already, but not tdx_sept_map_leaf_spte() looks like.
> Hmm, there's an implicit KVM_BUG_ON() inside tdx_sept_map_leaf_spte() about
> the
> mapping level: both tdx_mem_page_aug() and tdx_mem_page_add() return error if
> the mapping level is 1GB.
Oh right. So it's covered. I guess the only thing missing is explicit KVM_BUG_ON
for documentation. I'm ok leaving it out though.