← Documents Documentation/arch/powerpc/kvm-nested.rst GitHub 원문 ↗

Linux 6.18.37 · Architecture

Nested KVM on POWER

POWER nested virtualization의 L0/L1/L2 모델, PAPR v2 HCALL lifecycle과 전체 Guest State Buffer ID를 설명합니다.

Source pathDocumentation/arch/powerpc/kvm-nested.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

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

1. 요약·해설

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

요약과 해설

kvm-nested.rst:1-656

v2 API는 L2와 vCPU의 수명 및 state ownership을 명시합니다. GSB는 guest-wide, host accounting, thread register와 run buffer를 typed element로 교환하며 L1의 lazy cache가 HCALL 수를 줄입니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2
3 ====================================
4 Nested KVM on POWER
5 ====================================
6
7 Introduction
8 ============
9
10 This document explains how a guest operating system can act as a
11 hypervisor and run nested guests through the use of hypercalls, if the
12 hypervisor has implemented them. The terms L0, L1, and L2 are used to
13 refer to different software entities. L0 is the hypervisor mode entity
14 that would normally be called the "host" or "hypervisor". L1 is a
15 guest virtual machine that is directly run under L0 and is initiated
16 and controlled by L0. L2 is a guest virtual machine that is initiated
17 and controlled by L1 acting as a hypervisor.
18
19 Existing API
20 ============
21
22 Linux/KVM has had support for Nesting as an L0 or L1 since 2018
23
24 The L0 code was added::
25
26 commit 8e3f5fc1045dc49fd175b978c5457f5f51e7a2ce
27 Author: Paul Mackerras <[email protected]>
28 Date: Mon Oct 8 16:31:03 2018 +1100
29 KVM: PPC: Book3S HV: Framework and hcall stubs for nested virtualization
30
31 The L1 code was added::
32
33 commit 360cae313702cdd0b90f82c261a8302fecef030a
34 Author: Paul Mackerras <[email protected]>
35 Date: Mon Oct 8 16:31:04 2018 +1100
36 KVM: PPC: Book3S HV: Nested guest entry via hypercall
37
38 This API works primarily using a single hcall h_enter_nested(). This
39 call made by the L1 to tell the L0 to start an L2 vCPU with the given
40 state. The L0 then starts this L2 and runs until an L2 exit condition
41 is reached. Once the L2 exits, the state of the L2 is given back to
42 the L1 by the L0. The full L2 vCPU state is always transferred from
43 and to L1 when the L2 is run. The L0 doesn't keep any state on the L2
44 vCPU (except in the short sequence in the L0 on L1 -> L2 entry and L2
45 -> L1 exit).
46
47 The only state kept by the L0 is the partition table. The L1 registers
48 it's partition table using the h_set_partition_table() hcall. All
49 other state held by the L0 about the L2s is cached state (such as
50 shadow page tables).
51
52 The L1 may run any L2 or vCPU without first informing the L0. It
53 simply starts the vCPU using h_enter_nested(). The creation of L2s and
54 vCPUs is done implicitly whenever h_enter_nested() is called.
55
56 In this document, we call this existing API the v1 API.
57
58 New PAPR API
59 ===============
60
61 The new PAPR API changes from the v1 API such that the creating L2 and
62 associated vCPUs is explicit. In this document, we call this the v2
63 API.
64
65 h_enter_nested() is replaced with H_GUEST_VCPU_RUN(). Before this can
66 be called the L1 must explicitly create the L2 using h_guest_create()
67 and any associated vCPUs() created with h_guest_create_vCPU(). Getting
68 and setting vCPU state can also be performed using h_guest_{g|s}et
69 hcall.
70
71 The basic execution flow is for an L1 to create an L2, run it, and
72 delete it is:
73
74 - L1 and L0 negotiate capabilities with H_GUEST_{G,S}ET_CAPABILITIES()
75 (normally at L1 boot time).
76
77 - L1 requests the L0 create an L2 with H_GUEST_CREATE() and receives a token
78
79 - L1 requests the L0 create an L2 vCPU with H_GUEST_CREATE_VCPU()
80
81 - L1 and L0 communicate the vCPU state using the H_GUEST_{G,S}ET() hcall
82
83 - L1 requests the L0 runs the vCPU running H_GUEST_VCPU_RUN() hcall
84
85 - L1 deletes L2 with H_GUEST_DELETE()
86
87 More details of the individual hcalls follows:
88
89 HCALL Details
90 =============
91
92 This documentation is provided to give an overall understating of the
93 API. It doesn't aim to provide all the details required to implement
94 an L1 or L0. Latest version of PAPR can be referred to for more details.
95
96 All these HCALLs are made by the L1 to the L0.
97
98 H_GUEST_GET_CAPABILITIES()
99 --------------------------
100
101 This is called to get the capabilities of the L0 nested
102 hypervisor. This includes capabilities such the CPU versions (eg
103 POWER9, POWER10) that are supported as L2s::
104
105 H_GUEST_GET_CAPABILITIES(uint64 flags)
106
107 Parameters:
108 Input:
109 flags: Reserved
110 Output:
111 R3: Return code
112 R4: Hypervisor Supported Capabilities bitmap 1
113
114 H_GUEST_SET_CAPABILITIES()
115 --------------------------
116
117 This is called to inform the L0 of the capabilities of the L1
118 hypervisor. The set of flags passed here are the same as
119 H_GUEST_GET_CAPABILITIES()
120
121 Typically, GET will be called first and then SET will be called with a
122 subset of the flags returned from GET. This process allows the L0 and
123 L1 to negotiate an agreed set of capabilities::
124
125 H_GUEST_SET_CAPABILITIES(uint64 flags,
126 uint64 capabilitiesBitmap1)
127 Parameters:
128 Input:
129 flags: Reserved
130 capabilitiesBitmap1: Only capabilities advertised through
131 H_GUEST_GET_CAPABILITIES
132 Output:
133 R3: Return code
134 R4: If R3 = H_P2: The number of invalid bitmaps
135 R5: If R3 = H_P2: The index of first invalid bitmap
136
137 H_GUEST_CREATE()
138 ----------------
139
140 This is called to create an L2. A unique ID of the L2 created
141 (similar to an LPID) is returned, which can be used on subsequent HCALLs to
142 identify the L2::
143
144 H_GUEST_CREATE(uint64 flags,
145 uint64 continueToken);
146 Parameters:
147 Input:
148 flags: Reserved
149 continueToken: Initial call set to -1. Subsequent calls,
150 after H_Busy or H_LongBusyOrder has been
151 returned, value that was returned in R4.
152 Output:
153 R3: Return code. Notable:
154 H_Not_Enough_Resources: Unable to create Guest VCPU due to not
155 enough Hypervisor memory. See H_GUEST_CREATE_GET_STATE(flags =
156 takeOwnershipOfVcpuState)
157 R4: If R3 = H_Busy or_H_LongBusyOrder -> continueToken
158
159 H_GUEST_CREATE_VCPU()
160 ---------------------
161
162 This is called to create a vCPU associated with an L2. The L2 id
163 (returned from H_GUEST_CREATE()) should be passed it. Also passed in
164 is a unique (for this L2) vCPUid. This vCPUid is allocated by the
165 L1::
166
167 H_GUEST_CREATE_VCPU(uint64 flags,
168 uint64 guestId,
169 uint64 vcpuId);
170 Parameters:
171 Input:
172 flags: Reserved
173 guestId: ID obtained from H_GUEST_CREATE
174 vcpuId: ID of the vCPU to be created. This must be within the
175 range of 0 to 2047
176 Output:
177 R3: Return code. Notable:
178 H_Not_Enough_Resources: Unable to create Guest VCPU due to not
179 enough Hypervisor memory. See H_GUEST_CREATE_GET_STATE(flags =
180 takeOwnershipOfVcpuState)
181
182 H_GUEST_GET_STATE()
183 -------------------
184
185 This is called to get state associated with an L2 (Guest-wide or vCPU specific).
186 This info is passed via the Guest State Buffer (GSB), a standard format as
187 explained later in this doc, necessary details below:
188
189 This can get either L2 wide or vcpu specific information. Examples of
190 L2 wide is the timebase offset or process scoped page table
191 info. Examples of vCPU specific are GPRs or VSRs. A bit in the flags
192 parameter specifies if this call is L2 wide or vCPU specific and the
193 IDs in the GSB must match this.
194
195 The L1 provides a pointer to the GSB as a parameter to this call. Also
196 provided is the L2 and vCPU IDs associated with the state to set.
197
198 The L1 writes only the IDs and sizes in the GSB. L0 writes the
199 associated values for each ID in the GSB::
200
201 H_GUEST_GET_STATE(uint64 flags,
202 uint64 guestId,
203 uint64 vcpuId,
204 uint64 dataBuffer,
205 uint64 dataBufferSizeInBytes);
206 Parameters:
207 Input:
208 flags:
209 Bit 0: getGuestWideState: Request state of the Guest instead
210 of an individual VCPU.
211 Bit 1: getHostWideState: Request stats of the Host. This causes
212 the guestId and vcpuId parameters to be ignored and attempting
213 to get the VCPU/Guest state will cause an error.
214 Bits 2-63: Reserved
215 guestId: ID obtained from H_GUEST_CREATE
216 vcpuId: ID of the vCPU pass to H_GUEST_CREATE_VCPU
217 dataBuffer: A L1 real address of the GSB.
218 If takeOwnershipOfVcpuState, size must be at least the size
219 returned by ID=0x0001
220 dataBufferSizeInBytes: Size of dataBuffer
221 Output:
222 R3: Return code
223 R4: If R3 = H_Invalid_Element_Id: The array index of the bad
224 element ID.
225 If R3 = H_Invalid_Element_Size: The array index of the bad
226 element size.
227 If R3 = H_Invalid_Element_Value: The array index of the bad
228 element value.
229
230 H_GUEST_SET_STATE()
231 -------------------
232
233 This is called to set L2 wide or vCPU specific L2 state. This info is
234 passed via the Guest State Buffer (GSB), necessary details below:
235
236 This can set either L2 wide or vcpu specific information. Examples of
237 L2 wide is the timebase offset or process scoped page table
238 info. Examples of vCPU specific are GPRs or VSRs. A bit in the flags
239 parameter specifies if this call is L2 wide or vCPU specific and the
240 IDs in the GSB must match this.
241
242 The L1 provides a pointer to the GSB as a parameter to this call. Also
243 provided is the L2 and vCPU IDs associated with the state to set.
244
245 The L1 writes all values in the GSB and the L0 only reads the GSB for
246 this call::
247
248 H_GUEST_SET_STATE(uint64 flags,
249 uint64 guestId,
250 uint64 vcpuId,
251 uint64 dataBuffer,
252 uint64 dataBufferSizeInBytes);
253 Parameters:
254 Input:
255 flags:
256 Bit 0: getGuestWideState: Request state of the Guest instead
257 of an individual VCPU.
258 Bit 1: returnOwnershipOfVcpuState Return Guest VCPU state. See
259 GET_STATE takeOwnershipOfVcpuState
260 Bits 2-63: Reserved
261 guestId: ID obtained from H_GUEST_CREATE
262 vcpuId: ID of the vCPU pass to H_GUEST_CREATE_VCPU
263 dataBuffer: A L1 real address of the GSB.
264 If takeOwnershipOfVcpuState, size must be at least the size
265 returned by ID=0x0001
266 dataBufferSizeInBytes: Size of dataBuffer
267 Output:
268 R3: Return code
269 R4: If R3 = H_Invalid_Element_Id: The array index of the bad
270 element ID.
271 If R3 = H_Invalid_Element_Size: The array index of the bad
272 element size.
273 If R3 = H_Invalid_Element_Value: The array index of the bad
274 element value.
275
276 H_GUEST_RUN_VCPU()
277 ------------------
278
279 This is called to run an L2 vCPU. The L2 and vCPU IDs are passed in as
280 parameters. The vCPU runs with the state set previously using
281 H_GUEST_SET_STATE(). When the L2 exits, the L1 will resume from this
282 hcall.
283
284 This hcall also has associated input and output GSBs. Unlike
285 H_GUEST_{S,G}ET_STATE(), these GSB pointers are not passed in as
286 parameters to the hcall (This was done in the interest of
287 performance). The locations of these GSBs must be preregistered using
288 the H_GUEST_SET_STATE() call with ID 0x0c00 and 0x0c01 (see table
289 below).
290
291 The input GSB may contain only VCPU specific elements to be set. This
292 GSB may also contain zero elements (ie 0 in the first 4 bytes of the
293 GSB) if nothing needs to be set.
294
295 On exit from the hcall, the output buffer is filled with elements
296 determined by the L0. The reason for the exit is contained in GPR4 (ie
297 NIP is put in GPR4). The elements returned depend on the exit
298 type. For example, if the exit reason is the L2 doing a hcall (GPR4 =
299 0xc00), then GPR3-12 are provided in the output GSB as this is the
300 state likely needed to service the hcall. If additional state is
301 needed, H_GUEST_GET_STATE() may be called by the L1.
302
303 To synthesize interrupts in the L2, when calling H_GUEST_RUN_VCPU()
304 the L1 may set a flag (as a hcall parameter) and the L0 will
305 synthesize the interrupt in the L2. Alternatively, the L1 may
306 synthesize the interrupt itself using H_GUEST_SET_STATE() or the
307 H_GUEST_RUN_VCPU() input GSB to set the state appropriately::
308
309 H_GUEST_RUN_VCPU(uint64 flags,
310 uint64 guestId,
311 uint64 vcpuId,
312 uint64 dataBuffer,
313 uint64 dataBufferSizeInBytes);
314 Parameters:
315 Input:
316 flags:
317 Bit 0: generateExternalInterrupt: Generate an external interrupt
318 Bit 1: generatePrivilegedDoorbell: Generate a Privileged Doorbell
319 Bit 2: sendToSystemReset”: Generate a System Reset Interrupt
320 Bits 3-63: Reserved
321 guestId: ID obtained from H_GUEST_CREATE
322 vcpuId: ID of the vCPU pass to H_GUEST_CREATE_VCPU
323 Output:
324 R3: Return code
325 R4: If R3 = H_Success: The reason L1 VCPU exited (ie. NIA)
326 0x000: The VCPU stopped running for an unspecified reason. An
327 example of this is the Hypervisor stopping a VCPU running
328 due to an outstanding interrupt for the Host Partition.
329 0x980: HDEC
330 0xC00: HCALL
331 0xE00: HDSI
332 0xE20: HISI
333 0xE40: HEA
334 0xF80: HV Fac Unavail
335 If R3 = H_Invalid_Element_Id, H_Invalid_Element_Size, or
336 H_Invalid_Element_Value: R4 is offset of the invalid element
337 in the input buffer.
338
339 H_GUEST_DELETE()
340 ----------------
341
342 This is called to delete an L2. All associated vCPUs are also
343 deleted. No specific vCPU delete call is provided.
344
345 A flag may be provided to delete all guests. This is used to reset the
346 L0 in the case of kdump/kexec::
347
348 H_GUEST_DELETE(uint64 flags,
349 uint64 guestId)
350 Parameters:
351 Input:
352 flags:
353 Bit 0: deleteAllGuests: deletes all guests
354 Bits 1-63: Reserved
355 guestId: ID obtained from H_GUEST_CREATE
356 Output:
357 R3: Return code
358
359 Guest State Buffer
360 ==================
361
362 The Guest State Buffer (GSB) is the main method of communicating state
363 about the L2 between the L1 and L0 via H_GUEST_{G,S}ET() and
364 H_GUEST_VCPU_RUN() calls.
365
366 State may be associated with a whole L2 (eg timebase offset) or a
367 specific L2 vCPU (eg. GPR state). Only L2 VCPU state maybe be set by
368 H_GUEST_VCPU_RUN().
369
370 All data in the GSB is big endian (as is standard in PAPR)
371
372 The Guest state buffer has a header which gives the number of
373 elements, followed by the GSB elements themselves.
374
375 GSB header:
376
377 +----------+----------+-------------------------------------------+
378 | Offset | Size | Purpose |
379 | Bytes | Bytes | |
380 +==========+==========+===========================================+
381 | 0 | 4 | Number of elements |
382 +----------+----------+-------------------------------------------+
383 | 4 | | Guest state buffer elements |
384 +----------+----------+-------------------------------------------+
385
386 GSB element:
387
388 +----------+----------+-------------------------------------------+
389 | Offset | Size | Purpose |
390 | Bytes | Bytes | |
391 +==========+==========+===========================================+
392 | 0 | 2 | ID |
393 +----------+----------+-------------------------------------------+
394 | 2 | 2 | Size of Value |
395 +----------+----------+-------------------------------------------+
396 | 4 | As above | Value |
397 +----------+----------+-------------------------------------------+
398
399 The ID in the GSB element specifies what is to be set. This includes
400 archtected state like GPRs, VSRs, SPRs, plus also some meta data about
401 the partition like the timebase offset and partition scoped page
402 table information.
403
404 +--------+-------+----+--------+----------------------------------+
405 | ID | Size | RW |(H)ost | Details |
406 | | Bytes | |(G)uest | |
407 | | | |(T)hread| |
408 | | | |Scope | |
409 +========+=======+====+========+==================================+
410 | 0x0000 | | RW | TG | NOP element |
411 +--------+-------+----+--------+----------------------------------+
412 | 0x0001 | 0x08 | R | G | Size of L0 vCPU state. See: |
413 | | | | | H_GUEST_GET_STATE: |
414 | | | | | flags = takeOwnershipOfVcpuState |
415 +--------+-------+----+--------+----------------------------------+
416 | 0x0002 | 0x08 | R | G | Size Run vCPU out buffer |
417 +--------+-------+----+--------+----------------------------------+
418 | 0x0003 | 0x04 | RW | G | Logical PVR |
419 +--------+-------+----+--------+----------------------------------+
420 | 0x0004 | 0x08 | RW | G | TB Offset (L1 relative) |
421 +--------+-------+----+--------+----------------------------------+
422 | 0x0005 | 0x18 | RW | G |Partition scoped page tbl info: |
423 | | | | | |
424 | | | | |- 0x00 Addr part scope table |
425 | | | | |- 0x08 Num addr bits |
426 | | | | |- 0x10 Size root dir |
427 +--------+-------+----+--------+----------------------------------+
428 | 0x0006 | 0x10 | RW | G |Process Table Information: |
429 | | | | | |
430 | | | | |- 0x0 Addr proc scope table |
431 | | | | |- 0x8 Table size. |
432 +--------+-------+----+--------+----------------------------------+
433 | 0x0007-| | | | Reserved |
434 | 0x07FF | | | | |
435 +--------+-------+----+--------+----------------------------------+
436 | 0x0800 | 0x08 | R | H | Current usage in bytes of the |
437 | | | | | L0's Guest Management Space |
438 | | | | | for an L1-Lpar. |
439 +--------+-------+----+--------+----------------------------------+
440 | 0x0801 | 0x08 | R | H | Max bytes available in the |
441 | | | | | L0's Guest Management Space for |
442 | | | | | an L1-Lpar |
443 +--------+-------+----+--------+----------------------------------+
444 | 0x0802 | 0x08 | R | H | Current usage in bytes of the |
445 | | | | | L0's Guest Page Table Management |
446 | | | | | Space for an L1-Lpar |
447 +--------+-------+----+--------+----------------------------------+
448 | 0x0803 | 0x08 | R | H | Max bytes available in the L0's |
449 | | | | | Guest Page Table Management |
450 | | | | | Space for an L1-Lpar |
451 +--------+-------+----+--------+----------------------------------+
452 | 0x0804 | 0x08 | R | H | Cumulative Reclaimed bytes from |
453 | | | | | L0 Guest's Page Table Management |
454 | | | | | Space due to overcommit |
455 +--------+-------+----+--------+----------------------------------+
456 | 0x0805-| | | | Reserved |
457 | 0x0BFF | | | | |
458 +--------+-------+----+--------+----------------------------------+
459 | 0x0C00 | 0x10 | RW | T |Run vCPU Input Buffer: |
460 | | | | | |
461 | | | | |- 0x0 Addr of buffer |
462 | | | | |- 0x8 Buffer Size. |
463 +--------+-------+----+--------+----------------------------------+
464 | 0x0C01 | 0x10 | RW | T |Run vCPU Output Buffer: |
465 | | | | | |
466 | | | | |- 0x0 Addr of buffer |
467 | | | | |- 0x8 Buffer Size. |
468 +--------+-------+----+--------+----------------------------------+
469 | 0x0C02 | 0x08 | RW | T | vCPU VPA Address |
470 +--------+-------+----+--------+----------------------------------+
471 | 0x0C03-| | | | Reserved |
472 | 0x0FFF | | | | |
473 +--------+-------+----+--------+----------------------------------+
474 | 0x1000-| 0x08 | RW | T | GPR 0-31 |
475 | 0x101F | | | | |
476 +--------+-------+----+--------+----------------------------------+
477 | 0x1020 | 0x08 | T | T | HDEC expiry TB |
478 +--------+-------+----+--------+----------------------------------+
479 | 0x1021 | 0x08 | RW | T | NIA |
480 +--------+-------+----+--------+----------------------------------+
481 | 0x1022 | 0x08 | RW | T | MSR |
482 +--------+-------+----+--------+----------------------------------+
483 | 0x1023 | 0x08 | RW | T | LR |
484 +--------+-------+----+--------+----------------------------------+
485 | 0x1024 | 0x08 | RW | T | XER |
486 +--------+-------+----+--------+----------------------------------+
487 | 0x1025 | 0x08 | RW | T | CTR |
488 +--------+-------+----+--------+----------------------------------+
489 | 0x1026 | 0x08 | RW | T | CFAR |
490 +--------+-------+----+--------+----------------------------------+
491 | 0x1027 | 0x08 | RW | T | SRR0 |
492 +--------+-------+----+--------+----------------------------------+
493 | 0x1028 | 0x08 | RW | T | SRR1 |
494 +--------+-------+----+--------+----------------------------------+
495 | 0x1029 | 0x08 | RW | T | DAR |
496 +--------+-------+----+--------+----------------------------------+
497 | 0x102A | 0x08 | RW | T | DEC expiry TB |
498 +--------+-------+----+--------+----------------------------------+
499 | 0x102B | 0x08 | RW | T | VTB |
500 +--------+-------+----+--------+----------------------------------+
501 | 0x102C | 0x08 | RW | T | LPCR |
502 +--------+-------+----+--------+----------------------------------+
503 | 0x102D | 0x08 | RW | T | HFSCR |
504 +--------+-------+----+--------+----------------------------------+
505 | 0x102E | 0x08 | RW | T | FSCR |
506 +--------+-------+----+--------+----------------------------------+
507 | 0x102F | 0x08 | RW | T | FPSCR |
508 +--------+-------+----+--------+----------------------------------+
509 | 0x1030 | 0x08 | RW | T | DAWR0 |
510 +--------+-------+----+--------+----------------------------------+
511 | 0x1031 | 0x08 | RW | T | DAWR1 |
512 +--------+-------+----+--------+----------------------------------+
513 | 0x1032 | 0x08 | RW | T | CIABR |
514 +--------+-------+----+--------+----------------------------------+
515 | 0x1033 | 0x08 | RW | T | PURR |
516 +--------+-------+----+--------+----------------------------------+
517 | 0x1034 | 0x08 | RW | T | SPURR |
518 +--------+-------+----+--------+----------------------------------+
519 | 0x1035 | 0x08 | RW | T | IC |
520 +--------+-------+----+--------+----------------------------------+
521 | 0x1036-| 0x08 | RW | T | SPRG 0-3 |
522 | 0x1039 | | | | |
523 +--------+-------+----+--------+----------------------------------+
524 | 0x103A | 0x08 | W | T | PPR |
525 +--------+-------+----+--------+----------------------------------+
526 | 0x103B | 0x08 | RW | T | MMCR 0-3 |
527 | 0x103E | | | | |
528 +--------+-------+----+--------+----------------------------------+
529 | 0x103F | 0x08 | RW | T | MMCRA |
530 +--------+-------+----+--------+----------------------------------+
531 | 0x1040 | 0x08 | RW | T | SIER |
532 +--------+-------+----+--------+----------------------------------+
533 | 0x1041 | 0x08 | RW | T | SIER 2 |
534 +--------+-------+----+--------+----------------------------------+
535 | 0x1042 | 0x08 | RW | T | SIER 3 |
536 +--------+-------+----+--------+----------------------------------+
537 | 0x1043 | 0x08 | RW | T | BESCR |
538 +--------+-------+----+--------+----------------------------------+
539 | 0x1044 | 0x08 | RW | T | EBBHR |
540 +--------+-------+----+--------+----------------------------------+
541 | 0x1045 | 0x08 | RW | T | EBBRR |
542 +--------+-------+----+--------+----------------------------------+
543 | 0x1046 | 0x08 | RW | T | AMR |
544 +--------+-------+----+--------+----------------------------------+
545 | 0x1047 | 0x08 | RW | T | IAMR |
546 +--------+-------+----+--------+----------------------------------+
547 | 0x1048 | 0x08 | RW | T | AMOR |
548 +--------+-------+----+--------+----------------------------------+
549 | 0x1049 | 0x08 | RW | T | UAMOR |
550 +--------+-------+----+--------+----------------------------------+
551 | 0x104A | 0x08 | RW | T | SDAR |
552 +--------+-------+----+--------+----------------------------------+
553 | 0x104B | 0x08 | RW | T | SIAR |
554 +--------+-------+----+--------+----------------------------------+
555 | 0x104C | 0x08 | RW | T | DSCR |
556 +--------+-------+----+--------+----------------------------------+
557 | 0x104D | 0x08 | RW | T | TAR |
558 +--------+-------+----+--------+----------------------------------+
559 | 0x104E | 0x08 | RW | T | DEXCR |
560 +--------+-------+----+--------+----------------------------------+
561 | 0x104F | 0x08 | RW | T | HDEXCR |
562 +--------+-------+----+--------+----------------------------------+
563 | 0x1050 | 0x08 | RW | T | HASHKEYR |
564 +--------+-------+----+--------+----------------------------------+
565 | 0x1051 | 0x08 | RW | T | HASHPKEYR |
566 +--------+-------+----+--------+----------------------------------+
567 | 0x1052 | 0x08 | RW | T | CTRL |
568 +--------+-------+----+--------+----------------------------------+
569 | 0x1053 | 0x08 | RW | T | DPDES |
570 +--------+-------+----+--------+----------------------------------+
571 | 0x1054-| | | | Reserved |
572 | 0x1FFF | | | | |
573 +--------+-------+----+--------+----------------------------------+
574 | 0x2000 | 0x04 | RW | T | CR |
575 +--------+-------+----+--------+----------------------------------+
576 | 0x2001 | 0x04 | RW | T | PIDR |
577 +--------+-------+----+--------+----------------------------------+
578 | 0x2002 | 0x04 | RW | T | DSISR |
579 +--------+-------+----+--------+----------------------------------+
580 | 0x2003 | 0x04 | RW | T | VSCR |
581 +--------+-------+----+--------+----------------------------------+
582 | 0x2004 | 0x04 | RW | T | VRSAVE |
583 +--------+-------+----+--------+----------------------------------+
584 | 0x2005 | 0x04 | RW | T | DAWRX0 |
585 +--------+-------+----+--------+----------------------------------+
586 | 0x2006 | 0x04 | RW | T | DAWRX1 |
587 +--------+-------+----+--------+----------------------------------+
588 | 0x2007-| 0x04 | RW | T | PMC 1-6 |
589 | 0x200c | | | | |
590 +--------+-------+----+--------+----------------------------------+
591 | 0x200D | 0x04 | RW | T | WORT |
592 +--------+-------+----+--------+----------------------------------+
593 | 0x200E | 0x04 | RW | T | PSPB |
594 +--------+-------+----+--------+----------------------------------+
595 | 0x200F-| | | | Reserved |
596 | 0x2FFF | | | | |
597 +--------+-------+----+--------+----------------------------------+
598 | 0x3000-| 0x10 | RW | T | VSR 0-63 |
599 | 0x303F | | | | |
600 +--------+-------+----+--------+----------------------------------+
601 | 0x3040-| | | | Reserved |
602 | 0xEFFF | | | | |
603 +--------+-------+----+--------+----------------------------------+
604 | 0xF000 | 0x08 | R | T | HDAR |
605 +--------+-------+----+--------+----------------------------------+
606 | 0xF001 | 0x04 | R | T | HDSISR |
607 +--------+-------+----+--------+----------------------------------+
608 | 0xF002 | 0x04 | R | T | HEIR |
609 +--------+-------+----+--------+----------------------------------+
610 | 0xF003 | 0x08 | R | T | ASDR |
611 +--------+-------+----+--------+----------------------------------+
612
613
614 Miscellaneous info
615 ==================
616
617 State not in ptregs/hvregs
618 --------------------------
619
620 In the v1 API, some state is not in the ptregs/hvstate. This includes
621 the vector register and some SPRs. For the L1 to set this state for
622 the L2, the L1 loads up these hardware registers before the
623 h_enter_nested() call and the L0 ensures they end up as the L2 state
624 (by not touching them).
625
626 The v2 API removes this and explicitly sets this state via the GSB.
627
628 L1 Implementation details: Caching state
629 ----------------------------------------
630
631 In the v1 API, all state is sent from the L1 to the L0 and vice versa
632 on every h_enter_nested() hcall. If the L0 is not currently running
633 any L2s, the L0 has no state information about them. The only
634 exception to this is the location of the partition table, registered
635 via h_set_partition_table().
636
637 The v2 API changes this so that the L0 retains the L2 state even when
638 it's vCPUs are no longer running. This means that the L1 only needs to
639 communicate with the L0 about L2 state when it needs to modify the L2
640 state, or when it's value is out of date. This provides an opportunity
641 for performance optimisation.
642
643 When a vCPU exits from a H_GUEST_RUN_VCPU() call, the L1 internally
644 marks all L2 state as invalid. This means that if the L1 wants to know
645 the L2 state (say via a kvm_get_one_reg() call), it needs call
646 H_GUEST_GET_STATE() to get that state. Once it's read, it's marked as
647 valid in L1 until the L2 is run again.
648
649 Also, when an L1 modifies L2 vcpu state, it doesn't need to write it
650 to the L0 until that L2 vcpu runs again. Hence when the L1 updates
651 state (say via a kvm_set_one_reg() call), it writes to an internal L1
652 copy and only flushes this copy to the L0 when the L2 runs again via
653 the H_GUEST_VCPU_RUN() input buffer.
654
655 This lazy updating of state by the L1 avoids unnecessary
656 H_GUEST_{G|S}ET_STATE() calls.
657

