From: Dave Hansen <dave.hansen@intel.com>
To: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>,
linux-kernel@vger.kernel.org, linux-tip-commits@vger.kernel.org,
"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
x86@kernel.org
Subject: Re: [tip: x86/urgent] x86/tdx: Prepare for using "INFO" call for a second purpose
Date: Mon, 7 Nov 2022 05:26:27 -0800 [thread overview]
Message-ID: <2145ca92-66f2-4411-7847-618a885c203b@intel.com> (raw)
In-Reply-To: <Y2gP+AT1XdapImV4@zn.tnic>
[-- Attachment #1: Type: text/plain, Size: 1166 bytes --]
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.
[-- Attachment #2: tdinfo.patch --]
[-- Type: text/x-patch, Size: 1739 bytes --]
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);
/*
prev parent reply other threads:[~2022-11-07 13:26 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-01 23:25 tip-bot2 for Dave Hansen
2022-11-06 12:45 ` Borislav Petkov
2022-11-06 17:02 ` Dave Hansen
2022-11-06 19:50 ` Borislav Petkov
2022-11-07 13:26 ` Dave Hansen [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2145ca92-66f2-4411-7847-618a885c203b@intel.com \
--to=dave.hansen@intel.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®