public inbox for linux-coco@lists.linux.dev
 help / color / mirror / Atom feed
From: Chao Gao <chao.gao@intel.com>
To: x86@kernel.org, linux-coco@lists.linux.dev, kvm@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: vishal.l.verma@intel.com, kai.huang@intel.com,
	dan.j.williams@intel.com, yilun.xu@linux.intel.com,
	vannapurve@google.com, Chao Gao <chao.gao@intel.com>,
	Kiryl Shutsemau <kas@kernel.org>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Rick Edgecombe <rick.p.edgecombe@intel.com>
Subject: [PATCH v2 2/3] coco/tdx-host: Expose TDX Module version
Date: Sun,  4 Jan 2026 23:43:45 -0800	[thread overview]
Message-ID: <20260105074350.98564-3-chao.gao@intel.com> (raw)
In-Reply-To: <20260105074350.98564-1-chao.gao@intel.com>

Currently there is no way to know the TDX Module version from the
userspace. Such information is always helpful for bug reporting or
debugging.

With the tdx-host device in place, expose the TDX Module version as
a device attribute via sysfs.

Signed-off-by: Chao Gao <chao.gao@intel.com>
---
v2: 
 - No need to update MAINTAINERS to include sysfs-devices-faux-tdx-host
   explicitly (Kirill)

 .../ABI/testing/sysfs-devices-faux-tdx-host   |  6 +++++
 drivers/virt/coco/tdx-host/tdx-host.c         | 26 ++++++++++++++++++-
 2 files changed, 31 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/ABI/testing/sysfs-devices-faux-tdx-host

diff --git a/Documentation/ABI/testing/sysfs-devices-faux-tdx-host b/Documentation/ABI/testing/sysfs-devices-faux-tdx-host
new file mode 100644
index 000000000000..35ef21f53c2e
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-devices-faux-tdx-host
@@ -0,0 +1,6 @@
+What:		/sys/devices/faux/tdx_host/version
+Contact:	linux-coco@lists.linux.dev
+Description:	(RO) Report the version of the loaded TDX Module. The TDX Module
+		version is formatted as x.y.z, where "x" is the major version,
+		"y" is the minor version and "z" is the update version. Versions
+		are used for bug reporting, TD-Preserving updates and etc.
diff --git a/drivers/virt/coco/tdx-host/tdx-host.c b/drivers/virt/coco/tdx-host/tdx-host.c
index ced1c980dc6f..2883c6638faf 100644
--- a/drivers/virt/coco/tdx-host/tdx-host.c
+++ b/drivers/virt/coco/tdx-host/tdx-host.c
@@ -9,6 +9,7 @@
 #include <linux/mod_devicetable.h>
 #include <linux/device/faux.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),
@@ -18,12 +19,35 @@ MODULE_DEVICE_TABLE(x86cpu, tdx_host_ids);
 
 static struct faux_device *fdev;
 
+static ssize_t version_show(struct device *dev, struct device_attribute *attr,
+			    char *buf)
+{
+	const struct tdx_sys_info *tdx_sysinfo = tdx_get_sysinfo();
+	const struct tdx_sys_info_version *ver;
+
+	if (!tdx_sysinfo)
+		return -ENXIO;
+
+	ver = &tdx_sysinfo->version;
+
+	return sysfs_emit(buf, "%u.%u.%02u\n", ver->major_version,
+					       ver->minor_version,
+					       ver->update_version);
+}
+static DEVICE_ATTR_RO(version);
+
+static struct attribute *tdx_host_attrs[] = {
+	&dev_attr_version.attr,
+	NULL,
+};
+ATTRIBUTE_GROUPS(tdx_host);
+
 static int __init tdx_host_init(void)
 {
 	if (!x86_match_cpu(tdx_host_ids))
 		return -ENODEV;
 
-	fdev = faux_device_create(KBUILD_MODNAME, NULL, NULL);
+	fdev = faux_device_create_with_groups(KBUILD_MODNAME, NULL, NULL, tdx_host_groups);
 	if (!fdev)
 		return -ENODEV;
 
-- 
2.47.3


  parent reply	other threads:[~2026-01-05  7:43 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-05  7:43 [PATCH v2 0/3] Expose TDX Module version Chao Gao
2026-01-05  7:43 ` [PATCH v2 1/3] x86/virt/tdx: Retrieve " Chao Gao
2026-01-05  7:43 ` Chao Gao [this message]
2026-01-05  7:43 ` [PATCH v2 3/3] x86/virt/tdx: Print TDX Module version during init Chao Gao
2026-01-05 10:38 ` [PATCH v2 0/3] Expose TDX Module version Kiryl Shutsemau
2026-01-05 16:04   ` Dave Hansen
2026-01-05 17:04     ` Kiryl Shutsemau
2026-01-05 17:19       ` Dave Hansen
2026-01-05 18:03         ` Kiryl Shutsemau
2026-01-07 21:34         ` dan.j.williams
2026-01-07 22:26           ` Dave Hansen
2026-01-06 10:23     ` Chao Gao
2026-01-06 16:37       ` Dave Hansen
2026-01-06  6:47   ` Chao Gao
2026-01-06  9:17     ` Nikolay Borisov
2026-01-06 11:19     ` Kiryl Shutsemau
2026-01-06 13:31       ` Chao Gao
2026-01-07  0:36     ` dan.j.williams

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=20260105074350.98564-3-chao.gao@intel.com \
    --to=chao.gao@intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=kai.huang@intel.com \
    --cc=kas@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rick.p.edgecombe@intel.com \
    --cc=vannapurve@google.com \
    --cc=vishal.l.verma@intel.com \
    --cc=x86@kernel.org \
    --cc=yilun.xu@linux.intel.com \
    /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