3. 한국어 전문 번역

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

POWER nested KVM

1-6

이 문서는 POWER에서 guest operating system이 hypervisor 역할을 하며 nested guest를 실행하는 KVM API를 설명합니다.

L0·L1·L2 모델

7-18

Hypervisor가 필요한 hypercall을 구현했다면 guest OS가 다시 hypervisor가 되어 nested guest를 실행할 수 있습니다.

계층역할
L0일반적으로 host 또는 hypervisor라 부르는 hypervisor-mode entity
L1L0가 직접 시작하고 제어하는 guest VM이며 L2에 대해서는 hypervisor로 동작
L2L1이 시작하고 제어하는 nested guest VM
Nested virtualization 계층
L0 host/hypervisorL1 guest hypervisorL2 nested guest

제어권과 guest 실행 관계를 L0에서 L2까지 표시합니다.

기존 v1 API

19-57

Linux/KVM은 2018년부터 L0와 L1 양쪽의 nesting을 지원합니다. L0 framework와 hcall stub은 다음 commit에서 추가되었습니다.

commit 8e3f5fc1045dc49fd175b978c5457f5f51e7a2ce
Author: Paul Mackerras <[email protected]>
Date:   Mon Oct 8 16:31:03 2018 +1100
KVM: PPC: Book3S HV: Framework and hcall stubs for nested virtualization

