* [PATCH] x86/sgx: Skip EPC initialization in the kdump kernel
@ 2026-11-11 12:39 Yuanhe Shu
2026-11-11 15:06 ` Dave Hansen
0 siblings, 1 reply; 2+ messages in thread
From: Yuanhe Shu @ 2026-11-11 12:39 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.
Reported-by: Challvy Tee <challvy.tee@gmail.com>
Signed-off-by: Yuanhe Shu <xiangzao@linux.alibaba.com>
---
arch/x86/kernel/cpu/sgx/main.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c
index 4505f808af5e..5454cd3c976f 100644
--- a/arch/x86/kernel/cpu/sgx/main.c
+++ b/arch/x86/kernel/cpu/sgx/main.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
/* Copyright(c) 2016-20 Intel Corporation. */
+#include <linux/crash_dump.h>
#include <linux/file.h>
#include <linux/freezer.h>
#include <linux/highmem.h>
@@ -1027,6 +1028,10 @@ static int __init sgx_init(void)
int ret;
int i;
+ /* The kdump kernel has no use for SGX. Skip it. */
+ if (is_kdump_kernel())
+ return -ENODEV;
+
if (!cpu_feature_enabled(X86_FEATURE_SGX))
return -ENODEV;
--
2.43.7
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] x86/sgx: Skip EPC initialization in the kdump kernel
2026-11-11 12:39 [PATCH] x86/sgx: Skip EPC initialization in the kdump kernel Yuanhe Shu
@ 2026-11-11 15:06 ` Dave Hansen
0 siblings, 0 replies; 2+ messages in thread
From: Dave Hansen @ 2026-11-11 15:06 UTC (permalink / raw)
To: Yuanhe Shu, jarkko, dave.hansen, tglx, mingo, bp, hpa
Cc: x86, linux-sgx, linux-kernel, kexec, challvy.tee
On 11/11/26 04:39, Yuanhe Shu wrote:
> + /* The kdump kernel has no use for SGX. Skip it. */
> + if (is_kdump_kernel())
> + return -ENODEV;
I'd much rather this be inverted: have the kdump code maintain a list of
things it needs to turn off rather than sprinkle is_kdump_kernel()
around any further.
I'd suggest a small bit of kdump specific code that does:
setup_clear_cpu_cap(X86_FEATURE_SGX);
It'll need to be in x86 code or under an x86 #ifdef.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-11 15:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-11 12:39 [PATCH] x86/sgx: Skip EPC initialization in the kdump kernel Yuanhe Shu
2026-11-11 15:06 ` Dave Hansen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®