Re: [PATCH v6 03/11] x86/virt/tdx: Add tdx_alloc/free_control_page() helpers
From: Edgecombe, Rick P
Date: Wed Jul 08 2026 - 18:54:54 EST
On Tue, 2026-07-07 at 20:50 -0700, Sohil Mehta wrote:
> How about?
>
> x86/virt/tdx: Add tdx_{alloc,free}_control_page() helpers
Sure.
>
> On 5/25/2026 7:35 PM, Rick Edgecombe wrote:
> > From: "Kirill A. Shutemov" <kirill.shutemov@xxxxxxxxxxxxxxx>
> >
> > Add helpers to use when allocating or preparing pages that are handed to
> > the TDX-Module for use as control/S-EPT pages, and thus need Dynamic PAMT
> > adjustments.
> >
> > The TDX module tracks some state for each page of physical memory that it
> > might use. It calls this state the PAMT. It includes separate state for
> > each page size a physical page could be utilized at within the TDX module
> > (1GB, 2MB, 4KB). In Dynamic PAMT, only the 4KB page size state is
> > allocated dynamically. So for pages that TDX will use as 2MB physically
> > contiguous pages, Dynamic PAMT backing is not needed.
>
> I lost the continuation in the last sentence. Why does it only talk
> about 2MB if only 4KB is dynamically allocated. What about 1GB?
>
> (Probably due to my lack of TDX knowledge)
> Similarly, why do these functions only refer to 2MB only and not 1GB?
>
> pamt_2mb_arg(), tdh_phymem_pamt_add(), tdh_phymem_pamt_remove().
We only need to dynamically allocate the 4k level of the PAMT. This is the
detail we discussed in patch 2. There it was necessary to explain why we are
changing the 4K level of the PAMT to be a bitmap thing, and not the others. Here
I think it is useful to understand why the helpers are all for 4KB page size of
host memory. I think it's clearer actually with just the last line removed:
The TDX module tracks some state for each page of physical memory that it
might use. It calls this state the PAMT. It includes separate state for
each page size a physical page could be utilized at within the TDX module
(1GB, 2MB, 4KB). In Dynamic PAMT, only the 4KB page size state is
allocated dynamically.
KVM will need to hand pages to the TDX module that it will use at 4KB
granularity. So these pages will need Dynamic PAMT backing added before
they are used by the TDX module, and removed afterwards.
And, I'll address the trimmed style comments.