L1의 nested guest entry code는 다음 commit에서 추가되었습니다.

commit 360cae313702cdd0b90f82c261a8302fecef030a
Author: Paul Mackerras <[email protected]>
Date:   Mon Oct 8 16:31:04 2018 +1100
KVM: PPC: Book3S HV: Nested guest entry via hypercall

v1 API의 중심은 `h_enter_nested()`입니다. L1은 전체 L2 vCPU state를 넘겨 실행을 요청하고, L0는 exit condition까지 L2를 실행한 뒤 전체 state를 L1에 돌려줍니다.

L0는 L1→L2 entry와 L2→L1 exit의 짧은 구간 외에는 L2 vCPU state를 유지하지 않습니다. 영구적으로 유지하는 유일한 state는 L1이 `h_set_partition_table()`로 등록한 partition table이며 shadow page table 같은 나머지는 cache입니다.

L1은 L2나 vCPU를 미리 등록하지 않고도 `h_enter_nested()`를 호출할 수 있습니다. 이 호출이 L2와 vCPU 생성을 암묵적으로 수행합니다. 문서에서는 이를 v1 API라고 부릅니다.

새 PAPR v2 API와 lifecycle

58-88

v2 API는 L2와 vCPU 생성을 명시적으로 바꿉니다. `h_enter_nested()` 대신 `H_GUEST_VCPU_RUN()`을 사용하며, 먼저 `H_GUEST_CREATE()`와 `H_GUEST_CREATE_VCPU()`를 호출해야 합니다.

