Re: [PATCH v6 09/11] KVM: TDX: Get/put PAMT pages when (un)mapping private memory
From: Edgecombe, Rick P
Date: Wed Jul 08 2026 - 21:23:38 EST
On Wed, 2026-07-08 at 16:35 +0800, Chao Gao wrote:
> On Mon, May 25, 2026 at 07:35:13PM -0700, Rick Edgecombe wrote:
> > From: "Kirill A. Shutemov" <kirill.shutemov@xxxxxxxxxxxxxxx>
> >
> > Add Dynamic PAMT support to KVM's S-EPT MMU by "getting" a PAMT page when
> > adding guest memory (PAGE.ADD or PAGE.AUG), and "putting" the page when
> > removing guest memory (PAGE.REMOVE).
> >
> > To access the per-vCPU PAMT caches without plumbing @vcpu throughout the
> > TDP MMU, begrudgingly use kvm_get_running_vcpu() to get the vCPU, and bug
> > the VM if KVM attempts to set an S-EPT leaf without an active vCPU. KVM
> > only supports creating _new_ mappings in page (pre)fault paths, all of
> > which require an active vCPU.
> >
> > The PAMT memory holds metadata for TDX-protected memory. With Dynamic
> > PAMT, PAMT_4K is allocated on demand. The kernel supplies the TDX module
> > with a few pages that cover 2M of host physical memory.
> >
> > Releases are balanced via tdx_pamt_put(): every control-page free goes
> > through tdx_free_control_page(), and guest data pages are put directly on
> > the successful tdh_mem_page_remove() path and in the
> > tdx_mem_page_add/aug() error path.
> >
> > Assisted-by: Sashiko:claude-opus-4-6 GitHub Copilot:claude-opus-4-6 Claude:claude-opus-4-7
> > Signed-off-by: Kirill A. Shutemov <kirill.shutemov@xxxxxxxxxxxxxxx>
> > Co-developed-by: Sean Christopherson <seanjc@xxxxxxxxxx>
> > Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
> > Co-developed-by: Rick Edgecombe <rick.p.edgecombe@xxxxxxxxx>
> > Signed-off-by: Rick Edgecombe <rick.p.edgecombe@xxxxxxxxx>
> > ---
> > v6:
> > - Don't have topup op take a min param (Yan, Sean)
>
> The topup_external_cache x86 op still takes int min_nr_spts. Did you
> forget to remove it, or am I misreading this changelog?
There was some discussion on v5 to drop the "min" param, but it got added back
in later discussion and renamed min_nr_spts:
https://lore.kernel.org/lkml/aYprxnSHKHUtk7pt@xxxxxxxxxx/#t