Re: [PATCH v4 07/16] x86/virt/tdx: Add tdx_alloc/free_page() helpers
From: Edgecombe, Rick P
Date: Fri Jan 16 2026 - 18:25:55 EST
On Fri, 2026-01-16 at 15:17 -0800, Sean Christopherson wrote:
> On Thu, Nov 20, 2025, Rick Edgecombe wrote:
> > +/*
> > + * Return a page that can be used as TDX private memory
> > + * and obtain TDX protections.
>
> Wrap at ~80.
>
> This comment is also misleading, arguably wrong. Because from KVM's perspective,
> these APIs are _never_ used to back TDX private memory. They are used only for
> control pages, which yeah, I suppose might be encrypted with the guest's private
> key, but most readers will interpret "used as TDX private memory" to mean that
> these are _the_ source of pages for guest private memory.
Maybe just drop "private" and call it TDX memory?
>
> > + */
> > +struct page *tdx_alloc_page(void)
>
> And in a similar vein, given terminology in other places, maybe call these
> tdx_{alloc,free}_control_page()?
True, that is the only use today, but also there is nothing control page
specific about the functions themselves. I'm ok changing it, but I'm not sure it
helps that much.
>
> > +{
> > + struct page *page;
> > +
> > + page = alloc_page(GFP_KERNEL);
>
> GFP_KERNEL_ACCOUNT, all of these allocations are tied to a VM.
Yes, thanks.
>
> > + if (!page)
> > + return NULL;
> > +
> > + if (tdx_pamt_get(page)) {
> > + __free_page(page);
> > + return NULL;
> > + }
> > +
> > + return page;
> > +}
> > +EXPORT_SYMBOL_GPL(tdx_alloc_page);
>
> Note, these can all now be EXPORT_SYMBOL_FOR_KVM.
Sure.