vCPU state는 `H_GUEST_GET_STATE()`와 `H_GUEST_SET_STATE()` 계열 hcall로 주고받습니다.

  • L1과 L0가 `H_GUEST_GET_CAPABILITIES()` 및 `H_GUEST_SET_CAPABILITIES()`로 capability를 협상합니다. 보통 L1 boot 때 수행합니다.
  • L1이 `H_GUEST_CREATE()`로 L2 생성을 요청하고 token을 받습니다.
  • L1이 `H_GUEST_CREATE_VCPU()`로 L2 vCPU를 만듭니다.
  • `H_GUEST_GET_STATE()`와 `H_GUEST_SET_STATE()`로 vCPU state를 교환합니다.
  • `H_GUEST_VCPU_RUN()` 또는 문서 signature의 `H_GUEST_RUN_VCPU()`로 vCPU를 실행합니다.
  • 마지막에 `H_GUEST_DELETE()`로 L2와 모든 vCPU를 삭제합니다.
PAPR nested guest lifecycle
GET/SET capabilitiesCREATE L2CREATE_VCPUSET/GET stateRUN_VCPUDELETE L2

Capability 협상부터 L2 제거까지의 명시적 v2 절차입니다.

HCALL 설명의 범위

89-97

이 설명은 API 전체 구조를 이해하기 위한 것이며 L0 또는 L1 구현에 필요한 모든 세부 사항을 제공하지는 않습니다. 최신 PAPR specification을 함께 참조해야 합니다.

