[PATCH 16/20] x86/tdx: Convert VP_INFO tdcall to use new TDCALL_5() macro

Kirill A. Shutemov posted 20 patches 1 year, 8 months ago
[PATCH 16/20] x86/tdx: Convert VP_INFO tdcall to use new TDCALL_5() macro
Posted by Kirill A. Shutemov 1 year, 8 months ago
Use newly introduced TDCALL_5() instead of tdcall() to issue VP_INFO
tdcall.

It cuts code bloat slightly:

Function                                     old     new   delta
tdx_early_init                               780     744     -36

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
---
 arch/x86/coco/tdx/tdx.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c
index e7ffe1cd6d32..e1849878f3bc 100644
--- a/arch/x86/coco/tdx/tdx.c
+++ b/arch/x86/coco/tdx/tdx.c
@@ -247,20 +247,22 @@ static void enable_cpu_topology_enumeration(void)
 	tdg_vm_wr(TDCS_TD_CTLS, TD_CTLS_ENUM_TOPOLOGY, TD_CTLS_ENUM_TOPOLOGY);
 }
 
+static void tdg_vp_info(u64 *gpa_width, u64 *attributes)
+{
+	u64 dummy, ret;
+
+	ret = TDCALL_5(TDG_VP_INFO, 0, 0, 0, 0, *gpa_width, *attributes, dummy,
+		       dummy, dummy);
+	BUG_ON(ret);
+
+	*gpa_width &= GENMASK(5, 0);
+}
+
 static void tdx_setup(u64 *cc_mask)
 {
-	struct tdx_module_args args = {};
-	unsigned int gpa_width;
-	u64 td_attr;
+	u64 gpa_width, td_attr;
 
-	/*
-	 * TDINFO TDX module call is used to get the TD execution environment
-	 * information like GPA width, number of available vcpus, debug mode
-	 * information, etc. More details about the ABI can be found in TDX
-	 * Guest-Host-Communication Interface (GHCI), section 2.4.2 TDCALL
-	 * [TDG.VP.INFO].
-	 */
-	tdcall(TDG_VP_INFO, &args);
+	tdg_vp_info(&gpa_width, &td_attr);
 
 	/*
 	 * The highest bit of a guest physical address is the "sharing" bit.
@@ -269,11 +271,8 @@ static void tdx_setup(u64 *cc_mask)
 	 * The GPA width that comes out of this call is critical. TDX guests
 	 * can not meaningfully run without it.
 	 */
-	gpa_width = args.rcx & GENMASK(5, 0);
 	*cc_mask = BIT_ULL(gpa_width - 1);
 
-	td_attr = args.rdx;
-
 	/* Kernel does not use NOTIFY_ENABLES and does not need random #VEs */
 	tdg_vm_wr(TDCS_NOTIFY_ENABLES, 0, -1ULL);
 
-- 
2.43.0
Re: [PATCH 16/20] x86/tdx: Convert VP_INFO tdcall to use new TDCALL_5() macro
Posted by Dave Hansen 1 year, 8 months ago
On 5/17/24 07:19, Kirill A. Shutemov wrote:
> -	/*
> -	 * TDINFO TDX module call is used to get the TD execution environment
> -	 * information like GPA width, number of available vcpus, debug mode
> -	 * information, etc. More details about the ABI can be found in TDX
> -	 * Guest-Host-Communication Interface (GHCI), section 2.4.2 TDCALL
> -	 * [TDG.VP.INFO].
> -	 */
> -	tdcall(TDG_VP_INFO, &args);
> +	tdg_vp_info(&gpa_width, &td_attr);

Why is the comment going away?
Re: [PATCH 16/20] x86/tdx: Convert VP_INFO tdcall to use new TDCALL_5() macro
Posted by Kirill A. Shutemov 1 year, 8 months ago
On Fri, May 17, 2024 at 08:57:10AM -0700, Dave Hansen wrote:
> On 5/17/24 07:19, Kirill A. Shutemov wrote:
> > -	/*
> > -	 * TDINFO TDX module call is used to get the TD execution environment
> > -	 * information like GPA width, number of available vcpus, debug mode
> > -	 * information, etc. More details about the ABI can be found in TDX
> > -	 * Guest-Host-Communication Interface (GHCI), section 2.4.2 TDCALL
> > -	 * [TDG.VP.INFO].
> > -	 */
> > -	tdcall(TDG_VP_INFO, &args);
> > +	tdg_vp_info(&gpa_width, &td_attr);
> 
> Why is the comment going away?

By mistake. Will fix.

-- 
  Kiryl Shutsemau / Kirill A. Shutemov