Skip to content

Commit cd9ce82

Browse files
kirylhansendc
authored andcommitted
x86/tdx: Disable unnecessary virtualization exceptions
Originally, #VE was defined as the TDX behavior in order to support paravirtualization of x86 features that can’t be virtualized by the TDX module. The intention is that if guest software wishes to use such a feature, it implements some logic to support this. This logic resides in the #VE exception handler it may work in cooperation with the host VMM. Theoretically, the guest TD’s #VE handler was supposed to act as a "TDX enlightenment agent" inside the TD. However, in practice, the #VE handler is simplistic: - #VE on CPUID is handled by returning all-0 to the code which executed CPUID. In many cases, an all-0 value is not the correct value, and may cause improper operation. - #VE on RDMSR is handled by requesting the MSR value from the host VMM. This is prone to security issues since the host VMM is untrusted. It may also be functionally incorrect in case the expected operation is to paravirtualize some CPU functionality. Newer TDX modules provide a "REDUCE_VE" feature. When enabled, it drastically cuts cases when guests receive #VE on MSR and CPUID accesses. Basically, instead of punting the problem to the VMM, the TDX module fills in good data. What the TDX module provides is obviously highly specific to the MSR or CPUID. This is all spelled out in excruciating detail in the TDX specs. Enable REDUCE_VE. Make TDX guest behaviour less odd, and closer to how a normal CPU behaves. Note that enabling of the feature doesn't eliminate need in #VE handler for CPUID and MSR accesses. Some MSRs still generate #VE (notably APIC-related) and kernel needs CPUID #VE handler to ask VMM for leafs in hypervisor range. [ dhansen: changelog tweaks, rename/rework VE reduction function ] Signed-off-by: Kirill A. Shutemov <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Reviewed-by: Nikolay Borisov <[email protected]> Link: https://lore.kernel.org/all/20241202072431.447380-1-kirill.shutemov%40linux.intel.com
1 parent 40384c8 commit cd9ce82

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

arch/x86/coco/tdx/tdx.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,20 @@ static void enable_cpu_topology_enumeration(void)
274274
tdg_vm_wr(TDCS_TD_CTLS, TD_CTLS_ENUM_TOPOLOGY, TD_CTLS_ENUM_TOPOLOGY);
275275
}
276276

277+
static void reduce_unnecessary_ve(void)
278+
{
279+
u64 err = tdg_vm_wr(TDCS_TD_CTLS, TD_CTLS_REDUCE_VE, TD_CTLS_REDUCE_VE);
280+
281+
if (err == TDX_SUCCESS)
282+
return;
283+
284+
/*
285+
* Enabling REDUCE_VE includes ENUM_TOPOLOGY. Only try to
286+
* enable ENUM_TOPOLOGY if REDUCE_VE was not successful.
287+
*/
288+
enable_cpu_topology_enumeration();
289+
}
290+
277291
static void tdx_setup(u64 *cc_mask)
278292
{
279293
struct tdx_module_args args = {};
@@ -305,7 +319,8 @@ static void tdx_setup(u64 *cc_mask)
305319
tdg_vm_wr(TDCS_NOTIFY_ENABLES, 0, -1ULL);
306320

307321
disable_sept_ve(td_attr);
308-
enable_cpu_topology_enumeration();
322+
323+
reduce_unnecessary_ve();
309324
}
310325

311326
/*

arch/x86/include/asm/shared/tdx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
/* TDCS_TD_CTLS bits */
3232
#define TD_CTLS_PENDING_VE_DISABLE BIT_ULL(0)
3333
#define TD_CTLS_ENUM_TOPOLOGY BIT_ULL(1)
34+
#define TD_CTLS_REDUCE_VE BIT_ULL(3)
3435

3536
/* TDX hypercall Leaf IDs */
3637
#define TDVMCALL_MAP_GPA 0x10001

0 commit comments

Comments
 (0)