아래 HCALL은 모두 L1이 L0에 호출합니다.

`H_GUEST_GET_CAPABILITIES()`

98-113

L0 nested hypervisor가 L2로 지원하는 CPU version(예: POWER9, POWER10)을 포함한 capability를 조회합니다. `flags`는 reserved이고 R3에 return code, R4에 capability bitmap 1이 반환됩니다.

H_GUEST_GET_CAPABILITIES(uint64 flags)

Parameters:
  Input:
    flags: Reserved
  Output:
    R3: Return code
    R4: Hypervisor Supported Capabilities bitmap 1

`H_GUEST_SET_CAPABILITIES()`

114-136

L1이 자신이 사용할 capability를 L0에 알립니다. 일반적으로 GET 결과 중 subset을 SET하여 양쪽이 합의한 capability 집합을 정합니다.

H_GUEST_SET_CAPABILITIES(uint64 flags,
                         uint64 capabilitiesBitmap1)
Parameters:
  Input:
    flags: Reserved
    capabilitiesBitmap1: Only capabilities advertised through
                         H_GUEST_GET_CAPABILITIES
  Output:
    R3: Return code
    R4: If R3 = H_P2: The number of invalid bitmaps
    R5: If R3 = H_P2: The index of first invalid bitmap

광고되지 않은 bitmap을 넘겨 `H_P2`가 반환되면 R4는 invalid bitmap 수, R5는 첫 invalid bitmap index입니다.

