[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231122170106.270266-2-jpiotrowski@linux.microsoft.com>
Date: Wed, 22 Nov 2023 18:01:05 +0100
From: Jeremi Piotrowski <jpiotrowski@...ux.microsoft.com>
To: linux-kernel@...r.kernel.org, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>,
"H. Peter Anvin" <hpa@...or.com>, Ingo Molnar <mingo@...hat.com>,
"Kirill A. Shutemov" <kirill.shutemov@...ux.intel.com>,
Michael Kelley <mhkelley58@...il.com>,
Nikolay Borisov <nik.borisov@...e.com>,
Peter Zijlstra <peterz@...radead.org>,
Thomas Gleixner <tglx@...utronix.de>,
Tom Lendacky <thomas.lendacky@....com>, x86@...nel.org,
Dexuan Cui <decui@...rosoft.com>
Cc: Jeremi Piotrowski <jpiotrowski@...ux.microsoft.com>,
linux-hyperv@...r.kernel.org, stefan.bader@...onical.com,
tim.gardner@...onical.com, roxana.nicolescu@...onical.com,
cascardo@...onical.com, kys@...rosoft.com, haiyangz@...rosoft.com,
wei.liu@...nel.org, sashal@...nel.org, stable@...r.kernel.org
Subject: [PATCH v1 2/3] x86/coco: Disable TDX module calls when TD partitioning is active
Introduce CC_ATTR_TDX_MODULE_CALLS to allow code to check whether TDX module
calls are available. When TD partitioning is enabled, a L1 TD VMM handles most
TDX facilities and the kernel running as an L2 TD VM does not have access to
TDX module calls. The kernel still has access to TDVMCALL(0) which is forwarded
to the VMM for processing, which is the L1 TD VM in this case.
Cc: <stable@...r.kernel.org> # v6.5+
Signed-off-by: Jeremi Piotrowski <jpiotrowski@...ux.microsoft.com>
---
arch/x86/coco/core.c | 3 +++
arch/x86/include/asm/unaccepted_memory.h | 2 +-
drivers/virt/coco/tdx-guest/tdx-guest.c | 3 +++
include/linux/cc_platform.h | 8 ++++++++
4 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/arch/x86/coco/core.c b/arch/x86/coco/core.c
index eeec9986570e..2c1116da4d54 100644
--- a/arch/x86/coco/core.c
+++ b/arch/x86/coco/core.c
@@ -12,6 +12,7 @@
#include <asm/coco.h>
#include <asm/processor.h>
+#include <asm/tdx.h>
enum cc_vendor cc_vendor __ro_after_init = CC_VENDOR_NONE;
static u64 cc_mask __ro_after_init;
@@ -24,6 +25,8 @@ static bool noinstr intel_cc_platform_has(enum cc_attr attr)
case CC_ATTR_GUEST_MEM_ENCRYPT:
case CC_ATTR_MEM_ENCRYPT:
return true;
+ case CC_ATTR_TDX_MODULE_CALLS:
+ return !tdx_partitioning_active;
default:
return false;
}
diff --git a/arch/x86/include/asm/unaccepted_memory.h b/arch/x86/include/asm/unaccepted_memory.h
index f5937e9866ac..b666062555ac 100644
--- a/arch/x86/include/asm/unaccepted_memory.h
+++ b/arch/x86/include/asm/unaccepted_memory.h
@@ -8,7 +8,7 @@
static inline void arch_accept_memory(phys_addr_t start, phys_addr_t end)
{
/* Platform-specific memory-acceptance call goes here */
- if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) {
+ if (cc_platform_has(CC_ATTR_TDX_MODULE_CALLS)) {
if (!tdx_accept_memory(start, end))
panic("TDX: Failed to accept memory\n");
} else if (cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) {
diff --git a/drivers/virt/coco/tdx-guest/tdx-guest.c b/drivers/virt/coco/tdx-guest/tdx-guest.c
index 5e44a0fa69bd..2f995df8c795 100644
--- a/drivers/virt/coco/tdx-guest/tdx-guest.c
+++ b/drivers/virt/coco/tdx-guest/tdx-guest.c
@@ -87,6 +87,9 @@ static int __init tdx_guest_init(void)
if (!x86_match_cpu(tdx_guest_ids))
return -ENODEV;
+ if (!cc_platform_has(CC_ATTR_TDX_MODULE_CALLS))
+ return -ENODEV;
+
return misc_register(&tdx_misc_dev);
}
module_init(tdx_guest_init);
diff --git a/include/linux/cc_platform.h b/include/linux/cc_platform.h
index cb0d6cd1c12f..d3c57e86773d 100644
--- a/include/linux/cc_platform.h
+++ b/include/linux/cc_platform.h
@@ -90,6 +90,14 @@ enum cc_attr {
* Examples include TDX Guest.
*/
CC_ATTR_HOTPLUG_DISABLED,
+
+ /**
+ * @CC_ATTR_TDX_MODULE_CALLS: TDX module calls are available.
+ *
+ * The platform supports issuing calls directly to the TDX module.
+ * This is not a given when TD partitioning is active.
+ */
+ CC_ATTR_TDX_MODULE_CALLS,
};
#ifdef CONFIG_ARCH_HAS_CC_PLATFORM
--
2.39.2
Powered by blists - more mailing lists