Skip to content

Commit 71acdcd

Browse files
kirylhansendc
authored andcommitted
x86/tdx: Use ReportFatalError to report missing SEPT_VE_DISABLE
Linux TDX guests require that the SEPT_VE_DISABLE "attribute" be set. If it is not set, the kernel is theoretically required to handle exceptions anywhere that kernel memory is accessed, including places like NMI handlers and in the syscall entry gap. Rather than even try to handle these exceptions, the kernel refuses to run if SEPT_VE_DISABLE is unset. However, the SEPT_VE_DISABLE detection and refusal code happens very early in boot, even before earlyprintk runs. Calling panic() will effectively just hang the system. Instead, call a TDX-specific panic() function. This makes a very simple TDVMCALL which gets a short error string out to the hypervisor without any console infrastructure. Use TDG.VP.VMCALL<ReportFatalError> to report the error. The hypercall can encode message up to 64 bytes in eight registers. [ dhansen: tweak comment and remove while loop brackets. ] Signed-off-by: Kirill A. Shutemov <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Link: https://lore.kernel.org/all/20230126221159.8635-6-kirill.shutemov%40linux.intel.com
1 parent 752d133 commit 71acdcd

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

arch/x86/coco/tdx/tdx.c

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
/* TDX hypercall Leaf IDs */
2424
#define TDVMCALL_MAP_GPA 0x10001
25+
#define TDVMCALL_REPORT_FATAL_ERROR 0x10003
2526

2627
/* MMIO direction */
2728
#define EPT_READ 0
@@ -140,6 +141,41 @@ int tdx_mcall_get_report0(u8 *reportdata, u8 *tdreport)
140141
}
141142
EXPORT_SYMBOL_GPL(tdx_mcall_get_report0);
142143

144+
static void __noreturn tdx_panic(const char *msg)
145+
{
146+
struct tdx_hypercall_args args = {
147+
.r10 = TDX_HYPERCALL_STANDARD,
148+
.r11 = TDVMCALL_REPORT_FATAL_ERROR,
149+
.r12 = 0, /* Error code: 0 is Panic */
150+
};
151+
union {
152+
/* Define register order according to the GHCI */
153+
struct { u64 r14, r15, rbx, rdi, rsi, r8, r9, rdx; };
154+
155+
char str[64];
156+
} message;
157+
158+
/* VMM assumes '\0' in byte 65, if the message took all 64 bytes */
159+
strncpy(message.str, msg, 64);
160+
161+
args.r8 = message.r8;
162+
args.r9 = message.r9;
163+
args.r14 = message.r14;
164+
args.r15 = message.r15;
165+
args.rdi = message.rdi;
166+
args.rsi = message.rsi;
167+
args.rbx = message.rbx;
168+
args.rdx = message.rdx;
169+
170+
/*
171+
* This hypercall should never return and it is not safe
172+
* to keep the guest running. Call it forever if it
173+
* happens to return.
174+
*/
175+
while (1)
176+
__tdx_hypercall(&args, 0);
177+
}
178+
143179
static void tdx_parse_tdinfo(u64 *cc_mask)
144180
{
145181
struct tdx_module_output out;
@@ -172,7 +208,7 @@ static void tdx_parse_tdinfo(u64 *cc_mask)
172208
*/
173209
td_attr = out.rdx;
174210
if (!(td_attr & ATTR_SEPT_VE_DISABLE))
175-
panic("TD misconfiguration: SEPT_VE_DISABLE attibute must be set.\n");
211+
tdx_panic("TD misconfiguration: SEPT_VE_DISABLE attribute must be set.");
176212
}
177213

178214
/*

0 commit comments

Comments
 (0)