`H_GUEST_CREATE()`

137-158

L2를 만들고 이후 HCALL에서 식별할 unique ID를 반환합니다. 이 ID는 LPID와 비슷한 역할을 합니다.

H_GUEST_CREATE(uint64 flags,
               uint64 continueToken);
Parameters:
  Input:
    flags: Reserved
    continueToken: Initial call set to -1. Subsequent calls,
                   after H_Busy or H_LongBusyOrder has been
                   returned, value that was returned in R4.
  Output:
    R3: Return code. Notable:
      H_Not_Enough_Resources: Unable to create Guest VCPU due to not
      enough Hypervisor memory. See H_GUEST_CREATE_GET_STATE(flags =
      takeOwnershipOfVcpuState)
    R4: If R3 = H_Busy or_H_LongBusyOrder -> continueToken

첫 호출의 `continueToken`은 `-1`입니다. `H_Busy` 또는 `H_LongBusyOrder` 뒤에는 R4에서 받은 token으로 이어서 호출합니다. Hypervisor memory가 부족하면 `H_Not_Enough_Resources`가 반환될 수 있습니다.

`H_GUEST_CREATE_VCPU()`

159-181

지정한 L2에 vCPU를 만듭니다. `guestId`는 `H_GUEST_CREATE()` 결과이고 L1이 배정하는 `vcpuId`는 해당 L2 안에서 고유해야 하며 `0..2047` 범위입니다.

H_GUEST_CREATE_VCPU(uint64 flags,
                    uint64 guestId,
                    uint64 vcpuId);
Parameters:
  Input:
    flags: Reserved
    guestId: ID obtained from H_GUEST_CREATE
    vcpuId: ID of the vCPU to be created. This must be within the
            range of 0 to 2047
  Output:
    R3: Return code. Notable:
      H_Not_Enough_Resources: Unable to create Guest VCPU due to not
      enough Hypervisor memory. See H_GUEST_CREATE_GET_STATE(flags =
      takeOwnershipOfVcpuState)

vCPU state를 위한 hypervisor memory가 부족하면 `H_Not_Enough_Resources`가 반환될 수 있습니다.

`H_GUEST_GET_STATE()`

182-229

L2 전체 또는 특정 vCPU에 연관된 state를 Guest State Buffer(GSB)로 읽습니다. Guest-wide 예시는 timebase offset과 process-scoped page table이고 vCPU-specific 예시는 GPR과 VSR입니다.

Flag bit가 guest-wide, host-wide 또는 vCPU-specific 요청을 구분하며 GSB 안의 ID도 scope와 일치해야 합니다. Host-wide 요청에서는 `guestId`와 `vcpuId`를 무시하고 guest/vCPU state element를 요청하면 오류입니다.

L1은 GSB의 element ID와 size만 채우고, L0가 각 ID의 value를 씁니다. `dataBuffer`는 L1 real address입니다.

H_GUEST_GET_STATE(uint64 flags,
                         uint64 guestId,
                         uint64 vcpuId,
                         uint64 dataBuffer,
                         uint64 dataBufferSizeInBytes);
Parameters:
  Input:
    flags:
       Bit 0: getGuestWideState: Request state of the Guest instead
         of an individual VCPU.
       Bit 1: getHostWideState: Request stats of the Host. This causes
         the guestId and vcpuId parameters to be ignored and attempting
         to get the VCPU/Guest state will cause an error.
       Bits 2-63: Reserved
    guestId: ID obtained from H_GUEST_CREATE
    vcpuId: ID of the vCPU pass to H_GUEST_CREATE_VCPU
    dataBuffer: A L1 real address of the GSB.
      If takeOwnershipOfVcpuState, size must be at least the size
      returned by ID=0x0001
    dataBufferSizeInBytes: Size of dataBuffer
  Output:
    R3: Return code
    R4: If R3 = H_Invalid_Element_Id: The array index of the bad
          element ID.
        If R3 = H_Invalid_Element_Size: The array index of the bad
           element size.
        If R3 = H_Invalid_Element_Value: The array index of the bad
           element value.

Invalid element ID, size 또는 value가 있으면 R4에 문제가 있는 array index가 반환됩니다.

`H_GUEST_SET_STATE()`

230-275

L2-wide 또는 vCPU-specific state를 GSB로 설정합니다. Scope 예시와 ID 일치 규칙은 GET과 같습니다.

