Skip to content

Commit 113691c

Browse files
committed
Merge tag 'x86_tdx_for_6.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 TDX updates from Dave Hansen: "Intel Trust Domain updates. The existing TDX code needs a _bit_ of metadata from the TDX module. But KVM is going to need a bunch more very shortly. Rework the interface with the TDX module to be more consistent and handle the new higher volume. The TDX module has added a few new features. The first is a promise not to clobber RBP under any circumstances. Basically the kernel now will refuse to use any modules that don't have this promise. Second, enable the new "REDUCE_VE" feature. This ensures that the TDX module will not send some silly virtualization exceptions that the guest had no good way to handle anyway. - Centralize global metadata infrastructure - Use new TDX module features for exception suppression and RBP clobbering" * tag 'x86_tdx_for_6.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/virt/tdx: Require the module to assert it has the NO_RBP_MOD mitigation x86/virt/tdx: Switch to use auto-generated global metadata reading code x86/virt/tdx: Use dedicated struct members for PAMT entry sizes x86/virt/tdx: Use auto-generated code to read global metadata x86/virt/tdx: Start to track all global metadata in one structure x86/virt/tdx: Rename 'struct tdx_tdmr_sysinfo' to reflect the spec better x86/tdx: Dump attributes and TD_CTLS on boot x86/tdx: Disable unnecessary virtualization exceptions
2 parents 5b7f723 + 6f5c71c commit 113691c

File tree

9 files changed

+252
-112
lines changed

9 files changed

+252
-112
lines changed

arch/x86/coco/tdx/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# SPDX-License-Identifier: GPL-2.0
22

3-
obj-y += tdx.o tdx-shared.o tdcall.o
3+
obj-y += debug.o tdcall.o tdx.o tdx-shared.o

arch/x86/coco/tdx/debug.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#undef pr_fmt
4+
#define pr_fmt(fmt) "tdx: " fmt
5+
6+
#include <linux/array_size.h>
7+
#include <linux/printk.h>
8+
#include <asm/tdx.h>
9+
10+
#define DEF_TDX_ATTR_NAME(_name) [TDX_ATTR_##_name##_BIT] = __stringify(_name)
11+
12+
static __initdata const char *tdx_attributes[] = {
13+
DEF_TDX_ATTR_NAME(DEBUG),
14+
DEF_TDX_ATTR_NAME(HGS_PLUS_PROF),
15+
DEF_TDX_ATTR_NAME(PERF_PROF),
16+
DEF_TDX_ATTR_NAME(PMT_PROF),
17+
DEF_TDX_ATTR_NAME(ICSSD),
18+
DEF_TDX_ATTR_NAME(LASS),
19+
DEF_TDX_ATTR_NAME(SEPT_VE_DISABLE),
20+
DEF_TDX_ATTR_NAME(MIGRTABLE),
21+
DEF_TDX_ATTR_NAME(PKS),
22+
DEF_TDX_ATTR_NAME(KL),
23+
DEF_TDX_ATTR_NAME(TPA),
24+
DEF_TDX_ATTR_NAME(PERFMON),
25+
};
26+
27+
#define DEF_TD_CTLS_NAME(_name) [TD_CTLS_##_name##_BIT] = __stringify(_name)
28+
29+
static __initdata const char *tdcs_td_ctls[] = {
30+
DEF_TD_CTLS_NAME(PENDING_VE_DISABLE),
31+
DEF_TD_CTLS_NAME(ENUM_TOPOLOGY),
32+
DEF_TD_CTLS_NAME(VIRT_CPUID2),
33+
DEF_TD_CTLS_NAME(REDUCE_VE),
34+
DEF_TD_CTLS_NAME(LOCK),
35+
};
36+
37+
void __init tdx_dump_attributes(u64 td_attr)
38+
{
39+
pr_info("Attributes:");
40+
41+
for (int i = 0; i < ARRAY_SIZE(tdx_attributes); i++) {
42+
if (!tdx_attributes[i])
43+
continue;
44+
if (td_attr & BIT(i))
45+
pr_cont(" %s", tdx_attributes[i]);
46+
td_attr &= ~BIT(i);
47+
}
48+
49+
if (td_attr)
50+
pr_cont(" unknown:%#llx", td_attr);
51+
pr_cont("\n");
52+
53+
}
54+
55+
void __init tdx_dump_td_ctls(u64 td_ctls)
56+
{
57+
pr_info("TD_CTLS:");
58+
59+
for (int i = 0; i < ARRAY_SIZE(tdcs_td_ctls); i++) {
60+
if (!tdcs_td_ctls[i])
61+
continue;
62+
if (td_ctls & BIT(i))
63+
pr_cont(" %s", tdcs_td_ctls[i]);
64+
td_ctls &= ~BIT(i);
65+
}
66+
if (td_ctls)
67+
pr_cont(" unknown:%#llx", td_ctls);
68+
pr_cont("\n");
69+
}

