All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] x86/crash: Disable SGX in the kdump kernel
@ 2026-11-13  3:50 Yuanhe Shu
  2026-11-13  3:58 ` sashiko-bot
  2026-11-13  4:15 ` Borislav Petkov
  0 siblings, 2 replies; 4+ messages in thread
From: Yuanhe Shu @ 2026-11-13  3:50 UTC (permalink / raw)
  To: jarkko, dave.hansen, tglx, mingo, bp, hpa
  Cc: x86, linux-sgx, linux-kernel, kexec, challvy.tee, xiangzao

The kdump capture kernel cannot use SGX: EPC memory is e820-reserved,
so it is not part of the crash dump, and no enclave will ever run
during dump capture.  Yet sgx_init() runs unconditionally and pays the
full EPC bookkeeping: sgx_setup_epc_section() allocates one struct
sgx_epc_page (32 bytes) per 4K EPC page, i.e. EPC/128, plus a memremap
of the whole EPC range.

The capture kernel has no memory other than the crashkernel
reservation.  On a VM with 15.5G EPC the bookkeeping alone costs
124 MB of vmalloc - nearly half of the stock crashkernel=256M -
and the cost scales with EPC size, not RAM.

That is enough to break kdump outright: with the default 256M the
capture kernel OOMs in early userspace (udevadm and journald are killed
before the root device is enumerated) and no vmcore is produced, while
512M works.  With this change the same 256M reservation captures a
complete vmcore; SGX initializes as usual on normal boots.

Clear X86_FEATURE_SGX from an x86 early handler for elfcorehdr=, which
only the capture kernel receives, so sgx_init() bails out on its
existing capability check and no kdump knowledge leaks into the SGX
code.  Like nosgx, it has to be an early parameter: clearing a feature
after alternatives are patched is too late.

Reported-by: Challvy Tee <challvy.tee@gmail.com>
Suggested-by: Dave Hansen <dave.hansen@linux.intel.com>
Signed-off-by: Yuanhe Shu <xiangzao@linux.alibaba.com>
---
v1: https://lore.kernel.org/r/20261111123942.3842771-1-xiangzao@linux.alibaba.com/

- Clear X86_FEATURE_SGX from an x86 elfcorehdr= early handler instead
  of checking is_kdump_kernel() in sgx_init() (Dave Hansen); retitled
  to x86/crash accordingly.

 arch/x86/kernel/crash_dump_64.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
index 32d710f7eb84..4a275b969f3c 100644
--- a/arch/x86/kernel/crash_dump_64.c
+++ b/arch/x86/kernel/crash_dump_64.c
@@ -12,6 +12,8 @@
 #include <linux/io.h>
 #include <linux/cc_platform.h>
 
+#include <asm/cpufeature.h>
+
 static ssize_t __copy_oldmem_page(struct iov_iter *iter, unsigned long pfn,
 				  size_t csize, unsigned long offset,
 				  bool encrypted)
@@ -62,3 +64,15 @@ ssize_t elfcorehdr_read(char *buf, size_t count, u64 *ppos)
 	return read_from_oldmem(&iter, count, ppos,
 				cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT));
 }
+
+/*
+ * elfcorehdr= is passed only to the capture kernel.  Turn off the
+ * features it has no use for.
+ */
+static int __init kdump_disable_features(char *arg)
+{
+	/* SGX metadata for a large EPC can exhaust crashkernel memory. */
+	setup_clear_cpu_cap(X86_FEATURE_SGX);
+	return 0;
+}
+early_param("elfcorehdr", kdump_disable_features);
-- 
2.43.7


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-13  5:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-13  3:50 [PATCH v2] x86/crash: Disable SGX in the kdump kernel Yuanhe Shu
2026-11-13  3:58 ` sashiko-bot
2026-11-13  4:15 ` Borislav Petkov
2026-11-13  5:57   ` Yuanhe Shu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.