SET에서는 L1이 GSB의 모든 value를 쓰고 L0는 이를 읽기만 합니다. `returnOwnershipOfVcpuState` flag는 GET의 `takeOwnershipOfVcpuState`와 짝을 이룹니다.

H_GUEST_SET_STATE(uint64 flags,
                  uint64 guestId,
                  uint64 vcpuId,
                  uint64 dataBuffer,
                  uint64 dataBufferSizeInBytes);
Parameters:
  Input:
    flags:
       Bit 0: getGuestWideState: Request state of the Guest instead
         of an individual VCPU.
       Bit 1: returnOwnershipOfVcpuState Return Guest VCPU state. See
         GET_STATE takeOwnershipOfVcpuState
       Bits 2-63: Reserved
    guestId: ID obtained from H_GUEST_CREATE
    vcpuId: ID of the vCPU pass to H_GUEST_CREATE_VCPU
    dataBuffer: A L1 real address of the GSB.
      If takeOwnershipOfVcpuState, size must be at least the size
      returned by ID=0x0001
    dataBufferSizeInBytes: Size of dataBuffer
  Output:
    R3: Return code
    R4: If R3 = H_Invalid_Element_Id: The array index of the bad
          element ID.
        If R3 = H_Invalid_Element_Size: The array index of the bad
           element size.
        If R3 = H_Invalid_Element_Value: The array index of the bad
           element value.

Invalid element ID, size 또는 value에 대해서는 GET과 마찬가지로 R4가 문제가 있는 element index를 반환합니다.

`H_GUEST_RUN_VCPU()`

276-338

미리 `H_GUEST_SET_STATE()`로 설정한 state를 사용해 L2 vCPU를 실행합니다. L2가 exit하면 L1은 이 hcall 다음 위치에서 다시 실행됩니다.

성능을 위해 input/output GSB pointer는 hcall parameter로 매번 전달하지 않습니다. ID `0x0C00`과 `0x0C01`을 사용한 `H_GUEST_SET_STATE()`로 먼저 등록합니다.

Input GSB는 vCPU-specific element만 포함하며 설정할 것이 없으면 첫 4 byte의 element count를 0으로 둘 수 있습니다. Output GSB의 element는 L0가 exit type에 따라 채웁니다.

Exit reason은 GPR4에 들어갑니다. 예를 들어 L2 hcall exit `0xC00`에서는 service에 필요한 GPR3-12가 output GSB에 제공되며 추가 state는 `H_GUEST_GET_STATE()`로 읽습니다.

L1은 run flag로 external interrupt, privileged doorbell 또는 system reset interrupt를 L0가 합성하도록 요청할 수 있습니다. 또는 SET_STATE나 input GSB로 직접 적절한 state를 만들 수 있습니다.

H_GUEST_RUN_VCPU(uint64 flags,
                 uint64 guestId,
                 uint64 vcpuId,
                 uint64 dataBuffer,
                 uint64 dataBufferSizeInBytes);
Parameters:
  Input:
    flags:
       Bit 0: generateExternalInterrupt: Generate an external interrupt
       Bit 1: generatePrivilegedDoorbell: Generate a Privileged Doorbell
       Bit 2: sendToSystemReset”: Generate a System Reset Interrupt
       Bits 3-63: Reserved
    guestId: ID obtained from H_GUEST_CREATE
    vcpuId: ID of the vCPU pass to H_GUEST_CREATE_VCPU
  Output:
    R3: Return code
    R4: If R3 = H_Success: The reason L1 VCPU exited (ie. NIA)
          0x000: The VCPU stopped running for an unspecified reason. An
            example of this is the Hypervisor stopping a VCPU running
            due to an outstanding interrupt for the Host Partition.
          0x980: HDEC
          0xC00: HCALL
          0xE00: HDSI
          0xE20: HISI
          0xE40: HEA
          0xF80: HV Fac Unavail
        If R3 = H_Invalid_Element_Id, H_Invalid_Element_Size, or
          H_Invalid_Element_Value: R4 is offset of the invalid element
          in the input buffer.
R4 exit reason의미
`0x000`명시되지 않은 이유로 중지. 예: host partition interrupt
`0x980`HDEC
`0xC00`HCALL
`0xE00`HDSI
`0xE20`HISI
`0xE40`HEA
`0xF80`HV facility unavailable

`H_GUEST_DELETE()`

339-358

L2를 삭제하면 연결된 모든 vCPU도 함께 삭제됩니다. 별도의 vCPU delete HCALL은 없습니다.

`kdump` 또는 `kexec`에서 L0를 reset할 때는 `deleteAllGuests` flag로 모든 guest를 삭제할 수 있습니다.

H_GUEST_DELETE(uint64 flags,
               uint64 guestId)
Parameters:
  Input:
    flags:
       Bit 0: deleteAllGuests: deletes all guests
       Bits 1-63: Reserved
    guestId: ID obtained from H_GUEST_CREATE
  Output:
    R3: Return code

Guest State Buffer 개요

359-374

GSB는 `H_GUEST_GET_STATE()`, `H_GUEST_SET_STATE()`와 `H_GUEST_VCPU_RUN()` 사이에서 L1과 L0가 L2 state를 교환하는 주된 형식입니다.

State는 L2 전체(timebase offset 등) 또는 특정 vCPU(GPR 등)에 속할 수 있습니다. RUN call에서는 L2 vCPU state만 설정할 수 있습니다.

PAPR 관례에 따라 GSB의 모든 data는 big-endian입니다.

GSB header와 element 형식

375-398
Offset (bytes)Size (bytes)목적
04Element 수
4가변연속된 Guest State Buffer element
Offset (bytes)Size (bytes)목적
02ID
22Value size
4위 size만큼Value
GSB binary layout
영역Offset구성
Header032-bit element count
Element 0416-bit ID + 16-bit size + value
Element N가변다음 ID + size + value

Header의 count 뒤에 ID, size, value로 구성된 element가 연속됩니다.

GSB state ID 전체 표

399-612

Element ID는 architecture state(GPR, VSR, SPR)와 timebase offset, partition/process-scoped page table 같은 metadata를 지정합니다. Scope는 H(host), G(guest-wide), T(thread/vCPU)입니다.

