Skip to content

Commit

Permalink
x86/cpu: Do logical cpu level TDX module initialization
Browse files Browse the repository at this point in the history
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 committed Jan 25, 2022
1 parent 9e0be81 commit b9feae7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
27 changes: 27 additions & 0 deletions arch/x86/kernel/cpu/tdx/tdx.c
Expand Up @@ -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)
{
Expand All @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions arch/x86/kernel/cpu/tdx/tdx_seamcall.h
Expand Up @@ -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)
Expand All @@ -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;
Expand Down

0 comments on commit b9feae7

Please sign in to comment.