Re: [tip: x86/urgent] x86/tdx: Prepare for using "INFO" call for a second purpose

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11/6/22 11:50, Borislav Petkov wrote:
> On Sun, Nov 06, 2022 at 09:02:27AM -0800, Dave Hansen wrote:
>> It's fine for now, except that the naming on this:
>>
>> -	tdx_parse_tdinfo(&cc_mask);
>> +	cc_mask = tdx_parse_tdinfo();
>>
>> is a bit funky since tdx_parse_tdinfo() is doing a couple of things
> Yeah, that was the next thing that was bothering me.
> 
>> and will need to return a second item shortly.
> Well, then rename this one back to get_cc_mask() and have a new function
> return the second item?

That's doable.  It would look something like what I've attached for now.
 The only downside to this is making two tdx_module_call(TDX_GET_INFO...)
calls.  That seems a bit wasteful, but it's not the end of the world.
It would look something like the attached patch.

I kinda like the idea of making one tdx_module_call() and parsing it all
in one place.  The calls are kinda slow, but two of them versus one
isn't going to hurt anybody.

The other thing I considered was keeping a temporary 'struct
tdx_guest_info' structure or something, filling it one, and parsing it
in get_cc_mask() and attribute checking functions.  But, that seemed
like overkill.
diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c
index b8998cf0508a..a4bf2b67d3d7 100644
--- a/arch/x86/coco/tdx/tdx.c
+++ b/arch/x86/coco/tdx/tdx.c
@@ -13,7 +13,7 @@
 #include <asm/pgtable.h>
 
 /* TDX module Call Leaf IDs */
-#define TDX_GET_INFO			1
+#define TDX_GET_INFO			1 /* TDG.VP.INFO */
 #define TDX_GET_VEINFO			3
 #define TDX_ACCEPT_PAGE			6
 
@@ -100,19 +100,10 @@ static inline void tdx_module_call(u64 fn, u64 rcx, u64 rdx, u64 r8, u64 r9,
 		panic("TDCALL %lld failed (Buggy TDX module!)\n", fn);
 }
 
-static void tdx_parse_tdinfo(u64 *cc_mask)
+static u64 get_cc_mask(void)
 {
 	struct tdx_module_output out;
-	unsigned int gpa_width;
-	u64 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].
-	 */
 	tdx_module_call(TDX_GET_INFO, 0, 0, 0, 0, &out);
 
 	/*
@@ -123,7 +114,15 @@ static void tdx_parse_tdinfo(u64 *cc_mask)
 	 * can not meaningfully run without it.
 	 */
 	gpa_width = out.rcx & GENMASK(5, 0);
-	*cc_mask = BIT_ULL(gpa_width - 1);
+	return  BIT_ULL(gpa_width - 1);
+}
+
+static void tdx_check_tdinfo(void)
+{
+	struct tdx_module_output out;
+	u64 td_attr;
+
+	tdx_module_call(TDX_GET_INFO, 0, 0, 0, 0, &out);
 
 	/*
 	 * The kernel can not handle #VE's when accessing normal kernel
@@ -769,7 +768,8 @@ void __init tdx_early_init(void)
 	setup_force_cpu_cap(X86_FEATURE_TDX_GUEST);
 
 	cc_set_vendor(CC_VENDOR_INTEL);
-	tdx_parse_tdinfo(&cc_mask);
+	tdx_check_tdinfo();
+	cc_mask = get_cc_mask();
 	cc_set_mask(cc_mask);
 
 	/*

[Index of Archives]     [Linux Stable Commits]     [Linux Stable Kernel]     [Linux Kernel]     [Linux USB Devel]     [Linux Video &Media]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux