mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git
synced 2026-04-18 03:23:53 -04:00
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>
116 lines
2.6 KiB
C
116 lines
2.6 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef LINUX_KEXEC_HANDOVER_H
|
|
#define LINUX_KEXEC_HANDOVER_H
|
|
|
|
#include <linux/types.h>
|
|
#include <linux/errno.h>
|
|
|
|
struct kho_scratch {
|
|
phys_addr_t addr;
|
|
phys_addr_t size;
|
|
};
|
|
|
|
/* KHO Notifier index */
|
|
enum kho_event {
|
|
KEXEC_KHO_FINALIZE = 0,
|
|
KEXEC_KHO_ABORT = 1,
|
|
};
|
|
|
|
struct folio;
|
|
struct notifier_block;
|
|
|
|
#define DECLARE_KHOSER_PTR(name, type) \
|
|
union { \
|
|
phys_addr_t phys; \
|
|
type ptr; \
|
|
} name
|
|
#define KHOSER_STORE_PTR(dest, val) \
|
|
({ \
|
|
typeof(val) v = val; \
|
|
typecheck(typeof((dest).ptr), v); \
|
|
(dest).phys = virt_to_phys(v); \
|
|
})
|
|
#define KHOSER_LOAD_PTR(src) \
|
|
({ \
|
|
typeof(src) s = src; \
|
|
(typeof((s).ptr))((s).phys ? phys_to_virt((s).phys) : NULL); \
|
|
})
|
|
|
|
struct kho_serialization;
|
|
|
|
#ifdef CONFIG_KEXEC_HANDOVER
|
|
bool kho_is_enabled(void);
|
|
bool is_kho_boot(void);
|
|
|
|
int kho_preserve_folio(struct folio *folio);
|
|
int kho_preserve_phys(phys_addr_t phys, size_t size);
|
|
struct folio *kho_restore_folio(phys_addr_t phys);
|
|
int kho_add_subtree(struct kho_serialization *ser, const char *name, void *fdt);
|
|
int kho_retrieve_subtree(const char *name, phys_addr_t *phys);
|
|
|
|
int register_kho_notifier(struct notifier_block *nb);
|
|
int unregister_kho_notifier(struct notifier_block *nb);
|
|
|
|
void kho_memory_init(void);
|
|
|
|
void kho_populate(phys_addr_t fdt_phys, u64 fdt_len, phys_addr_t scratch_phys,
|
|
u64 scratch_len);
|
|
#else
|
|
static inline bool kho_is_enabled(void)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
static inline bool is_kho_boot(void)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
static inline int kho_preserve_folio(struct folio *folio)
|
|
{
|
|
return -EOPNOTSUPP;
|
|
}
|
|
|
|
static inline int kho_preserve_phys(phys_addr_t phys, size_t size)
|
|
{
|
|
return -EOPNOTSUPP;
|
|
}
|
|
|
|
static inline struct folio *kho_restore_folio(phys_addr_t phys)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
static inline int kho_add_subtree(struct kho_serialization *ser,
|
|
const char *name, void *fdt)
|
|
{
|
|
return -EOPNOTSUPP;
|
|
}
|
|
|
|
static inline int kho_retrieve_subtree(const char *name, phys_addr_t *phys)
|
|
{
|
|
return -EOPNOTSUPP;
|
|
}
|
|
|
|
static inline int register_kho_notifier(struct notifier_block *nb)
|
|
{
|
|
return -EOPNOTSUPP;
|
|
}
|
|
|
|
static inline int unregister_kho_notifier(struct notifier_block *nb)
|
|
{
|
|
return -EOPNOTSUPP;
|
|
}
|
|
|
|
static inline void kho_memory_init(void)
|
|
{
|
|
}
|
|
|
|
static inline void kho_populate(phys_addr_t fdt_phys, u64 fdt_len,
|
|
phys_addr_t scratch_phys, u64 scratch_len)
|
|
{
|
|
}
|
|
#endif /* CONFIG_KEXEC_HANDOVER */
|
|
|
|
#endif /* LINUX_KEXEC_HANDOVER_H */
|