kvm-nested.rst 29 KB

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