From: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
dave.hansen@intel.com, luto@kernel.org, peterz@infradead.org
Cc: sathyanarayanan.kuppuswamy@linux.intel.com, ak@linux.intel.com,
dan.j.williams@intel.com, david@redhat.com, hpa@zytor.com,
seanjc@google.com, thomas.lendacky@amd.com,
elena.reshetova@intel.com, x86@kernel.org,
linux-kernel@vger.kernel.org,
"Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>
Subject: [PATCH 1/2] x86/tdx: Extract GET_INFO call from get_cc_mask()
Date: Fri, 28 Oct 2022 17:12:19 +0300 [thread overview]
Message-ID: <20221028141220.29217-2-kirill.shutemov@linux.intel.com> (raw)
In-Reply-To: <20221028141220.29217-1-kirill.shutemov@linux.intel.com>
From: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
TDCALL [TDG.VP.INFO] is used to get details like gpa_width,
TD attributes, etc.
So far only gpa_width was needed to enumerate the shared bit, but
upcoming changes will need TD attributes too.
Extract GET_INFO call out of get_cc_mask() into a separate helper and
save attributes.
Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
---
arch/x86/coco/tdx/tdx.c | 25 ++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)
diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c
index 928dcf7a20d9..343d60853b71 100644
--- a/arch/x86/coco/tdx/tdx.c
+++ b/arch/x86/coco/tdx/tdx.c
@@ -34,6 +34,12 @@
#define VE_GET_PORT_NUM(e) ((e) >> 16)
#define VE_IS_IO_STRING(e) ((e) & BIT(4))
+/* Caches GPA width from TDG.VP.INFO TDCALL */
+static unsigned int gpa_width __ro_after_init;
+
+/* Caches TD Attributes from TDG.VP.INFO TDCALL */
+static u64 td_attr __ro_after_init;
+
/*
* Wrapper for standard use of __tdx_hypercall with no output aside from
* return code.
@@ -98,17 +104,16 @@ 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 u64 get_cc_mask(void)
+static void tdx_parse_tdinfo(void)
{
struct tdx_module_output out;
- unsigned int gpa_width;
/*
* 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].
+ * information, TD attributes etc. More details about the ABI can be
+ * found in TDX Guest-Host-Communication Interface (GHCI), section
+ * 2.4.2 TDCALL [TDG.VP.INFO].
*
* The GPA width that comes out of this call is critical. TDX guests
* can not meaningfully run without it.
@@ -116,7 +121,11 @@ static u64 get_cc_mask(void)
tdx_module_call(TDX_GET_INFO, 0, 0, 0, 0, &out);
gpa_width = out.rcx & GENMASK(5, 0);
+ td_attr = out.rdx;
+}
+static u64 get_cc_mask(void)
+{
/*
* The highest bit of a guest physical address is the "sharing" bit.
* Set it for shared pages and clear it for private pages.
@@ -755,6 +764,12 @@ void __init tdx_early_init(void)
if (memcmp(TDX_IDENT, sig, sizeof(sig)))
return;
+ /*
+ * Initializes gpa_width and td_attr. Must be called before
+ * get_cc_mask() or attribute checks.
+ */
+ tdx_parse_tdinfo();
+
setup_force_cpu_cap(X86_FEATURE_TDX_GUEST);
cc_set_vendor(CC_VENDOR_INTEL);
--
2.38.0
next prev parent reply other threads:[~2022-10-28 14:12 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-28 14:12 [PATCH 0/2] x86/tdx: Enforce no #VE on private memory accesses Kirill A. Shutemov
2022-10-28 14:12 ` Kirill A. Shutemov [this message]
2022-10-28 15:43 ` [PATCH 1/2] x86/tdx: Extract GET_INFO call from get_cc_mask() Dave Hansen
2022-10-28 23:27 ` Dave Hansen
2022-10-28 23:59 ` Kirill A. Shutemov
2022-10-31 4:12 ` Kirill A. Shutemov
2022-10-31 16:42 ` Dave Hansen
2022-10-31 19:19 ` Kirill A. Shutemov
2022-10-31 19:27 ` Andi Kleen
2022-10-31 19:44 ` Dave Hansen
2022-10-31 22:10 ` Kirill A. Shutemov
2022-10-28 14:12 ` [PATCH 2/2] x86/tdx: Do not allow #VE due to EPT violation on the private memory Kirill A. Shutemov
2022-10-28 15:41 ` Dave Hansen
2022-10-31 4:07 ` Guorui Yu
2022-10-31 4:33 ` Kirill A. Shutemov
2022-10-31 14:22 ` Dave Hansen
2022-11-04 22:36 ` Erdem Aktas
2022-11-04 22:50 ` Dave Hansen
2022-11-07 22:53 ` Erdem Aktas
2022-11-07 23:30 ` Dave Hansen
2022-11-07 5:10 ` Guorui Yu
2022-11-07 13:31 ` Dave Hansen
2022-11-07 13:43 ` Guorui Yu
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=20221028141220.29217-2-kirill.shutemov@linux.intel.com \
--to=kirill.shutemov@linux.intel.com \
--cc=ak@linux.intel.com \
--cc=bp@alien8.de \
--cc=dan.j.williams@intel.com \
--cc=dave.hansen@intel.com \
--cc=david@redhat.com \
--cc=elena.reshetova@intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=sathyanarayanan.kuppuswamy@linux.intel.com \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=thomas.lendacky@amd.com \
--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;
as well as URLs for NNTP newsgroup(s).