From: Rick Edgecombe <rick.p.edgecombe@intel.com>
To: bp@alien8.de, dave.hansen@intel.com, hpa@zytor.com,
kas@kernel.org, kvm@vger.kernel.org, linux-coco@lists.linux.dev,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
mingo@redhat.com, nik.borisov@suse.com, pbonzini@redhat.com,
seanjc@google.com, tglx@kernel.org, vannapurve@google.com,
x86@kernel.org, chao.gao@intel.com, yan.y.zhao@intel.com,
kai.huang@intel.com, tony.lindgren@linux.intel.com,
binbin.wu@intel.com, sohil.mehta@intel.com
Cc: rick.p.edgecombe@intel.com, Hongyu Ning <hongyu.ning@linux.intel.com>
Subject: [PATCH v9 09/11] x86/virt/tdx: Enable Dynamic PAMT
Date: Wed, 5 Aug 2026 19:08:48 -0700 [thread overview]
Message-ID: <20260806020850.1221381-10-rick.p.edgecombe@intel.com> (raw)
In-Reply-To: <20260806020850.1221381-1-rick.p.edgecombe@intel.com>
From: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
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 is a TDX module feature that can reduce this
memory use by allocating part of the PAMT dynamically.
The TDX module exposes whether Dynamic PAMT 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 Dynamic PAMT.
For the decision of whether to make it a boot time option and/or compile
time option, consider that Dynamic PAMT'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 Dynamic PAMT if it is supported and the
user passes a kernel parameter.
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Co-developed-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
Tested-by: Hongyu Ning <hongyu.ning@linux.intel.com>
Reviewed-by: Tony Lindgren <tony.lindgren@linux.intel.com>
Acked-by: Sohil Mehta <sohil.mehta@intel.com>
---
v8:
- Order tdx_dpamt in kernel-parameters.txt (Sohil)
- Make tdx_enable_dpamt static (Sashiko)
v7:
- Add kernel parameter following some twists and turns, derriving
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 | 21 +++++++++++++++++--
3 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index b5493a7f8f228..49bcd7798876c 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -7512,6 +7512,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 9cbd250bbd39b..7910901a7ba21 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 7fd427174b8b6..f2ea034773bb2 100644
--- a/arch/x86/virt/vmx/tdx/tdx.c
+++ b/arch/x86/virt/vmx/tdx/tdx.c
@@ -47,6 +47,8 @@
#include "seamcall_internal.h"
#include "tdx.h"
+static bool tdx_enable_dpamt __ro_after_init;
+
struct tdx_module_state {
bool initialized;
bool sysinit_done;
@@ -1028,6 +1030,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)
{
@@ -1056,6 +1060,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. */
@@ -2041,8 +2051,8 @@ 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;
+ return sysinfo->features.tdx_features0 & TDX_FEATURES0_DYNAMIC_PAMT &&
+ tdx_enable_dpamt;
}
EXPORT_SYMBOL_FOR_KVM(tdx_supports_dynamic_pamt);
@@ -2300,6 +2310,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.54.0
next prev parent reply other threads:[~2026-08-06 2:09 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-06 2:08 [PATCH v9 00/11] Dynamic PAMT Rick Edgecombe
2026-08-06 2:08 ` [PATCH v9 01/11] x86/virt/tdx: Simplify PAMT layout calculation Rick Edgecombe
2026-08-06 20:58 ` Dave Hansen
2026-08-06 2:08 ` [PATCH v9 02/11] x86/virt/tdx: Allocate page bitmap for Dynamic PAMT Rick Edgecombe
2026-08-06 20:58 ` Dave Hansen
2026-08-06 2:08 ` [PATCH v9 03/11] x86/virt/tdx: Add tdx_alloc/free_control_page() helpers Rick Edgecombe
2026-08-06 17:17 ` Dave Hansen
2026-08-06 17:20 ` Dave Hansen
2026-08-06 22:22 ` Edgecombe, Rick P
2026-08-06 22:42 ` Dave Hansen
2026-08-06 2:08 ` [PATCH v9 04/11] x86/virt/tdx: Allocate refcounts for Dynamic PAMT memory Rick Edgecombe
2026-08-06 20:56 ` Dave Hansen
2026-08-06 21:56 ` Edgecombe, Rick P
[not found] ` <20260806022158.586A11F000E9@smtp.kernel.org>
2026-08-06 22:02 ` Edgecombe, Rick P
2026-08-06 22:09 ` Dave Hansen
2026-08-06 2:08 ` [PATCH v9 05/11] x86/virt/tdx: Handle multiple callers in tdx_pamt_get/put() Rick Edgecombe
2026-08-06 22:17 ` Dave Hansen
2026-08-06 2:08 ` [PATCH v9 06/11] KVM: TDX: Allocate PAMT memory for TD and vCPU control structures Rick Edgecombe
2026-08-06 22:19 ` Dave Hansen
2026-08-06 2:08 ` [PATCH v9 07/11] x86/tdx: Add APIs to support Dynamic PAMT ops from KVM's fault path Rick Edgecombe
2026-08-06 22:19 ` Dave Hansen
2026-08-06 2:08 ` [PATCH v9 08/11] KVM: TDX: Get/put PAMT pages when (un)mapping private memory Rick Edgecombe
2026-08-06 23:48 ` Dave Hansen
2026-08-06 2:08 ` Rick Edgecombe [this message]
2026-08-06 2:08 ` [PATCH v9 10/11] Documentation/x86: Add documentation for TDX's Dynamic PAMT Rick Edgecombe
2026-08-06 2:08 ` [PATCH v9 11/11] x86/virt/tdx: Optimize tdx_pamt_get/put() Rick Edgecombe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260806020850.1221381-10-rick.p.edgecombe@intel.com \
--to=rick.p.edgecombe@intel.com \
--cc=binbin.wu@intel.com \
--cc=bp@alien8.de \
--cc=chao.gao@intel.com \
--cc=dave.hansen@intel.com \
--cc=hongyu.ning@linux.intel.com \
--cc=hpa@zytor.com \
--cc=kai.huang@intel.com \
--cc=kas@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-coco@lists.linux.dev \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=nik.borisov@suse.com \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=sohil.mehta@intel.com \
--cc=tglx@kernel.org \
--cc=tony.lindgren@linux.intel.com \
--cc=vannapurve@google.com \
--cc=x86@kernel.org \
--cc=yan.y.zhao@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox