[PATCH v4 03/10] x86/virt/tdx: Convert the features metadata reader

From: Chao Gao

Date: Mon Oct 12 2026 - 05:51:47 EST


Continue converting the metadata readers to the table-driven helper.

Add a table that pairs each field ID with the 'struct
tdx_sys_info_features' member that holds its value, and read all fields by
walking that table.

Even though the structure has only one field, add a table anyway for
symmetry with the other classes. Adding a field later then becomes a
one-line change.

Annotate the table as __initconst as it is referenced only during init.

AI was used under supervision to review code and workshop logs.

Signed-off-by: Chao Gao <chao.gao@xxxxxxxxx>
Reviewed-by: Rick Edgecombe <rick.p.edgecombe@xxxxxxxxx>
---
v4:
- Collect tags [Rick]
- Drop per-class macros [Nikolay, Dave]
- Rename feature_mappings to features_mappings to match
struct tdx_sys_info_features [LLM]
---
arch/x86/virt/vmx/tdx/tdx.c | 4 ++++
arch/x86/virt/vmx/tdx/tdx.h | 3 +++
arch/x86/virt/vmx/tdx/tdx_global_metadata.c | 13 +------------
3 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c
index 3b7d13a1aa32..9f17c52c026a 100644
--- a/arch/x86/virt/vmx/tdx/tdx.c
+++ b/arch/x86/virt/vmx/tdx/tdx.c
@@ -443,6 +443,10 @@ static const struct field_mapping version_mappings[] = {
FIELD_MAP(TDX_FIELD_UPDATE_VERSION, version, update_version),
};

+static const struct field_mapping features_mappings[] __initconst = {
+ FIELD_MAP(TDX_FIELD_TDX_FEATURES0, features, tdx_features0),
+};
+
#include "tdx_global_metadata.c"

static __init int check_features(struct tdx_sys_info *sysinfo)
diff --git a/arch/x86/virt/vmx/tdx/tdx.h b/arch/x86/virt/vmx/tdx/tdx.h
index 10cbc2d77a5a..87e055a2546c 100644
--- a/arch/x86/virt/vmx/tdx/tdx.h
+++ b/arch/x86/virt/vmx/tdx/tdx.h
@@ -62,6 +62,9 @@
#define TDX_FIELD_MAJOR_VERSION 0x0800000100000004ULL
#define TDX_FIELD_UPDATE_VERSION 0x0800000100000005ULL

+/* Class "TDX Module Info" */
+#define TDX_FIELD_TDX_FEATURES0 0x0A00000300000008ULL
+
/* TDX page types */
#define PT_NDA 0x0
#define PT_RSVD 0x1
diff --git a/arch/x86/virt/vmx/tdx/tdx_global_metadata.c b/arch/x86/virt/vmx/tdx/tdx_global_metadata.c
index c55674cd4ce6..62c24dda0ca9 100644
--- a/arch/x86/virt/vmx/tdx/tdx_global_metadata.c
+++ b/arch/x86/virt/vmx/tdx/tdx_global_metadata.c
@@ -7,17 +7,6 @@
* Include this file to other C file instead.
*/

-static __init int get_tdx_sys_info_features(struct tdx_sys_info_features *sysinfo_features)
-{
- int ret = 0;
- u64 val;
-
- if (!ret && !(ret = read_sys_metadata_field(0x0A00000300000008, &val)))
- sysinfo_features->tdx_features0 = val;
-
- return ret;
-}
-
static __init int get_tdx_sys_info_tdmr_dpamt(struct tdx_sys_info_tdmr *sysinfo_tdmr)
{
int ret;
@@ -121,7 +110,7 @@ static __init int get_tdx_sys_info(struct tdx_sys_info *sysinfo)
sysinfo->version.minor_version,
sysinfo->version.update_version);

- ret = ret ?: get_tdx_sys_info_features(&sysinfo->features);
+ ret = ret ?: read_sys_metadata_table(features_mappings, &sysinfo->features);
ret = ret ?: get_tdx_sys_info_tdmr(&sysinfo->tdmr);
ret = ret ?: get_tdx_sys_info_td_ctrl(&sysinfo->td_ctrl);
ret = ret ?: get_tdx_sys_info_td_conf(&sysinfo->td_conf);
--
2.52.0