arch/x86/coco/tdx/tdx.c

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@
3232
#define VE_GET_PORT_NUM(e) ((e) >> 16)
3333
#define VE_IS_IO_STRING(e) ((e) & BIT(4))
3434

35-
#define ATTR_DEBUG BIT(0)
36-
#define ATTR_SEPT_VE_DISABLE BIT(28)
37-
3835
/* TDX Module call error codes */
3936
#define TDCALL_RETURN_CODE(a) ((a) >> 32)
4037
#define TDCALL_INVALID_OPERAND 0xc0000100
@@ -200,14 +197,14 @@ static void __noreturn tdx_panic(const char *msg)
200197
*
201198
* TDX 1.0 does not allow the guest to disable SEPT #VE on its own. The VMM
202199
* controls if the guest will receive such #VE with TD attribute
203-
* ATTR_SEPT_VE_DISABLE.
200+
* TDX_ATTR_SEPT_VE_DISABLE.
204201
*
205202
* Newer TDX modules allow the guest to control if it wants to receive SEPT
206203
* violation #VEs.
207204
*
208205
* Check if the feature is available and disable SEPT #VE if possible.
209206
*
210-
* If the TD is allowed to disable/enable SEPT #VEs, the ATTR_SEPT_VE_DISABLE
207+
* If the TD is allowed to disable/enable SEPT #VEs, the TDX_ATTR_SEPT_VE_DISABLE
211208
* attribute is no longer reliable. It reflects the initial state of the
212209
* control for the TD, but it will not be updated if someone (e.g. bootloader)
213210
* changes it before the kernel starts. Kernel must check TDCS_TD_CTLS bit to
@@ -216,14 +213,14 @@ static void __noreturn tdx_panic(const char *msg)
216213
static void disable_sept_ve(u64 td_attr)
217214
{
218215
const char *msg = "TD misconfiguration: SEPT #VE has to be disabled";
219-
bool debug = td_attr & ATTR_DEBUG;
216+
bool debug = td_attr & TDX_ATTR_DEBUG;
220217
u64 config, controls;
221218

222219
/* Is this TD allowed to disable SEPT #VE */
223220
tdg_vm_rd(TDCS_CONFIG_FLAGS, &config);
224221
if (!(config & TDCS_CONFIG_FLEXIBLE_PENDING_VE)) {
225222
/* No SEPT #VE controls for the guest: check the attribute */
226-
if (td_attr & ATTR_SEPT_VE_DISABLE)
223+
if (td_attr & TDX_ATTR_SEPT_VE_DISABLE)
227224
return;
228225

229226
/* Relax SEPT_VE_DISABLE check for debug TD for backtraces */
@@ -274,6 +271,20 @@ static void enable_cpu_topology_enumeration(void)
274271
tdg_vm_wr(TDCS_TD_CTLS, TD_CTLS_ENUM_TOPOLOGY, TD_CTLS_ENUM_TOPOLOGY);
275272
}
276273

274+
static void reduce_unnecessary_ve(void)
275+
{
276+
u64 err = tdg_vm_wr(TDCS_TD_CTLS, TD_CTLS_REDUCE_VE, TD_CTLS_REDUCE_VE);
277+
278+
if (err == TDX_SUCCESS)
279+
return;
280+
281+
/*
282+
* Enabling REDUCE_VE includes ENUM_TOPOLOGY. Only try to
283+
* enable ENUM_TOPOLOGY if REDUCE_VE was not successful.
284+
*/
285+
enable_cpu_topology_enumeration();
286+
}
287+
277288
static void tdx_setup(u64 *cc_mask)
278289
{
279290
struct tdx_module_args args = {};
@@ -305,7 +316,8 @@ static void tdx_setup(u64 *cc_mask)
305316
tdg_vm_wr(TDCS_NOTIFY_ENABLES, 0, -1ULL);
306317

307318
disable_sept_ve(td_attr);
308-
enable_cpu_topology_enumeration();
319+
320+
reduce_unnecessary_ve();
309321
}
310322

311323
/*
@@ -1025,6 +1037,20 @@ static void tdx_kexec_finish(void)
10251037
}
10261038
}
10271039

1040+
static __init void tdx_announce(void)
1041+
{
1042+
struct tdx_module_args args = {};
1043+
u64 controls;
1044+
1045+
pr_info("Guest detected\n");
1046+
1047+
tdcall(TDG_VP_INFO, &args);
1048+
tdx_dump_attributes(args.rdx);
1049+
1050+
tdg_vm_rd(TDCS_TD_CTLS, &controls);
1051+
tdx_dump_td_ctls(controls);
1052+
}
1053+
10281054
void __init tdx_early_init(void)
10291055
{
10301056
u64 cc_mask;
@@ -1094,5 +1120,5 @@ void __init tdx_early_init(void)
10941120
*/
10951121
x86_cpuinit.parallel_bringup = false;
10961122

1097-
pr_info("Guest detected\n");
1123+
tdx_announce();
10981124
}

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

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,32 @@
1919
#define TDG_VM_RD 7
2020
#define TDG_VM_WR 8
2121

