[PATCH 2/6] x86/virt/tdx: Move read_sys_metadata_field() to where it is called

From: Xu Yilun
Date: Tue Dec 02 2025 - 00:25:12 EST


Moving read_sys_metadata_field() to tdx_global_metadata.c marks the end
of auto-generating global metadata parsing code. The source of the
auto-generation, the JSON file, is not stable and not authoritative
enough. Switch back to manual editing and improve code readability.

The only possible usage of read_sys_metadata_field() is to cache all
global metadata in system memory on TDX Module initialization. Moving it
alongside other metadata reading code improves readability.

Take the opportunity to remove any description for auto-generation.

Signed-off-by: Xu Yilun <yilun.xu@xxxxxxxxxxxxxxx>
---
arch/x86/include/asm/tdx_global_metadata.h | 6 +++---
arch/x86/virt/vmx/tdx/tdx.c | 20 -------------------
arch/x86/virt/vmx/tdx/tdx_global_metadata.c | 22 ++++++++++++++++++++-
3 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/arch/x86/include/asm/tdx_global_metadata.h b/arch/x86/include/asm/tdx_global_metadata.h
index 060a2ad744bf..b44f1df013b2 100644
--- a/arch/x86/include/asm/tdx_global_metadata.h
+++ b/arch/x86/include/asm/tdx_global_metadata.h
@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0 */
-/* Automatically generated TDX global metadata structures. */
-#ifndef _X86_VIRT_TDX_AUTO_GENERATED_TDX_GLOBAL_METADATA_H
-#define _X86_VIRT_TDX_AUTO_GENERATED_TDX_GLOBAL_METADATA_H
+/* TDX global metadata structures. */
+#ifndef _X86_VIRT_TDX_GLOBAL_METADATA_H
+#define _X86_VIRT_TDX_GLOBAL_METADATA_H

#include <linux/types.h>

diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c
index eac403248462..0d7f9bdac8a4 100644
--- a/arch/x86/virt/vmx/tdx/tdx.c
+++ b/arch/x86/virt/vmx/tdx/tdx.c
@@ -257,26 +257,6 @@ static int build_tdx_memlist(struct list_head *tmb_list)
return ret;
}

-static int read_sys_metadata_field(u64 field_id, u64 *data)
-{
- struct tdx_module_args args = {};
- int ret;
-
- /*
- * TDH.SYS.RD -- reads one global metadata field
- * - RDX (in): the field to read
- * - R8 (out): the field data
- */
- args.rdx = field_id;
- ret = seamcall_prerr_ret(TDH_SYS_RD, &args);
- if (ret)
- return ret;
-
- *data = args.r8;
-
- return 0;
-}
-
#include "tdx_global_metadata.c"

static int check_features(struct tdx_sys_info *sysinfo)
diff --git a/arch/x86/virt/vmx/tdx/tdx_global_metadata.c b/arch/x86/virt/vmx/tdx/tdx_global_metadata.c
index 13ad2663488b..0dfb3a9995fe 100644
--- a/arch/x86/virt/vmx/tdx/tdx_global_metadata.c
+++ b/arch/x86/virt/vmx/tdx/tdx_global_metadata.c
@@ -1,12 +1,32 @@
// SPDX-License-Identifier: GPL-2.0
/*
- * Automatically generated functions to read TDX global metadata.
+ * Functions to read TDX global metadata.
*
* This file doesn't compile on its own as it lacks of inclusion
* of SEAMCALL wrapper primitive which reads global metadata.
* Include this file to other C file instead.
*/

+static int read_sys_metadata_field(u64 field_id, u64 *data)
+{
+ struct tdx_module_args args = {};
+ int ret;
+
+ /*
+ * TDH.SYS.RD -- reads one global metadata field
+ * - RDX (in): the field to read
+ * - R8 (out): the field data
+ */
+ args.rdx = field_id;
+ ret = seamcall_prerr_ret(TDH_SYS_RD, &args);
+ if (ret)
+ return ret;
+
+ *data = args.r8;
+
+ return 0;
+}
+
static int get_tdx_sys_info_features(struct tdx_sys_info_features *sysinfo_features)
{
int ret = 0;
--
2.25.1