[PATCH v9 06/18] x86/virt/tdx: Do TDX module global initialization
From: Kai Huang
Date: Mon Feb 13 2023 - 07:01:43 EST
Start to transit out the "multi-steps" of initializing the TDX module as
listed in the skeleton infrastructure. Do the first step to do module
global initialization, which is one SEAMCALL on any logical cpu.
Signed-off-by: Kai Huang <kai.huang@xxxxxxxxx>
Reviewed-by: Isaku Yamahata <isaku.yamahata@xxxxxxxxx>
---
v8 -> v9:
- Added this patch back.
---
arch/x86/virt/vmx/tdx/tdx.c | 11 ++++++++++-
arch/x86/virt/vmx/tdx/tdx.h | 12 ++++++++++++
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c
index 5ae3d71b70b4..79cee28c51b5 100644
--- a/arch/x86/virt/vmx/tdx/tdx.c
+++ b/arch/x86/virt/vmx/tdx/tdx.c
@@ -172,10 +172,19 @@ static int __always_unused seamcall(u64 fn, u64 rcx, u64 rdx, u64 r8, u64 r9,
static int init_tdx_module(void)
{
+ int ret;
+
+ /*
+ * TDX module global initialization. All '0's are just
+ * unused parameters.
+ */
+ ret = seamcall(TDH_SYS_INIT, 0, 0, 0, 0, NULL, NULL);
+ if (ret)
+ return ret;
+
/*
* TODO:
*
- * - TDX module global initialization.
* - TDX module per-cpu initialization.
* - Get TDX module information and TDX-capable memory regions.
* - Build the list of TDX-usable memory regions.
diff --git a/arch/x86/virt/vmx/tdx/tdx.h b/arch/x86/virt/vmx/tdx/tdx.h
index 931a50f0f44c..55472e085bc8 100644
--- a/arch/x86/virt/vmx/tdx/tdx.h
+++ b/arch/x86/virt/vmx/tdx/tdx.h
@@ -4,6 +4,18 @@
#include <linux/types.h>
+/*
+ * This file contains both macros and data structures defined by the TDX
+ * architecture and Linux defined software data structures and functions.
+ * The two should not be mixed together for better readability. The
+ * architectural definitions come first.
+ */
+
+ /*
+ * TDX module SEAMCALL leaf functions
+ */
+#define TDH_SYS_INIT 33
+
/* Kernel defined TDX module status during module initialization. */
enum tdx_module_status_t {
TDX_MODULE_UNKNOWN,
--
2.39.1