Skip to content

Commit

Permalink
x86/virt/tdx: Don't initialize module that doesn't support NO_RBP_MOD…
Browse files Browse the repository at this point in the history
… feature

Old TDX modules can clobber RBP in the TDH.VP.ENTER SEAMCALL.  However
RBP is used as frame pointer in the x86_64 calling convention, and
clobbering RBP could result in bad things like being unable to unwind
the stack if any non-maskable exceptions (NMI, #MC etc) happens in that
gap.

A new "NO_RBP_MOD" feature was introduced to more recent TDX modules to
not clobber RBP.  This feature is reported in the TDX_FEATURES0 global
metadata field via bit 18.

Don't initialize the TDX module if this feature is not supported [1].

Link: https://lore.kernel.org/all/[email protected]/T/#mef98469c51e2382ead2c537ea189752360bd2bef [1]
Signed-off-by: Kai Huang <[email protected]>
  • Loading branch information
kaihuang committed Jun 25, 2024
1 parent 7da0bea commit be294be
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions arch/x86/virt/vmx/tdx/tdx.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,18 @@ static int get_tdx_sysinfo(struct tdx_sysinfo *sysinfo)
return get_tdx_tdmr_sysinfo(&sysinfo->tdmr_info);
}

static int check_module_compatibility(struct tdx_sysinfo *sysinfo)
{
u64 tdx_features0 = sysinfo->module_info.tdx_features0;

if (!(tdx_features0 & TDX_FEATURES0_NO_RBP_MOD)) {
pr_err("NO_RBP_MOD feature is not supported\n");
return -EINVAL;
}

return 0;
}

/* Calculate the actual TDMR size */
static int tdmr_size_single(u16 max_reserved_per_tdmr)
{
Expand Down Expand Up @@ -1304,6 +1316,11 @@ static int init_tdx_module(void)

print_basic_sysinfo(&sysinfo);

/* Check whether the kernel can support this module */
ret = check_module_compatibility(&sysinfo);
if (ret)
return ret;

/*
* To keep things simple, assume that all TDX-protected memory
* will come from the page allocator. Make sure all pages in the
Expand Down
1 change: 1 addition & 0 deletions arch/x86/virt/vmx/tdx/tdx.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ struct tdx_sysinfo_module_info {
};

#define TDX_SYS_ATTR_DEBUG_MODULE 0x1
#define TDX_FEATURES0_NO_RBP_MOD _BITULL(18)

/* Class "TDX Module Version" */
struct tdx_sysinfo_module_version {
Expand Down

0 comments on commit be294be

Please sign in to comment.