After providing all required memory to TDX Module, initialize TDX Module Extensions via TDH.EXT.INIT, so Extension-SEAMCALLs can be used. Co-developed-by: Zhenzhong Duan Signed-off-by: Zhenzhong Duan Signed-off-by: Xu Yilun --- arch/x86/virt/vmx/tdx/tdx.h | 1 + arch/x86/virt/vmx/tdx/tdx.c | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/arch/x86/virt/vmx/tdx/tdx.h b/arch/x86/virt/vmx/tdx/tdx.h index 2335f88bbb10..c5bffd118145 100644 --- a/arch/x86/virt/vmx/tdx/tdx.h +++ b/arch/x86/virt/vmx/tdx/tdx.h @@ -46,6 +46,7 @@ #define TDH_PHYMEM_PAGE_WBINVD 41 #define TDH_VP_WR 43 #define TDH_SYS_CONFIG 45 +#define TDH_EXT_INIT 60 #define TDH_EXT_MEM_ADD 61 #define TDH_SYS_DISABLE 69 diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c index 622399d8da68..ff2b96c20d2b 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -1200,6 +1200,22 @@ static u64 to_hpa_list_info(struct page *root, unsigned int nr_pages) FIELD_PREP(HPA_LIST_INFO_LAST_ENTRY, nr_pages - 1); } +/* Initialize the TDX Module Extensions then Extension-SEAMCALLs can be used */ +static int tdx_ext_init(void) +{ + struct tdx_module_args args = {}; + u64 r; + + do { + r = seamcall(TDH_EXT_INIT, &args); + } while (r == TDX_INTERRUPTED_RESUMABLE); + + if (r != TDX_SUCCESS) + return -EFAULT; + + return 0; +} + static int tdx_ext_mem_add(struct page *root, unsigned int nr_pages) { struct tdx_module_args args = { @@ -1287,6 +1303,8 @@ static int tdx_ext_mem_setup(void) static int __maybe_unused init_tdx_ext(void) { + int ret; + if (!(tdx_sysinfo.features.tdx_features0 & TDX_FEATURES0_EXT)) return 0; @@ -1294,7 +1312,11 @@ static int __maybe_unused init_tdx_ext(void) if (!tdx_sysinfo.ext.ext_required) return 0; - return tdx_ext_mem_setup(); + ret = tdx_ext_mem_setup(); + if (ret) + return ret; + + return tdx_ext_init(); } static __init int init_tdx_module(void) -- 2.25.1