]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
coco/tdx-host: Introduce a "tdx_host" device
authorChao Gao <chao.gao@intel.com>
Wed, 20 May 2026 22:28:52 +0000 (15:28 -0700)
committerDave Hansen <dave.hansen@linux.intel.com>
Wed, 3 Jun 2026 15:14:51 +0000 (08:14 -0700)
TDX depends on a platform firmware module that runs on the CPU.
Unlike other CoCo architectures, TDX has no hardware "device"
running the show, just a blob on the CPU.

Create a virtual device to anchor interactions with this platform
firmware. This lets later code:

 - expose metadata: TDX module version, seamldr version, to userspace
   as device attributes

 - implement firmware uploader APIs (which are tied to a device) to
   support TDX module runtime updates

Use a faux device because the TDX module is singular within the system
and has no platform resources. Using a faux device eliminates the need
to create a stub bus.

The call to tdx_get_sysinfo() ensures that the TDX module is ready to
provide services.

Note that AMD has a PCI device for the PSP for SEV and ARM CCA will
likely have a faux device [1].

Thanks to Dan and Yilun for all the help on this one.

[ dhansen: trim changelog ]

Signed-off-by: Chao Gao <chao.gao@intel.com>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Reviewed-by: Tony Lindgren <tony.lindgren@linux.intel.com>
Reviewed-by: Xu Yilun <yilun.xu@linux.intel.com>
Reviewed-by: Kai Huang <kai.huang@intel.com>
Reviewed-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
Link: https://lore.kernel.org/all/2025073035-bulginess-rematch-b92e@gregkh/
Link: https://patch.msgid.link/20260520133909.409394-7-chao.gao@intel.com
arch/x86/virt/vmx/tdx/tdx.c
drivers/virt/coco/Kconfig
drivers/virt/coco/Makefile
drivers/virt/coco/tdx-host/Kconfig [new file with mode: 0644]
drivers/virt/coco/tdx-host/Makefile [new file with mode: 0644]
drivers/virt/coco/tdx-host/tdx-host.c [new file with mode: 0644]

index b329791db9c2d7438c6335cb6e16fee3f8087915..5fb0441a9ac6ce49df0a7ef9c5a502aa6fdfd670 100644 (file)
@@ -1527,7 +1527,7 @@ const struct tdx_sys_info *tdx_get_sysinfo(void)
 
        return (const struct tdx_sys_info *)&tdx_sysinfo;
 }
-EXPORT_SYMBOL_FOR_KVM(tdx_get_sysinfo);
+EXPORT_SYMBOL_FOR_MODULES(tdx_get_sysinfo, "kvm-intel,tdx-host");
 
 u32 tdx_get_nr_guest_keyids(void)
 {
index df1cfaf26c658ae4cfd77bd836dcdee281acc50e..f7691f64fbe32de1891879237114f66c7b06a20a 100644 (file)
@@ -17,5 +17,7 @@ source "drivers/virt/coco/arm-cca-guest/Kconfig"
 source "drivers/virt/coco/guest/Kconfig"
 endif
 
+source "drivers/virt/coco/tdx-host/Kconfig"
+
 config TSM
        bool
index cb52021912b34e39bc32dab36b3562078386e14a..b323b0ae4f82da10ab339ee08b50d1a37be83366 100644 (file)
@@ -6,6 +6,7 @@ obj-$(CONFIG_EFI_SECRET)        += efi_secret/
 obj-$(CONFIG_ARM_PKVM_GUEST)   += pkvm-guest/
 obj-$(CONFIG_SEV_GUEST)                += sev-guest/
 obj-$(CONFIG_INTEL_TDX_GUEST)  += tdx-guest/
+obj-$(CONFIG_INTEL_TDX_HOST)   += tdx-host/
 obj-$(CONFIG_ARM_CCA_GUEST)    += arm-cca-guest/
 obj-$(CONFIG_TSM)              += tsm-core.o
 obj-$(CONFIG_TSM_GUEST)                += guest/
diff --git a/drivers/virt/coco/tdx-host/Kconfig b/drivers/virt/coco/tdx-host/Kconfig
new file mode 100644 (file)
index 0000000..cfe81b9
--- /dev/null
@@ -0,0 +1,4 @@
+config TDX_HOST_SERVICES
+       tristate
+       depends on INTEL_TDX_HOST
+       default m
diff --git a/drivers/virt/coco/tdx-host/Makefile b/drivers/virt/coco/tdx-host/Makefile
new file mode 100644 (file)
index 0000000..e61e749
--- /dev/null
@@ -0,0 +1 @@
+obj-$(CONFIG_TDX_HOST_SERVICES) += tdx-host.o
diff --git a/drivers/virt/coco/tdx-host/tdx-host.c b/drivers/virt/coco/tdx-host/tdx-host.c
new file mode 100644 (file)
index 0000000..c778853
--- /dev/null
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * TDX host user interface driver
+ *
+ * Copyright (C) 2025 Intel Corporation
+ */
+
+#include <linux/device/faux.h>
+#include <linux/module.h>
+#include <linux/mod_devicetable.h>
+
+#include <asm/cpu_device_id.h>
+#include <asm/tdx.h>
+
+static const struct x86_cpu_id tdx_host_ids[] = {
+       X86_MATCH_FEATURE(X86_FEATURE_TDX_HOST_PLATFORM, NULL),
+       {}
+};
+MODULE_DEVICE_TABLE(x86cpu, tdx_host_ids);
+
+static struct faux_device *fdev;
+
+static int __init tdx_host_init(void)
+{
+       if (!x86_match_cpu(tdx_host_ids) || !tdx_get_sysinfo())
+               return -ENODEV;
+
+       fdev = faux_device_create(KBUILD_MODNAME, NULL, NULL);
+       if (!fdev)
+               return -ENODEV;
+
+       return 0;
+}
+module_init(tdx_host_init);
+
+static void __exit tdx_host_exit(void)
+{
+       faux_device_destroy(fdev);
+}
+module_exit(tdx_host_exit);
+
+MODULE_DESCRIPTION("TDX Host Services");
+MODULE_LICENSE("GPL");