22+
/* TDX attributes */
23+
#define TDX_ATTR_DEBUG_BIT 0
24+
#define TDX_ATTR_DEBUG BIT_ULL(TDX_ATTR_DEBUG_BIT)
25+
#define TDX_ATTR_HGS_PLUS_PROF_BIT 4
26+
#define TDX_ATTR_HGS_PLUS_PROF BIT_ULL(TDX_ATTR_HGS_PLUS_PROF_BIT)
27+
#define TDX_ATTR_PERF_PROF_BIT 5
28+
#define TDX_ATTR_PERF_PROF BIT_ULL(TDX_ATTR_PERF_PROF_BIT)
29+
#define TDX_ATTR_PMT_PROF_BIT 6
30+
#define TDX_ATTR_PMT_PROF BIT_ULL(TDX_ATTR_PMT_PROF_BIT)
31+
#define TDX_ATTR_ICSSD_BIT 16
32+
#define TDX_ATTR_ICSSD BIT_ULL(TDX_ATTR_ICSSD_BIT)
33+
#define TDX_ATTR_LASS_BIT 27
34+
#define TDX_ATTR_LASS BIT_ULL(TDX_ATTR_LASS_BIT)
35+
#define TDX_ATTR_SEPT_VE_DISABLE_BIT 28
36+
#define TDX_ATTR_SEPT_VE_DISABLE BIT_ULL(TDX_ATTR_SEPT_VE_DISABLE_BIT)
37+
#define TDX_ATTR_MIGRTABLE_BIT 29
38+
#define TDX_ATTR_MIGRTABLE BIT_ULL(TDX_ATTR_MIGRTABLE_BIT)
39+
#define TDX_ATTR_PKS_BIT 30
40+
#define TDX_ATTR_PKS BIT_ULL(TDX_ATTR_PKS_BIT)
41+
#define TDX_ATTR_KL_BIT 31
42+
#define TDX_ATTR_KL BIT_ULL(TDX_ATTR_KL_BIT)
43+
#define TDX_ATTR_TPA_BIT 62
44+
#define TDX_ATTR_TPA BIT_ULL(TDX_ATTR_TPA_BIT)
45+
#define TDX_ATTR_PERFMON_BIT 63
46+
#define TDX_ATTR_PERFMON BIT_ULL(TDX_ATTR_PERFMON_BIT)
47+
2248
/* TDX TD-Scope Metadata. To be used by TDG.VM.WR and TDG.VM.RD */
2349
#define TDCS_CONFIG_FLAGS 0x1110000300000016
2450
#define TDCS_TD_CTLS 0x1110000300000017
@@ -29,8 +55,16 @@
2955
#define TDCS_CONFIG_FLEXIBLE_PENDING_VE BIT_ULL(1)
3056

3157
/* TDCS_TD_CTLS bits */
32-
#define TD_CTLS_PENDING_VE_DISABLE BIT_ULL(0)
33-
#define TD_CTLS_ENUM_TOPOLOGY BIT_ULL(1)
58+
#define TD_CTLS_PENDING_VE_DISABLE_BIT 0
59+
#define TD_CTLS_PENDING_VE_DISABLE BIT_ULL(TD_CTLS_PENDING_VE_DISABLE_BIT)
60+
#define TD_CTLS_ENUM_TOPOLOGY_BIT 1
61+
#define TD_CTLS_ENUM_TOPOLOGY BIT_ULL(TD_CTLS_ENUM_TOPOLOGY_BIT)
62+
#define TD_CTLS_VIRT_CPUID2_BIT 2
63+
#define TD_CTLS_VIRT_CPUID2 BIT_ULL(TD_CTLS_VIRT_CPUID2_BIT)
64+
#define TD_CTLS_REDUCE_VE_BIT 3
65+
#define TD_CTLS_REDUCE_VE BIT_ULL(TD_CTLS_REDUCE_VE_BIT)
66+
#define TD_CTLS_LOCK_BIT 63
67+
#define TD_CTLS_LOCK BIT_ULL(TD_CTLS_LOCK_BIT)
3468

3569
/* TDX hypercall Leaf IDs */
3670
#define TDVMCALL_MAP_GPA 0x10001

arch/x86/include/asm/tdx.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ int tdx_mcall_get_report0(u8 *reportdata, u8 *tdreport);
6666

6767
u64 tdx_hcall_get_quote(u8 *buf, size_t size);
6868

69+
void __init tdx_dump_attributes(u64 td_attr);
70+
void __init tdx_dump_td_ctls(u64 td_ctls);
71+
6972
#else
7073

7174
static inline void tdx_early_init(void) { };

0 commit comments

Comments
 (0)