TDX module state was packed as handoff data during module shutdown. After per-CPU initialization, the new module can restore TDX module state from handoff data to preserve running TDs. Once the restoration is done, the TDX module update is complete, which means the new module is ready to handle requests from the host and guests. Implement the new TDH.SYS.UPDATE SEAMCALL to restore TDX module state and invoke it on one CPU since it only needs to be called once. Note that IntelĀ® Trust Domain Extensions (IntelĀ® TDX) Module Base Architecture Specification, Revision 348549-007, Chapter 4.5.5 states: If TDH.SYS.UPDATE returns an error, then the host VMM can continue with the non-update sequence (TDH.SYS.CONFIG, 15 TDH.SYS.KEY.CONFIG etc.). In this case all existing TDs are lost. Alternatively, the host VMM can request the P-SEAMLDR to update to another TDX module. If that update is successful, existing TDs are preserved Don't implement the two alternatives due to their complexity and unclear benefits. Also note that the location and the format of handoff data is defined by the TDX module. The new module knows where to get handoff data and how to parse it. The kernel doesn't need to provide its location, format etc. Signed-off-by: Chao Gao Reviewed-by: Tony Lindgren Reviewed-by: Kai Huang --- v5: - Massage changelog [Kai] v3: - use seamcall_prerr() rather than raw seamcall() [Binbin] - use pr_err() to print error message [Binbin] --- arch/x86/virt/vmx/tdx/seamldr.c | 5 +++++ arch/x86/virt/vmx/tdx/tdx.c | 16 ++++++++++++++++ arch/x86/virt/vmx/tdx/tdx.h | 2 ++ 3 files changed, 23 insertions(+) diff --git a/arch/x86/virt/vmx/tdx/seamldr.c b/arch/x86/virt/vmx/tdx/seamldr.c index 4d8c96d82c05..806edf50a952 100644 --- a/arch/x86/virt/vmx/tdx/seamldr.c +++ b/arch/x86/virt/vmx/tdx/seamldr.c @@ -189,6 +189,7 @@ enum module_update_state { MODULE_UPDATE_SHUTDOWN, MODULE_UPDATE_CPU_INSTALL, MODULE_UPDATE_CPU_INIT, + MODULE_UPDATE_RUN_UPDATE, MODULE_UPDATE_DONE, }; @@ -254,6 +255,10 @@ static int do_seamldr_install_module(void *seamldr_params) case MODULE_UPDATE_CPU_INIT: ret = tdx_cpu_enable(); break; + case MODULE_UPDATE_RUN_UPDATE: + if (primary) + 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 cfe76d4ca570..9f137d15553f 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -1207,6 +1207,22 @@ int tdx_module_shutdown(void) return 0; } +int tdx_module_run_update(void) +{ + struct tdx_module_args args = {}; + int ret; + + ret = seamcall_prerr(TDH_SYS_UPDATE, &args); + if (ret) { + pr_err("update failed (%d)\n", ret); + tdx_module_status = TDX_MODULE_ERROR; + return ret; + } + + tdx_module_status = TDX_MODULE_INITIALIZED; + return 0; +} + 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 1c4da9540ae0..c62874b87d7a 100644 --- a/arch/x86/virt/vmx/tdx/tdx.h +++ b/arch/x86/virt/vmx/tdx/tdx.h @@ -47,6 +47,7 @@ #define TDH_VP_WR 43 #define TDH_SYS_CONFIG 45 #define TDH_SYS_SHUTDOWN 52 +#define TDH_SYS_UPDATE 53 /* * SEAMCALL leaf: @@ -120,5 +121,6 @@ struct tdmr_info_list { }; int tdx_module_shutdown(void); +int tdx_module_run_update(void); #endif -- 2.47.3