[PATCH 07/30] x86/virt/tdx: allocate tdx_sys_info in static memory

Paolo Bonzini posted 30 patches 9 months, 4 weeks ago
There is a newer version of this series
[PATCH 07/30] x86/virt/tdx: allocate tdx_sys_info in static memory
Posted by Paolo Bonzini 9 months, 4 weeks ago
Adding all the information that KVM needs increases the size of struct
tdx_sys_info, to the point that you can get warnings about the stack
size of init_tdx_module().  Since KVM also needs to read the TDX metadata
after init_tdx_module() returns, make the variable a global.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 arch/x86/virt/vmx/tdx/tdx.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c
index 369b264f4d9b..578ad468634b 100644
--- a/arch/x86/virt/vmx/tdx/tdx.c
+++ b/arch/x86/virt/vmx/tdx/tdx.c
@@ -53,6 +53,8 @@ static DEFINE_MUTEX(tdx_module_lock);
 /* All TDX-usable memory regions.  Protected by mem_hotplug_lock. */
 static LIST_HEAD(tdx_memlist);
 
+static struct tdx_sys_info tdx_sysinfo;
+
 typedef void (*sc_err_func_t)(u64 fn, u64 err, struct tdx_module_args *args);
 
 static inline void seamcall_err(u64 fn, u64 err, struct tdx_module_args *args)
@@ -1061,15 +1063,14 @@ static int init_tdmrs(struct tdmr_info_list *tdmr_list)
 
 static int init_tdx_module(void)
 {
-	struct tdx_sys_info sysinfo;
 	int ret;
 
-	ret = get_tdx_sys_info(&sysinfo);
+	ret = get_tdx_sys_info(&tdx_sysinfo);
 	if (ret)
 		return ret;
 
 	/* Check whether the kernel can support this module */
-	ret = check_features(&sysinfo);
+	ret = check_features(&tdx_sysinfo);
 	if (ret)
 		return ret;
 
@@ -1090,12 +1091,12 @@ static int init_tdx_module(void)
 		goto out_put_tdxmem;
 
 	/* Allocate enough space for constructing TDMRs */
-	ret = alloc_tdmr_list(&tdx_tdmr_list, &sysinfo.tdmr);
+	ret = alloc_tdmr_list(&tdx_tdmr_list, &tdx_sysinfo.tdmr);
 	if (ret)
 		goto err_free_tdxmem;
 
 	/* Cover all TDX-usable memory regions in TDMRs */
-	ret = construct_tdmrs(&tdx_memlist, &tdx_tdmr_list, &sysinfo.tdmr);
+	ret = construct_tdmrs(&tdx_memlist, &tdx_tdmr_list, &tdx_sysinfo.tdmr);
 	if (ret)
 		goto err_free_tdmrs;
 
-- 
2.43.5
Re: [PATCH 07/30] x86/virt/tdx: allocate tdx_sys_info in static memory
Posted by Edgecombe, Rick P 9 months, 4 weeks ago
On Thu, 2025-02-20 at 12:05 -0500, Paolo Bonzini wrote:
> Adding all the information that KVM needs increases the size of struct
> tdx_sys_info, to the point that you can get warnings about the stack
> size of init_tdx_module().  Since KVM also needs to read the TDX metadata
> after init_tdx_module() returns, make the variable a global.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

It looks like the same code just lifted and moved earlier out of the already
acked patch.

Reviewed-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
Re: [PATCH 07/30] x86/virt/tdx: allocate tdx_sys_info in static memory
Posted by Huang, Kai 9 months, 4 weeks ago
On Thu, 2025-02-20 at 12:05 -0500, Paolo Bonzini wrote:
> Adding all the information that KVM needs increases the size of struct
> tdx_sys_info, to the point that you can get warnings about the stack
> size of init_tdx_module().  Since KVM also needs to read the TDX metadata
> after init_tdx_module() returns, make the variable a global.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> 

Reviewed-by: Kai Huang <kai.huang@intel.com>