TD-Preserving doesn't need to re-configure the global HKID, TDMRs or PAMTs. The new module can import the handoff data created by the old module to establish all necessary contexts. The TDH.SYS.UPDATE API is introduced for the import process Once the import is done, the module update is complete, and the new module is ready to handle requests from the VMM and guests. Signed-off-by: Chao Gao <chao.gao@xxxxxxxxx> Tested-by: Farrah Chen <farrah.chen@xxxxxxxxx> --- arch/x86/virt/vmx/tdx/seamldr.c | 7 +++++++ arch/x86/virt/vmx/tdx/tdx.c | 16 ++++++++++++++++ arch/x86/virt/vmx/tdx/tdx.h | 2 ++ 3 files changed, 25 insertions(+) diff --git a/arch/x86/virt/vmx/tdx/seamldr.c b/arch/x86/virt/vmx/tdx/seamldr.c index c4e1b7540a43..168fd2afd0c9 100644 --- a/arch/x86/virt/vmx/tdx/seamldr.c +++ b/arch/x86/virt/vmx/tdx/seamldr.c @@ -246,6 +246,7 @@ enum tdp_state { TDP_SHUTDOWN, TDP_CPU_INSTALL, TDP_CPU_INIT, + TDP_RUN_UPDATE, TDP_DONE, }; @@ -322,6 +323,12 @@ static int do_seamldr_install_module(void *params) case TDP_CPU_INIT: ret = tdx_cpu_enable(); break; + case TDP_RUN_UPDATE: + if (!primary) + break; + + ret = tdx_module_run_update(); + break; default: break; } diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c index 331c86eeddcf..5f678c9da4ee 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -1390,6 +1390,22 @@ void tdx_module_set_error(void) tdx_module_status = TDX_MODULE_ERROR; } +int tdx_module_run_update(void) +{ + struct tdx_module_args args = {}; + int ret; + + ret = seamcall(TDH_SYS_UPDATE, &args); + if (ret) { + tdx_module_status = TDX_MODULE_ERROR; + pr_info("module update failed: %d\n", ret); + return ret; + } + + tdx_module_status = TDX_MODULE_INITIALIZED; + return ret; +} + static bool is_pamt_page(unsigned long phys) { struct tdmr_info_list *tdmr_list = &tdx_tdmr_list; diff --git a/arch/x86/virt/vmx/tdx/tdx.h b/arch/x86/virt/vmx/tdx/tdx.h index ed3d74c991f6..a05e3c21e7f5 100644 --- a/arch/x86/virt/vmx/tdx/tdx.h +++ b/arch/x86/virt/vmx/tdx/tdx.h @@ -49,6 +49,7 @@ #define TDH_VP_WR 43 #define TDH_SYS_CONFIG 45 #define TDH_SYS_SHUTDOWN 52 +#define TDH_SYS_UPDATE 53 /* * SEAMCALL leaf: @@ -126,5 +127,6 @@ int seamldr_prerr(u64 fn, struct tdx_module_args *args); int tdx_module_shutdown(void); void tdx_module_set_error(void); +int tdx_module_run_update(void); #endif -- 2.47.1