IDSizeAccessScope세부 내용
`0x0000`-RWTGNOP element
`0x0001``0x08`RGL0 vCPU state 크기. `H_GUEST_GET_STATE`의 `takeOwnershipOfVcpuState`에서 사용
`0x0002``0x08`RGRun-vCPU output buffer 크기
`0x0003``0x04`RWGLogical PVR
`0x0004``0x08`RWGL1-relative TB offset
`0x0005``0x18`RWGPartition-scoped page table: `+0x00` address, `+0x08` address bit 수, `+0x10` root directory 크기
`0x0006``0x10`RWGProcess table: `+0x0` address, `+0x8` table 크기
`0x0007-0x07FF`---Reserved
`0x0800``0x08`RH해당 L1 LPAR가 쓰는 L0 Guest Management Space byte 수
`0x0801``0x08`RH해당 L1 LPAR에 허용된 L0 Guest Management Space 최대 byte 수
`0x0802``0x08`RH해당 L1 LPAR가 쓰는 L0 Guest Page Table Management Space byte 수
`0x0803``0x08`RH해당 L1 LPAR에 허용된 Guest Page Table Management Space 최대 byte 수
`0x0804``0x08`RHOvercommit 때문에 L0 guest page-table space에서 누적 회수한 byte 수
`0x0805-0x0BFF`---Reserved
`0x0C00``0x10`RWTRun-vCPU input buffer: `+0x0` address, `+0x8` buffer size
`0x0C01``0x10`RWTRun-vCPU output buffer: `+0x0` address, `+0x8` buffer size
`0x0C02``0x08`RWTvCPU VPA address
`0x0C03-0x0FFF`---Reserved
`0x1000-0x101F``0x08`RWTGPR 0-31
`0x1020``0x08`TTHDEC expiry TB
`0x1021``0x08`RWTNIA
`0x1022``0x08`RWTMSR
`0x1023``0x08`RWTLR
`0x1024``0x08`RWTXER
`0x1025``0x08`RWTCTR
`0x1026``0x08`RWTCFAR
`0x1027``0x08`RWTSRR0
`0x1028``0x08`RWTSRR1
`0x1029``0x08`RWTDAR
`0x102A``0x08`RWTDEC expiry TB
`0x102B``0x08`RWTVTB
`0x102C``0x08`RWTLPCR
`0x102D``0x08`RWTHFSCR
`0x102E``0x08`RWTFSCR
`0x102F``0x08`RWTFPSCR
`0x1030``0x08`RWTDAWR0
`0x1031``0x08`RWTDAWR1
`0x1032``0x08`RWTCIABR
`0x1033``0x08`RWTPURR
`0x1034``0x08`RWTSPURR
`0x1035``0x08`RWTIC
`0x1036-0x1039``0x08`RWTSPRG 0-3
`0x103A``0x08`WTPPR
`0x103B-0x103E``0x08`RWTMMCR 0-3
`0x103F``0x08`RWTMMCRA
`0x1040``0x08`RWTSIER
`0x1041``0x08`RWTSIER 2
`0x1042``0x08`RWTSIER 3
`0x1043``0x08`RWTBESCR
`0x1044``0x08`RWTEBBHR
`0x1045``0x08`RWTEBBRR
`0x1046``0x08`RWTAMR
`0x1047``0x08`RWTIAMR
`0x1048``0x08`RWTAMOR
`0x1049``0x08`RWTUAMOR
`0x104A``0x08`RWTSDAR
`0x104B``0x08`RWTSIAR
`0x104C``0x08`RWTDSCR
`0x104D``0x08`RWTTAR
`0x104E``0x08`RWTDEXCR
`0x104F``0x08`RWTHDEXCR
`0x1050``0x08`RWTHASHKEYR
`0x1051``0x08`RWTHASHPKEYR
`0x1052``0x08`RWTCTRL
`0x1053``0x08`RWTDPDES
`0x1054-0x1FFF`---Reserved
`0x2000``0x04`RWTCR
`0x2001``0x04`RWTPIDR
`0x2002``0x04`RWTDSISR
`0x2003``0x04`RWTVSCR
`0x2004``0x04`RWTVRSAVE
`0x2005``0x04`RWTDAWRX0
`0x2006``0x04`RWTDAWRX1
`0x2007-0x200C``0x04`RWTPMC 1-6
`0x200D``0x04`RWTWORT
`0x200E``0x04`RWTPSPB
`0x200F-0x2FFF`---Reserved
`0x3000-0x303F``0x10`RWTVSR 0-63
`0x3040-0xEFFF`---Reserved
`0xF000``0x08`RTHDAR
`0xF001``0x04`RTHDSISR
`0xF002``0x04`RTHEIR
`0xF003``0x08`RTASDR
GSB ID address space
ID rangeScope대표 state
`0x0000-0x07FF`Guest/ThreadPVR, TB, page/process table
`0x0800-0x0BFF`HostGuest-management memory accounting
`0x0C00-0x0FFF`ThreadRun input/output buffer, VPA
`0x1000-0x1FFF`Thread 64-bitGPR, NIA, MSR, SPR
`0x2000-0x2FFF`Thread 32-bitCR, PIDR, PMC, control state
`0x3000-0xEFFF`Thread 128-bitVSR 0-63
`0xF000-0xF003`Thread read-onlyHDAR, HDSISR, HEIR, ASDR

ID 대역은 guest metadata, host accounting, run buffer, 64/32/128-bit thread state와 hypervisor exit state로 나뉩니다.

Run-vCPU GSB buffers
ID방향사용 시점
`0x0C00`L1 → L0Run 직전 변경 state 전달
`0x0C01`L0 → L1Exit reason에 필요한 state 반환
`0x0C02`L1 → L0vCPU VPA address 등록

등록된 input/output GSB가 hot execution path의 parameter 전달을 줄입니다.

ptregs/hvregs 밖의 state

613-627

v1 API에서는 vector register와 일부 SPR처럼 `ptregs`/`hvstate`에 없는 state가 있습니다. L1이 `h_enter_nested()` 전에 실제 hardware register에 값을 올리고 L0가 건드리지 않아 L2 state로 이어지게 합니다.

v2 API는 이 암묵적 전달을 제거하고 모든 해당 state를 GSB로 명시적으로 설정합니다.

L1 state cache와 lazy update

628-656

v1은 `h_enter_nested()`마다 모든 state를 양방향 전송하고, L2가 실행 중이 아니면 L0가 partition table 위치 외의 state를 유지하지 않습니다.

v2에서는 vCPU가 멈춘 뒤에도 L0가 L2 state를 유지합니다. 따라서 L1은 state를 변경하거나 cache가 낡았을 때만 L0와 통신하면 됩니다.

`H_GUEST_RUN_VCPU()` exit 뒤 L1은 내부 L2 state를 invalid로 표시합니다. 이후 `kvm_get_one_reg()` 같은 조회가 오면 `H_GUEST_GET_STATE()`로 읽고 다음 run까지 valid로 둡니다.

L1이 `kvm_set_one_reg()`로 state를 바꿀 때도 즉시 L0에 쓰지 않고 내부 copy를 갱신합니다. 다음 run 때 `H_GUEST_VCPU_RUN()` input buffer로 flush합니다.

이 lazy update는 불필요한 `H_GUEST_GET_STATE()`와 `H_GUEST_SET_STATE()` 호출을 줄입니다.

L1의 lazy state cache
RUN_VCPU exitL1 cache invalid`kvm_get_one_reg()`GET_STATEcache valid
`kvm_set_one_reg()`L1 copy dirty다음 RUN_VCPUinput GSB flush

Read miss와 다음 run 직전의 write-back만 L0 통신을 일으킵니다.