[PATCH v6 10/10] x86/virt/tdx: Print TDX module version

Kai Huang posted 10 patches 3 weeks, 6 days ago
There is a newer version of this series
[PATCH v6 10/10] x86/virt/tdx: Print TDX module version
Posted by Kai Huang 3 weeks, 6 days ago
Currently the kernel doesn't print any TDX module version information.
In practice such information is useful, especially to the developers.

For instance:

1) When something goes wrong around using TDX, the module version is
   normally the first information the users want to know [1].

2) The users want to quickly know module version to see whether the
   loaded module is the expected one.

Dump TDX module version.  The actual dmesg will look like:

  virt/tdx: module version: 1.5.00.00.0481 (build_date 20230323).

And dump right after reading global metadata, so that this information is
printed no matter whether module initialization fails or not.

Link: https://lore.kernel.org/lkml/4b3adb59-50ea-419e-ad02-e19e8ca20dee@intel.com/ [1]
Signed-off-by: Kai Huang <kai.huang@intel.com>
---
 arch/x86/virt/vmx/tdx/tdx.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c
index 9bc827a6cee8..6982e100536d 100644
--- a/arch/x86/virt/vmx/tdx/tdx.c
+++ b/arch/x86/virt/vmx/tdx/tdx.c
@@ -312,6 +312,23 @@ static void print_cmrs(struct tdx_sys_info_cmr *sysinfo_cmr)
 	}
 }
 
+static void print_module_version(struct tdx_sys_info_version *version)
+{
+       /*
+	* TDX module version encoding:
+	*
+	*   <major>.<minor>.<update>.<internal>.<build_num>
+	*
+	* When printed as text, <major> and <minor> are 1-digit,
+	* <update> and <internal> are 2-digits and <build_num>
+	* is 4-digits.
+	*/
+	pr_info("module version: %u.%u.%02u.%02u.%04u (build_date %u).\n",
+			version->major_version,	 version->minor_version,
+			version->update_version, version->internal_version,
+			version->build_num,	 version->build_date);
+}
+
 static int init_tdx_sys_info(struct tdx_sys_info *sysinfo)
 {
 	int ret;
@@ -322,6 +339,7 @@ static int init_tdx_sys_info(struct tdx_sys_info *sysinfo)
 
 	trim_null_tail_cmrs(&sysinfo->cmr);
 	print_cmrs(&sysinfo->cmr);
+	print_module_version(&sysinfo->version);
 
 	return 0;
 }
-- 
2.46.2
Re: [PATCH v6 10/10] x86/virt/tdx: Print TDX module version
Posted by Dan Williams 3 weeks, 6 days ago
Kai Huang wrote:
> Currently the kernel doesn't print any TDX module version information.
> In practice such information is useful, especially to the developers.
> 
> For instance:
> 
> 1) When something goes wrong around using TDX, the module version is
>    normally the first information the users want to know [1].
> 
> 2) The users want to quickly know module version to see whether the
>    loaded module is the expected one.
> 
> Dump TDX module version.  The actual dmesg will look like:
> 
>   virt/tdx: module version: 1.5.00.00.0481 (build_date 20230323).
> 
> And dump right after reading global metadata, so that this information is
> printed no matter whether module initialization fails or not.
> 
> Link: https://lore.kernel.org/lkml/4b3adb59-50ea-419e-ad02-e19e8ca20dee@intel.com/ [1]
> Signed-off-by: Kai Huang <kai.huang@intel.com>

LGTM, would be nice if the build hash was also included to precisely
identify the image, but will need to ask for that metadata to be added.

Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Re: [PATCH v6 10/10] x86/virt/tdx: Print TDX module version
Posted by Huang, Kai 3 weeks, 6 days ago

On 29/10/2024 11:36 am, Dan Williams wrote:
> Kai Huang wrote:
>> Currently the kernel doesn't print any TDX module version information.
>> In practice such information is useful, especially to the developers.
>>
>> For instance:
>>
>> 1) When something goes wrong around using TDX, the module version is
>>     normally the first information the users want to know [1].
>>
>> 2) The users want to quickly know module version to see whether the
>>     loaded module is the expected one.
>>
>> Dump TDX module version.  The actual dmesg will look like:
>>
>>    virt/tdx: module version: 1.5.00.00.0481 (build_date 20230323).
>>
>> And dump right after reading global metadata, so that this information is
>> printed no matter whether module initialization fails or not.
>>
>> Link: https://lore.kernel.org/lkml/4b3adb59-50ea-419e-ad02-e19e8ca20dee@intel.com/ [1]
>> Signed-off-by: Kai Huang <kai.huang@intel.com>
> 
> LGTM, would be nice if the build hash was also included to precisely
> identify the image, but will need to ask for that metadata to be added.

Yes. If that is needed we will need to ask TDX module team to add.

> 
> Reviewed-by: Dan Williams <dan.j.williams@intel.com>

Thanks!