Re: [PATCH v4 12/16] x86/virt/tdx: Add helpers to allow for pre-allocating pages

From: Huang, Kai

Date: Tue Jan 20 2026 - 02:11:05 EST


On Thu, 2025-11-27 at 10:38 +0800, Binbin Wu wrote:
>
> On 11/27/2025 6:33 AM, Edgecombe, Rick P wrote:
> > > >
> > > >    static int tdx_topup_external_fault_cache(struct kvm_vcpu *vcpu, unsigned int cnt)
> > > >    {
> > > > - struct vcpu_tdx *tdx = to_tdx(vcpu);
> > > > + struct tdx_prealloc *prealloc = &to_tdx(vcpu)->prealloc;
> > > > + int min_fault_cache_size;
> > > >
> > > > - return kvm_mmu_topup_memory_cache(&tdx->mmu_external_spt_cache, cnt);
> > > > + /* External page tables */
> > > > + min_fault_cache_size = cnt;
> > > > + /* Dynamic PAMT pages (if enabled) */
> > > > + min_fault_cache_size += tdx_dpamt_entry_pages() * PT64_ROOT_MAX_LEVEL;
> > > Is the value PT64_ROOT_MAX_LEVEL intended, since dynamic PAMT pages are only
> > > needed for 4KB level?
> > I'm not sure I follow. We need DPAMT backing for each S-EPT page table.
> Oh, right!
>
> IIUIC,  PT64_ROOT_MAX_LEVEL is actually
> - PT64_ROOT_MAX_LEVEL - 1 for S-ETP pages since root page is not needed.
> - 1 for TD private memory page
>
> It's better to add a comment about it.
>

But theoretically we don't need a pair of DPAMT pages for one 4K S-EPT
page -- we only need a pair for a entire 2M range. If these S-EPT pages
in the fault path are allocated from the same 2M range, we are actually
over allocating DPAMT pages.

And AFAICT unfortunately there's no way to resolve this, unless we use
tdx_alloc_page() for S-EPT pages.