Skip to content
Permalink
Browse files
x86/cpu: make init_tdx() system wide info about TDX module
TDX KVM needs system-wide information about the TDX module, struct
tdsysinfo_struct.  Make init_tdx() return it instead of KVM getting it with
various error checks.  Move out the struct definition about it to common
place tdx_host.h.

Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
  • Loading branch information
yamahata committed Feb 8, 2022
1 parent 8a00e0c commit 13dd0fa9c0ba8880c196a8feecd826f4c16b18f8
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 46 deletions.
@@ -8,13 +8,56 @@
#define _ASM_X86_TDX_HOST_H

#ifdef CONFIG_INTEL_TDX_HOST
struct tdx_cpuid_config {
u32 leaf;
u32 sub_leaf;
u32 eax;
u32 ebx;
u32 ecx;
u32 edx;
} __packed;

#define TDSYSINFO_STRUCT_ALIGNMENT 1024
struct tdsysinfo_struct {
/* TDX-SEAM Module Info */
u32 attributes;
u32 vendor_id;
u32 build_date;
u16 build_num;
u16 minor_version;
u16 major_version;
u8 reserved0[14];
/* Memory Info */
u16 max_tdmrs;
u16 max_reserved_per_tdmr;
u16 pamt_entry_size;
u8 reserved1[10];
/* Control Struct Info */
u16 tdcs_base_size;
u8 reserved2[2];
u16 tdvps_base_size;
u8 tdvps_xfam_dependent_size;
u8 reserved3[9];
/* TD Capabilities */
u64 attributes_fixed0;
u64 attributes_fixed1;
u64 xfam_fixed0;
u64 xfam_fixed1;
u8 reserved4[32];
u32 num_cpuid_config;
union {
struct tdx_cpuid_config cpuid_configs[0];
u8 reserved5[892];
};
} __packed __aligned(TDSYSINFO_STRUCT_ALIGNMENT);

void detect_tdx_keyids(struct cpuinfo_x86 *c);
int detect_tdx(void);
int init_tdx(void);
int init_tdx(struct tdsysinfo_struct *r);
#else
static inline void detect_tdx_keyids(struct cpuinfo_x86 *c) { }
static inline int detect_tdx(void) { return -ENODEV; }
static inline int init_tdx(void) { return -ENODEV; }
static inline int init_tdx(struct tdsysinfo_struct *r) { return -ENODEV; }
#endif /* CONFIG_INTEL_TDX_HOST */

#endif /* _ASM_X86_TDX_HOST_H */
@@ -16,6 +16,7 @@
#include <linux/sort.h>
#include <asm/e820/api.h>
#include <asm/pgtable.h>
#include <asm/tdx_host.h>
#include "tdmr.h"

/*
@@ -674,7 +674,7 @@ EXPORT_SYMBOL_GPL(detect_tdx);
* * -ENODEV: The TDX module is not loaded.
* * -EFAULT: Fatal error during TDX module initialization.
*/
int init_tdx(void)
int init_tdx(struct tdsysinfo_struct *r)
{
int ret;

@@ -698,6 +698,8 @@ int init_tdx(void)
ret = -EFAULT;
break;
}
if (r && !ret)
*r = tdx_sysinfo;
mutex_unlock(&tdx_module_lock);

return ret;
@@ -19,49 +19,6 @@ struct cmr_info {
#define MAX_CMRS 32
#define CMR_INFO_ARRAY_ALIGNMENT 512

struct cpuid_config {
u32 leaf;
u32 sub_leaf;
u32 eax;
u32 ebx;
u32 ecx;
u32 edx;
} __packed;

#define TDSYSINFO_STRUCT_ALIGNMENT 1024
struct tdsysinfo_struct {
/* TDX-SEAM Module Info */
u32 attributes;
u32 vendor_id;
u32 build_date;
u16 build_num;
u16 minor_version;
u16 major_version;
u8 reserved0[14];
/* Memory Info */
u16 max_tdmrs;
u16 max_reserved_per_tdmr;
u16 pamt_entry_size;
u8 reserved1[10];
/* Control Struct Info */
u16 tdcs_base_size;
u8 reserved2[2];
u16 tdvps_base_size;
u8 tdvps_xfam_dependent_size;
u8 reserved3[9];
/* TD Capabilities */
u64 attributes_fixed0;
u64 attributes_fixed1;
u64 xfam_fixed0;
u64 xfam_fixed1;
u8 reserved4[32];
u32 num_cpuid_config;
union {
struct cpuid_config cpuid_configs[0];
u8 reserved5[892];
};
} __packed __aligned(TDSYSINFO_STRUCT_ALIGNMENT);

struct tdmr_reserved_area {
u64 offset;
u64 size;

0 comments on commit 13dd0fa

Please sign in to comment.