commit e3907269b34e4f488284f35716f231da7bc3e6b3 Author: Kai Huang Date: Thu May 23 23:17:28 2024 +1200 x86/virt/tdx: check NO_RBP_MOD and print module version Signed-off-by: Kai Huang diff --git a/arch/x86/virt/vmx/tdx/tdx.c b/arch/x86/virt/vmx/tdx/tdx.c index 4d6826a76f78..ffc1c27b9134 100644 --- a/arch/x86/virt/vmx/tdx/tdx.c +++ b/arch/x86/virt/vmx/tdx/tdx.c @@ -1097,11 +1097,60 @@ static int init_tdmrs(struct tdmr_info_list *tdmr_list) return 0; } +static int check_module_compatibility(void) +{ + u64 tdx_features0; + int ret; + + ret = read_sys_metadata_field(MD_FIELD_ID_TDX_FEATURES0, + &tdx_features0); + + if (ret) + return ret; + + if (!(tdx_features0 & TDX_FEATURES0_NO_RBP_MOD)) { + pr_err("NO_RBP_MOD feature is not supported\n"); + return -EINVAL; + } + + return 0; +} + +static void print_tdx_version(void) +{ + u64 major, minor, update, internal; + int ret; + + ret = read_sys_metadata_field(MD_FIELD_ID_MAJOR_VERSION, &major); + if (ret) + return; + + ret = read_sys_metadata_field(MD_FIELD_ID_MINOR_VERSION, &minor); + if (ret) + return; + + ret = read_sys_metadata_field(MD_FIELD_ID_UPDATE_VERSION, &update); + if (ret) + return; + + ret = read_sys_metadata_field(MD_FIELD_ID_INTERNAL_VERSION, &internal); + if (ret) + return; + + pr_info("module verson: %u.%u.%u.%u\n", + (u16)major, (u16)minor, (u16)update, (u16)internal); +} + static int init_tdx_module(void) { struct tdx_tdmr_sysinfo tdmr_sysinfo; int ret; + /* Make sure TDX module meets kernel's expectation */ + ret = check_module_compatibility(); + if (ret) + goto out; + /* * To keep things simple, assume that all TDX-protected memory * will come from the page allocator. Make sure all pages in the @@ -1155,6 +1204,10 @@ static int init_tdx_module(void) * Lock out memory hotplug code while building it. */ put_online_mems(); + +out: + print_tdx_version(); + return ret; err_reset_pamts: diff --git a/arch/x86/virt/vmx/tdx/tdx.h b/arch/x86/virt/vmx/tdx/tdx.h index b701f69485d3..13ad52352e35 100644 --- a/arch/x86/virt/vmx/tdx/tdx.h +++ b/arch/x86/virt/vmx/tdx/tdx.h @@ -37,6 +37,14 @@ #define MD_FIELD_ID_PAMT_2M_ENTRY_SIZE 0x9100000100000011ULL #define MD_FIELD_ID_PAMT_1G_ENTRY_SIZE 0x9100000100000012ULL +#define MD_FIELD_ID_TDX_FEATURES0 0x0A00000300000008ULL +#define TDX_FEATURES0_NO_RBP_MOD BIT_ULL(18) + +#define MD_FIELD_ID_MINOR_VERSION 0x0800000100000003ULL +#define MD_FIELD_ID_MAJOR_VERSION 0x0800000100000004ULL +#define MD_FIELD_ID_UPDATE_VERSION 0x0800000100000005ULL +#define MD_FIELD_ID_INTERNAL_VERSION 0x0800000100000006ULL + /* * Sub-field definition of metadata field ID. *