[PATCH v6 6/8] LoongArch: Enable kexec handover (KHO)
From: George Guo
Date: Thu Oct 29 2026 - 13:31:25 EST
From: George Guo <guodongtai@xxxxxxxxxx>
Enable ARCH_SUPPORTS_KEXEC_HANDOVER on 64-bit LoongArch with EFI_STUB.
KHO state is passed through an EFI configuration table installed by
the stub.
Disable KHO at boot if the table is missing, since the kernel cannot
pass KHO state to the next kernel without it.
Co-developed-by: Kexin Liu <liukexin@xxxxxxxxxx>
Signed-off-by: Kexin Liu <liukexin@xxxxxxxxxx>
Signed-off-by: George Guo <guodongtai@xxxxxxxxxx>
---
arch/loongarch/Kconfig | 3 +++
arch/loongarch/kernel/setup.c | 16 ++++++++++++++++
2 files changed, 19 insertions(+)
diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig
index a21f51e5815e..d35ddd6ec540 100644
--- a/arch/loongarch/Kconfig
+++ b/arch/loongarch/Kconfig
@@ -685,6 +685,9 @@ config ARCH_SUPPORTS_KEXEC
config ARCH_SUPPORTS_KEXEC_FILE
def_bool 64BIT
+config ARCH_SUPPORTS_KEXEC_HANDOVER
+ def_bool 64BIT && EFI_STUB
+
config ARCH_SELECTS_KEXEC_FILE
def_bool 64BIT
depends on KEXEC_FILE
diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c
index dff2e0c67ea0..e1023f93460c 100644
--- a/arch/loongarch/kernel/setup.c
+++ b/arch/loongarch/kernel/setup.c
@@ -20,6 +20,7 @@
#include <linux/initrd.h>
#include <linux/ioport.h>
#include <linux/kexec.h>
+#include <linux/kexec_handover.h>
#include <linux/crash_dump.h>
#include <linux/root_dev.h>
#include <linux/console.h>
@@ -594,6 +595,20 @@ static void __init prefill_possible_map(void)
}
#endif
+/*
+ * Only the EFI stub installs the KHO table, on a cold boot. A kernel
+ * started by kexec from a kernel that did not install it has no table,
+ * and the next kernel would not find what this kernel preserves, so
+ * turn KHO off.
+ */
+static void __init kho_check_efi_table(void)
+{
+ if (kho_is_enabled() && !efi_kho_table_found()) {
+ pr_warn("No EFI KHO table, disabling kexec handover\n");
+ kho_disable();
+ }
+}
+
void __init setup_arch(char **cmdline_p)
{
cpu_probe();
@@ -608,6 +623,7 @@ void __init setup_arch(char **cmdline_p)
bootcmdline_init(cmdline_p);
jump_label_init(); /* Initialise the static keys for early params */
parse_early_param();
+ kho_check_efi_table();
reserve_initrd_mem();
platform_init();
--
2.53.0