Skip to content

Commit 47e67cf

Browse files
kirylhansendc
authored andcommitted
x86/tdx: Relax SEPT_VE_DISABLE check for debug TD
A "SEPT #VE" occurs when a TDX guest touches memory that is not properly mapped into the "secure EPT". This can be the result of hypervisor attacks or bugs, *OR* guest bugs. Most notably, buggy guests might touch unaccepted memory for lots of different memory safety bugs like buffer overflows. TDX guests do not want to continue in the face of hypervisor attacks or hypervisor bugs. They want to terminate as fast and safely as possible. SEPT_VE_DISABLE ensures that TDX guests *can't* continue in the face of these kinds of issues. But, that causes a problem. TDX guests that can't continue can't spit out oopses or other debugging info. In essence SEPT_VE_DISABLE=1 guests are not debuggable. Relax the SEPT_VE_DISABLE check to warning on debug TD and panic() in the #VE handler on EPT-violation on private memory. It will produce useful backtrace. Signed-off-by: Kirill A. Shutemov <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Link: https://lore.kernel.org/all/20230126221159.8635-7-kirill.shutemov%40linux.intel.com
1 parent 71acdcd commit 47e67cf

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

arch/x86/coco/tdx/tdx.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#define VE_GET_PORT_NUM(e) ((e) >> 16)
3939
#define VE_IS_IO_STRING(e) ((e) & BIT(4))
4040

41+
#define ATTR_DEBUG BIT(0)
4142
#define ATTR_SEPT_VE_DISABLE BIT(28)
4243

4344
/* TDX Module call error codes */
@@ -207,8 +208,15 @@ static void tdx_parse_tdinfo(u64 *cc_mask)
207208
* TD-private memory. Only VMM-shared memory (MMIO) will #VE.
208209
*/
209210
td_attr = out.rdx;
210-
if (!(td_attr & ATTR_SEPT_VE_DISABLE))
211-
tdx_panic("TD misconfiguration: SEPT_VE_DISABLE attribute must be set.");
211+
if (!(td_attr & ATTR_SEPT_VE_DISABLE)) {
212+
const char *msg = "TD misconfiguration: SEPT_VE_DISABLE attribute must be set.";
213+
214+
/* Relax SEPT_VE_DISABLE check for debug TD. */
215+
if (td_attr & ATTR_DEBUG)
216+
pr_warn("%s\n", msg);
217+
else
218+
tdx_panic(msg);
219+
}
212220
}
213221

214222
/*
@@ -664,6 +672,11 @@ static int virt_exception_user(struct pt_regs *regs, struct ve_info *ve)
664672
}
665673
}
666674

675+
static inline bool is_private_gpa(u64 gpa)
676+
{
677+
return gpa == cc_mkenc(gpa);
678+
}
679+
667680
/*
668681
* Handle the kernel #VE.
669682
*
@@ -682,6 +695,8 @@ static int virt_exception_kernel(struct pt_regs *regs, struct ve_info *ve)
682695
case EXIT_REASON_CPUID:
683696
return handle_cpuid(regs, ve);
684697
case EXIT_REASON_EPT_VIOLATION:
698+
if (is_private_gpa(ve->gpa))
699+
panic("Unexpected EPT-violation on private memory.");
685700
return handle_mmio(regs, ve);
686701
case EXIT_REASON_IO_INSTRUCTION:
687702
return handle_io(regs, ve);

0 commit comments

Comments
 (0)