Re: [PATCH v2] x86/tdx: Dump TDX version During the TD Bootup

From: kirill . shutemov
Date: Tue Sep 26 2023 - 04:05:56 EST


On Fri, Sep 22, 2023 at 04:03:22PM +0800, Yi Sun wrote:
> It is essential for TD users to be aware of the vendor and version of
> the current TDX. Additionally, they can reference the TDX version when
> reporting bugs or issues.
>
> Furthermore, the applications or device drivers running in TD can achieve
> enhanced reliability and flexibility by following the TDX Module ABI
> specification, because there are significant differences between different
> versions of TDX, as mentioned in the "Intel® TDX Module Incompatibilities
> between v1.0 and v1.5" reference. Here are a few examples:
>
> MSR Name Index Reason
> ----------------------------------------------
> IA32_UARCH_MISC_CTL 0x1B01 From v1.5
> IA32_ARCH_CAPABILITIES 0x010A Changed in v1.5
> IA32_TSX_CTRL 0x0122 Changed in v1.5
>
> CPUID Leaf Sub-leaf Reason
> ---------------------------------------
> 0x7 2 From v1.5
> 0x22 0 From v1.5
> 0x23 0~3 From v1.5
> 0x80000007 0 From v1.5
>
> During TD initialization, the TDX version info can be obtained by calling
> TDG.SYS.RD. This will fetch the current version of TDX, including the major
> and minor version numbers and vendor ID.
>
> The TDCALL TDG.SYS.RD originates from TDX version 1.5. If the error
> TDCALL_INVALID_OPERAND occurs, it should be treated as TDX version 1.0.
>
> Co-developed-by: Dongcheng Yan <dongcheng.yan@xxxxxxxxx>
> Signed-off-by: Dongcheng Yan <dongcheng.yan@xxxxxxxxx>
> Signed-off-by: Yi Sun <yi.sun@xxxxxxxxx>
>
> diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c
> index 1d6b863c42b0..0f51123aa0b9 100644
> --- a/arch/x86/coco/tdx/tdx.c
> +++ b/arch/x86/coco/tdx/tdx.c
> @@ -37,6 +37,27 @@
>
> #define TDREPORT_SUBTYPE_0 0
>
> +/*
> + * TDX metadata base field id, used by TDCALL TDG.SYS.RD
> + * See TDX ABI Spec section 3.3.2.3 Global Metadata Fields
> + */
> +#define TDX_SYS_VENDOR_ID_FID 0x0800000200000000ULL
> +#define TDX_SYS_MINOR_FID 0x0800000100000003ULL
> +#define TDX_SYS_MAJOR_FID 0x0800000100000004ULL
> +#define TDX_VENDOR_INTEL 0x8086
> +
> +struct tdg_sys_info {
> + u32 vendor_id;
> + u16 major_version;
> + u16 minor_version;
> +};
> +
> +/*
> + * Fetch TDX Module global-scope metadata field via TDG.SYS.RD TDCALL
> + * Do NOT change it once initialized.
> + */
> +static struct tdg_sys_info td_sys_info;
> +

Why here?

I think we can allocate on stack inside tdx_early_init() and pass down to
tdg_get_sysinfo() to fill. The variable is not needed after
tdx_early_init() returns.


--
Kiryl Shutsemau / Kirill A. Shutemov