xref: /linux/Documentation/core-api/kho/index.rst (revision 20bed0d6ff62d985fe8222958825504b8aad4e88)
1.. SPDX-License-Identifier: GPL-2.0-or-later
2
3.. _kho-concepts:
4
5========================
6Kexec Handover Subsystem
7========================
8
9Overview
10========
11
12Kexec HandOver (KHO) is a mechanism that allows Linux to preserve memory
13regions, which could contain serialized system states, across kexec.
14
15KHO uses :ref:`flattened device tree (FDT) <kho_fdt>` to pass information about
16the preserved state from pre-exec kernel to post-kexec kernel and :ref:`boot
17memory regions <kho_bootmem>` to ensure integrity of the preserved memory.
18
19.. _kho_fdt:
20
21KHO FDT
22=======
23Every KHO kexec carries a KHO specific flattened device tree (FDT) blob that
24describes the preserved state. The FDT includes properties describing preserved
25memory regions and nodes that hold subsystem specific state.
26
27The preserved memory regions contain either serialized subsystem states, or
28in-memory data that shall not be touched across kexec. After KHO, subsystems
29can retrieve and restore the preserved state from KHO FDT.
30
31Subsystems participating in KHO can define their own format for state
32serialization and preservation.
33
34KHO FDT and structures defined by the subsystems form an ABI between pre-kexec
35and post-kexec kernels. This ABI is defined by header files in
36``include/linux/kho/abi`` directory.
37
38.. toctree::
39   :maxdepth: 1
40
41   abi.rst
42
43.. _kho_bootmem:
44
45Boot Memory Regions
46===================
47
48To boot into kexec, we need to have a physically contiguous memory range that
49contains no handed over memory. Kexec then places the target kernel and initrd
50into that region. The new kernel exclusively uses this region for memory
51allocations before during boot up to the initialization of the page allocator.
52
53We guarantee that we always have such regions through the boot memory regions:
54On first boot KHO allocates several physically contiguous memory regions. Since
55after kexec these regions will be used by early memory allocations, there is a
56boot memory region per NUMA node plus a boot memory region to satisfy
57allocations requests that do not require particular NUMA node assignment. By
58default, size of the boot memory region is calculated based on amount of memory
59allocated during boot. The ``kho_bootmem`` kernel command line option may be
60used to explicitly define size of the boot memory regions. The boot memory
61regions are declared as CMA when page allocator is initialized so that their
62memory can be used during system lifetime. CMA gives us the guarantee that no
63handover pages land in that region, because handover pages must be at a static
64physical memory location and CMA enforces that only movable pages can be located
65inside.
66
67After KHO kexec, we ignore the ``kho_bootmem`` kernel command line option and
68instead reuse the exact same region that was originally allocated. This allows
69us to recursively execute any amount of KHO kexecs. Because we used this region
70for boot memory allocations and as target memory for kexec blobs, some parts
71of that memory region may be reserved. These reservations are irrelevant for
72the next KHO, because kexec can overwrite even the original kernel.
73
74Kexec Handover Radix Tree
75=========================
76
77.. kernel-doc:: include/linux/kho_radix_tree.h
78  :doc: Kexec Handover Radix Tree
79
80Public API
81==========
82
83.. kernel-doc:: kernel/liveupdate/kexec_handover.c
84  :export:
85
86KHO Serialization Blocks API
87============================
88
89.. kernel-doc:: kernel/liveupdate/kho_block.c
90  :doc: KHO Serialization Blocks
91
92.. kernel-doc:: include/linux/kho_block.h
93
94.. kernel-doc:: kernel/liveupdate/kho_block.c
95  :internal:
96
97See Also
98========
99
100- :doc:`/admin-guide/mm/kho`
101