mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson
synced 2025-08-27 06:50:37 +00:00

Introduce APIs allowing KHO users to preserve memory across kexec and get access to that memory after boot of the kexeced kernel kho_preserve_folio() - record a folio to be preserved over kexec kho_restore_folio() - recreates the folio from the preserved memory kho_preserve_phys() - record physically contiguous range to be preserved over kexec. The memory preservations are tracked by two levels of xarrays to manage chunks of per-order 512 byte bitmaps. For instance if PAGE_SIZE = 4096, the entire 1G order of a 1TB x86 system would fit inside a single 512 byte bitmap. For order 0 allocations each bitmap will cover 16M of address space. Thus, for 16G of memory at most 512K of bitmap memory will be needed for order 0. At serialization time all bitmaps are recorded in a linked list of pages for the next kernel to process and the physical address of the list is recorded in KHO FDT. The next kernel then processes that list, reserves the memory ranges and later, when a user requests a folio or a physical range, KHO restores corresponding memory map entries. Link: https://lkml.kernel.org/r/20250509074635.3187114-7-changyuanl@google.com Suggested-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Co-developed-by: Changyuan Lyu <changyuanl@google.com> Signed-off-by: Changyuan Lyu <changyuanl@google.com> Cc: Alexander Graf <graf@amazon.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Anthony Yznaga <anthony.yznaga@oracle.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Ashish Kalra <ashish.kalra@amd.com> Cc: Ben Herrenschmidt <benh@kernel.crashing.org> Cc: Borislav Betkov <bp@alien8.de> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: David Woodhouse <dwmw2@infradead.org> Cc: Eric Biederman <ebiederm@xmission.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Gowans <jgowans@amazon.com> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Krzysztof Kozlowski <krzk@kernel.org> Cc: Marc Rutland <mark.rutland@arm.com> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Pratyush Yadav <ptyadav@amazon.de> Cc: Rob Herring <robh@kernel.org> Cc: Saravana Kannan <saravanak@google.com> Cc: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Thomas Gleinxer <tglx@linutronix.de> Cc: Thomas Lendacky <thomas.lendacky@amd.com> Cc: Will Deacon <will@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
110 lines
2.5 KiB
C
110 lines
2.5 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);
|
|
|
|
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 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 */
|