[PATCH v10 09/11] x86/virt/tdx: Enable Dynamic PAMT

From: Rick Edgecombe

Date: Wed Sep 02 2026 - 21:57:56 EST


The Physical Address Metadata Table (PAMT) holds TDX metadata for
physical memory and must be allocated by the kernel during TDX module
initialization. Dynamic PAMT (DPAMT) is a TDX module feature that can
reduce this memory use by allocating part of the PAMT dynamically.

The TDX module exposes whether DPAMT is supported via a bit in the
'features0' metadata. Unfortunately, the TDX module exposes the feature as
supported even when it does not support using it with the number of keyids
currently configured in the BIOS. Since no TDX modules exist today with
that issue fixed, make the feature default off to prevent users from
upgrading their kernel and encountering TDX erroring out when trying to
enable DPAMT.

For the decision of whether to make it a boot time option and/or compile
time option, consider that DPAMT's memory savings are significant enough
to make it a good default configuration. That is most TDX users should
want it unless they have strange keyid configurations.

The feature increases the kernel size by 2KB (when TDX is configured in the
build).

All pieces are in place to enable DPAMT if it is supported and the user
passes a kernel parameter.

AI was used to review code. It made a style suggestion.

Based on a patch originally by Kiryl Shutsemau.

Signed-off-by: Rick Edgecombe <rick.p.edgecombe@xxxxxxxxx>
Tested-by: Hongyu Ning <hongyu.ning@xxxxxxxxxxxxxxx>
Reviewed-by: Tony Lindgren <tony.lindgren@xxxxxxxxxxxxxxx>
Reviewed-by: Vishal Annapurve <vannapurve@xxxxxxxxxx>
Acked-by: Sohil Mehta <sohil.mehta@xxxxxxxxx>
---
v10:
- Change "Dynamic PAMT" to "DPAMT" at the second reference in the
logs. (Dave)
- Adjust tdx_supports_dynamic_pamt() to check multiple conditions in a
more tip style. (AI nit checker)
v8:
- Order tdx_dpamt in kernel-parameters.txt (Sohil)
- Make tdx_enable_dpamt static (Sashiko)

v7:
- Add kernel parameter following some twists and turns, deriving
originally from a comment by (Chao)
---
.../admin-guide/kernel-parameters.txt | 7 ++++++
arch/x86/include/asm/tdx.h | 1 +
arch/x86/virt/vmx/tdx/tdx.c | 23 +++++++++++++++++--
3 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 68647ff4bdd24..f32aa58f744a1 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -7582,6 +7582,13 @@ Kernel parameters

tdfx= [HW,DRM]

+ tdx_dpamt=
+ [X86] Controls whether TDX will use Dynamic PAMT
+ to save memory, when supported.
+
+ Valid parameters: "on", "off"
+ Default: "off"
+
test_suspend= [SUSPEND]
Format: { "mem" | "standby" | "freeze" }[,N]
Specify "mem" (for Suspend-to-RAM) or "standby" (for
diff --git a/arch/x86/include/asm/tdx.h b/arch/x86/include/asm/tdx.h
index 8c7839d61296d..e186dfe5bf885 100644
--- a/arch/x86/include/asm/tdx.h
+++ b/arch/x86/include/asm/tdx.h
@@ -36,6 +36,7 @@
/* Bit definitions of TDX_FEATURES0 metadata field */
#define TDX_FEATURES0_TD_PRESERVING BIT_ULL(1)
#define TDX_FEATURES0_NO_RBP_MOD BIT_ULL(18)
+#define TDX_FEATURES0_DYNAMIC_PAMT BIT_ULL(36)

#ifndef __ASSEMBLER__

diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c
index ff00ee6d5705a..3daa8c63f9c51 100644
--- a/arch/x86/virt/vmx/tdx/tdx.c
+++ b/arch/x86/virt/vmx/tdx/tdx.c
@@ -50,6 +50,8 @@
/* Number of DPAMT pages to be provided to TDX module per 2MB region of PA */
#define TDX_DPAMT_ENTRY_PAGE_CNT 2

+static bool tdx_enable_dpamt __ro_after_init;
+
struct tdx_module_state {
bool initialized;
bool sysinit_done;
@@ -1031,6 +1033,8 @@ static __init int construct_tdmrs(struct list_head *tmb_list,
return ret;
}

+#define TDX_SYS_CONFIG_DYNAMIC_PAMT BIT(16)
+
static __init int config_tdx_module(struct tdmr_info_list *tdmr_list,
u64 global_keyid)
{
@@ -1059,6 +1063,12 @@ static __init int config_tdx_module(struct tdmr_info_list *tdmr_list,
args.rcx = __pa(tdmr_pa_array);
args.rdx = tdmr_list->nr_consumed_tdmrs;
args.r8 = global_keyid;
+
+ if (tdx_supports_dynamic_pamt(&tdx_sysinfo)) {
+ pr_info("Enable Dynamic PAMT\n");
+ args.r8 |= TDX_SYS_CONFIG_DYNAMIC_PAMT;
+ }
+
ret = seamcall_prerr(TDH_SYS_CONFIG, &args);

/* Free the array as it is not required anymore. */
@@ -2046,8 +2056,10 @@ EXPORT_SYMBOL_FOR_KVM(tdh_phymem_page_wbinvd_hkid);

bool tdx_supports_dynamic_pamt(const struct tdx_sys_info *sysinfo)
{
- /* To be enabled when kernel is ready. */
- return false;
+ if (!tdx_enable_dpamt)
+ return false;
+
+ return sysinfo->features.tdx_features0 & TDX_FEATURES0_DYNAMIC_PAMT;
}
EXPORT_SYMBOL_FOR_KVM(tdx_supports_dynamic_pamt);

@@ -2308,6 +2320,13 @@ void tdx_free_control_page(struct page *page)
}
EXPORT_SYMBOL_FOR_KVM(tdx_free_control_page);

+static int __init tdx_dpamt_setup(char *str)
+{
+ return kstrtobool(str, &tdx_enable_dpamt) == 0;
+}
+
+__setup("tdx_dpamt=", tdx_dpamt_setup);
+
void tdx_sys_disable(void)
{
struct tdx_module_args args = {};
--
2.55.0