diff mbox series

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

Message ID 57eaa1b17429315f8b5207774307f3c1dd40cf37.1730118186.git.kai.huang@intel.com (mailing list archive)
State New
Headers show
Series TDX host: metadata reading tweaks, bug fix and info dump | expand

Commit Message

Huang, Kai Oct. 28, 2024, 12:41 p.m. UTC
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(+)

Comments

Dan Williams Oct. 28, 2024, 10:36 p.m. UTC | #1
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>
Huang, Kai Oct. 28, 2024, 10:59 p.m. UTC | #2
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!
diff mbox series

Patch

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;
 }