18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci.. _ultravisor:
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci============================
58c2ecf20Sopenharmony_ciProtected Execution Facility
68c2ecf20Sopenharmony_ci============================
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci.. contents::
98c2ecf20Sopenharmony_ci    :depth: 3
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ciIntroduction
128c2ecf20Sopenharmony_ci############
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci    Protected Execution Facility (PEF) is an architectural change for
158c2ecf20Sopenharmony_ci    POWER 9 that enables Secure Virtual Machines (SVMs). DD2.3 chips
168c2ecf20Sopenharmony_ci    (PVR=0x004e1203) or greater will be PEF-capable. A new ISA release
178c2ecf20Sopenharmony_ci    will include the PEF RFC02487 changes.
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci    When enabled, PEF adds a new higher privileged mode, called Ultravisor
208c2ecf20Sopenharmony_ci    mode, to POWER architecture. Along with the new mode there is new
218c2ecf20Sopenharmony_ci    firmware called the Protected Execution Ultravisor (or Ultravisor
228c2ecf20Sopenharmony_ci    for short). Ultravisor mode is the highest privileged mode in POWER
238c2ecf20Sopenharmony_ci    architecture.
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci	+------------------+
268c2ecf20Sopenharmony_ci	| Privilege States |
278c2ecf20Sopenharmony_ci	+==================+
288c2ecf20Sopenharmony_ci	|  Problem         |
298c2ecf20Sopenharmony_ci	+------------------+
308c2ecf20Sopenharmony_ci	|  Supervisor      |
318c2ecf20Sopenharmony_ci	+------------------+
328c2ecf20Sopenharmony_ci	|  Hypervisor      |
338c2ecf20Sopenharmony_ci	+------------------+
348c2ecf20Sopenharmony_ci	|  Ultravisor      |
358c2ecf20Sopenharmony_ci	+------------------+
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci    PEF protects SVMs from the hypervisor, privileged users, and other
388c2ecf20Sopenharmony_ci    VMs in the system. SVMs are protected while at rest and can only be
398c2ecf20Sopenharmony_ci    executed by an authorized machine. All virtual machines utilize
408c2ecf20Sopenharmony_ci    hypervisor services. The Ultravisor filters calls between the SVMs
418c2ecf20Sopenharmony_ci    and the hypervisor to assure that information does not accidentally
428c2ecf20Sopenharmony_ci    leak. All hypercalls except H_RANDOM are reflected to the hypervisor.
438c2ecf20Sopenharmony_ci    H_RANDOM is not reflected to prevent the hypervisor from influencing
448c2ecf20Sopenharmony_ci    random values in the SVM.
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci    To support this there is a refactoring of the ownership of resources
478c2ecf20Sopenharmony_ci    in the CPU. Some of the resources which were previously hypervisor
488c2ecf20Sopenharmony_ci    privileged are now ultravisor privileged.
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ciHardware
518c2ecf20Sopenharmony_ci========
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci    The hardware changes include the following:
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci    * There is a new bit in the MSR that determines whether the current
568c2ecf20Sopenharmony_ci      process is running in secure mode, MSR(S) bit 41. MSR(S)=1, process
578c2ecf20Sopenharmony_ci      is in secure mode, MSR(s)=0 process is in normal mode.
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci    * The MSR(S) bit can only be set by the Ultravisor.
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci    * HRFID cannot be used to set the MSR(S) bit. If the hypervisor needs
628c2ecf20Sopenharmony_ci      to return to a SVM it must use an ultracall. It can determine if
638c2ecf20Sopenharmony_ci      the VM it is returning to is secure.
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci    * There is a new Ultravisor privileged register, SMFCTRL, which has an
668c2ecf20Sopenharmony_ci      enable/disable bit SMFCTRL(E).
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci    * The privilege of a process is now determined by three MSR bits,
698c2ecf20Sopenharmony_ci      MSR(S, HV, PR). In each of the tables below the modes are listed
708c2ecf20Sopenharmony_ci      from least privilege to highest privilege. The higher privilege
718c2ecf20Sopenharmony_ci      modes can access all the resources of the lower privilege modes.
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci      **Secure Mode MSR Settings**
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci      +---+---+---+---------------+
768c2ecf20Sopenharmony_ci      | S | HV| PR|Privilege      |
778c2ecf20Sopenharmony_ci      +===+===+===+===============+
788c2ecf20Sopenharmony_ci      | 1 | 0 | 1 | Problem       |
798c2ecf20Sopenharmony_ci      +---+---+---+---------------+
808c2ecf20Sopenharmony_ci      | 1 | 0 | 0 | Privileged(OS)|
818c2ecf20Sopenharmony_ci      +---+---+---+---------------+
828c2ecf20Sopenharmony_ci      | 1 | 1 | 0 | Ultravisor    |
838c2ecf20Sopenharmony_ci      +---+---+---+---------------+
848c2ecf20Sopenharmony_ci      | 1 | 1 | 1 | Reserved      |
858c2ecf20Sopenharmony_ci      +---+---+---+---------------+
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci      **Normal Mode MSR Settings**
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci      +---+---+---+---------------+
908c2ecf20Sopenharmony_ci      | S | HV| PR|Privilege      |
918c2ecf20Sopenharmony_ci      +===+===+===+===============+
928c2ecf20Sopenharmony_ci      | 0 | 0 | 1 | Problem       |
938c2ecf20Sopenharmony_ci      +---+---+---+---------------+
948c2ecf20Sopenharmony_ci      | 0 | 0 | 0 | Privileged(OS)|
958c2ecf20Sopenharmony_ci      +---+---+---+---------------+
968c2ecf20Sopenharmony_ci      | 0 | 1 | 0 | Hypervisor    |
978c2ecf20Sopenharmony_ci      +---+---+---+---------------+
988c2ecf20Sopenharmony_ci      | 0 | 1 | 1 | Problem (Host)|
998c2ecf20Sopenharmony_ci      +---+---+---+---------------+
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci    * Memory is partitioned into secure and normal memory. Only processes
1028c2ecf20Sopenharmony_ci      that are running in secure mode can access secure memory.
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci    * The hardware does not allow anything that is not running secure to
1058c2ecf20Sopenharmony_ci      access secure memory. This means that the Hypervisor cannot access
1068c2ecf20Sopenharmony_ci      the memory of the SVM without using an ultracall (asking the
1078c2ecf20Sopenharmony_ci      Ultravisor). The Ultravisor will only allow the hypervisor to see
1088c2ecf20Sopenharmony_ci      the SVM memory encrypted.
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci    * I/O systems are not allowed to directly address secure memory. This
1118c2ecf20Sopenharmony_ci      limits the SVMs to virtual I/O only.
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci    * The architecture allows the SVM to share pages of memory with the
1148c2ecf20Sopenharmony_ci      hypervisor that are not protected with encryption. However, this
1158c2ecf20Sopenharmony_ci      sharing must be initiated by the SVM.
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci    * When a process is running in secure mode all hypercalls
1188c2ecf20Sopenharmony_ci      (syscall lev=1) go to the Ultravisor.
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci    * When a process is in secure mode all interrupts go to the
1218c2ecf20Sopenharmony_ci      Ultravisor.
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci    * The following resources have become Ultravisor privileged and
1248c2ecf20Sopenharmony_ci      require an Ultravisor interface to manipulate:
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci      * Processor configurations registers (SCOMs).
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci      * Stop state information.
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci      * The debug registers CIABR, DAWR, and DAWRX when SMFCTRL(D) is set.
1318c2ecf20Sopenharmony_ci        If SMFCTRL(D) is not set they do not work in secure mode. When set,
1328c2ecf20Sopenharmony_ci        reading and writing requires an Ultravisor call, otherwise that
1338c2ecf20Sopenharmony_ci        will cause a Hypervisor Emulation Assistance interrupt.
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci      * PTCR and partition table entries (partition table is in secure
1368c2ecf20Sopenharmony_ci        memory). An attempt to write to PTCR will cause a Hypervisor
1378c2ecf20Sopenharmony_ci        Emulation Assitance interrupt.
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci      * LDBAR (LD Base Address Register) and IMC (In-Memory Collection)
1408c2ecf20Sopenharmony_ci        non-architected registers. An attempt to write to them will cause a
1418c2ecf20Sopenharmony_ci        Hypervisor Emulation Assistance interrupt.
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ci      * Paging for an SVM, sharing of memory with Hypervisor for an SVM.
1448c2ecf20Sopenharmony_ci        (Including Virtual Processor Area (VPA) and virtual I/O).
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ciSoftware/Microcode
1488c2ecf20Sopenharmony_ci==================
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci    The software changes include:
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci    * SVMs are created from normal VM using (open source) tooling supplied
1538c2ecf20Sopenharmony_ci      by IBM.
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci    * All SVMs start as normal VMs and utilize an ultracall, UV_ESM
1568c2ecf20Sopenharmony_ci      (Enter Secure Mode), to make the transition.
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci    * When the UV_ESM ultracall is made the Ultravisor copies the VM into
1598c2ecf20Sopenharmony_ci      secure memory, decrypts the verification information, and checks the
1608c2ecf20Sopenharmony_ci      integrity of the SVM. If the integrity check passes the Ultravisor
1618c2ecf20Sopenharmony_ci      passes control in secure mode.
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci    * The verification information includes the pass phrase for the
1648c2ecf20Sopenharmony_ci      encrypted disk associated with the SVM. This pass phrase is given
1658c2ecf20Sopenharmony_ci      to the SVM when requested.
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ci    * The Ultravisor is not involved in protecting the encrypted disk of
1688c2ecf20Sopenharmony_ci      the SVM while at rest.
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci    * For external interrupts the Ultravisor saves the state of the SVM,
1718c2ecf20Sopenharmony_ci      and reflects the interrupt to the hypervisor for processing.
1728c2ecf20Sopenharmony_ci      For hypercalls, the Ultravisor inserts neutral state into all
1738c2ecf20Sopenharmony_ci      registers not needed for the hypercall then reflects the call to
1748c2ecf20Sopenharmony_ci      the hypervisor for processing. The H_RANDOM hypercall is performed
1758c2ecf20Sopenharmony_ci      by the Ultravisor and not reflected.
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci    * For virtual I/O to work bounce buffering must be done.
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci    * The Ultravisor uses AES (IAPM) for protection of SVM memory. IAPM
1808c2ecf20Sopenharmony_ci      is a mode of AES that provides integrity and secrecy concurrently.
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci    * The movement of data between normal and secure pages is coordinated
1838c2ecf20Sopenharmony_ci      with the Ultravisor by a new HMM plug-in in the Hypervisor.
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ci    The Ultravisor offers new services to the hypervisor and SVMs. These
1868c2ecf20Sopenharmony_ci    are accessed through ultracalls.
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ciTerminology
1898c2ecf20Sopenharmony_ci===========
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci    * Hypercalls: special system calls used to request services from
1928c2ecf20Sopenharmony_ci      Hypervisor.
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ci    * Normal memory: Memory that is accessible to Hypervisor.
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci    * Normal page: Page backed by normal memory and available to
1978c2ecf20Sopenharmony_ci      Hypervisor.
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci    * Shared page: A page backed by normal memory and available to both
2008c2ecf20Sopenharmony_ci      the Hypervisor/QEMU and the SVM (i.e page has mappings in SVM and
2018c2ecf20Sopenharmony_ci      Hypervisor/QEMU).
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci    * Secure memory: Memory that is accessible only to Ultravisor and
2048c2ecf20Sopenharmony_ci      SVMs.
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ci    * Secure page: Page backed by secure memory and only available to
2078c2ecf20Sopenharmony_ci      Ultravisor and SVM.
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_ci    * SVM: Secure Virtual Machine.
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci    * Ultracalls: special system calls used to request services from
2128c2ecf20Sopenharmony_ci      Ultravisor.
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ciUltravisor calls API
2168c2ecf20Sopenharmony_ci####################
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ci    This section describes Ultravisor calls (ultracalls) needed to
2198c2ecf20Sopenharmony_ci    support Secure Virtual Machines (SVM)s and Paravirtualized KVM. The
2208c2ecf20Sopenharmony_ci    ultracalls allow the SVMs and Hypervisor to request services from the
2218c2ecf20Sopenharmony_ci    Ultravisor such as accessing a register or memory region that can only
2228c2ecf20Sopenharmony_ci    be accessed when running in Ultravisor-privileged mode.
2238c2ecf20Sopenharmony_ci
2248c2ecf20Sopenharmony_ci    The specific service needed from an ultracall is specified in register
2258c2ecf20Sopenharmony_ci    R3 (the first parameter to the ultracall). Other parameters to the
2268c2ecf20Sopenharmony_ci    ultracall, if any, are specified in registers R4 through R12.
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci    Return value of all ultracalls is in register R3. Other output values
2298c2ecf20Sopenharmony_ci    from the ultracall, if any, are returned in registers R4 through R12.
2308c2ecf20Sopenharmony_ci    The only exception to this register usage is the ``UV_RETURN``
2318c2ecf20Sopenharmony_ci    ultracall described below.
2328c2ecf20Sopenharmony_ci
2338c2ecf20Sopenharmony_ci    Each ultracall returns specific error codes, applicable in the context
2348c2ecf20Sopenharmony_ci    of the ultracall. However, like with the PowerPC Architecture Platform
2358c2ecf20Sopenharmony_ci    Reference (PAPR), if no specific error code is defined for a
2368c2ecf20Sopenharmony_ci    particular situation, then the ultracall will fallback to an erroneous
2378c2ecf20Sopenharmony_ci    parameter-position based code. i.e U_PARAMETER, U_P2, U_P3 etc
2388c2ecf20Sopenharmony_ci    depending on the ultracall parameter that may have caused the error.
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_ci    Some ultracalls involve transferring a page of data between Ultravisor
2418c2ecf20Sopenharmony_ci    and Hypervisor.  Secure pages that are transferred from secure memory
2428c2ecf20Sopenharmony_ci    to normal memory may be encrypted using dynamically generated keys.
2438c2ecf20Sopenharmony_ci    When the secure pages are transferred back to secure memory, they may
2448c2ecf20Sopenharmony_ci    be decrypted using the same dynamically generated keys. Generation and
2458c2ecf20Sopenharmony_ci    management of these keys will be covered in a separate document.
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_ci    For now this only covers ultracalls currently implemented and being
2488c2ecf20Sopenharmony_ci    used by Hypervisor and SVMs but others can be added here when it
2498c2ecf20Sopenharmony_ci    makes sense.
2508c2ecf20Sopenharmony_ci
2518c2ecf20Sopenharmony_ci    The full specification for all hypercalls/ultracalls will eventually
2528c2ecf20Sopenharmony_ci    be made available in the public/OpenPower version of the PAPR
2538c2ecf20Sopenharmony_ci    specification.
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci    .. note::
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci        If PEF is not enabled, the ultracalls will be redirected to the
2588c2ecf20Sopenharmony_ci        Hypervisor which must handle/fail the calls.
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_ciUltracalls used by Hypervisor
2618c2ecf20Sopenharmony_ci=============================
2628c2ecf20Sopenharmony_ci
2638c2ecf20Sopenharmony_ci    This section describes the virtual memory management ultracalls used
2648c2ecf20Sopenharmony_ci    by the Hypervisor to manage SVMs.
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_ciUV_PAGE_OUT
2678c2ecf20Sopenharmony_ci-----------
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_ci    Encrypt and move the contents of a page from secure memory to normal
2708c2ecf20Sopenharmony_ci    memory.
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_ciSyntax
2738c2ecf20Sopenharmony_ci~~~~~~
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_ci.. code-block:: c
2768c2ecf20Sopenharmony_ci
2778c2ecf20Sopenharmony_ci	uint64_t ultracall(const uint64_t UV_PAGE_OUT,
2788c2ecf20Sopenharmony_ci		uint16_t lpid,		/* LPAR ID */
2798c2ecf20Sopenharmony_ci		uint64_t dest_ra,	/* real address of destination page */
2808c2ecf20Sopenharmony_ci		uint64_t src_gpa,	/* source guest-physical-address */
2818c2ecf20Sopenharmony_ci		uint8_t  flags,		/* flags */
2828c2ecf20Sopenharmony_ci		uint64_t order)		/* page size order */
2838c2ecf20Sopenharmony_ci
2848c2ecf20Sopenharmony_ciReturn values
2858c2ecf20Sopenharmony_ci~~~~~~~~~~~~~
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_ci    One of the following values:
2888c2ecf20Sopenharmony_ci
2898c2ecf20Sopenharmony_ci	* U_SUCCESS	on success.
2908c2ecf20Sopenharmony_ci	* U_PARAMETER	if ``lpid`` is invalid.
2918c2ecf20Sopenharmony_ci	* U_P2 		if ``dest_ra`` is invalid.
2928c2ecf20Sopenharmony_ci	* U_P3		if the ``src_gpa`` address is invalid.
2938c2ecf20Sopenharmony_ci	* U_P4		if any bit in the ``flags`` is unrecognized
2948c2ecf20Sopenharmony_ci	* U_P5		if the ``order`` parameter is unsupported.
2958c2ecf20Sopenharmony_ci	* U_FUNCTION	if functionality is not supported.
2968c2ecf20Sopenharmony_ci	* U_BUSY	if page cannot be currently paged-out.
2978c2ecf20Sopenharmony_ci
2988c2ecf20Sopenharmony_ciDescription
2998c2ecf20Sopenharmony_ci~~~~~~~~~~~
3008c2ecf20Sopenharmony_ci
3018c2ecf20Sopenharmony_ci    Encrypt the contents of a secure-page and make it available to
3028c2ecf20Sopenharmony_ci    Hypervisor in a normal page.
3038c2ecf20Sopenharmony_ci
3048c2ecf20Sopenharmony_ci    By default, the source page is unmapped from the SVM's partition-
3058c2ecf20Sopenharmony_ci    scoped page table. But the Hypervisor can provide a hint to the
3068c2ecf20Sopenharmony_ci    Ultravisor to retain the page mapping by setting the ``UV_SNAPSHOT``
3078c2ecf20Sopenharmony_ci    flag in ``flags`` parameter.
3088c2ecf20Sopenharmony_ci
3098c2ecf20Sopenharmony_ci    If the source page is already a shared page the call returns
3108c2ecf20Sopenharmony_ci    U_SUCCESS, without doing anything.
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_ciUse cases
3138c2ecf20Sopenharmony_ci~~~~~~~~~
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_ci    #. QEMU attempts to access an address belonging to the SVM but the
3168c2ecf20Sopenharmony_ci       page frame for that address is not mapped into QEMU's address
3178c2ecf20Sopenharmony_ci       space. In this case, the Hypervisor will allocate a page frame,
3188c2ecf20Sopenharmony_ci       map it into QEMU's address space and issue the ``UV_PAGE_OUT``
3198c2ecf20Sopenharmony_ci       call to retrieve the encrypted contents of the page.
3208c2ecf20Sopenharmony_ci
3218c2ecf20Sopenharmony_ci    #. When Ultravisor runs low on secure memory and it needs to page-out
3228c2ecf20Sopenharmony_ci       an LRU page. In this case, Ultravisor will issue the
3238c2ecf20Sopenharmony_ci       ``H_SVM_PAGE_OUT`` hypercall to the Hypervisor. The Hypervisor will
3248c2ecf20Sopenharmony_ci       then allocate a normal page and issue the ``UV_PAGE_OUT`` ultracall
3258c2ecf20Sopenharmony_ci       and the Ultravisor will encrypt and move the contents of the secure
3268c2ecf20Sopenharmony_ci       page into the normal page.
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_ci    #. When Hypervisor accesses SVM data, the Hypervisor requests the
3298c2ecf20Sopenharmony_ci       Ultravisor to transfer the corresponding page into a insecure page,
3308c2ecf20Sopenharmony_ci       which the Hypervisor can access. The data in the normal page will
3318c2ecf20Sopenharmony_ci       be encrypted though.
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_ciUV_PAGE_IN
3348c2ecf20Sopenharmony_ci----------
3358c2ecf20Sopenharmony_ci
3368c2ecf20Sopenharmony_ci    Move the contents of a page from normal memory to secure memory.
3378c2ecf20Sopenharmony_ci
3388c2ecf20Sopenharmony_ciSyntax
3398c2ecf20Sopenharmony_ci~~~~~~
3408c2ecf20Sopenharmony_ci
3418c2ecf20Sopenharmony_ci.. code-block:: c
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci	uint64_t ultracall(const uint64_t UV_PAGE_IN,
3448c2ecf20Sopenharmony_ci		uint16_t lpid,		/* the LPAR ID */
3458c2ecf20Sopenharmony_ci		uint64_t src_ra,	/* source real address of page */
3468c2ecf20Sopenharmony_ci		uint64_t dest_gpa,	/* destination guest physical address */
3478c2ecf20Sopenharmony_ci		uint64_t flags,		/* flags */
3488c2ecf20Sopenharmony_ci		uint64_t order)		/* page size order */
3498c2ecf20Sopenharmony_ci
3508c2ecf20Sopenharmony_ciReturn values
3518c2ecf20Sopenharmony_ci~~~~~~~~~~~~~
3528c2ecf20Sopenharmony_ci
3538c2ecf20Sopenharmony_ci    One of the following values:
3548c2ecf20Sopenharmony_ci
3558c2ecf20Sopenharmony_ci	* U_SUCCESS	on success.
3568c2ecf20Sopenharmony_ci	* U_BUSY	if page cannot be currently paged-in.
3578c2ecf20Sopenharmony_ci	* U_FUNCTION	if functionality is not supported
3588c2ecf20Sopenharmony_ci	* U_PARAMETER	if ``lpid`` is invalid.
3598c2ecf20Sopenharmony_ci	* U_P2 		if ``src_ra`` is invalid.
3608c2ecf20Sopenharmony_ci	* U_P3		if the ``dest_gpa`` address is invalid.
3618c2ecf20Sopenharmony_ci	* U_P4		if any bit in the ``flags`` is unrecognized
3628c2ecf20Sopenharmony_ci	* U_P5		if the ``order`` parameter is unsupported.
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_ciDescription
3658c2ecf20Sopenharmony_ci~~~~~~~~~~~
3668c2ecf20Sopenharmony_ci
3678c2ecf20Sopenharmony_ci    Move the contents of the page identified by ``src_ra`` from normal
3688c2ecf20Sopenharmony_ci    memory to secure memory and map it to the guest physical address
3698c2ecf20Sopenharmony_ci    ``dest_gpa``.
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ci    If `dest_gpa` refers to a shared address, map the page into the
3728c2ecf20Sopenharmony_ci    partition-scoped page-table of the SVM.  If `dest_gpa` is not shared,
3738c2ecf20Sopenharmony_ci    copy the contents of the page into the corresponding secure page.
3748c2ecf20Sopenharmony_ci    Depending on the context, decrypt the page before being copied.
3758c2ecf20Sopenharmony_ci
3768c2ecf20Sopenharmony_ci    The caller provides the attributes of the page through the ``flags``
3778c2ecf20Sopenharmony_ci    parameter. Valid values for ``flags`` are:
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_ci	* CACHE_INHIBITED
3808c2ecf20Sopenharmony_ci	* CACHE_ENABLED
3818c2ecf20Sopenharmony_ci	* WRITE_PROTECTION
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_ci    The Hypervisor must pin the page in memory before making
3848c2ecf20Sopenharmony_ci    ``UV_PAGE_IN`` ultracall.
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_ciUse cases
3878c2ecf20Sopenharmony_ci~~~~~~~~~
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_ci    #. When a normal VM switches to secure mode, all its pages residing
3908c2ecf20Sopenharmony_ci       in normal memory, are moved into secure memory.
3918c2ecf20Sopenharmony_ci
3928c2ecf20Sopenharmony_ci    #. When an SVM requests to share a page with Hypervisor the Hypervisor
3938c2ecf20Sopenharmony_ci       allocates a page and informs the Ultravisor.
3948c2ecf20Sopenharmony_ci
3958c2ecf20Sopenharmony_ci    #. When an SVM accesses a secure page that has been paged-out,
3968c2ecf20Sopenharmony_ci       Ultravisor invokes the Hypervisor to locate the page. After
3978c2ecf20Sopenharmony_ci       locating the page, the Hypervisor uses UV_PAGE_IN to make the
3988c2ecf20Sopenharmony_ci       page available to Ultravisor.
3998c2ecf20Sopenharmony_ci
4008c2ecf20Sopenharmony_ciUV_PAGE_INVAL
4018c2ecf20Sopenharmony_ci-------------
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_ci    Invalidate the Ultravisor mapping of a page.
4048c2ecf20Sopenharmony_ci
4058c2ecf20Sopenharmony_ciSyntax
4068c2ecf20Sopenharmony_ci~~~~~~
4078c2ecf20Sopenharmony_ci
4088c2ecf20Sopenharmony_ci.. code-block:: c
4098c2ecf20Sopenharmony_ci
4108c2ecf20Sopenharmony_ci	uint64_t ultracall(const uint64_t UV_PAGE_INVAL,
4118c2ecf20Sopenharmony_ci		uint16_t lpid,		/* the LPAR ID */
4128c2ecf20Sopenharmony_ci		uint64_t guest_pa,	/* destination guest-physical-address */
4138c2ecf20Sopenharmony_ci		uint64_t order)		/* page size order */
4148c2ecf20Sopenharmony_ci
4158c2ecf20Sopenharmony_ciReturn values
4168c2ecf20Sopenharmony_ci~~~~~~~~~~~~~
4178c2ecf20Sopenharmony_ci
4188c2ecf20Sopenharmony_ci    One of the following values:
4198c2ecf20Sopenharmony_ci
4208c2ecf20Sopenharmony_ci	* U_SUCCESS	on success.
4218c2ecf20Sopenharmony_ci	* U_PARAMETER	if ``lpid`` is invalid.
4228c2ecf20Sopenharmony_ci	* U_P2 		if ``guest_pa`` is invalid (or corresponds to a secure
4238c2ecf20Sopenharmony_ci                        page mapping).
4248c2ecf20Sopenharmony_ci	* U_P3		if the ``order`` is invalid.
4258c2ecf20Sopenharmony_ci	* U_FUNCTION	if functionality is not supported.
4268c2ecf20Sopenharmony_ci	* U_BUSY	if page cannot be currently invalidated.
4278c2ecf20Sopenharmony_ci
4288c2ecf20Sopenharmony_ciDescription
4298c2ecf20Sopenharmony_ci~~~~~~~~~~~
4308c2ecf20Sopenharmony_ci
4318c2ecf20Sopenharmony_ci    This ultracall informs Ultravisor that the page mapping in Hypervisor
4328c2ecf20Sopenharmony_ci    corresponding to the given guest physical address has been invalidated
4338c2ecf20Sopenharmony_ci    and that the Ultravisor should not access the page. If the specified
4348c2ecf20Sopenharmony_ci    ``guest_pa`` corresponds to a secure page, Ultravisor will ignore the
4358c2ecf20Sopenharmony_ci    attempt to invalidate the page and return U_P2.
4368c2ecf20Sopenharmony_ci
4378c2ecf20Sopenharmony_ciUse cases
4388c2ecf20Sopenharmony_ci~~~~~~~~~
4398c2ecf20Sopenharmony_ci
4408c2ecf20Sopenharmony_ci    #. When a shared page is unmapped from the QEMU's page table, possibly
4418c2ecf20Sopenharmony_ci       because it is paged-out to disk, Ultravisor needs to know that the
4428c2ecf20Sopenharmony_ci       page should not be accessed from its side too.
4438c2ecf20Sopenharmony_ci
4448c2ecf20Sopenharmony_ci
4458c2ecf20Sopenharmony_ciUV_WRITE_PATE
4468c2ecf20Sopenharmony_ci-------------
4478c2ecf20Sopenharmony_ci
4488c2ecf20Sopenharmony_ci    Validate and write the partition table entry (PATE) for a given
4498c2ecf20Sopenharmony_ci    partition.
4508c2ecf20Sopenharmony_ci
4518c2ecf20Sopenharmony_ciSyntax
4528c2ecf20Sopenharmony_ci~~~~~~
4538c2ecf20Sopenharmony_ci
4548c2ecf20Sopenharmony_ci.. code-block:: c
4558c2ecf20Sopenharmony_ci
4568c2ecf20Sopenharmony_ci	uint64_t ultracall(const uint64_t UV_WRITE_PATE,
4578c2ecf20Sopenharmony_ci		uint32_t lpid,		/* the LPAR ID */
4588c2ecf20Sopenharmony_ci		uint64_t dw0		/* the first double word to write */
4598c2ecf20Sopenharmony_ci		uint64_t dw1)		/* the second double word to write */
4608c2ecf20Sopenharmony_ci
4618c2ecf20Sopenharmony_ciReturn values
4628c2ecf20Sopenharmony_ci~~~~~~~~~~~~~
4638c2ecf20Sopenharmony_ci
4648c2ecf20Sopenharmony_ci    One of the following values:
4658c2ecf20Sopenharmony_ci
4668c2ecf20Sopenharmony_ci	* U_SUCCESS	on success.
4678c2ecf20Sopenharmony_ci	* U_BUSY	if PATE cannot be currently written to.
4688c2ecf20Sopenharmony_ci	* U_FUNCTION	if functionality is not supported.
4698c2ecf20Sopenharmony_ci	* U_PARAMETER	if ``lpid`` is invalid.
4708c2ecf20Sopenharmony_ci	* U_P2 		if ``dw0`` is invalid.
4718c2ecf20Sopenharmony_ci	* U_P3		if the ``dw1`` address is invalid.
4728c2ecf20Sopenharmony_ci	* U_PERMISSION	if the Hypervisor is attempting to change the PATE
4738c2ecf20Sopenharmony_ci			of a secure virtual machine or if called from a
4748c2ecf20Sopenharmony_ci			context other than Hypervisor.
4758c2ecf20Sopenharmony_ci
4768c2ecf20Sopenharmony_ciDescription
4778c2ecf20Sopenharmony_ci~~~~~~~~~~~
4788c2ecf20Sopenharmony_ci
4798c2ecf20Sopenharmony_ci    Validate and write a LPID and its partition-table-entry for the given
4808c2ecf20Sopenharmony_ci    LPID.  If the LPID is already allocated and initialized, this call
4818c2ecf20Sopenharmony_ci    results in changing the partition table entry.
4828c2ecf20Sopenharmony_ci
4838c2ecf20Sopenharmony_ciUse cases
4848c2ecf20Sopenharmony_ci~~~~~~~~~
4858c2ecf20Sopenharmony_ci
4868c2ecf20Sopenharmony_ci    #. The Partition table resides in Secure memory and its entries,
4878c2ecf20Sopenharmony_ci       called PATE (Partition Table Entries), point to the partition-
4888c2ecf20Sopenharmony_ci       scoped page tables for the Hypervisor as well as each of the
4898c2ecf20Sopenharmony_ci       virtual machines (both secure and normal). The Hypervisor
4908c2ecf20Sopenharmony_ci       operates in partition 0 and its partition-scoped page tables
4918c2ecf20Sopenharmony_ci       reside in normal memory.
4928c2ecf20Sopenharmony_ci
4938c2ecf20Sopenharmony_ci    #. This ultracall allows the Hypervisor to register the partition-
4948c2ecf20Sopenharmony_ci       scoped and process-scoped page table entries for the Hypervisor
4958c2ecf20Sopenharmony_ci       and other partitions (virtual machines) with the Ultravisor.
4968c2ecf20Sopenharmony_ci
4978c2ecf20Sopenharmony_ci    #. If the value of the PATE for an existing partition (VM) changes,
4988c2ecf20Sopenharmony_ci       the TLB cache for the partition is flushed.
4998c2ecf20Sopenharmony_ci
5008c2ecf20Sopenharmony_ci    #. The Hypervisor is responsible for allocating LPID. The LPID and
5018c2ecf20Sopenharmony_ci       its PATE entry are registered together.  The Hypervisor manages
5028c2ecf20Sopenharmony_ci       the PATE entries for a normal VM and can change the PATE entry
5038c2ecf20Sopenharmony_ci       anytime. Ultravisor manages the PATE entries for an SVM and
5048c2ecf20Sopenharmony_ci       Hypervisor is not allowed to modify them.
5058c2ecf20Sopenharmony_ci
5068c2ecf20Sopenharmony_ciUV_RETURN
5078c2ecf20Sopenharmony_ci---------
5088c2ecf20Sopenharmony_ci
5098c2ecf20Sopenharmony_ci    Return control from the Hypervisor back to the Ultravisor after
5108c2ecf20Sopenharmony_ci    processing an hypercall or interrupt that was forwarded (aka
5118c2ecf20Sopenharmony_ci    *reflected*) to the Hypervisor.
5128c2ecf20Sopenharmony_ci
5138c2ecf20Sopenharmony_ciSyntax
5148c2ecf20Sopenharmony_ci~~~~~~
5158c2ecf20Sopenharmony_ci
5168c2ecf20Sopenharmony_ci.. code-block:: c
5178c2ecf20Sopenharmony_ci
5188c2ecf20Sopenharmony_ci	uint64_t ultracall(const uint64_t UV_RETURN)
5198c2ecf20Sopenharmony_ci
5208c2ecf20Sopenharmony_ciReturn values
5218c2ecf20Sopenharmony_ci~~~~~~~~~~~~~
5228c2ecf20Sopenharmony_ci
5238c2ecf20Sopenharmony_ci     This call never returns to Hypervisor on success.  It returns
5248c2ecf20Sopenharmony_ci     U_INVALID if ultracall is not made from a Hypervisor context.
5258c2ecf20Sopenharmony_ci
5268c2ecf20Sopenharmony_ciDescription
5278c2ecf20Sopenharmony_ci~~~~~~~~~~~
5288c2ecf20Sopenharmony_ci
5298c2ecf20Sopenharmony_ci    When an SVM makes an hypercall or incurs some other exception, the
5308c2ecf20Sopenharmony_ci    Ultravisor usually forwards (aka *reflects*) the exceptions to the
5318c2ecf20Sopenharmony_ci    Hypervisor.  After processing the exception, Hypervisor uses the
5328c2ecf20Sopenharmony_ci    ``UV_RETURN`` ultracall to return control back to the SVM.
5338c2ecf20Sopenharmony_ci
5348c2ecf20Sopenharmony_ci    The expected register state on entry to this ultracall is:
5358c2ecf20Sopenharmony_ci
5368c2ecf20Sopenharmony_ci    * Non-volatile registers are restored to their original values.
5378c2ecf20Sopenharmony_ci    * If returning from an hypercall, register R0 contains the return
5388c2ecf20Sopenharmony_ci      value (**unlike other ultracalls**) and, registers R4 through R12
5398c2ecf20Sopenharmony_ci      contain any output values of the hypercall.
5408c2ecf20Sopenharmony_ci    * R3 contains the ultracall number, i.e UV_RETURN.
5418c2ecf20Sopenharmony_ci    * If returning with a synthesized interrupt, R2 contains the
5428c2ecf20Sopenharmony_ci      synthesized interrupt number.
5438c2ecf20Sopenharmony_ci
5448c2ecf20Sopenharmony_ciUse cases
5458c2ecf20Sopenharmony_ci~~~~~~~~~
5468c2ecf20Sopenharmony_ci
5478c2ecf20Sopenharmony_ci    #. Ultravisor relies on the Hypervisor to provide several services to
5488c2ecf20Sopenharmony_ci       the SVM such as processing hypercall and other exceptions. After
5498c2ecf20Sopenharmony_ci       processing the exception, Hypervisor uses UV_RETURN to return
5508c2ecf20Sopenharmony_ci       control back to the Ultravisor.
5518c2ecf20Sopenharmony_ci
5528c2ecf20Sopenharmony_ci    #. Hypervisor has to use this ultracall to return control to the SVM.
5538c2ecf20Sopenharmony_ci
5548c2ecf20Sopenharmony_ci
5558c2ecf20Sopenharmony_ciUV_REGISTER_MEM_SLOT
5568c2ecf20Sopenharmony_ci--------------------
5578c2ecf20Sopenharmony_ci
5588c2ecf20Sopenharmony_ci    Register an SVM address-range with specified properties.
5598c2ecf20Sopenharmony_ci
5608c2ecf20Sopenharmony_ciSyntax
5618c2ecf20Sopenharmony_ci~~~~~~
5628c2ecf20Sopenharmony_ci
5638c2ecf20Sopenharmony_ci.. code-block:: c
5648c2ecf20Sopenharmony_ci
5658c2ecf20Sopenharmony_ci	uint64_t ultracall(const uint64_t UV_REGISTER_MEM_SLOT,
5668c2ecf20Sopenharmony_ci		uint64_t lpid,		/* LPAR ID of the SVM */
5678c2ecf20Sopenharmony_ci		uint64_t start_gpa,	/* start guest physical address */
5688c2ecf20Sopenharmony_ci		uint64_t size,		/* size of address range in bytes */
5698c2ecf20Sopenharmony_ci		uint64_t flags		/* reserved for future expansion */
5708c2ecf20Sopenharmony_ci		uint16_t slotid)	/* slot identifier */
5718c2ecf20Sopenharmony_ci
5728c2ecf20Sopenharmony_ciReturn values
5738c2ecf20Sopenharmony_ci~~~~~~~~~~~~~
5748c2ecf20Sopenharmony_ci
5758c2ecf20Sopenharmony_ci    One of the following values:
5768c2ecf20Sopenharmony_ci
5778c2ecf20Sopenharmony_ci	* U_SUCCESS	on success.
5788c2ecf20Sopenharmony_ci	* U_PARAMETER	if ``lpid`` is invalid.
5798c2ecf20Sopenharmony_ci	* U_P2 		if ``start_gpa`` is invalid.
5808c2ecf20Sopenharmony_ci	* U_P3		if ``size`` is invalid.
5818c2ecf20Sopenharmony_ci	* U_P4		if any bit in the ``flags`` is unrecognized.
5828c2ecf20Sopenharmony_ci	* U_P5		if the ``slotid`` parameter is unsupported.
5838c2ecf20Sopenharmony_ci	* U_PERMISSION	if called from context other than Hypervisor.
5848c2ecf20Sopenharmony_ci	* U_FUNCTION	if functionality is not supported.
5858c2ecf20Sopenharmony_ci
5868c2ecf20Sopenharmony_ci
5878c2ecf20Sopenharmony_ciDescription
5888c2ecf20Sopenharmony_ci~~~~~~~~~~~
5898c2ecf20Sopenharmony_ci
5908c2ecf20Sopenharmony_ci    Register a memory range for an SVM.  The memory range starts at the
5918c2ecf20Sopenharmony_ci    guest physical address ``start_gpa`` and is ``size`` bytes long.
5928c2ecf20Sopenharmony_ci
5938c2ecf20Sopenharmony_ciUse cases
5948c2ecf20Sopenharmony_ci~~~~~~~~~
5958c2ecf20Sopenharmony_ci
5968c2ecf20Sopenharmony_ci
5978c2ecf20Sopenharmony_ci    #. When a virtual machine goes secure, all the memory slots managed by
5988c2ecf20Sopenharmony_ci       the Hypervisor move into secure memory. The Hypervisor iterates
5998c2ecf20Sopenharmony_ci       through each of memory slots, and registers the slot with
6008c2ecf20Sopenharmony_ci       Ultravisor.  Hypervisor may discard some slots such as those used
6018c2ecf20Sopenharmony_ci       for firmware (SLOF).
6028c2ecf20Sopenharmony_ci
6038c2ecf20Sopenharmony_ci    #. When new memory is hot-plugged, a new memory slot gets registered.
6048c2ecf20Sopenharmony_ci
6058c2ecf20Sopenharmony_ci
6068c2ecf20Sopenharmony_ciUV_UNREGISTER_MEM_SLOT
6078c2ecf20Sopenharmony_ci----------------------
6088c2ecf20Sopenharmony_ci
6098c2ecf20Sopenharmony_ci    Unregister an SVM address-range that was previously registered using
6108c2ecf20Sopenharmony_ci    UV_REGISTER_MEM_SLOT.
6118c2ecf20Sopenharmony_ci
6128c2ecf20Sopenharmony_ciSyntax
6138c2ecf20Sopenharmony_ci~~~~~~
6148c2ecf20Sopenharmony_ci
6158c2ecf20Sopenharmony_ci.. code-block:: c
6168c2ecf20Sopenharmony_ci
6178c2ecf20Sopenharmony_ci	uint64_t ultracall(const uint64_t UV_UNREGISTER_MEM_SLOT,
6188c2ecf20Sopenharmony_ci		uint64_t lpid,		/* LPAR ID of the SVM */
6198c2ecf20Sopenharmony_ci		uint64_t slotid)	/* reservation slotid */
6208c2ecf20Sopenharmony_ci
6218c2ecf20Sopenharmony_ciReturn values
6228c2ecf20Sopenharmony_ci~~~~~~~~~~~~~
6238c2ecf20Sopenharmony_ci
6248c2ecf20Sopenharmony_ci    One of the following values:
6258c2ecf20Sopenharmony_ci
6268c2ecf20Sopenharmony_ci	* U_SUCCESS	on success.
6278c2ecf20Sopenharmony_ci	* U_FUNCTION	if functionality is not supported.
6288c2ecf20Sopenharmony_ci	* U_PARAMETER	if ``lpid`` is invalid.
6298c2ecf20Sopenharmony_ci	* U_P2 		if ``slotid`` is invalid.
6308c2ecf20Sopenharmony_ci	* U_PERMISSION	if called from context other than Hypervisor.
6318c2ecf20Sopenharmony_ci
6328c2ecf20Sopenharmony_ciDescription
6338c2ecf20Sopenharmony_ci~~~~~~~~~~~
6348c2ecf20Sopenharmony_ci
6358c2ecf20Sopenharmony_ci    Release the memory slot identified by ``slotid`` and free any
6368c2ecf20Sopenharmony_ci    resources allocated towards the reservation.
6378c2ecf20Sopenharmony_ci
6388c2ecf20Sopenharmony_ciUse cases
6398c2ecf20Sopenharmony_ci~~~~~~~~~
6408c2ecf20Sopenharmony_ci
6418c2ecf20Sopenharmony_ci    #. Memory hot-remove.
6428c2ecf20Sopenharmony_ci
6438c2ecf20Sopenharmony_ci
6448c2ecf20Sopenharmony_ciUV_SVM_TERMINATE
6458c2ecf20Sopenharmony_ci----------------
6468c2ecf20Sopenharmony_ci
6478c2ecf20Sopenharmony_ci    Terminate an SVM and release its resources.
6488c2ecf20Sopenharmony_ci
6498c2ecf20Sopenharmony_ciSyntax
6508c2ecf20Sopenharmony_ci~~~~~~
6518c2ecf20Sopenharmony_ci
6528c2ecf20Sopenharmony_ci.. code-block:: c
6538c2ecf20Sopenharmony_ci
6548c2ecf20Sopenharmony_ci	uint64_t ultracall(const uint64_t UV_SVM_TERMINATE,
6558c2ecf20Sopenharmony_ci		uint64_t lpid,		/* LPAR ID of the SVM */)
6568c2ecf20Sopenharmony_ci
6578c2ecf20Sopenharmony_ciReturn values
6588c2ecf20Sopenharmony_ci~~~~~~~~~~~~~
6598c2ecf20Sopenharmony_ci
6608c2ecf20Sopenharmony_ci    One of the following values:
6618c2ecf20Sopenharmony_ci
6628c2ecf20Sopenharmony_ci	* U_SUCCESS	on success.
6638c2ecf20Sopenharmony_ci	* U_FUNCTION	if functionality is not supported.
6648c2ecf20Sopenharmony_ci	* U_PARAMETER	if ``lpid`` is invalid.
6658c2ecf20Sopenharmony_ci	* U_INVALID	if VM is not secure.
6668c2ecf20Sopenharmony_ci	* U_PERMISSION  if not called from a Hypervisor context.
6678c2ecf20Sopenharmony_ci
6688c2ecf20Sopenharmony_ciDescription
6698c2ecf20Sopenharmony_ci~~~~~~~~~~~
6708c2ecf20Sopenharmony_ci
6718c2ecf20Sopenharmony_ci    Terminate an SVM and release all its resources.
6728c2ecf20Sopenharmony_ci
6738c2ecf20Sopenharmony_ciUse cases
6748c2ecf20Sopenharmony_ci~~~~~~~~~
6758c2ecf20Sopenharmony_ci
6768c2ecf20Sopenharmony_ci    #. Called by Hypervisor when terminating an SVM.
6778c2ecf20Sopenharmony_ci
6788c2ecf20Sopenharmony_ci
6798c2ecf20Sopenharmony_ciUltracalls used by SVM
6808c2ecf20Sopenharmony_ci======================
6818c2ecf20Sopenharmony_ci
6828c2ecf20Sopenharmony_ciUV_SHARE_PAGE
6838c2ecf20Sopenharmony_ci-------------
6848c2ecf20Sopenharmony_ci
6858c2ecf20Sopenharmony_ci    Share a set of guest physical pages with the Hypervisor.
6868c2ecf20Sopenharmony_ci
6878c2ecf20Sopenharmony_ciSyntax
6888c2ecf20Sopenharmony_ci~~~~~~
6898c2ecf20Sopenharmony_ci
6908c2ecf20Sopenharmony_ci.. code-block:: c
6918c2ecf20Sopenharmony_ci
6928c2ecf20Sopenharmony_ci	uint64_t ultracall(const uint64_t UV_SHARE_PAGE,
6938c2ecf20Sopenharmony_ci		uint64_t gfn,	/* guest page frame number */
6948c2ecf20Sopenharmony_ci		uint64_t num)	/* number of pages of size PAGE_SIZE */
6958c2ecf20Sopenharmony_ci
6968c2ecf20Sopenharmony_ciReturn values
6978c2ecf20Sopenharmony_ci~~~~~~~~~~~~~
6988c2ecf20Sopenharmony_ci
6998c2ecf20Sopenharmony_ci    One of the following values:
7008c2ecf20Sopenharmony_ci
7018c2ecf20Sopenharmony_ci	* U_SUCCESS	on success.
7028c2ecf20Sopenharmony_ci	* U_FUNCTION	if functionality is not supported.
7038c2ecf20Sopenharmony_ci	* U_INVALID	if the VM is not secure.
7048c2ecf20Sopenharmony_ci	* U_PARAMETER	if ``gfn`` is invalid.
7058c2ecf20Sopenharmony_ci	* U_P2 		if ``num`` is invalid.
7068c2ecf20Sopenharmony_ci
7078c2ecf20Sopenharmony_ciDescription
7088c2ecf20Sopenharmony_ci~~~~~~~~~~~
7098c2ecf20Sopenharmony_ci
7108c2ecf20Sopenharmony_ci    Share the ``num`` pages starting at guest physical frame number ``gfn``
7118c2ecf20Sopenharmony_ci    with the Hypervisor. Assume page size is PAGE_SIZE bytes. Zero the
7128c2ecf20Sopenharmony_ci    pages before returning.
7138c2ecf20Sopenharmony_ci
7148c2ecf20Sopenharmony_ci    If the address is already backed by a secure page, unmap the page and
7158c2ecf20Sopenharmony_ci    back it with an insecure page, with the help of the Hypervisor. If it
7168c2ecf20Sopenharmony_ci    is not backed by any page yet, mark the PTE as insecure and back it
7178c2ecf20Sopenharmony_ci    with an insecure page when the address is accessed. If it is already
7188c2ecf20Sopenharmony_ci    backed by an insecure page, zero the page and return.
7198c2ecf20Sopenharmony_ci
7208c2ecf20Sopenharmony_ciUse cases
7218c2ecf20Sopenharmony_ci~~~~~~~~~
7228c2ecf20Sopenharmony_ci
7238c2ecf20Sopenharmony_ci    #. The Hypervisor cannot access the SVM pages since they are backed by
7248c2ecf20Sopenharmony_ci       secure pages. Hence an SVM must explicitly request Ultravisor for
7258c2ecf20Sopenharmony_ci       pages it can share with Hypervisor.
7268c2ecf20Sopenharmony_ci
7278c2ecf20Sopenharmony_ci    #. Shared pages are needed to support virtio and Virtual Processor Area
7288c2ecf20Sopenharmony_ci       (VPA) in SVMs.
7298c2ecf20Sopenharmony_ci
7308c2ecf20Sopenharmony_ci
7318c2ecf20Sopenharmony_ciUV_UNSHARE_PAGE
7328c2ecf20Sopenharmony_ci---------------
7338c2ecf20Sopenharmony_ci
7348c2ecf20Sopenharmony_ci    Restore a shared SVM page to its initial state.
7358c2ecf20Sopenharmony_ci
7368c2ecf20Sopenharmony_ciSyntax
7378c2ecf20Sopenharmony_ci~~~~~~
7388c2ecf20Sopenharmony_ci
7398c2ecf20Sopenharmony_ci.. code-block:: c
7408c2ecf20Sopenharmony_ci
7418c2ecf20Sopenharmony_ci	uint64_t ultracall(const uint64_t UV_UNSHARE_PAGE,
7428c2ecf20Sopenharmony_ci		uint64_t gfn,	/* guest page frame number */
7438c2ecf20Sopenharmony_ci		uint73 num)	/* number of pages of size PAGE_SIZE*/
7448c2ecf20Sopenharmony_ci
7458c2ecf20Sopenharmony_ciReturn values
7468c2ecf20Sopenharmony_ci~~~~~~~~~~~~~
7478c2ecf20Sopenharmony_ci
7488c2ecf20Sopenharmony_ci    One of the following values:
7498c2ecf20Sopenharmony_ci
7508c2ecf20Sopenharmony_ci	* U_SUCCESS	on success.
7518c2ecf20Sopenharmony_ci	* U_FUNCTION	if functionality is not supported.
7528c2ecf20Sopenharmony_ci	* U_INVALID	if VM is not secure.
7538c2ecf20Sopenharmony_ci	* U_PARAMETER	if ``gfn`` is invalid.
7548c2ecf20Sopenharmony_ci	* U_P2 		if ``num`` is invalid.
7558c2ecf20Sopenharmony_ci
7568c2ecf20Sopenharmony_ciDescription
7578c2ecf20Sopenharmony_ci~~~~~~~~~~~
7588c2ecf20Sopenharmony_ci
7598c2ecf20Sopenharmony_ci    Stop sharing ``num`` pages starting at ``gfn`` with the Hypervisor.
7608c2ecf20Sopenharmony_ci    Assume that the page size is PAGE_SIZE. Zero the pages before
7618c2ecf20Sopenharmony_ci    returning.
7628c2ecf20Sopenharmony_ci
7638c2ecf20Sopenharmony_ci    If the address is already backed by an insecure page, unmap the page
7648c2ecf20Sopenharmony_ci    and back it with a secure page. Inform the Hypervisor to release
7658c2ecf20Sopenharmony_ci    reference to its shared page. If the address is not backed by a page
7668c2ecf20Sopenharmony_ci    yet, mark the PTE as secure and back it with a secure page when that
7678c2ecf20Sopenharmony_ci    address is accessed. If it is already backed by an secure page zero
7688c2ecf20Sopenharmony_ci    the page and return.
7698c2ecf20Sopenharmony_ci
7708c2ecf20Sopenharmony_ciUse cases
7718c2ecf20Sopenharmony_ci~~~~~~~~~
7728c2ecf20Sopenharmony_ci
7738c2ecf20Sopenharmony_ci    #. The SVM may decide to unshare a page from the Hypervisor.
7748c2ecf20Sopenharmony_ci
7758c2ecf20Sopenharmony_ci
7768c2ecf20Sopenharmony_ciUV_UNSHARE_ALL_PAGES
7778c2ecf20Sopenharmony_ci--------------------
7788c2ecf20Sopenharmony_ci
7798c2ecf20Sopenharmony_ci    Unshare all pages the SVM has shared with Hypervisor.
7808c2ecf20Sopenharmony_ci
7818c2ecf20Sopenharmony_ciSyntax
7828c2ecf20Sopenharmony_ci~~~~~~
7838c2ecf20Sopenharmony_ci
7848c2ecf20Sopenharmony_ci.. code-block:: c
7858c2ecf20Sopenharmony_ci
7868c2ecf20Sopenharmony_ci	uint64_t ultracall(const uint64_t UV_UNSHARE_ALL_PAGES)
7878c2ecf20Sopenharmony_ci
7888c2ecf20Sopenharmony_ciReturn values
7898c2ecf20Sopenharmony_ci~~~~~~~~~~~~~
7908c2ecf20Sopenharmony_ci
7918c2ecf20Sopenharmony_ci    One of the following values:
7928c2ecf20Sopenharmony_ci
7938c2ecf20Sopenharmony_ci	* U_SUCCESS	on success.
7948c2ecf20Sopenharmony_ci	* U_FUNCTION	if functionality is not supported.
7958c2ecf20Sopenharmony_ci	* U_INVAL	if VM is not secure.
7968c2ecf20Sopenharmony_ci
7978c2ecf20Sopenharmony_ciDescription
7988c2ecf20Sopenharmony_ci~~~~~~~~~~~
7998c2ecf20Sopenharmony_ci
8008c2ecf20Sopenharmony_ci    Unshare all shared pages from the Hypervisor. All unshared pages are
8018c2ecf20Sopenharmony_ci    zeroed on return. Only pages explicitly shared by the SVM with the
8028c2ecf20Sopenharmony_ci    Hypervisor (using UV_SHARE_PAGE ultracall) are unshared. Ultravisor
8038c2ecf20Sopenharmony_ci    may internally share some pages with the Hypervisor without explicit
8048c2ecf20Sopenharmony_ci    request from the SVM.  These pages will not be unshared by this
8058c2ecf20Sopenharmony_ci    ultracall.
8068c2ecf20Sopenharmony_ci
8078c2ecf20Sopenharmony_ciUse cases
8088c2ecf20Sopenharmony_ci~~~~~~~~~
8098c2ecf20Sopenharmony_ci
8108c2ecf20Sopenharmony_ci    #. This call is needed when ``kexec`` is used to boot a different
8118c2ecf20Sopenharmony_ci       kernel. It may also be needed during SVM reset.
8128c2ecf20Sopenharmony_ci
8138c2ecf20Sopenharmony_ciUV_ESM
8148c2ecf20Sopenharmony_ci------
8158c2ecf20Sopenharmony_ci
8168c2ecf20Sopenharmony_ci    Secure the virtual machine (*enter secure mode*).
8178c2ecf20Sopenharmony_ci
8188c2ecf20Sopenharmony_ciSyntax
8198c2ecf20Sopenharmony_ci~~~~~~
8208c2ecf20Sopenharmony_ci
8218c2ecf20Sopenharmony_ci.. code-block:: c
8228c2ecf20Sopenharmony_ci
8238c2ecf20Sopenharmony_ci	uint64_t ultracall(const uint64_t UV_ESM,
8248c2ecf20Sopenharmony_ci		uint64_t esm_blob_addr,	/* location of the ESM blob */
8258c2ecf20Sopenharmony_ci		unint64_t fdt)		/* Flattened device tree */
8268c2ecf20Sopenharmony_ci
8278c2ecf20Sopenharmony_ciReturn values
8288c2ecf20Sopenharmony_ci~~~~~~~~~~~~~
8298c2ecf20Sopenharmony_ci
8308c2ecf20Sopenharmony_ci    One of the following values:
8318c2ecf20Sopenharmony_ci
8328c2ecf20Sopenharmony_ci	* U_SUCCESS	on success (including if VM is already secure).
8338c2ecf20Sopenharmony_ci	* U_FUNCTION	if functionality is not supported.
8348c2ecf20Sopenharmony_ci	* U_INVALID	if VM is not secure.
8358c2ecf20Sopenharmony_ci	* U_PARAMETER	if ``esm_blob_addr`` is invalid.
8368c2ecf20Sopenharmony_ci	* U_P2 		if ``fdt`` is invalid.
8378c2ecf20Sopenharmony_ci	* U_PERMISSION	if any integrity checks fail.
8388c2ecf20Sopenharmony_ci	* U_RETRY	insufficient memory to create SVM.
8398c2ecf20Sopenharmony_ci	* U_NO_KEY	symmetric key unavailable.
8408c2ecf20Sopenharmony_ci
8418c2ecf20Sopenharmony_ciDescription
8428c2ecf20Sopenharmony_ci~~~~~~~~~~~
8438c2ecf20Sopenharmony_ci
8448c2ecf20Sopenharmony_ci    Secure the virtual machine. On successful completion, return
8458c2ecf20Sopenharmony_ci    control to the virtual machine at the address specified in the
8468c2ecf20Sopenharmony_ci    ESM blob.
8478c2ecf20Sopenharmony_ci
8488c2ecf20Sopenharmony_ciUse cases
8498c2ecf20Sopenharmony_ci~~~~~~~~~
8508c2ecf20Sopenharmony_ci
8518c2ecf20Sopenharmony_ci    #. A normal virtual machine can choose to switch to a secure mode.
8528c2ecf20Sopenharmony_ci
8538c2ecf20Sopenharmony_ciHypervisor Calls API
8548c2ecf20Sopenharmony_ci####################
8558c2ecf20Sopenharmony_ci
8568c2ecf20Sopenharmony_ci    This document describes the Hypervisor calls (hypercalls) that are
8578c2ecf20Sopenharmony_ci    needed to support the Ultravisor. Hypercalls are services provided by
8588c2ecf20Sopenharmony_ci    the Hypervisor to virtual machines and Ultravisor.
8598c2ecf20Sopenharmony_ci
8608c2ecf20Sopenharmony_ci    Register usage for these hypercalls is identical to that of the other
8618c2ecf20Sopenharmony_ci    hypercalls defined in the Power Architecture Platform Reference (PAPR)
8628c2ecf20Sopenharmony_ci    document.  i.e on input, register R3 identifies the specific service
8638c2ecf20Sopenharmony_ci    that is being requested and registers R4 through R11 contain
8648c2ecf20Sopenharmony_ci    additional parameters to the hypercall, if any. On output, register
8658c2ecf20Sopenharmony_ci    R3 contains the return value and registers R4 through R9 contain any
8668c2ecf20Sopenharmony_ci    other output values from the hypercall.
8678c2ecf20Sopenharmony_ci
8688c2ecf20Sopenharmony_ci    This document only covers hypercalls currently implemented/planned
8698c2ecf20Sopenharmony_ci    for Ultravisor usage but others can be added here when it makes sense.
8708c2ecf20Sopenharmony_ci
8718c2ecf20Sopenharmony_ci    The full specification for all hypercalls/ultracalls will eventually
8728c2ecf20Sopenharmony_ci    be made available in the public/OpenPower version of the PAPR
8738c2ecf20Sopenharmony_ci    specification.
8748c2ecf20Sopenharmony_ci
8758c2ecf20Sopenharmony_ciHypervisor calls to support Ultravisor
8768c2ecf20Sopenharmony_ci======================================
8778c2ecf20Sopenharmony_ci
8788c2ecf20Sopenharmony_ci    Following are the set of hypercalls needed to support Ultravisor.
8798c2ecf20Sopenharmony_ci
8808c2ecf20Sopenharmony_ciH_SVM_INIT_START
8818c2ecf20Sopenharmony_ci----------------
8828c2ecf20Sopenharmony_ci
8838c2ecf20Sopenharmony_ci    Begin the process of converting a normal virtual machine into an SVM.
8848c2ecf20Sopenharmony_ci
8858c2ecf20Sopenharmony_ciSyntax
8868c2ecf20Sopenharmony_ci~~~~~~
8878c2ecf20Sopenharmony_ci
8888c2ecf20Sopenharmony_ci.. code-block:: c
8898c2ecf20Sopenharmony_ci
8908c2ecf20Sopenharmony_ci	uint64_t hypercall(const uint64_t H_SVM_INIT_START)
8918c2ecf20Sopenharmony_ci
8928c2ecf20Sopenharmony_ciReturn values
8938c2ecf20Sopenharmony_ci~~~~~~~~~~~~~
8948c2ecf20Sopenharmony_ci
8958c2ecf20Sopenharmony_ci    One of the following values:
8968c2ecf20Sopenharmony_ci
8978c2ecf20Sopenharmony_ci	* H_SUCCESS	 on success.
8988c2ecf20Sopenharmony_ci        * H_STATE        if the VM is not in a position to switch to secure.
8998c2ecf20Sopenharmony_ci
9008c2ecf20Sopenharmony_ciDescription
9018c2ecf20Sopenharmony_ci~~~~~~~~~~~
9028c2ecf20Sopenharmony_ci
9038c2ecf20Sopenharmony_ci    Initiate the process of securing a virtual machine. This involves
9048c2ecf20Sopenharmony_ci    coordinating with the Ultravisor, using ultracalls, to allocate
9058c2ecf20Sopenharmony_ci    resources in the Ultravisor for the new SVM, transferring the VM's
9068c2ecf20Sopenharmony_ci    pages from normal to secure memory etc. When the process is
9078c2ecf20Sopenharmony_ci    completed, Ultravisor issues the H_SVM_INIT_DONE hypercall.
9088c2ecf20Sopenharmony_ci
9098c2ecf20Sopenharmony_ciUse cases
9108c2ecf20Sopenharmony_ci~~~~~~~~~
9118c2ecf20Sopenharmony_ci
9128c2ecf20Sopenharmony_ci     #. Ultravisor uses this hypercall to inform Hypervisor that a VM
9138c2ecf20Sopenharmony_ci        has initiated the process of switching to secure mode.
9148c2ecf20Sopenharmony_ci
9158c2ecf20Sopenharmony_ci
9168c2ecf20Sopenharmony_ciH_SVM_INIT_DONE
9178c2ecf20Sopenharmony_ci---------------
9188c2ecf20Sopenharmony_ci
9198c2ecf20Sopenharmony_ci    Complete the process of securing an SVM.
9208c2ecf20Sopenharmony_ci
9218c2ecf20Sopenharmony_ciSyntax
9228c2ecf20Sopenharmony_ci~~~~~~
9238c2ecf20Sopenharmony_ci
9248c2ecf20Sopenharmony_ci.. code-block:: c
9258c2ecf20Sopenharmony_ci
9268c2ecf20Sopenharmony_ci	uint64_t hypercall(const uint64_t H_SVM_INIT_DONE)
9278c2ecf20Sopenharmony_ci
9288c2ecf20Sopenharmony_ciReturn values
9298c2ecf20Sopenharmony_ci~~~~~~~~~~~~~
9308c2ecf20Sopenharmony_ci
9318c2ecf20Sopenharmony_ci    One of the following values:
9328c2ecf20Sopenharmony_ci
9338c2ecf20Sopenharmony_ci	* H_SUCCESS 		on success.
9348c2ecf20Sopenharmony_ci	* H_UNSUPPORTED		if called from the wrong context (e.g.
9358c2ecf20Sopenharmony_ci				from an SVM or before an H_SVM_INIT_START
9368c2ecf20Sopenharmony_ci				hypercall).
9378c2ecf20Sopenharmony_ci	* H_STATE		if the hypervisor could not successfully
9388c2ecf20Sopenharmony_ci                                transition the VM to Secure VM.
9398c2ecf20Sopenharmony_ci
9408c2ecf20Sopenharmony_ciDescription
9418c2ecf20Sopenharmony_ci~~~~~~~~~~~
9428c2ecf20Sopenharmony_ci
9438c2ecf20Sopenharmony_ci    Complete the process of securing a virtual machine. This call must
9448c2ecf20Sopenharmony_ci    be made after a prior call to ``H_SVM_INIT_START`` hypercall.
9458c2ecf20Sopenharmony_ci
9468c2ecf20Sopenharmony_ciUse cases
9478c2ecf20Sopenharmony_ci~~~~~~~~~
9488c2ecf20Sopenharmony_ci
9498c2ecf20Sopenharmony_ci    On successfully securing a virtual machine, the Ultravisor informs
9508c2ecf20Sopenharmony_ci    Hypervisor about it. Hypervisor can use this call to finish setting
9518c2ecf20Sopenharmony_ci    up its internal state for this virtual machine.
9528c2ecf20Sopenharmony_ci
9538c2ecf20Sopenharmony_ci
9548c2ecf20Sopenharmony_ciH_SVM_INIT_ABORT
9558c2ecf20Sopenharmony_ci----------------
9568c2ecf20Sopenharmony_ci
9578c2ecf20Sopenharmony_ci    Abort the process of securing an SVM.
9588c2ecf20Sopenharmony_ci
9598c2ecf20Sopenharmony_ciSyntax
9608c2ecf20Sopenharmony_ci~~~~~~
9618c2ecf20Sopenharmony_ci
9628c2ecf20Sopenharmony_ci.. code-block:: c
9638c2ecf20Sopenharmony_ci
9648c2ecf20Sopenharmony_ci	uint64_t hypercall(const uint64_t H_SVM_INIT_ABORT)
9658c2ecf20Sopenharmony_ci
9668c2ecf20Sopenharmony_ciReturn values
9678c2ecf20Sopenharmony_ci~~~~~~~~~~~~~
9688c2ecf20Sopenharmony_ci
9698c2ecf20Sopenharmony_ci    One of the following values:
9708c2ecf20Sopenharmony_ci
9718c2ecf20Sopenharmony_ci	* H_PARAMETER 		on successfully cleaning up the state,
9728c2ecf20Sopenharmony_ci				Hypervisor will return this value to the
9738c2ecf20Sopenharmony_ci				**guest**, to indicate that the underlying
9748c2ecf20Sopenharmony_ci				UV_ESM ultracall failed.
9758c2ecf20Sopenharmony_ci
9768c2ecf20Sopenharmony_ci	* H_STATE		if called after a VM has gone secure (i.e
9778c2ecf20Sopenharmony_ci				H_SVM_INIT_DONE hypercall was successful).
9788c2ecf20Sopenharmony_ci
9798c2ecf20Sopenharmony_ci	* H_UNSUPPORTED		if called from a wrong context (e.g. from a
9808c2ecf20Sopenharmony_ci				normal VM).
9818c2ecf20Sopenharmony_ci
9828c2ecf20Sopenharmony_ciDescription
9838c2ecf20Sopenharmony_ci~~~~~~~~~~~
9848c2ecf20Sopenharmony_ci
9858c2ecf20Sopenharmony_ci    Abort the process of securing a virtual machine. This call must
9868c2ecf20Sopenharmony_ci    be made after a prior call to ``H_SVM_INIT_START`` hypercall and
9878c2ecf20Sopenharmony_ci    before a call to ``H_SVM_INIT_DONE``.
9888c2ecf20Sopenharmony_ci
9898c2ecf20Sopenharmony_ci    On entry into this hypercall the non-volatile GPRs and FPRs are
9908c2ecf20Sopenharmony_ci    expected to contain the values they had at the time the VM issued
9918c2ecf20Sopenharmony_ci    the UV_ESM ultracall. Further ``SRR0`` is expected to contain the
9928c2ecf20Sopenharmony_ci    address of the instruction after the ``UV_ESM`` ultracall and ``SRR1``
9938c2ecf20Sopenharmony_ci    the MSR value with which to return to the VM.
9948c2ecf20Sopenharmony_ci
9958c2ecf20Sopenharmony_ci    This hypercall will cleanup any partial state that was established for
9968c2ecf20Sopenharmony_ci    the VM since the prior ``H_SVM_INIT_START`` hypercall, including paging
9978c2ecf20Sopenharmony_ci    out pages that were paged-into secure memory, and issue the
9988c2ecf20Sopenharmony_ci    ``UV_SVM_TERMINATE`` ultracall to terminate the VM.
9998c2ecf20Sopenharmony_ci
10008c2ecf20Sopenharmony_ci    After the partial state is cleaned up, control returns to the VM
10018c2ecf20Sopenharmony_ci    (**not Ultravisor**), at the address specified in ``SRR0`` with the
10028c2ecf20Sopenharmony_ci    MSR values set to the value in ``SRR1``.
10038c2ecf20Sopenharmony_ci
10048c2ecf20Sopenharmony_ciUse cases
10058c2ecf20Sopenharmony_ci~~~~~~~~~
10068c2ecf20Sopenharmony_ci
10078c2ecf20Sopenharmony_ci    If after a successful call to ``H_SVM_INIT_START``, the Ultravisor
10088c2ecf20Sopenharmony_ci    encounters an error while securing a virtual machine, either due
10098c2ecf20Sopenharmony_ci    to lack of resources or because the VM's security information could
10108c2ecf20Sopenharmony_ci    not be validated, Ultravisor informs the Hypervisor about it.
10118c2ecf20Sopenharmony_ci    Hypervisor should use this call to clean up any internal state for
10128c2ecf20Sopenharmony_ci    this virtual machine and return to the VM.
10138c2ecf20Sopenharmony_ci
10148c2ecf20Sopenharmony_ciH_SVM_PAGE_IN
10158c2ecf20Sopenharmony_ci-------------
10168c2ecf20Sopenharmony_ci
10178c2ecf20Sopenharmony_ci    Move the contents of a page from normal memory to secure memory.
10188c2ecf20Sopenharmony_ci
10198c2ecf20Sopenharmony_ciSyntax
10208c2ecf20Sopenharmony_ci~~~~~~
10218c2ecf20Sopenharmony_ci
10228c2ecf20Sopenharmony_ci.. code-block:: c
10238c2ecf20Sopenharmony_ci
10248c2ecf20Sopenharmony_ci	uint64_t hypercall(const uint64_t H_SVM_PAGE_IN,
10258c2ecf20Sopenharmony_ci		uint64_t guest_pa,	/* guest-physical-address */
10268c2ecf20Sopenharmony_ci		uint64_t flags,		/* flags */
10278c2ecf20Sopenharmony_ci		uint64_t order)		/* page size order */
10288c2ecf20Sopenharmony_ci
10298c2ecf20Sopenharmony_ciReturn values
10308c2ecf20Sopenharmony_ci~~~~~~~~~~~~~
10318c2ecf20Sopenharmony_ci
10328c2ecf20Sopenharmony_ci    One of the following values:
10338c2ecf20Sopenharmony_ci
10348c2ecf20Sopenharmony_ci	* H_SUCCESS	on success.
10358c2ecf20Sopenharmony_ci	* H_PARAMETER	if ``guest_pa`` is invalid.
10368c2ecf20Sopenharmony_ci	* H_P2		if ``flags`` is invalid.
10378c2ecf20Sopenharmony_ci	* H_P3		if ``order`` of page is invalid.
10388c2ecf20Sopenharmony_ci
10398c2ecf20Sopenharmony_ciDescription
10408c2ecf20Sopenharmony_ci~~~~~~~~~~~
10418c2ecf20Sopenharmony_ci
10428c2ecf20Sopenharmony_ci    Retrieve the content of the page, belonging to the VM at the specified
10438c2ecf20Sopenharmony_ci    guest physical address.
10448c2ecf20Sopenharmony_ci
10458c2ecf20Sopenharmony_ci    Only valid value(s) in ``flags`` are:
10468c2ecf20Sopenharmony_ci
10478c2ecf20Sopenharmony_ci        * H_PAGE_IN_SHARED which indicates that the page is to be shared
10488c2ecf20Sopenharmony_ci	  with the Ultravisor.
10498c2ecf20Sopenharmony_ci
10508c2ecf20Sopenharmony_ci	* H_PAGE_IN_NONSHARED indicates that the UV is not anymore
10518c2ecf20Sopenharmony_ci          interested in the page. Applicable if the page is a shared page.
10528c2ecf20Sopenharmony_ci
10538c2ecf20Sopenharmony_ci    The ``order`` parameter must correspond to the configured page size.
10548c2ecf20Sopenharmony_ci
10558c2ecf20Sopenharmony_ciUse cases
10568c2ecf20Sopenharmony_ci~~~~~~~~~
10578c2ecf20Sopenharmony_ci
10588c2ecf20Sopenharmony_ci    #. When a normal VM becomes a secure VM (using the UV_ESM ultracall),
10598c2ecf20Sopenharmony_ci       the Ultravisor uses this hypercall to move contents of each page of
10608c2ecf20Sopenharmony_ci       the VM from normal memory to secure memory.
10618c2ecf20Sopenharmony_ci
10628c2ecf20Sopenharmony_ci    #. Ultravisor uses this hypercall to ask Hypervisor to provide a page
10638c2ecf20Sopenharmony_ci       in normal memory that can be shared between the SVM and Hypervisor.
10648c2ecf20Sopenharmony_ci
10658c2ecf20Sopenharmony_ci    #. Ultravisor uses this hypercall to page-in a paged-out page. This
10668c2ecf20Sopenharmony_ci       can happen when the SVM touches a paged-out page.
10678c2ecf20Sopenharmony_ci
10688c2ecf20Sopenharmony_ci    #. If SVM wants to disable sharing of pages with Hypervisor, it can
10698c2ecf20Sopenharmony_ci       inform Ultravisor to do so. Ultravisor will then use this hypercall
10708c2ecf20Sopenharmony_ci       and inform Hypervisor that it has released access to the normal
10718c2ecf20Sopenharmony_ci       page.
10728c2ecf20Sopenharmony_ci
10738c2ecf20Sopenharmony_ciH_SVM_PAGE_OUT
10748c2ecf20Sopenharmony_ci---------------
10758c2ecf20Sopenharmony_ci
10768c2ecf20Sopenharmony_ci    Move the contents of the page to normal memory.
10778c2ecf20Sopenharmony_ci
10788c2ecf20Sopenharmony_ciSyntax
10798c2ecf20Sopenharmony_ci~~~~~~
10808c2ecf20Sopenharmony_ci
10818c2ecf20Sopenharmony_ci.. code-block:: c
10828c2ecf20Sopenharmony_ci
10838c2ecf20Sopenharmony_ci	uint64_t hypercall(const uint64_t H_SVM_PAGE_OUT,
10848c2ecf20Sopenharmony_ci		uint64_t guest_pa,	/* guest-physical-address */
10858c2ecf20Sopenharmony_ci		uint64_t flags,		/* flags (currently none) */
10868c2ecf20Sopenharmony_ci		uint64_t order)		/* page size order */
10878c2ecf20Sopenharmony_ci
10888c2ecf20Sopenharmony_ciReturn values
10898c2ecf20Sopenharmony_ci~~~~~~~~~~~~~
10908c2ecf20Sopenharmony_ci
10918c2ecf20Sopenharmony_ci    One of the following values:
10928c2ecf20Sopenharmony_ci
10938c2ecf20Sopenharmony_ci	* H_SUCCESS	on success.
10948c2ecf20Sopenharmony_ci	* H_PARAMETER	if ``guest_pa`` is invalid.
10958c2ecf20Sopenharmony_ci	* H_P2		if ``flags`` is invalid.
10968c2ecf20Sopenharmony_ci	* H_P3		if ``order`` is invalid.
10978c2ecf20Sopenharmony_ci
10988c2ecf20Sopenharmony_ciDescription
10998c2ecf20Sopenharmony_ci~~~~~~~~~~~
11008c2ecf20Sopenharmony_ci
11018c2ecf20Sopenharmony_ci    Move the contents of the page identified by ``guest_pa`` to normal
11028c2ecf20Sopenharmony_ci    memory.
11038c2ecf20Sopenharmony_ci
11048c2ecf20Sopenharmony_ci    Currently ``flags`` is unused and must be set to 0. The ``order``
11058c2ecf20Sopenharmony_ci    parameter must correspond to the configured page size.
11068c2ecf20Sopenharmony_ci
11078c2ecf20Sopenharmony_ciUse cases
11088c2ecf20Sopenharmony_ci~~~~~~~~~
11098c2ecf20Sopenharmony_ci
11108c2ecf20Sopenharmony_ci    #. If Ultravisor is running low on secure pages, it can move the
11118c2ecf20Sopenharmony_ci       contents of some secure pages, into normal pages using this
11128c2ecf20Sopenharmony_ci       hypercall. The content will be encrypted.
11138c2ecf20Sopenharmony_ci
11148c2ecf20Sopenharmony_ciReferences
11158c2ecf20Sopenharmony_ci##########
11168c2ecf20Sopenharmony_ci
11178c2ecf20Sopenharmony_ci- `Supporting Protected Computing on IBM Power Architecture <https://developer.ibm.com/articles/l-support-protected-computing/>`_
1118