2024-05-12 14:51:23

by Kirill A. Shutemov

[permalink] [raw]
Subject: [PATCHv4 0/4] x86/tdx: Adjust TD settings on boot

The patchset adjusts a few TD settings on boot for the optimal functioning
of the system:

- Disable EPT violation #VE on private memory if TD can control it

The newer TDX module allows the guest to control whether it wants to
see #VE on EPT violation on private memory. The Linux kernel does not
want such #VEs and needs to disable them.

- Enable virtualization of topology-related CPUID leafs X2APIC_APICID MSR;

The ENUM_TOPOLOGY feature allows the VMM to provide topology
information to the guest. Enabling the feature eliminates
topology-related #VEs: the TDX module virtualizes accesses to the
CPUID leafs and the MSR.

It allows TDX guest to run with non-trivial topology configuration.

v4:
- Drop unnecessary enumeration;
- Drop TDG.SYS.RD wrapper;
- CC stable@ for SEPT disable patch;
- Update commit messages;
v3:
- Update commit messages;
- Rework patches 3/4 and 4/4;
v2:
- Rebased;
- Allow write to TDCS_TD_CTLS to fail;
- Adjust commit messages;

Kirill A. Shutemov (4):
x86/tdx: Factor out TD metadata write TDCALL
x86/tdx: Rename tdx_parse_tdinfo() to tdx_setup()
x86/tdx: Dynamically disable SEPT violations from causing #VEs
x86/tdx: Enable CPU topology enumeration

arch/x86/coco/tdx/tdx.c | 140 +++++++++++++++++++++++++-----
arch/x86/include/asm/shared/tdx.h | 13 ++-
2 files changed, 130 insertions(+), 23 deletions(-)

--
2.43.0



2024-05-12 16:31:30

by Kirill A. Shutemov

[permalink] [raw]
Subject: [PATCHv4 2/4] x86/tdx: Rename tdx_parse_tdinfo() to tdx_setup()

Rename tdx_parse_tdinfo() to tdx_setup() and move setting NOTIFY_ENABLES
there.

The function will be extended to adjust TD configuration.

Signed-off-by: Kirill A. Shutemov <[email protected]>
Reviewed-by: Kuppuswamy Sathyanarayanan <[email protected]>
Reviewed-by: Kai Huang <[email protected]>
Cc: [email protected]
---
arch/x86/coco/tdx/tdx.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c
index 4bb786dcd6b4..1ff571cb9177 100644
--- a/arch/x86/coco/tdx/tdx.c
+++ b/arch/x86/coco/tdx/tdx.c
@@ -179,7 +179,7 @@ static void __noreturn tdx_panic(const char *msg)
__tdx_hypercall(&args);
}

-static void tdx_parse_tdinfo(u64 *cc_mask)
+static void tdx_setup(u64 *cc_mask)
{
struct tdx_module_args args = {};
unsigned int gpa_width;
@@ -204,6 +204,9 @@ static void tdx_parse_tdinfo(u64 *cc_mask)
gpa_width = args.rcx & GENMASK(5, 0);
*cc_mask = BIT_ULL(gpa_width - 1);

+ /* Kernel does not use NOTIFY_ENABLES and does not need random #VEs */
+ tdg_vm_wr(TDCS_NOTIFY_ENABLES, 0, -1ULL);
+
/*
* The kernel can not handle #VE's when accessing normal kernel
* memory. Ensure that no #VE will be delivered for accesses to
@@ -927,11 +930,11 @@ void __init tdx_early_init(void)
setup_force_cpu_cap(X86_FEATURE_TSC_RELIABLE);

cc_vendor = CC_VENDOR_INTEL;
- tdx_parse_tdinfo(&cc_mask);
- cc_set_mask(cc_mask);

- /* Kernel does not use NOTIFY_ENABLES and does not need random #VEs */
- tdg_vm_wr(TDCS_NOTIFY_ENABLES, 0, -1ULL);
+ /* Configure the TD */
+ tdx_setup(&cc_mask);
+
+ cc_set_mask(cc_mask);

/*
* All bits above GPA width are reserved and kernel treats shared bit
--
2.43.0