Re: [PATCH v6 04/11] x86/virt/tdx: Allocate ref counts for Dynamic PAMT memory
From: Edgecombe, Rick P
Date: Mon Jul 06 2026 - 16:27:30 EST
On Mon, 2026-07-06 at 21:22 +0800, Chao Gao wrote:
> > +/*
> > + * Allocate PAMT reference counters for all physical memory.
> > + *
> > + * It consumes 2MiB for every 1TiB of physical memory.
> > + */
> > +static int init_pamt_refcounts(void)
> > +{
> > + size_t size = DIV_ROUND_UP(max_pfn, PTRS_PER_PTE) *
> > sizeof(*pamt_refcounts);
> > +
> > + if (!tdx_supports_dynamic_pamt(&tdx_sysinfo))
> > + return 0;
> > +
> > + pamt_refcounts = __vmalloc(size, GFP_KERNEL | __GFP_ZERO);
> > + if (!pamt_refcounts)
> > + return -ENOMEM;
> > +
> > + return 0;
> > +}
> > +
> > +static void free_pamt_refcounts(void)
> > +{
> > + if (!tdx_supports_dynamic_pamt(&tdx_sysinfo))
> > + return;
> > +
> > + vfree(pamt_refcounts);
> > + pamt_refcounts = NULL;
> > +}
>
> Both functions are only called during boot. They can be annotated with __init.
Yep, thanks.
>
> Reviewed-by: Chao Gao <chao.gao@xxxxxxxxx>