[PATCH 2/2] coco/tdx-host: Expose TDX module version

Chao Gao posted 2 patches 19 hours ago
[PATCH 2/2] coco/tdx-host: Expose TDX module version
Posted by Chao Gao 19 hours ago
Currently these is no way to know the TDX module version from the
userspace. such information is 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>
---
 .../ABI/testing/sysfs-devices-faux-tdx-host   |  6 +++++
 MAINTAINERS                                   |  1 +
 drivers/virt/coco/tdx-host/tdx-host.c         | 25 ++++++++++++++++++-
 3 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..18d4a4a71b80
--- /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/MAINTAINERS b/MAINTAINERS
index c1ad1294560c..7560dcf8a53d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -27333,6 +27333,7 @@ L:	x86@kernel.org
 L:	linux-coco@lists.linux.dev
 S:	Supported
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86/tdx
+F:	Documentation/ABI/testing/sysfs-devices-faux-tdx-host
 F:	Documentation/ABI/testing/sysfs-devices-virtual-misc-tdx_guest
 F:	arch/x86/boot/compressed/tdx*
 F:	arch/x86/coco/tdx/
diff --git a/drivers/virt/coco/tdx-host/tdx-host.c b/drivers/virt/coco/tdx-host/tdx-host.c
index 49c205913ef6..968a19f4e01a 100644
--- a/drivers/virt/coco/tdx-host/tdx-host.c
+++ b/drivers/virt/coco/tdx-host/tdx-host.c
@@ -22,6 +22,29 @@ 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)
 {
 	int r;
@@ -34,7 +57,7 @@ static int __init tdx_host_init(void)
 	if (r)
 		return r;
 
-	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
Re: [PATCH 2/2] coco/tdx-host: Expose TDX module version
Posted by Kiryl Shutsemau 9 hours ago
On Tue, Sep 30, 2025 at 07:22:45PM -0700, Chao Gao wrote:
> diff --git a/MAINTAINERS b/MAINTAINERS
> index c1ad1294560c..7560dcf8a53d 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -27333,6 +27333,7 @@ L:	x86@kernel.org
>  L:	linux-coco@lists.linux.dev
>  S:	Supported
>  T:	git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86/tdx
> +F:	Documentation/ABI/testing/sysfs-devices-faux-tdx-host
>  F:	Documentation/ABI/testing/sysfs-devices-virtual-misc-tdx_guest
>  F:	arch/x86/boot/compressed/tdx*
>  F:	arch/x86/coco/tdx/

The entry was updated recently:

https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/tree/MAINTAINERS?h=x86/tdx#n27325

I think you need to rebase onto current tip tree.

-- 
  Kiryl Shutsemau / Kirill A. Shutemov
Re: [PATCH 2/2] coco/tdx-host: Expose TDX module version
Posted by Huang, Kai 17 hours ago
On Tue, 2025-09-30 at 19:22 -0700, Chao Gao wrote:
> Currently these is no way to know the TDX module version from the
	    ^
	    there is

> userspace. such information is helpful for bug reporting or
	     ^
	     Such

> debugging.
> 
> 

[...]

> +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);

Nit: not sure whether the "%u.%u.%02u" needs a comment, e.g., why the %02u
is used for the update_version?
Re: [PATCH 2/2] coco/tdx-host: Expose TDX module version
Posted by Kiryl Shutsemau 10 hours ago
On Wed, Oct 01, 2025 at 04:12:10AM +0000, Huang, Kai wrote:
> On Tue, 2025-09-30 at 19:22 -0700, Chao Gao wrote:
> > Currently these is no way to know the TDX module version from the
> 	    ^
> 	    there is
> 
> > userspace. such information is helpful for bug reporting or
> 	     ^
> 	     Such
> 
> > debugging.
> > 
> > 
> 
> [...]
> 
> > +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);
> 
> Nit: not sure whether the "%u.%u.%02u" needs a comment, e.g., why the %02u
> is used for the update_version?

That's how TDX module version formatted:

https://github.com/intel/tdx-module/tags

I think it is good idea to match it.

-- 
  Kiryl Shutsemau / Kirill A. Shutemov