Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kexec: introduce is_kho_boot()

Patch series "efi: Fix EFI boot with kexec handover (KHO)", v3.

This patch series fixes a kernel panic that occurs when booting with both
EFI and KHO (Kexec HandOver) enabled.

The issue arises because EFI's `reserve_regions()` clears all memory
regions with `memblock_remove(0, PHYS_ADDR_MAX)` before rebuilding them
from EFI data. This destroys KHO scratch regions that were set up early
during device tree scanning, causing a panic as the kernel has no valid
memory regions for early allocations.

The first patch introduces `is_kho_boot()` to allow early boot components
to reliably detect if the kernel was booted via KHO-enabled kexec. The
existing `kho_is_enabled()` only checks the command line and doesn't
verify if an actual KHO FDT was passed.

The second patch modifies EFI's `reserve_regions()` to selectively remove
only non-KHO memory regions when KHO is active, preserving the critical
scratch regions while still allowing EFI to rebuild its memory map.


This patch (of 3):

During early initialisation, after a kexec, other components, like EFI
need to know if a KHO enabled kexec is performed. The `kho_is_enabled`
function is not enough as in the early stages, it only reflects whether
the cmdline has KHO enabled, not if an actual KHO FDT exists.

Extend the KHO API with `is_kho_boot()` to provide a way for components to
check if a KHO enabled kexec is performed.

Link: https://lkml.kernel.org/r/cover.1755721529.git.epetron@amazon.de
Link: https://lkml.kernel.org/r/7dc6674a76bf6e68cca0222ccff32427699cc02e.1755721529.git.epetron@amazon.de
Signed-off-by: Evangelos Petrongonas <epetron@amazon.de>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Reviewed-by: Pratyush Yadav <pratyush@kernel.org>
Cc: Alexander Graf <graf@amazon.com>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: Baoquan He <bhe@redhat.com>
Cc: Changyuan Lyu <changyuanl@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Evangelos Petrongonas and committed by
Andrew Morton
d6d51163 c25822cc

+26
+6
include/linux/kexec_handover.h
··· 40 40 41 41 #ifdef CONFIG_KEXEC_HANDOVER 42 42 bool kho_is_enabled(void); 43 + bool is_kho_boot(void); 43 44 44 45 int kho_preserve_folio(struct folio *folio); 45 46 int kho_preserve_phys(phys_addr_t phys, size_t size); ··· 57 56 u64 scratch_len); 58 57 #else 59 58 static inline bool kho_is_enabled(void) 59 + { 60 + return false; 61 + } 62 + 63 + static inline bool is_kho_boot(void) 60 64 { 61 65 return false; 62 66 }
+20
kernel/kexec_handover.c
··· 952 952 } 953 953 954 954 /** 955 + * is_kho_boot - check if current kernel was booted via KHO-enabled 956 + * kexec 957 + * 958 + * This function checks if the current kernel was loaded through a kexec 959 + * operation with KHO enabled, by verifying that a valid KHO FDT 960 + * was passed. 961 + * 962 + * Note: This function returns reliable results only after 963 + * kho_populate() has been called during early boot. Before that, 964 + * it may return false even if KHO data is present. 965 + * 966 + * Return: true if booted via KHO-enabled kexec, false otherwise 967 + */ 968 + bool is_kho_boot(void) 969 + { 970 + return !!kho_get_fdt(); 971 + } 972 + EXPORT_SYMBOL_GPL(is_kho_boot); 973 + 974 + /** 955 975 * kho_retrieve_subtree - retrieve a preserved sub FDT by its name. 956 976 * @name: the name of the sub FDT passed to kho_add_subtree(). 957 977 * @phys: if found, the physical address of the sub FDT is stored in @phys.