Re: [PATCH v3 11/16] KVM: TDX: Add x86 ops for external spt cache

Yan Zhao
2025-09-28T08:37:10Z

On Sat, Sep 27, 2025 at 06:10:44AM +0800, Edgecombe, Rick P wrote:
> On Tue, 2025-09-23 at 15:03 +0800, Yan Zhao wrote:
> > > @@ -625,7 +624,6 @@ static void mmu_free_memory_caches(struct
> > > kvm_vcpu *vcpu)
> > >    kvm_mmu_free_memory_cache(&vcpu-
> > > >arch.mmu_pte_list_desc_cache);
> > >    kvm_mmu_free_memory_cache(&vcpu-
> > > >arch.mmu_shadow_page_cache);
> > >    kvm_mmu_free_memory_cache(&vcpu-
> > > >arch.mmu_shadowed_info_cache);
> > > - kvm_mmu_free_memory_cache(&vcpu-
> > > >arch.mmu_external_spt_cache);
> > Though pre-allocated pages are eventually freed in tdx_vcpu_free() in
> > patch 13,
> > looks they are leaked in this patch.
> >
> > BTW, why not invoke kvm_x86_call(free_external_fault_cache)(vcpu)
> > here?
>
> The thought was to reduce the number of TDX callbacks in core MMU code.
>
> > It looks more natural to free the remaining pre-allocated pages in
> > mmu_free_memory_caches(), which is invoked after kvm_mmu_unload(vcpu)
> > while tdx_vcpu_free() is before it.
>
> Hmm, that is not so tidy. But on balance I think it would still be
> better to leave it more contained in TDX code. Any strong objection?
No strong opinion.

But if we opt to do the free internal in tdx_vcpu_free(), it looks like this
patch needs to first invoke kvm_mmu_free_memory_cache() in tdx_vcpu_free().

Also, better to have a comment in mmu_free_memory_caches() to explain why
there's no corresponding free_external_fault_cache op.