From: Kai Huang <kai.huang@intel.com>
To: dave.hansen@intel.com, kirill.shutemov@linux.intel.com,
tglx@linutronix.de, bp@alien8.de, peterz@infradead.org,
mingo@redhat.com, hpa@zytor.com, dan.j.williams@intel.com,
seanjc@google.com, pbonzini@redhat.com
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
rick.p.edgecombe@intel.com, isaku.yamahata@intel.com,
adrian.hunter@intel.com, nik.borisov@suse.com,
kai.huang@intel.com
Subject: [PATCH v8 9/9] x86/virt/tdx: Require the module to assert it has the NO_RBP_MOD mitigation
Date: Thu, 14 Nov 2024 00:57:14 +1300 [thread overview]
Message-ID: <2ce15d25ae52411f15742a4b13a8b68a1f5484cd.1731498635.git.kai.huang@intel.com> (raw)
In-Reply-To: <cover.1731498635.git.kai.huang@intel.com>
Old TDX modules can clobber RBP in the TDH.VP.ENTER SEAMCALL. However
RBP is used as frame pointer in the x86_64 calling convention, and
clobbering RBP could result in bad things like being unable to unwind
the stack if any non-maskable exceptions (NMI, #MC etc) happens in that
gap.
A new "NO_RBP_MOD" feature was introduced to more recent TDX modules to
not clobber RBP. This feature is reported in the TDX_FEATURES0 global
metadata field via bit 18.
Don't initialize the TDX module if this feature is not supported [1].
Note the bit definitions of TDX_FEATURES0 are not auto-generated in
tdx_global_metadata.h. Manually define a macro for it in "tdx.h".
Link: https://lore.kernel.org/fc0e8ab7-86d4-4428-be31-82e1ece6dd21@intel.com/ [1]
Signed-off-by: Kai Huang <kai.huang@intel.com>
Reviewed-by: Nikolay Borisov <nik.borisov@suse.com>
Reviewed-by: Adrian Hunter <adrian.hunter@intel.com>
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
---
arch/x86/virt/vmx/tdx/tdx.c | 17 +++++++++++++++++
arch/x86/virt/vmx/tdx/tdx.h | 4 ++++
2 files changed, 21 insertions(+)
diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c
index b14089f784bf..e4a7e0e17812 100644
--- a/arch/x86/virt/vmx/tdx/tdx.c
+++ b/arch/x86/virt/vmx/tdx/tdx.c
@@ -312,6 +312,18 @@ static int init_tdx_sys_info(struct tdx_sys_info *sysinfo)
return 0;
}
+static int check_features(struct tdx_sys_info *sysinfo)
+{
+ u64 tdx_features0 = sysinfo->features.tdx_features0;
+
+ if (!(tdx_features0 & TDX_FEATURES0_NO_RBP_MOD)) {
+ pr_err("frame pointer (RBP) clobber bug present, upgrade TDX module\n");
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
/* Calculate the actual TDMR size */
static int tdmr_size_single(u16 max_reserved_per_tdmr)
{
@@ -1095,6 +1107,11 @@ static int init_tdx_module(void)
if (ret)
return ret;
+ /* Check whether the kernel can support this module */
+ ret = check_features(&sysinfo);
+ if (ret)
+ return ret;
+
/*
* To keep things simple, assume that all TDX-protected memory
* will come from the page allocator. Make sure all pages in the
diff --git a/arch/x86/virt/vmx/tdx/tdx.h b/arch/x86/virt/vmx/tdx/tdx.h
index 0128b963b723..c8be00f6b15a 100644
--- a/arch/x86/virt/vmx/tdx/tdx.h
+++ b/arch/x86/virt/vmx/tdx/tdx.h
@@ -5,6 +5,7 @@
#include <linux/types.h>
#include <linux/compiler_attributes.h>
#include <linux/stddef.h>
+#include <linux/bits.h>
#include "tdx_global_metadata.h"
/*
@@ -54,6 +55,9 @@ struct tdmr_info {
DECLARE_FLEX_ARRAY(struct tdmr_reserved_area, reserved_areas);
} __packed __aligned(TDMR_INFO_ALIGNMENT);
+/* Bit definitions of TDX_FEATURES0 metadata field */
+#define TDX_FEATURES0_NO_RBP_MOD BIT(18)
+
/*
* Do not put any hardware-defined TDX structure representations below
* this comment!
--
2.46.2
next prev parent reply other threads:[~2024-11-13 11:57 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-13 11:57 [PATCH v8 0/9] TDX host: metadata reading tweaks and bug fixes Kai Huang
2024-11-13 11:57 ` [PATCH v8 1/9] x86/virt/tdx: Rename 'struct tdx_tdmr_sysinfo' to reflect the spec better Kai Huang
2024-11-13 11:57 ` [PATCH v8 2/9] x86/virt/tdx: Start to track all global metadata in one structure Kai Huang
2024-11-13 11:57 ` [PATCH v8 3/9] x86/virt/tdx: Use auto-generated code to read global metadata Kai Huang
2024-12-13 11:17 ` Huang, Kai
2024-11-13 11:57 ` [PATCH v8 4/9] x86/virt/tdx: Use dedicated struct members for PAMT entry sizes Kai Huang
2024-11-13 11:57 ` [PATCH v8 5/9] x86/virt/tdx: Add missing header file inclusion to local tdx.h Kai Huang
2024-11-13 11:57 ` [PATCH v8 6/9] x86/virt/tdx: Switch to use auto-generated global metadata reading code Kai Huang
2024-11-13 11:57 ` [PATCH v8 7/9] x86/virt/tdx: Trim away tail null CMRs Kai Huang
2024-11-13 11:57 ` [PATCH v8 8/9] x86/virt/tdx: Reduce TDMR's reserved areas by using CMRs to find memory holes Kai Huang
2024-12-04 14:22 ` Huang, Kai
2024-12-05 12:45 ` Huang, Kai
2024-12-05 12:40 ` [PATCH v8 8.1/9] " Kai Huang
2024-12-05 18:10 ` Dave Hansen
2024-12-06 2:45 ` Huang, Kai
2024-12-09 6:57 ` Huang, Kai
2024-12-09 6:50 ` [PATCH v8 8.2/9] " Kai Huang
2024-12-09 22:54 ` Dave Hansen
2024-12-10 2:26 ` Huang, Kai
2024-12-10 2:46 ` Dan Williams
2024-12-10 4:24 ` Huang, Kai
2024-12-10 16:58 ` Dave Hansen
2024-12-11 4:34 ` Huang, Kai
2024-11-13 11:57 ` Kai Huang [this message]
2024-11-13 22:25 ` [PATCH v8 0/9] TDX host: metadata reading tweaks and bug fixes Edgecombe, Rick P
2024-11-13 22:40 ` Huang, Kai
2024-11-13 22:53 ` Edgecombe, Rick P
2024-11-13 23:35 ` Huang, Kai
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=2ce15d25ae52411f15742a4b13a8b68a1f5484cd.1731498635.git.kai.huang@intel.com \
--to=kai.huang@intel.com \
--cc=adrian.hunter@intel.com \
--cc=bp@alien8.de \
--cc=dan.j.williams@intel.com \
--cc=dave.hansen@intel.com \
--cc=hpa@zytor.com \
--cc=isaku.yamahata@intel.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=nik.borisov@suse.com \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=rick.p.edgecombe@intel.com \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--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®