From nobody Wed Oct 1 21:27:09 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A79FB27A10C for ; Wed, 1 Oct 2025 02:23:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759285411; cv=none; b=Tl3kuj2q2h2fpCkvROpGsy17O9PUzT1ELYA1ztiU4y9YUW9YZY/6nY8ZK2Ixgv8Rt6CENdzyhHSq+lenoHgO09Y60/QYKk6KRpKokcOBXVDAcEUCHvfMklK43GCncG8CR4eslsb1gKvhgj2mipipg6ZfrXrvkoSwVNoT8y8TRvs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759285411; c=relaxed/simple; bh=5VOL+IkOmzM8PbSBheZHH3YB+5XVvkN8ZRBEIFdjqi0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PxQ2zEs5BsD9fZG3ijc/5iRFUJx4NeE5F53AmRjTKeg09F/FdEVEsyZYbRBPorp6gPx/WV139k2gVbCw0tosf7C7l2I9ByfT8QzAEnLdu6Lz94KQl1D0zqyWXSMnnzO99pzL5Jc7ZX2WU2jkx/lN9vZ3O8Go/keN7R9NPuxMkH8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=BA9xL5nk; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="BA9xL5nk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1759285409; x=1790821409; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5VOL+IkOmzM8PbSBheZHH3YB+5XVvkN8ZRBEIFdjqi0=; b=BA9xL5nkYXSCl0ubnQm9VC2HK9IpP6wQSxJVrld/guZPGLrpBvAaYk5x 3F8hiJzAXRjLwbqwRuith0LG1w9fWsCvOzErawTxiE9rQHUpyLVzTL05g E4YBi+LAbMQlZuInO5D79F15zNeajTYcw3mEFXQfYliH4s9LlloDMcv/4 LUHDTY1jTHUddpCPXgiwkKmeWZraZFxHuCaXuawJR4XU7NMwUQ4OiEuDW Z+2ronXXiZMvu8mUKQg6zpD3ThUcTiyY4SpgrLZKFgJeWOjwUGm5/3PCC PLRrRLSIN+QJuKa/6VbRLLF4iFxnkLjZBRV1akLL+1KV3RvMOrVtpK24K g==; X-CSE-ConnectionGUID: Z3aIDJTPT0yfLELnvSu0EQ== X-CSE-MsgGUID: W4N2o89FQo+NulqXgPUBKA== X-IronPort-AV: E=McAfee;i="6800,10657,11569"; a="61444983" X-IronPort-AV: E=Sophos;i="6.18,305,1751266800"; d="scan'208";a="61444983" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2025 19:23:28 -0700 X-CSE-ConnectionGUID: 3A3sQI1ARYWtB3CLIgH3gA== X-CSE-MsgGUID: s+nJgddKR0awZaDnA7Gzaw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.18,305,1751266800"; d="scan'208";a="183079906" Received: from 984fee019967.jf.intel.com ([10.165.54.94]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2025 19:23:28 -0700 From: Chao Gao To: linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, x86@kernel.org Cc: Chao Gao , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , "Kirill A. Shutemov" , Kai Huang , Paolo Bonzini , Dan Williams Subject: [PATCH 1/2] x86/virt/tdx: Retrieve TDX module version Date: Tue, 30 Sep 2025 19:22:44 -0700 Message-ID: <20251001022309.277238-2-chao.gao@intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251001022309.277238-1-chao.gao@intel.com> References: <20251001022309.277238-1-chao.gao@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Each TDX module is associated with a version in the x.y.z format, where x represents the major version, y the minor version, and z the update version. Knowing the running TDX module version is valuable for bug reporting and debugging. Retrieve the TDX module version using the existing metadata reading interface, in preparation for exposing it to userspace via sysfs. Note changes to tdx_global_metadata.{hc} are auto-generated by the following command. $ python tdx.py global_metadata.json tdx_global_metadata.h \ tdx_global_metadata.c The 'tdx.py' can be fetched from [1]. The 'global_metadata.json' can be fetched from [2]. And 'tdx.py' has "BUILD_DATE", "BUILD_NUM" and "INTERNAL_VERSION" in TDX_STRUCTS; they are removed before running the above command as they are not needed for now. Signed-off-by: Chao Gao Link: https://lore.kernel.org/kvm/0853b155ec9aac09c594caa60914ed6ea4dc0a71.= camel@intel.com/ # [1] Link: https://cdrdv2.intel.com/v1/dl/getContent/795381 # [2] --- arch/x86/include/asm/tdx_global_metadata.h | 7 +++++++ arch/x86/virt/vmx/tdx/tdx_global_metadata.c | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/arch/x86/include/asm/tdx_global_metadata.h b/arch/x86/include/= asm/tdx_global_metadata.h index 060a2ad744bf..40689c8dc67e 100644 --- a/arch/x86/include/asm/tdx_global_metadata.h +++ b/arch/x86/include/asm/tdx_global_metadata.h @@ -5,6 +5,12 @@ =20 #include =20 +struct tdx_sys_info_version { + u16 minor_version; + u16 major_version; + u16 update_version; +}; + struct tdx_sys_info_features { u64 tdx_features0; }; @@ -35,6 +41,7 @@ struct tdx_sys_info_td_conf { }; =20 struct tdx_sys_info { + struct tdx_sys_info_version version; struct tdx_sys_info_features features; struct tdx_sys_info_tdmr tdmr; struct tdx_sys_info_td_ctrl td_ctrl; diff --git a/arch/x86/virt/vmx/tdx/tdx_global_metadata.c b/arch/x86/virt/vm= x/tdx/tdx_global_metadata.c index 13ad2663488b..0454124803f3 100644 --- a/arch/x86/virt/vmx/tdx/tdx_global_metadata.c +++ b/arch/x86/virt/vmx/tdx/tdx_global_metadata.c @@ -7,6 +7,21 @@ * Include this file to other C file instead. */ =20 +static int get_tdx_sys_info_version(struct tdx_sys_info_version *sysinfo_v= ersion) +{ + int ret =3D 0; + u64 val; + + if (!ret && !(ret =3D read_sys_metadata_field(0x0800000100000003, &val))) + sysinfo_version->minor_version =3D val; + if (!ret && !(ret =3D read_sys_metadata_field(0x0800000100000004, &val))) + sysinfo_version->major_version =3D val; + if (!ret && !(ret =3D read_sys_metadata_field(0x0800000100000005, &val))) + sysinfo_version->update_version =3D val; + + return ret; +} + static int get_tdx_sys_info_features(struct tdx_sys_info_features *sysinfo= _features) { int ret =3D 0; @@ -89,6 +104,7 @@ static int get_tdx_sys_info(struct tdx_sys_info *sysinfo) { int ret =3D 0; =20 + ret =3D ret ?: get_tdx_sys_info_version(&sysinfo->version); ret =3D ret ?: get_tdx_sys_info_features(&sysinfo->features); ret =3D ret ?: get_tdx_sys_info_tdmr(&sysinfo->tdmr); ret =3D ret ?: get_tdx_sys_info_td_ctrl(&sysinfo->td_ctrl); --=20 2.47.3 From nobody Wed Oct 1 21:27:09 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF75D270542 for ; Wed, 1 Oct 2025 02:23:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759285429; cv=none; b=Y+iqNyQSEsa79FGQhi6TKW+VgXpB8pTZscmlHGkSqRLwFWFzJ6P/Hk9j0eAMutL/1xkXvDfHNaN+MU2zVzRjYycdFlVjQ2tEnSa/B223tDIRRhJnGhvx5nvhVqggaEpTdgkD+7eTmmEV86jkNhHDsPaUlfzpGTXWD5spzL2Z+uw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759285429; c=relaxed/simple; bh=WxXsKqyjvjdx1jE1eDRPPZIssIPZhCk1RArR1l+TZM8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=caFuQH1Q6OxGgW2btFCMxobV1KVgD6dPO8yuMHt40U7D9VpCbo7pnjx/36gSVj0QnBLFtuGQGZpQLxN3zdv6I1vzVv3byEkigrdU+/xvU7iIPp9UMkMCzEGgAMpcxcNyzwzPvmI+o2DAAXDS74c+cMc41yULPy5NYDE+Kyeumc0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Mg1OGnc7; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Mg1OGnc7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1759285426; x=1790821426; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WxXsKqyjvjdx1jE1eDRPPZIssIPZhCk1RArR1l+TZM8=; b=Mg1OGnc7WM2C4jRUUrlyKdBIXj3VI5BzLcbiqDaKJjv3ON+zL+otw8fo wHWYHFa1P6CXofj1LmZMyt3XGrG7LrkscmxEOPcnvRntzCOnWvzAx1hjz eKf6L9DkGb5yCPom76DzvuMI+Hle5CwaEcfMBxI/J07kXtlUMTuMfBrlT qUm5nJbmv/kHpVLBQvPW5NAx1Outsh70Zm2CKB92Kikcl9PCJMjlFUyIB RVOPo7Auvn12JxGkOZbnKZ5GvrHd/2Z7NXtKswHcshyIjkZtI9sNE98tD gBF9LxskxPShrLQhPIzs8Ov+6xOa+pT9cFdBb4JNPB9v0Nehi0Dy+VpV5 A==; X-CSE-ConnectionGUID: aLHZNFvTTrahCuK+0hZxpQ== X-CSE-MsgGUID: 1/ae4iBBSzCnrzIqLjnxtA== X-IronPort-AV: E=McAfee;i="6800,10657,11569"; a="61445010" X-IronPort-AV: E=Sophos;i="6.18,305,1751266800"; d="scan'208";a="61445010" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2025 19:23:46 -0700 X-CSE-ConnectionGUID: M0C/LwP+SzG+oRNWd6CY5Q== X-CSE-MsgGUID: Pf1CYrooQpWz68horitnaw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.18,305,1751266800"; d="scan'208";a="183079922" Received: from 984fee019967.jf.intel.com ([10.165.54.94]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2025 19:23:46 -0700 From: Chao Gao To: linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, x86@kernel.org Cc: Chao Gao , "Kirill A. Shutemov" , Dave Hansen , Dan Williams , Xu Yilun Subject: [PATCH 2/2] coco/tdx-host: Expose TDX module version Date: Tue, 30 Sep 2025 19:22:45 -0700 Message-ID: <20251001022309.277238-3-chao.gao@intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251001022309.277238-1-chao.gao@intel.com> References: <20251001022309.277238-1-chao.gao@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- .../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/Docume= ntation/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 mod= ule + 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); =20 static struct faux_device *fdev; =20 +static ssize_t version_show(struct device *dev, struct device_attribute *a= ttr, + char *buf) +{ + const struct tdx_sys_info *tdx_sysinfo =3D tdx_get_sysinfo(); + const struct tdx_sys_info_version *ver; + + if (!tdx_sysinfo) + return -ENXIO; + + ver =3D &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[] =3D { + &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; =20 - fdev =3D faux_device_create(KBUILD_MODNAME, NULL, NULL); + fdev =3D faux_device_create_with_groups(KBUILD_MODNAME, NULL, NULL, tdx_h= ost_groups); if (!fdev) return -ENODEV; =20 --=20 2.47.3