From: "Huang, Kai" <kai.huang@intel.com>
To: linux-kernel@vger.kernel.org
Cc: x86@kernel.org, dave.hansen@intel.com,
kirill.shutemov@linux.intel.com, tglx@linutronix.de,
bp@alien8.de, mingo@redhat.com, hpa@zytor.com, luto@kernel.org,
peterz@infradead.org, thomas.lendacky@amd.com,
chao.gao@intel.com, bhe@redhat.com, nik.borisov@suse.com,
pbonzini@redhat.com
Subject: [PATCH 2/4] x86/virt/tdx: Advertise the CC_ATTR_HOST_MEM_INCOHERENT for TDX host
Date: Wed, 31 Jan 2024 11:31:54 +0000 [thread overview]
Message-ID: <ebbc67eb2c6052dd56fda31cd22bb830d3d290ef.1706698706.git.kai.huang@intel.com> (raw)
In-Reply-To: <cover.1706698706.git.kai.huang@intel.com>
From: Kai Huang <kai.huang@intel.com>
On the TDX capable platform, during kexec() the old kernel needs to
flush dirty cachelines of all TDX private memory otherwise they may
silently corrupt the new kernel's memory.
Advertise the new introduced CC_ATTR_HOST_MEM_INCOHERENT attribute for
TDX host platform so the cache will be flushed during kexec().
Note theoretically cache flush is only needed when TDX module is
initialized, but the module initialization is done at runtime so just
advertise the CC attribute when the platform has TDX enabled.
Signed-off-by: Kai Huang <kai.huang@intel.com>
Reviewed-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Reviewed-by: Chao Gao <chao.gao@intel.com>
---
arch/x86/Kconfig | 1 +
arch/x86/coco/core.c | 21 ++++++++++++++++++++-
arch/x86/virt/vmx/tdx/tdx.c | 3 +++
include/linux/cc_platform.h | 3 ++-
4 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 502986237cb6..ac3b32149a77 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -1975,6 +1975,7 @@ config INTEL_TDX_HOST
depends on CONTIG_ALLOC
depends on !KEXEC_CORE
depends on X86_MCE
+ select ARCH_HAS_CC_PLATFORM
help
Intel Trust Domain Extensions (TDX) protects guest VMs from malicious
host and certain physical attacks. This option enables necessary TDX
diff --git a/arch/x86/coco/core.c b/arch/x86/coco/core.c
index 8d6d727e6e18..ecb15852b69d 100644
--- a/arch/x86/coco/core.c
+++ b/arch/x86/coco/core.c
@@ -12,11 +12,12 @@
#include <asm/coco.h>
#include <asm/processor.h>
+#include <asm/cpufeature.h>
enum cc_vendor cc_vendor __ro_after_init = CC_VENDOR_NONE;
static u64 cc_mask __ro_after_init;
-static bool noinstr intel_cc_platform_has(enum cc_attr attr)
+static bool noinstr intel_cc_platform_guest_has(enum cc_attr attr)
{
switch (attr) {
case CC_ATTR_GUEST_UNROLL_STRING_IO:
@@ -29,6 +30,24 @@ static bool noinstr intel_cc_platform_has(enum cc_attr attr)
}
}
+static bool noinstr intel_cc_platform_host_has(enum cc_attr attr)
+{
+ switch (attr) {
+ case CC_ATTR_HOST_MEM_INCOHERENT:
+ return true;
+ default:
+ return false;
+ }
+}
+
+static bool noinstr intel_cc_platform_has(enum cc_attr attr)
+{
+ if (boot_cpu_has(X86_FEATURE_TDX_HOST_PLATFORM))
+ return intel_cc_platform_host_has(attr);
+
+ return intel_cc_platform_guest_has(attr);
+}
+
/*
* Handle the SEV-SNP vTOM case where sme_me_mask is zero, and
* the other levels of SME/SEV functionality, including C-bit
diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c
index 4d6826a76f78..9f1fed458a32 100644
--- a/arch/x86/virt/vmx/tdx/tdx.c
+++ b/arch/x86/virt/vmx/tdx/tdx.c
@@ -37,6 +37,7 @@
#include <asm/intel-family.h>
#include <asm/processor.h>
#include <asm/mce.h>
+#include <asm/coco.h>
#include "tdx.h"
static u32 tdx_global_keyid __ro_after_init;
@@ -1488,5 +1489,7 @@ void __init tdx_init(void)
setup_force_cpu_cap(X86_FEATURE_TDX_HOST_PLATFORM);
+ cc_vendor = CC_VENDOR_INTEL;
+
check_tdx_erratum();
}
diff --git a/include/linux/cc_platform.h b/include/linux/cc_platform.h
index 2f7273596102..654777d64dc0 100644
--- a/include/linux/cc_platform.h
+++ b/include/linux/cc_platform.h
@@ -53,7 +53,8 @@ enum cc_attr {
* Use this in places where the cache coherency of the memory matters
* but the encryption status does not.
*
- * Includes all systems that set CC_ATTR_HOST_MEM_ENCRYPT.
+ * Includes all systems that set CC_ATTR_HOST_MEM_ENCRYPT, but
+ * additionally adds TDX hosts.
*/
CC_ATTR_HOST_MEM_INCOHERENT,
--
2.34.1
next prev parent reply other threads:[~2024-01-31 11:32 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-31 11:31 [PATCH 0/4] TDX host: kexec() support Huang, Kai
2024-01-31 11:31 ` [PATCH 1/4] x86/coco: Add a new CC attribute to unify cache flush during kexec Huang, Kai
2024-02-19 16:16 ` Borislav Petkov
2024-02-19 19:45 ` Tom Lendacky
2024-02-19 20:32 ` Borislav Petkov
2024-02-19 22:09 ` Tom Lendacky
2024-02-20 2:57 ` Huang, Kai
2024-02-20 14:40 ` Tom Lendacky
2024-02-20 14:28 ` Borislav Petkov
2024-02-20 14:47 ` Tom Lendacky
2024-02-20 20:07 ` Huang, Kai
2024-02-20 22:30 ` Tom Lendacky
2024-02-21 1:38 ` Huang, Kai
2024-02-21 9:28 ` Borislav Petkov
2024-02-22 11:49 ` Huang, Kai
2024-02-23 3:13 ` Dave Young
2024-02-23 10:41 ` Dave Young
2024-02-28 2:54 ` Dave Young
2024-02-28 9:21 ` Huang, Kai
2024-02-28 11:02 ` Borislav Petkov
2024-02-28 22:21 ` Huang, Kai
2024-02-28 10:44 ` Borislav Petkov
2024-02-20 3:12 ` Huang, Kai
2024-01-31 11:31 ` Huang, Kai [this message]
2024-01-31 17:11 ` [PATCH 2/4] x86/virt/tdx: Advertise the CC_ATTR_HOST_MEM_INCOHERENT for TDX host Dave Hansen
2024-02-01 14:42 ` Huang, Kai
2024-01-31 11:31 ` [PATCH 3/4] x86/kexec(): Reset TDX private memory on platforms with TDX erratum Huang, Kai
2024-01-31 21:21 ` Dave Hansen
2024-01-31 22:03 ` Kirill A. Shutemov
2024-02-01 14:22 ` Huang, Kai
2024-02-01 14:39 ` Kirill A. Shutemov
2024-02-01 14:47 ` Huang, Kai
2024-02-01 16:57 ` Dave Hansen
2024-02-05 6:49 ` Huang, Kai
2024-02-01 14:35 ` Huang, Kai
2024-02-02 0:54 ` Edgecombe, Rick P
2024-02-05 6:44 ` Huang, Kai
2024-01-31 11:31 ` [PATCH 4/4] x86/virt/tdx: Remove the !KEXEC_CORE dependency Huang, Kai
2024-02-01 18:28 ` [PATCH 0/4] TDX host: kexec() support Tom Lendacky
2024-02-05 6:50 ` Huang, Kai
2024-02-06 18:56 ` Kalra, Ashish
2024-02-07 1:43 ` 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=ebbc67eb2c6052dd56fda31cd22bb830d3d290ef.1706698706.git.kai.huang@intel.com \
--to=kai.huang@intel.com \
--cc=bhe@redhat.com \
--cc=bp@alien8.de \
--cc=chao.gao@intel.com \
--cc=dave.hansen@intel.com \
--cc=hpa@zytor.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=nik.borisov@suse.com \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--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
Powered by JetHome