kho.rst 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. .. SPDX-License-Identifier: GPL-2.0-or-later
  2. ====================
  3. Kexec Handover Usage
  4. ====================
  5. Kexec HandOver (KHO) is a mechanism that allows Linux to preserve memory
  6. regions, which could contain serialized system states, across kexec.
  7. This document expects that you are familiar with the base KHO
  8. :ref:`concepts <kho-concepts>`. If you have not read
  9. them yet, please do so now.
  10. Prerequisites
  11. =============
  12. KHO is available when the kernel is compiled with ``CONFIG_KEXEC_HANDOVER``
  13. set to y. Every KHO producer may have its own config option that you
  14. need to enable if you would like to preserve their respective state across
  15. kexec.
  16. To use KHO, please boot the kernel with the ``kho=on`` command line
  17. parameter. You may use ``kho_scratch`` parameter to define size of the
  18. scratch regions. For example ``kho_scratch=16M,512M,256M`` will reserve a
  19. 16 MiB low memory scratch area, a 512 MiB global scratch region, and 256 MiB
  20. per NUMA node scratch regions on boot.
  21. Perform a KHO kexec
  22. ===================
  23. First, before you perform a KHO kexec, you need to move the system into
  24. the :ref:`KHO finalization phase <kho-finalization-phase>` ::
  25. $ echo 1 > /sys/kernel/debug/kho/out/finalize
  26. After this command, the KHO FDT is available in
  27. ``/sys/kernel/debug/kho/out/fdt``. Other subsystems may also register
  28. their own preserved sub FDTs under
  29. ``/sys/kernel/debug/kho/out/sub_fdts/``.
  30. Next, load the target payload and kexec into it. It is important that you
  31. use the ``-s`` parameter to use the in-kernel kexec file loader, as user
  32. space kexec tooling currently has no support for KHO with the user space
  33. based file loader ::
  34. # kexec -l /path/to/bzImage --initrd /path/to/initrd -s
  35. # kexec -e
  36. The new kernel will boot up and contain some of the previous kernel's state.
  37. For example, if you used ``reserve_mem`` command line parameter to create
  38. an early memory reservation, the new kernel will have that memory at the
  39. same physical address as the old kernel.
  40. Abort a KHO exec
  41. ================
  42. You can move the system out of KHO finalization phase again by calling ::
  43. $ echo 0 > /sys/kernel/debug/kho/out/active
  44. After this command, the KHO FDT is no longer available in
  45. ``/sys/kernel/debug/kho/out/fdt``.
  46. debugfs Interfaces
  47. ==================
  48. Currently KHO creates the following debugfs interfaces. Notice that these
  49. interfaces may change in the future. They will be moved to sysfs once KHO is
  50. stabilized.
  51. ``/sys/kernel/debug/kho/out/finalize``
  52. Kexec HandOver (KHO) allows Linux to transition the state of
  53. compatible drivers into the next kexec'ed kernel. To do so,
  54. device drivers will instruct KHO to preserve memory regions,
  55. which could contain serialized kernel state.
  56. While the state is serialized, they are unable to perform
  57. any modifications to state that was serialized, such as
  58. handed over memory allocations.
  59. When this file contains "1", the system is in the transition
  60. state. When contains "0", it is not. To switch between the
  61. two states, echo the respective number into this file.
  62. ``/sys/kernel/debug/kho/out/fdt``
  63. When KHO state tree is finalized, the kernel exposes the
  64. flattened device tree blob that carries its current KHO
  65. state in this file. Kexec user space tooling can use this
  66. as input file for the KHO payload image.
  67. ``/sys/kernel/debug/kho/out/scratch_len``
  68. Lengths of KHO scratch regions, which are physically contiguous
  69. memory regions that will always stay available for future kexec
  70. allocations. Kexec user space tools can use this file to determine
  71. where it should place its payload images.
  72. ``/sys/kernel/debug/kho/out/scratch_phys``
  73. Physical locations of KHO scratch regions. Kexec user space tools
  74. can use this file in conjunction to scratch_phys to determine where
  75. it should place its payload images.
  76. ``/sys/kernel/debug/kho/out/sub_fdts/``
  77. In the KHO finalization phase, KHO producers register their own
  78. FDT blob under this directory.
  79. ``/sys/kernel/debug/kho/in/fdt``
  80. When the kernel was booted with Kexec HandOver (KHO),
  81. the state tree that carries metadata about the previous
  82. kernel's state is in this file in the format of flattened
  83. device tree. This file may disappear when all consumers of
  84. it finished to interpret their metadata.
  85. ``/sys/kernel/debug/kho/in/sub_fdts/``
  86. Similar to ``kho/out/sub_fdts/``, but contains sub FDT blobs
  87. of KHO producers passed from the old kernel.