Re: [PATCH v6 04/11] x86/virt/tdx: Allocate ref counts for Dynamic PAMT memory

From: Chao Gao

Date: Mon Jul 06 2026 - 10:11:58 EST


>+/*
>+ * 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.

Reviewed-by: Chao Gao <chao.gao@xxxxxxxxx>