Skip to content
Permalink
Browse files
x86/cpu: Do logical cpu level TDX module initialization
Logical cpu level initialization requires calling TDH.SYS.LP.INIT on all
logical cpus reported by BIOS, otherwise the SEAMCALL of next step
initialization will fail.  TDH.SYS.LP.INIT can be called concurrently
on all cpus.

Call TDH.SYS.LP.INIT on all online cpus via on_each_cpu().  To keep it
simple, skip the check of whether all cpus reported by BIOS are online
and return error early, but let the SEAMCALL of next step to fail.

Signed-off-by: Kai Huang <kai.huang@intel.com>
  • Loading branch information
kaihuang authored and yamahata committed Feb 8, 2022
1 parent b70d8dc commit 474e0c5f940be499b7c8996ba8e64c31f56d21fe
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
@@ -142,6 +142,28 @@ static int init_tdx_module_global(void)
return tdh_sys_init();
}

/* SMP call function to run TDH.SYS.LP.INIT */
static void smp_call_tdx_cpu_init(void *data)
{
atomic_t *err = (atomic_t *)err;

if (tdh_sys_lp_init())
atomic_set(err, -1);
}

static int init_tdx_module_cpus(void)
{
/*
* Logical cpu level initialization requires call
* TDH.SYS.LP.INIT on all cpus reported by BIOS,
* otherwise SEAMCALL of next step will fail.
*
* Caller to guarantee all cpus reported by BIOS
* are online.
*/
return tdx_on_each_cpu(smp_call_tdx_cpu_init);
}

/* Initialize the TDX module. */
static int init_tdx_module(void)
{
@@ -152,6 +174,11 @@ static int init_tdx_module(void)
if (ret)
goto out;

/* Logical cpu level initialization */
ret = init_tdx_module_cpus();
if (ret)
goto out;

ret = -EFAULT;
out:
return ret;
@@ -13,6 +13,7 @@

/* TDX module SEAMCALL leaf function numbers */
#define TDH_SYS_INIT 33
#define TDH_SYS_LP_INIT 35
#define TDH_SYS_LP_SHUTDOWN 44

static inline int tdh_sys_init(void)
@@ -28,6 +29,16 @@ static inline int tdh_sys_init(void)
return ret;
}

static inline int tdh_sys_lp_init(void)
{
int ret;

ret = tdx_seamcall(TDH_SYS_LP_INIT, NULL, NULL, NULL);
/* TDH.SYS.LP.INIT should not fail. WARN_ON() if it does. */
WARN_ON(ret);
return ret;
}

static inline int tdh_sys_lp_shutdown(void)
{
int ret;

0 comments on commit 474e0c5

Please sign in to comment.