← Documents Documentation/admin-guide/mm/kho.rst GitHub 원문 ↗

Linux 6.18.37 · Administration / Memory Management

Kexec Handover Usage

KHO finalization, FDT와 scratch region, in-kernel kexec loader를 이용해 kernel state를 다음 kernel로 넘기는 절차입니다.

Source pathDocumentation/admin-guide/mm/kho.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

KHO 실행 순서

kho.rst:1-115

KHO를 build·boot에서 활성화하고 state를 finalize한 뒤 in-kernel loader로 target kernel을 load합니다. FDT와 producer별 sub-FDT, scratch region metadata가 이전 kernel state를 전달합니다.

단계설정·interface
BuildCONFIG_KEXEC_HANDOVER=y
Bootkho=on, kho_scratch=<low>,<global>,<per-node>
Finalize/sys/kernel/debug/kho/out/finalize
Loadkexec -l ... -s
Abort/sys/kernel/debug/kho/out/active

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

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

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

Kexec HandOver 개요

1-13

이 문서는 GPL-2.0-or-later 라이선스를 따릅니다. Kexec HandOver(KHO)는 serialized system state를 담을 수 있는 memory region을 kexec 뒤의 새 Linux kernel까지 보존하는 mechanism입니다.

이 사용법은 KHO의 기본 `kho-concepts`를 알고 있다고 가정하므로 아직 읽지 않았다면 먼저 concept 문서를 확인해야 합니다.

build와 boot 조건

14-27

Kernel은 `CONFIG_KEXEC_HANDOVER=y`로 빌드해야 합니다. 각 KHO producer가 자신의 state를 kexec 너머로 보존하려면 producer별 config option도 따로 켜야 할 수 있습니다.

Boot command line에 `kho=on`을 지정합니다. `kho_scratch`로 scratch region 크기를 정할 수 있으며 `kho_scratch=16M,512M,256M`은 low-memory scratch 16 MiB, global scratch 512 MiB, NUMA node별 scratch 256 MiB를 boot 때 reserve합니다.

KHO kexec 실행

28-54

KHO kexec 전에 system을 KHO finalization phase로 전환합니다.

$ echo 1 > /sys/kernel/debug/kho/out/finalize

전환 뒤 KHO FDT는 `/sys/kernel/debug/kho/out/fdt`에 나타나고 다른 subsystem은 보존한 sub-FDT를 `/sys/kernel/debug/kho/out/sub_fdts/` 아래에 등록할 수 있습니다.

다음으로 target payload를 load하고 kexec합니다. User-space file loader는 아직 KHO를 지원하지 않으므로 반드시 `-s`로 in-kernel kexec file loader를 사용해야 합니다.

# kexec -l /path/to/bzImage --initrd /path/to/initrd -s
# kexec -e

새 kernel은 이전 kernel state 일부를 보존한 채 boot합니다. 예를 들어 `reserve_mem` boot parameter로 early memory reservation을 만들었다면 새 kernel에서도 같은 physical address에 그 memory가 있습니다.

KHO 실행 취소

55-64

다음 명령으로 system을 finalization phase에서 다시 빼낼 수 있습니다.

$ echo 0 > /sys/kernel/debug/kho/out/active

취소 후 `/sys/kernel/debug/kho/out/fdt`의 KHO FDT는 더 이상 제공되지 않습니다.

debugfs interface

65-115

현재 KHO interface는 debugfs에 있고 향후 바뀔 수 있습니다. KHO가 안정화되면 sysfs로 이동할 예정입니다.

path접근역할
/sys/kernel/debug/kho/out/finalizeRW1이면 finalization phase, 0이면 일반 상태로 전환
/sys/kernel/debug/kho/out/fdtROfinalized KHO state를 담은 flattened device tree blob
/sys/kernel/debug/kho/out/scratch_lenROfuture kexec allocation에 유지되는 contiguous scratch region 길이
/sys/kernel/debug/kho/out/scratch_physROscratch region의 physical location
/sys/kernel/debug/kho/out/sub_fdts/directoryfinalization 중 producer가 등록한 sub-FDT
/sys/kernel/debug/kho/in/fdtRO이전 kernel에서 전달된 KHO state tree
/sys/kernel/debug/kho/in/sub_fdts/directory이전 kernel의 producer별 sub-FDT

`out/finalize`가 1인 transition state에서는 compatible driver가 serialized state memory를 수정할 수 없습니다. `out/fdt`의 flattened device tree blob은 KHO payload image 입력으로 사용할 수 있습니다.

`scratch_len`과 `scratch_phys`는 future kexec allocation에도 유지되는 physically contiguous scratch region의 길이와 physical location을 제공해 user-space kexec tool이 payload 배치 위치를 정하게 합니다.

원문 99행은 `scratch_phys`를 `scratch_phys`와 함께 사용한다고 적었지만 문맥상 길이 파일인 `scratch_len`과 함께 사용한다는 뜻입니다. 원문과 line anchor는 그대로 보존하고 번역은 두 파일의 역할을 구분합니다.

`out/sub_fdts/`는 현재 kernel producer의 sub-FDT를 담습니다. KHO로 boot한 새 kernel의 `in/fdt`에는 이전 kernel metadata state tree가 있고 모든 consumer가 해석을 끝내면 사라질 수 있습니다. `in/sub_fdts/`에는 이전 kernel producer가 넘긴 sub-FDT가 있습니다.