xref: /OK3568_Linux_fs/kernel/Documentation/powerpc/ultravisor.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun.. _ultravisor:
3*4882a593Smuzhiyun
4*4882a593Smuzhiyun============================
5*4882a593SmuzhiyunProtected Execution Facility
6*4882a593Smuzhiyun============================
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun.. contents::
9*4882a593Smuzhiyun    :depth: 3
10*4882a593Smuzhiyun
11*4882a593SmuzhiyunIntroduction
12*4882a593Smuzhiyun############
13*4882a593Smuzhiyun
14*4882a593Smuzhiyun    Protected Execution Facility (PEF) is an architectural change for
15*4882a593Smuzhiyun    POWER 9 that enables Secure Virtual Machines (SVMs). DD2.3 chips
16*4882a593Smuzhiyun    (PVR=0x004e1203) or greater will be PEF-capable. A new ISA release
17*4882a593Smuzhiyun    will include the PEF RFC02487 changes.
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun    When enabled, PEF adds a new higher privileged mode, called Ultravisor
20*4882a593Smuzhiyun    mode, to POWER architecture. Along with the new mode there is new
21*4882a593Smuzhiyun    firmware called the Protected Execution Ultravisor (or Ultravisor
22*4882a593Smuzhiyun    for short). Ultravisor mode is the highest privileged mode in POWER
23*4882a593Smuzhiyun    architecture.
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun	+------------------+
26*4882a593Smuzhiyun	| Privilege States |
27*4882a593Smuzhiyun	+==================+
28*4882a593Smuzhiyun	|  Problem         |
29*4882a593Smuzhiyun	+------------------+
30*4882a593Smuzhiyun	|  Supervisor      |
31*4882a593Smuzhiyun	+------------------+
32*4882a593Smuzhiyun	|  Hypervisor      |
33*4882a593Smuzhiyun	+------------------+
34*4882a593Smuzhiyun	|  Ultravisor      |
35*4882a593Smuzhiyun	+------------------+
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun    PEF protects SVMs from the hypervisor, privileged users, and other
38*4882a593Smuzhiyun    VMs in the system. SVMs are protected while at rest and can only be
39*4882a593Smuzhiyun    executed by an authorized machine. All virtual machines utilize
40*4882a593Smuzhiyun    hypervisor services. The Ultravisor filters calls between the SVMs
41*4882a593Smuzhiyun    and the hypervisor to assure that information does not accidentally
42*4882a593Smuzhiyun    leak. All hypercalls except H_RANDOM are reflected to the hypervisor.
43*4882a593Smuzhiyun    H_RANDOM is not reflected to prevent the hypervisor from influencing
44*4882a593Smuzhiyun    random values in the SVM.
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun    To support this there is a refactoring of the ownership of resources
47*4882a593Smuzhiyun    in the CPU. Some of the resources which were previously hypervisor
48*4882a593Smuzhiyun    privileged are now ultravisor privileged.
49*4882a593Smuzhiyun
50*4882a593SmuzhiyunHardware
51*4882a593Smuzhiyun========
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun    The hardware changes include the following:
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun    * There is a new bit in the MSR that determines whether the current
56*4882a593Smuzhiyun      process is running in secure mode, MSR(S) bit 41. MSR(S)=1, process
57*4882a593Smuzhiyun      is in secure mode, MSR(s)=0 process is in normal mode.
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun    * The MSR(S) bit can only be set by the Ultravisor.
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun    * HRFID cannot be used to set the MSR(S) bit. If the hypervisor needs
62*4882a593Smuzhiyun      to return to a SVM it must use an ultracall. It can determine if
63*4882a593Smuzhiyun      the VM it is returning to is secure.
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun    * There is a new Ultravisor privileged register, SMFCTRL, which has an
66*4882a593Smuzhiyun      enable/disable bit SMFCTRL(E).
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun    * The privilege of a process is now determined by three MSR bits,
69*4882a593Smuzhiyun      MSR(S, HV, PR). In each of the tables below the modes are listed
70*4882a593Smuzhiyun      from least privilege to highest privilege. The higher privilege
71*4882a593Smuzhiyun      modes can access all the resources of the lower privilege modes.
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun      **Secure Mode MSR Settings**
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun      +---+---+---+---------------+
76*4882a593Smuzhiyun      | S | HV| PR|Privilege      |
77*4882a593Smuzhiyun      +===+===+===+===============+
78*4882a593Smuzhiyun      | 1 | 0 | 1 | Problem       |
79*4882a593Smuzhiyun      +---+---+---+---------------+
80*4882a593Smuzhiyun      | 1 | 0 | 0 | Privileged(OS)|
81*4882a593Smuzhiyun      +---+---+---+---------------+
82*4882a593Smuzhiyun      | 1 | 1 | 0 | Ultravisor    |
83*4882a593Smuzhiyun      +---+---+---+---------------+
84*4882a593Smuzhiyun      | 1 | 1 | 1 | Reserved      |
85*4882a593Smuzhiyun      +---+---+---+---------------+
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun      **Normal Mode MSR Settings**
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun      +---+---+---+---------------+
90*4882a593Smuzhiyun      | S | HV| PR|Privilege      |
91*4882a593Smuzhiyun      +===+===+===+===============+
92*4882a593Smuzhiyun      | 0 | 0 | 1 | Problem       |
93*4882a593Smuzhiyun      +---+---+---+---------------+
94*4882a593Smuzhiyun      | 0 | 0 | 0 | Privileged(OS)|
95*4882a593Smuzhiyun      +---+---+---+---------------+
96*4882a593Smuzhiyun      | 0 | 1 | 0 | Hypervisor    |
97*4882a593Smuzhiyun      +---+---+---+---------------+
98*4882a593Smuzhiyun      | 0 | 1 | 1 | Problem (Host)|
99*4882a593Smuzhiyun      +---+---+---+---------------+
100*4882a593Smuzhiyun
101*4882a593Smuzhiyun    * Memory is partitioned into secure and normal memory. Only processes
102*4882a593Smuzhiyun      that are running in secure mode can access secure memory.
103*4882a593Smuzhiyun
104*4882a593Smuzhiyun    * The hardware does not allow anything that is not running secure to
105*4882a593Smuzhiyun      access secure memory. This means that the Hypervisor cannot access
106*4882a593Smuzhiyun      the memory of the SVM without using an ultracall (asking the
107*4882a593Smuzhiyun      Ultravisor). The Ultravisor will only allow the hypervisor to see
108*4882a593Smuzhiyun      the SVM memory encrypted.
109*4882a593Smuzhiyun
110*4882a593Smuzhiyun    * I/O systems are not allowed to directly address secure memory. This
111*4882a593Smuzhiyun      limits the SVMs to virtual I/O only.
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun    * The architecture allows the SVM to share pages of memory with the
114*4882a593Smuzhiyun      hypervisor that are not protected with encryption. However, this
115*4882a593Smuzhiyun      sharing must be initiated by the SVM.
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun    * When a process is running in secure mode all hypercalls
118*4882a593Smuzhiyun      (syscall lev=1) go to the Ultravisor.
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun    * When a process is in secure mode all interrupts go to the
121*4882a593Smuzhiyun      Ultravisor.
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun    * The following resources have become Ultravisor privileged and
124*4882a593Smuzhiyun      require an Ultravisor interface to manipulate:
125*4882a593Smuzhiyun
126*4882a593Smuzhiyun      * Processor configurations registers (SCOMs).
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun      * Stop state information.
129*4882a593Smuzhiyun
130*4882a593Smuzhiyun      * The debug registers CIABR, DAWR, and DAWRX when SMFCTRL(D) is set.
131*4882a593Smuzhiyun        If SMFCTRL(D) is not set they do not work in secure mode. When set,
132*4882a593Smuzhiyun        reading and writing requires an Ultravisor call, otherwise that
133*4882a593Smuzhiyun        will cause a Hypervisor Emulation Assistance interrupt.
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun      * PTCR and partition table entries (partition table is in secure
136*4882a593Smuzhiyun        memory). An attempt to write to PTCR will cause a Hypervisor
137*4882a593Smuzhiyun        Emulation Assitance interrupt.
138*4882a593Smuzhiyun
139*4882a593Smuzhiyun      * LDBAR (LD Base Address Register) and IMC (In-Memory Collection)
140*4882a593Smuzhiyun        non-architected registers. An attempt to write to them will cause a
141*4882a593Smuzhiyun        Hypervisor Emulation Assistance interrupt.
142*4882a593Smuzhiyun
143*4882a593Smuzhiyun      * Paging for an SVM, sharing of memory with Hypervisor for an SVM.
144*4882a593Smuzhiyun        (Including Virtual Processor Area (VPA) and virtual I/O).
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun
147*4882a593SmuzhiyunSoftware/Microcode
148*4882a593Smuzhiyun==================
149*4882a593Smuzhiyun
150*4882a593Smuzhiyun    The software changes include:
151*4882a593Smuzhiyun
152*4882a593Smuzhiyun    * SVMs are created from normal VM using (open source) tooling supplied
153*4882a593Smuzhiyun      by IBM.
154*4882a593Smuzhiyun
155*4882a593Smuzhiyun    * All SVMs start as normal VMs and utilize an ultracall, UV_ESM
156*4882a593Smuzhiyun      (Enter Secure Mode), to make the transition.
157*4882a593Smuzhiyun
158*4882a593Smuzhiyun    * When the UV_ESM ultracall is made the Ultravisor copies the VM into
159*4882a593Smuzhiyun      secure memory, decrypts the verification information, and checks the
160*4882a593Smuzhiyun      integrity of the SVM. If the integrity check passes the Ultravisor
161*4882a593Smuzhiyun      passes control in secure mode.
162*4882a593Smuzhiyun
163*4882a593Smuzhiyun    * The verification information includes the pass phrase for the
164*4882a593Smuzhiyun      encrypted disk associated with the SVM. This pass phrase is given
165*4882a593Smuzhiyun      to the SVM when requested.
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun    * The Ultravisor is not involved in protecting the encrypted disk of
168*4882a593Smuzhiyun      the SVM while at rest.
169*4882a593Smuzhiyun
170*4882a593Smuzhiyun    * For external interrupts the Ultravisor saves the state of the SVM,
171*4882a593Smuzhiyun      and reflects the interrupt to the hypervisor for processing.
172*4882a593Smuzhiyun      For hypercalls, the Ultravisor inserts neutral state into all
173*4882a593Smuzhiyun      registers not needed for the hypercall then reflects the call to
174*4882a593Smuzhiyun      the hypervisor for processing. The H_RANDOM hypercall is performed
175*4882a593Smuzhiyun      by the Ultravisor and not reflected.
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun    * For virtual I/O to work bounce buffering must be done.
178*4882a593Smuzhiyun
179*4882a593Smuzhiyun    * The Ultravisor uses AES (IAPM) for protection of SVM memory. IAPM
180*4882a593Smuzhiyun      is a mode of AES that provides integrity and secrecy concurrently.
181*4882a593Smuzhiyun
182*4882a593Smuzhiyun    * The movement of data between normal and secure pages is coordinated
183*4882a593Smuzhiyun      with the Ultravisor by a new HMM plug-in in the Hypervisor.
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun    The Ultravisor offers new services to the hypervisor and SVMs. These
186*4882a593Smuzhiyun    are accessed through ultracalls.
187*4882a593Smuzhiyun
188*4882a593SmuzhiyunTerminology
189*4882a593Smuzhiyun===========
190*4882a593Smuzhiyun
191*4882a593Smuzhiyun    * Hypercalls: special system calls used to request services from
192*4882a593Smuzhiyun      Hypervisor.
193*4882a593Smuzhiyun
194*4882a593Smuzhiyun    * Normal memory: Memory that is accessible to Hypervisor.
195*4882a593Smuzhiyun
196*4882a593Smuzhiyun    * Normal page: Page backed by normal memory and available to
197*4882a593Smuzhiyun      Hypervisor.
198*4882a593Smuzhiyun
199*4882a593Smuzhiyun    * Shared page: A page backed by normal memory and available to both
200*4882a593Smuzhiyun      the Hypervisor/QEMU and the SVM (i.e page has mappings in SVM and
201*4882a593Smuzhiyun      Hypervisor/QEMU).
202*4882a593Smuzhiyun
203*4882a593Smuzhiyun    * Secure memory: Memory that is accessible only to Ultravisor and
204*4882a593Smuzhiyun      SVMs.
205*4882a593Smuzhiyun
206*4882a593Smuzhiyun    * Secure page: Page backed by secure memory and only available to
207*4882a593Smuzhiyun      Ultravisor and SVM.
208*4882a593Smuzhiyun
209*4882a593Smuzhiyun    * SVM: Secure Virtual Machine.
210*4882a593Smuzhiyun
211*4882a593Smuzhiyun    * Ultracalls: special system calls used to request services from
212*4882a593Smuzhiyun      Ultravisor.
213*4882a593Smuzhiyun
214*4882a593Smuzhiyun
215*4882a593SmuzhiyunUltravisor calls API
216*4882a593Smuzhiyun####################
217*4882a593Smuzhiyun
218*4882a593Smuzhiyun    This section describes Ultravisor calls (ultracalls) needed to
219*4882a593Smuzhiyun    support Secure Virtual Machines (SVM)s and Paravirtualized KVM. The
220*4882a593Smuzhiyun    ultracalls allow the SVMs and Hypervisor to request services from the
221*4882a593Smuzhiyun    Ultravisor such as accessing a register or memory region that can only
222*4882a593Smuzhiyun    be accessed when running in Ultravisor-privileged mode.
223*4882a593Smuzhiyun
224*4882a593Smuzhiyun    The specific service needed from an ultracall is specified in register
225*4882a593Smuzhiyun    R3 (the first parameter to the ultracall). Other parameters to the
226*4882a593Smuzhiyun    ultracall, if any, are specified in registers R4 through R12.
227*4882a593Smuzhiyun
228*4882a593Smuzhiyun    Return value of all ultracalls is in register R3. Other output values
229*4882a593Smuzhiyun    from the ultracall, if any, are returned in registers R4 through R12.
230*4882a593Smuzhiyun    The only exception to this register usage is the ``UV_RETURN``
231*4882a593Smuzhiyun    ultracall described below.
232*4882a593Smuzhiyun
233*4882a593Smuzhiyun    Each ultracall returns specific error codes, applicable in the context
234*4882a593Smuzhiyun    of the ultracall. However, like with the PowerPC Architecture Platform
235*4882a593Smuzhiyun    Reference (PAPR), if no specific error code is defined for a
236*4882a593Smuzhiyun    particular situation, then the ultracall will fallback to an erroneous
237*4882a593Smuzhiyun    parameter-position based code. i.e U_PARAMETER, U_P2, U_P3 etc
238*4882a593Smuzhiyun    depending on the ultracall parameter that may have caused the error.
239*4882a593Smuzhiyun
240*4882a593Smuzhiyun    Some ultracalls involve transferring a page of data between Ultravisor
241*4882a593Smuzhiyun    and Hypervisor.  Secure pages that are transferred from secure memory
242*4882a593Smuzhiyun    to normal memory may be encrypted using dynamically generated keys.
243*4882a593Smuzhiyun    When the secure pages are transferred back to secure memory, they may
244*4882a593Smuzhiyun    be decrypted using the same dynamically generated keys. Generation and
245*4882a593Smuzhiyun    management of these keys will be covered in a separate document.
246*4882a593Smuzhiyun
247*4882a593Smuzhiyun    For now this only covers ultracalls currently implemented and being
248*4882a593Smuzhiyun    used by Hypervisor and SVMs but others can be added here when it
249*4882a593Smuzhiyun    makes sense.
250*4882a593Smuzhiyun
251*4882a593Smuzhiyun    The full specification for all hypercalls/ultracalls will eventually
252*4882a593Smuzhiyun    be made available in the public/OpenPower version of the PAPR
253*4882a593Smuzhiyun    specification.
254*4882a593Smuzhiyun
255*4882a593Smuzhiyun    .. note::
256*4882a593Smuzhiyun
257*4882a593Smuzhiyun        If PEF is not enabled, the ultracalls will be redirected to the
258*4882a593Smuzhiyun        Hypervisor which must handle/fail the calls.
259*4882a593Smuzhiyun
260*4882a593SmuzhiyunUltracalls used by Hypervisor
261*4882a593Smuzhiyun=============================
262*4882a593Smuzhiyun
263*4882a593Smuzhiyun    This section describes the virtual memory management ultracalls used
264*4882a593Smuzhiyun    by the Hypervisor to manage SVMs.
265*4882a593Smuzhiyun
266*4882a593SmuzhiyunUV_PAGE_OUT
267*4882a593Smuzhiyun-----------
268*4882a593Smuzhiyun
269*4882a593Smuzhiyun    Encrypt and move the contents of a page from secure memory to normal
270*4882a593Smuzhiyun    memory.
271*4882a593Smuzhiyun
272*4882a593SmuzhiyunSyntax
273*4882a593Smuzhiyun~~~~~~
274*4882a593Smuzhiyun
275*4882a593Smuzhiyun.. code-block:: c
276*4882a593Smuzhiyun
277*4882a593Smuzhiyun	uint64_t ultracall(const uint64_t UV_PAGE_OUT,
278*4882a593Smuzhiyun		uint16_t lpid,		/* LPAR ID */
279*4882a593Smuzhiyun		uint64_t dest_ra,	/* real address of destination page */
280*4882a593Smuzhiyun		uint64_t src_gpa,	/* source guest-physical-address */
281*4882a593Smuzhiyun		uint8_t  flags,		/* flags */
282*4882a593Smuzhiyun		uint64_t order)		/* page size order */
283*4882a593Smuzhiyun
284*4882a593SmuzhiyunReturn values
285*4882a593Smuzhiyun~~~~~~~~~~~~~
286*4882a593Smuzhiyun
287*4882a593Smuzhiyun    One of the following values:
288*4882a593Smuzhiyun
289*4882a593Smuzhiyun	* U_SUCCESS	on success.
290*4882a593Smuzhiyun	* U_PARAMETER	if ``lpid`` is invalid.
291*4882a593Smuzhiyun	* U_P2 		if ``dest_ra`` is invalid.
292*4882a593Smuzhiyun	* U_P3		if the ``src_gpa`` address is invalid.
293*4882a593Smuzhiyun	* U_P4		if any bit in the ``flags`` is unrecognized
294*4882a593Smuzhiyun	* U_P5		if the ``order`` parameter is unsupported.
295*4882a593Smuzhiyun	* U_FUNCTION	if functionality is not supported.
296*4882a593Smuzhiyun	* U_BUSY	if page cannot be currently paged-out.
297*4882a593Smuzhiyun
298*4882a593SmuzhiyunDescription
299*4882a593Smuzhiyun~~~~~~~~~~~
300*4882a593Smuzhiyun
301*4882a593Smuzhiyun    Encrypt the contents of a secure-page and make it available to
302*4882a593Smuzhiyun    Hypervisor in a normal page.
303*4882a593Smuzhiyun
304*4882a593Smuzhiyun    By default, the source page is unmapped from the SVM's partition-
305*4882a593Smuzhiyun    scoped page table. But the Hypervisor can provide a hint to the
306*4882a593Smuzhiyun    Ultravisor to retain the page mapping by setting the ``UV_SNAPSHOT``
307*4882a593Smuzhiyun    flag in ``flags`` parameter.
308*4882a593Smuzhiyun
309*4882a593Smuzhiyun    If the source page is already a shared page the call returns
310*4882a593Smuzhiyun    U_SUCCESS, without doing anything.
311*4882a593Smuzhiyun
312*4882a593SmuzhiyunUse cases
313*4882a593Smuzhiyun~~~~~~~~~
314*4882a593Smuzhiyun
315*4882a593Smuzhiyun    #. QEMU attempts to access an address belonging to the SVM but the
316*4882a593Smuzhiyun       page frame for that address is not mapped into QEMU's address
317*4882a593Smuzhiyun       space. In this case, the Hypervisor will allocate a page frame,
318*4882a593Smuzhiyun       map it into QEMU's address space and issue the ``UV_PAGE_OUT``
319*4882a593Smuzhiyun       call to retrieve the encrypted contents of the page.
320*4882a593Smuzhiyun
321*4882a593Smuzhiyun    #. When Ultravisor runs low on secure memory and it needs to page-out
322*4882a593Smuzhiyun       an LRU page. In this case, Ultravisor will issue the
323*4882a593Smuzhiyun       ``H_SVM_PAGE_OUT`` hypercall to the Hypervisor. The Hypervisor will
324*4882a593Smuzhiyun       then allocate a normal page and issue the ``UV_PAGE_OUT`` ultracall
325*4882a593Smuzhiyun       and the Ultravisor will encrypt and move the contents of the secure
326*4882a593Smuzhiyun       page into the normal page.
327*4882a593Smuzhiyun
328*4882a593Smuzhiyun    #. When Hypervisor accesses SVM data, the Hypervisor requests the
329*4882a593Smuzhiyun       Ultravisor to transfer the corresponding page into a insecure page,
330*4882a593Smuzhiyun       which the Hypervisor can access. The data in the normal page will
331*4882a593Smuzhiyun       be encrypted though.
332*4882a593Smuzhiyun
333*4882a593SmuzhiyunUV_PAGE_IN
334*4882a593Smuzhiyun----------
335*4882a593Smuzhiyun
336*4882a593Smuzhiyun    Move the contents of a page from normal memory to secure memory.
337*4882a593Smuzhiyun
338*4882a593SmuzhiyunSyntax
339*4882a593Smuzhiyun~~~~~~
340*4882a593Smuzhiyun
341*4882a593Smuzhiyun.. code-block:: c
342*4882a593Smuzhiyun
343*4882a593Smuzhiyun	uint64_t ultracall(const uint64_t UV_PAGE_IN,
344*4882a593Smuzhiyun		uint16_t lpid,		/* the LPAR ID */
345*4882a593Smuzhiyun		uint64_t src_ra,	/* source real address of page */
346*4882a593Smuzhiyun		uint64_t dest_gpa,	/* destination guest physical address */
347*4882a593Smuzhiyun		uint64_t flags,		/* flags */
348*4882a593Smuzhiyun		uint64_t order)		/* page size order */
349*4882a593Smuzhiyun
350*4882a593SmuzhiyunReturn values
351*4882a593Smuzhiyun~~~~~~~~~~~~~
352*4882a593Smuzhiyun
353*4882a593Smuzhiyun    One of the following values:
354*4882a593Smuzhiyun
355*4882a593Smuzhiyun	* U_SUCCESS	on success.
356*4882a593Smuzhiyun	* U_BUSY	if page cannot be currently paged-in.
357*4882a593Smuzhiyun	* U_FUNCTION	if functionality is not supported
358*4882a593Smuzhiyun	* U_PARAMETER	if ``lpid`` is invalid.
359*4882a593Smuzhiyun	* U_P2 		if ``src_ra`` is invalid.
360*4882a593Smuzhiyun	* U_P3		if the ``dest_gpa`` address is invalid.
361*4882a593Smuzhiyun	* U_P4		if any bit in the ``flags`` is unrecognized
362*4882a593Smuzhiyun	* U_P5		if the ``order`` parameter is unsupported.
363*4882a593Smuzhiyun
364*4882a593SmuzhiyunDescription
365*4882a593Smuzhiyun~~~~~~~~~~~
366*4882a593Smuzhiyun
367*4882a593Smuzhiyun    Move the contents of the page identified by ``src_ra`` from normal
368*4882a593Smuzhiyun    memory to secure memory and map it to the guest physical address
369*4882a593Smuzhiyun    ``dest_gpa``.
370*4882a593Smuzhiyun
371*4882a593Smuzhiyun    If `dest_gpa` refers to a shared address, map the page into the
372*4882a593Smuzhiyun    partition-scoped page-table of the SVM.  If `dest_gpa` is not shared,
373*4882a593Smuzhiyun    copy the contents of the page into the corresponding secure page.
374*4882a593Smuzhiyun    Depending on the context, decrypt the page before being copied.
375*4882a593Smuzhiyun
376*4882a593Smuzhiyun    The caller provides the attributes of the page through the ``flags``
377*4882a593Smuzhiyun    parameter. Valid values for ``flags`` are:
378*4882a593Smuzhiyun
379*4882a593Smuzhiyun	* CACHE_INHIBITED
380*4882a593Smuzhiyun	* CACHE_ENABLED
381*4882a593Smuzhiyun	* WRITE_PROTECTION
382*4882a593Smuzhiyun
383*4882a593Smuzhiyun    The Hypervisor must pin the page in memory before making
384*4882a593Smuzhiyun    ``UV_PAGE_IN`` ultracall.
385*4882a593Smuzhiyun
386*4882a593SmuzhiyunUse cases
387*4882a593Smuzhiyun~~~~~~~~~
388*4882a593Smuzhiyun
389*4882a593Smuzhiyun    #. When a normal VM switches to secure mode, all its pages residing
390*4882a593Smuzhiyun       in normal memory, are moved into secure memory.
391*4882a593Smuzhiyun
392*4882a593Smuzhiyun    #. When an SVM requests to share a page with Hypervisor the Hypervisor
393*4882a593Smuzhiyun       allocates a page and informs the Ultravisor.
394*4882a593Smuzhiyun
395*4882a593Smuzhiyun    #. When an SVM accesses a secure page that has been paged-out,
396*4882a593Smuzhiyun       Ultravisor invokes the Hypervisor to locate the page. After
397*4882a593Smuzhiyun       locating the page, the Hypervisor uses UV_PAGE_IN to make the
398*4882a593Smuzhiyun       page available to Ultravisor.
399*4882a593Smuzhiyun
400*4882a593SmuzhiyunUV_PAGE_INVAL
401*4882a593Smuzhiyun-------------
402*4882a593Smuzhiyun
403*4882a593Smuzhiyun    Invalidate the Ultravisor mapping of a page.
404*4882a593Smuzhiyun
405*4882a593SmuzhiyunSyntax
406*4882a593Smuzhiyun~~~~~~
407*4882a593Smuzhiyun
408*4882a593Smuzhiyun.. code-block:: c
409*4882a593Smuzhiyun
410*4882a593Smuzhiyun	uint64_t ultracall(const uint64_t UV_PAGE_INVAL,
411*4882a593Smuzhiyun		uint16_t lpid,		/* the LPAR ID */
412*4882a593Smuzhiyun		uint64_t guest_pa,	/* destination guest-physical-address */
413*4882a593Smuzhiyun		uint64_t order)		/* page size order */
414*4882a593Smuzhiyun
415*4882a593SmuzhiyunReturn values
416*4882a593Smuzhiyun~~~~~~~~~~~~~
417*4882a593Smuzhiyun
418*4882a593Smuzhiyun    One of the following values:
419*4882a593Smuzhiyun
420*4882a593Smuzhiyun	* U_SUCCESS	on success.
421*4882a593Smuzhiyun	* U_PARAMETER	if ``lpid`` is invalid.
422*4882a593Smuzhiyun	* U_P2 		if ``guest_pa`` is invalid (or corresponds to a secure
423*4882a593Smuzhiyun                        page mapping).
424*4882a593Smuzhiyun	* U_P3		if the ``order`` is invalid.
425*4882a593Smuzhiyun	* U_FUNCTION	if functionality is not supported.
426*4882a593Smuzhiyun	* U_BUSY	if page cannot be currently invalidated.
427*4882a593Smuzhiyun
428*4882a593SmuzhiyunDescription
429*4882a593Smuzhiyun~~~~~~~~~~~
430*4882a593Smuzhiyun
431*4882a593Smuzhiyun    This ultracall informs Ultravisor that the page mapping in Hypervisor
432*4882a593Smuzhiyun    corresponding to the given guest physical address has been invalidated
433*4882a593Smuzhiyun    and that the Ultravisor should not access the page. If the specified
434*4882a593Smuzhiyun    ``guest_pa`` corresponds to a secure page, Ultravisor will ignore the
435*4882a593Smuzhiyun    attempt to invalidate the page and return U_P2.
436*4882a593Smuzhiyun
437*4882a593SmuzhiyunUse cases
438*4882a593Smuzhiyun~~~~~~~~~
439*4882a593Smuzhiyun
440*4882a593Smuzhiyun    #. When a shared page is unmapped from the QEMU's page table, possibly
441*4882a593Smuzhiyun       because it is paged-out to disk, Ultravisor needs to know that the
442*4882a593Smuzhiyun       page should not be accessed from its side too.
443*4882a593Smuzhiyun
444*4882a593Smuzhiyun
445*4882a593SmuzhiyunUV_WRITE_PATE
446*4882a593Smuzhiyun-------------
447*4882a593Smuzhiyun
448*4882a593Smuzhiyun    Validate and write the partition table entry (PATE) for a given
449*4882a593Smuzhiyun    partition.
450*4882a593Smuzhiyun
451*4882a593SmuzhiyunSyntax
452*4882a593Smuzhiyun~~~~~~
453*4882a593Smuzhiyun
454*4882a593Smuzhiyun.. code-block:: c
455*4882a593Smuzhiyun
456*4882a593Smuzhiyun	uint64_t ultracall(const uint64_t UV_WRITE_PATE,
457*4882a593Smuzhiyun		uint32_t lpid,		/* the LPAR ID */
458*4882a593Smuzhiyun		uint64_t dw0		/* the first double word to write */
459*4882a593Smuzhiyun		uint64_t dw1)		/* the second double word to write */
460*4882a593Smuzhiyun
461*4882a593SmuzhiyunReturn values
462*4882a593Smuzhiyun~~~~~~~~~~~~~
463*4882a593Smuzhiyun
464*4882a593Smuzhiyun    One of the following values:
465*4882a593Smuzhiyun
466*4882a593Smuzhiyun	* U_SUCCESS	on success.
467*4882a593Smuzhiyun	* U_BUSY	if PATE cannot be currently written to.
468*4882a593Smuzhiyun	* U_FUNCTION	if functionality is not supported.
469*4882a593Smuzhiyun	* U_PARAMETER	if ``lpid`` is invalid.
470*4882a593Smuzhiyun	* U_P2 		if ``dw0`` is invalid.
471*4882a593Smuzhiyun	* U_P3		if the ``dw1`` address is invalid.
472*4882a593Smuzhiyun	* U_PERMISSION	if the Hypervisor is attempting to change the PATE
473*4882a593Smuzhiyun			of a secure virtual machine or if called from a
474*4882a593Smuzhiyun			context other than Hypervisor.
475*4882a593Smuzhiyun
476*4882a593SmuzhiyunDescription
477*4882a593Smuzhiyun~~~~~~~~~~~
478*4882a593Smuzhiyun
479*4882a593Smuzhiyun    Validate and write a LPID and its partition-table-entry for the given
480*4882a593Smuzhiyun    LPID.  If the LPID is already allocated and initialized, this call
481*4882a593Smuzhiyun    results in changing the partition table entry.
482*4882a593Smuzhiyun
483*4882a593SmuzhiyunUse cases
484*4882a593Smuzhiyun~~~~~~~~~
485*4882a593Smuzhiyun
486*4882a593Smuzhiyun    #. The Partition table resides in Secure memory and its entries,
487*4882a593Smuzhiyun       called PATE (Partition Table Entries), point to the partition-
488*4882a593Smuzhiyun       scoped page tables for the Hypervisor as well as each of the
489*4882a593Smuzhiyun       virtual machines (both secure and normal). The Hypervisor
490*4882a593Smuzhiyun       operates in partition 0 and its partition-scoped page tables
491*4882a593Smuzhiyun       reside in normal memory.
492*4882a593Smuzhiyun
493*4882a593Smuzhiyun    #. This ultracall allows the Hypervisor to register the partition-
494*4882a593Smuzhiyun       scoped and process-scoped page table entries for the Hypervisor
495*4882a593Smuzhiyun       and other partitions (virtual machines) with the Ultravisor.
496*4882a593Smuzhiyun
497*4882a593Smuzhiyun    #. If the value of the PATE for an existing partition (VM) changes,
498*4882a593Smuzhiyun       the TLB cache for the partition is flushed.
499*4882a593Smuzhiyun
500*4882a593Smuzhiyun    #. The Hypervisor is responsible for allocating LPID. The LPID and
501*4882a593Smuzhiyun       its PATE entry are registered together.  The Hypervisor manages
502*4882a593Smuzhiyun       the PATE entries for a normal VM and can change the PATE entry
503*4882a593Smuzhiyun       anytime. Ultravisor manages the PATE entries for an SVM and
504*4882a593Smuzhiyun       Hypervisor is not allowed to modify them.
505*4882a593Smuzhiyun
506*4882a593SmuzhiyunUV_RETURN
507*4882a593Smuzhiyun---------
508*4882a593Smuzhiyun
509*4882a593Smuzhiyun    Return control from the Hypervisor back to the Ultravisor after
510*4882a593Smuzhiyun    processing an hypercall or interrupt that was forwarded (aka
511*4882a593Smuzhiyun    *reflected*) to the Hypervisor.
512*4882a593Smuzhiyun
513*4882a593SmuzhiyunSyntax
514*4882a593Smuzhiyun~~~~~~
515*4882a593Smuzhiyun
516*4882a593Smuzhiyun.. code-block:: c
517*4882a593Smuzhiyun
518*4882a593Smuzhiyun	uint64_t ultracall(const uint64_t UV_RETURN)
519*4882a593Smuzhiyun
520*4882a593SmuzhiyunReturn values
521*4882a593Smuzhiyun~~~~~~~~~~~~~
522*4882a593Smuzhiyun
523*4882a593Smuzhiyun     This call never returns to Hypervisor on success.  It returns
524*4882a593Smuzhiyun     U_INVALID if ultracall is not made from a Hypervisor context.
525*4882a593Smuzhiyun
526*4882a593SmuzhiyunDescription
527*4882a593Smuzhiyun~~~~~~~~~~~
528*4882a593Smuzhiyun
529*4882a593Smuzhiyun    When an SVM makes an hypercall or incurs some other exception, the
530*4882a593Smuzhiyun    Ultravisor usually forwards (aka *reflects*) the exceptions to the
531*4882a593Smuzhiyun    Hypervisor.  After processing the exception, Hypervisor uses the
532*4882a593Smuzhiyun    ``UV_RETURN`` ultracall to return control back to the SVM.
533*4882a593Smuzhiyun
534*4882a593Smuzhiyun    The expected register state on entry to this ultracall is:
535*4882a593Smuzhiyun
536*4882a593Smuzhiyun    * Non-volatile registers are restored to their original values.
537*4882a593Smuzhiyun    * If returning from an hypercall, register R0 contains the return
538*4882a593Smuzhiyun      value (**unlike other ultracalls**) and, registers R4 through R12
539*4882a593Smuzhiyun      contain any output values of the hypercall.
540*4882a593Smuzhiyun    * R3 contains the ultracall number, i.e UV_RETURN.
541*4882a593Smuzhiyun    * If returning with a synthesized interrupt, R2 contains the
542*4882a593Smuzhiyun      synthesized interrupt number.
543*4882a593Smuzhiyun
544*4882a593SmuzhiyunUse cases
545*4882a593Smuzhiyun~~~~~~~~~
546*4882a593Smuzhiyun
547*4882a593Smuzhiyun    #. Ultravisor relies on the Hypervisor to provide several services to
548*4882a593Smuzhiyun       the SVM such as processing hypercall and other exceptions. After
549*4882a593Smuzhiyun       processing the exception, Hypervisor uses UV_RETURN to return
550*4882a593Smuzhiyun       control back to the Ultravisor.
551*4882a593Smuzhiyun
552*4882a593Smuzhiyun    #. Hypervisor has to use this ultracall to return control to the SVM.
553*4882a593Smuzhiyun
554*4882a593Smuzhiyun
555*4882a593SmuzhiyunUV_REGISTER_MEM_SLOT
556*4882a593Smuzhiyun--------------------
557*4882a593Smuzhiyun
558*4882a593Smuzhiyun    Register an SVM address-range with specified properties.
559*4882a593Smuzhiyun
560*4882a593SmuzhiyunSyntax
561*4882a593Smuzhiyun~~~~~~
562*4882a593Smuzhiyun
563*4882a593Smuzhiyun.. code-block:: c
564*4882a593Smuzhiyun
565*4882a593Smuzhiyun	uint64_t ultracall(const uint64_t UV_REGISTER_MEM_SLOT,
566*4882a593Smuzhiyun		uint64_t lpid,		/* LPAR ID of the SVM */
567*4882a593Smuzhiyun		uint64_t start_gpa,	/* start guest physical address */
568*4882a593Smuzhiyun		uint64_t size,		/* size of address range in bytes */
569*4882a593Smuzhiyun		uint64_t flags		/* reserved for future expansion */
570*4882a593Smuzhiyun		uint16_t slotid)	/* slot identifier */
571*4882a593Smuzhiyun
572*4882a593SmuzhiyunReturn values
573*4882a593Smuzhiyun~~~~~~~~~~~~~
574*4882a593Smuzhiyun
575*4882a593Smuzhiyun    One of the following values:
576*4882a593Smuzhiyun
577*4882a593Smuzhiyun	* U_SUCCESS	on success.
578*4882a593Smuzhiyun	* U_PARAMETER	if ``lpid`` is invalid.
579*4882a593Smuzhiyun	* U_P2 		if ``start_gpa`` is invalid.
580*4882a593Smuzhiyun	* U_P3		if ``size`` is invalid.
581*4882a593Smuzhiyun	* U_P4		if any bit in the ``flags`` is unrecognized.
582*4882a593Smuzhiyun	* U_P5		if the ``slotid`` parameter is unsupported.
583*4882a593Smuzhiyun	* U_PERMISSION	if called from context other than Hypervisor.
584*4882a593Smuzhiyun	* U_FUNCTION	if functionality is not supported.
585*4882a593Smuzhiyun
586*4882a593Smuzhiyun
587*4882a593SmuzhiyunDescription
588*4882a593Smuzhiyun~~~~~~~~~~~
589*4882a593Smuzhiyun
590*4882a593Smuzhiyun    Register a memory range for an SVM.  The memory range starts at the
591*4882a593Smuzhiyun    guest physical address ``start_gpa`` and is ``size`` bytes long.
592*4882a593Smuzhiyun
593*4882a593SmuzhiyunUse cases
594*4882a593Smuzhiyun~~~~~~~~~
595*4882a593Smuzhiyun
596*4882a593Smuzhiyun
597*4882a593Smuzhiyun    #. When a virtual machine goes secure, all the memory slots managed by
598*4882a593Smuzhiyun       the Hypervisor move into secure memory. The Hypervisor iterates
599*4882a593Smuzhiyun       through each of memory slots, and registers the slot with
600*4882a593Smuzhiyun       Ultravisor.  Hypervisor may discard some slots such as those used
601*4882a593Smuzhiyun       for firmware (SLOF).
602*4882a593Smuzhiyun
603*4882a593Smuzhiyun    #. When new memory is hot-plugged, a new memory slot gets registered.
604*4882a593Smuzhiyun
605*4882a593Smuzhiyun
606*4882a593SmuzhiyunUV_UNREGISTER_MEM_SLOT
607*4882a593Smuzhiyun----------------------
608*4882a593Smuzhiyun
609*4882a593Smuzhiyun    Unregister an SVM address-range that was previously registered using
610*4882a593Smuzhiyun    UV_REGISTER_MEM_SLOT.
611*4882a593Smuzhiyun
612*4882a593SmuzhiyunSyntax
613*4882a593Smuzhiyun~~~~~~
614*4882a593Smuzhiyun
615*4882a593Smuzhiyun.. code-block:: c
616*4882a593Smuzhiyun
617*4882a593Smuzhiyun	uint64_t ultracall(const uint64_t UV_UNREGISTER_MEM_SLOT,
618*4882a593Smuzhiyun		uint64_t lpid,		/* LPAR ID of the SVM */
619*4882a593Smuzhiyun		uint64_t slotid)	/* reservation slotid */
620*4882a593Smuzhiyun
621*4882a593SmuzhiyunReturn values
622*4882a593Smuzhiyun~~~~~~~~~~~~~
623*4882a593Smuzhiyun
624*4882a593Smuzhiyun    One of the following values:
625*4882a593Smuzhiyun
626*4882a593Smuzhiyun	* U_SUCCESS	on success.
627*4882a593Smuzhiyun	* U_FUNCTION	if functionality is not supported.
628*4882a593Smuzhiyun	* U_PARAMETER	if ``lpid`` is invalid.
629*4882a593Smuzhiyun	* U_P2 		if ``slotid`` is invalid.
630*4882a593Smuzhiyun	* U_PERMISSION	if called from context other than Hypervisor.
631*4882a593Smuzhiyun
632*4882a593SmuzhiyunDescription
633*4882a593Smuzhiyun~~~~~~~~~~~
634*4882a593Smuzhiyun
635*4882a593Smuzhiyun    Release the memory slot identified by ``slotid`` and free any
636*4882a593Smuzhiyun    resources allocated towards the reservation.
637*4882a593Smuzhiyun
638*4882a593SmuzhiyunUse cases
639*4882a593Smuzhiyun~~~~~~~~~
640*4882a593Smuzhiyun
641*4882a593Smuzhiyun    #. Memory hot-remove.
642*4882a593Smuzhiyun
643*4882a593Smuzhiyun
644*4882a593SmuzhiyunUV_SVM_TERMINATE
645*4882a593Smuzhiyun----------------
646*4882a593Smuzhiyun
647*4882a593Smuzhiyun    Terminate an SVM and release its resources.
648*4882a593Smuzhiyun
649*4882a593SmuzhiyunSyntax
650*4882a593Smuzhiyun~~~~~~
651*4882a593Smuzhiyun
652*4882a593Smuzhiyun.. code-block:: c
653*4882a593Smuzhiyun
654*4882a593Smuzhiyun	uint64_t ultracall(const uint64_t UV_SVM_TERMINATE,
655*4882a593Smuzhiyun		uint64_t lpid,		/* LPAR ID of the SVM */)
656*4882a593Smuzhiyun
657*4882a593SmuzhiyunReturn values
658*4882a593Smuzhiyun~~~~~~~~~~~~~
659*4882a593Smuzhiyun
660*4882a593Smuzhiyun    One of the following values:
661*4882a593Smuzhiyun
662*4882a593Smuzhiyun	* U_SUCCESS	on success.
663*4882a593Smuzhiyun	* U_FUNCTION	if functionality is not supported.
664*4882a593Smuzhiyun	* U_PARAMETER	if ``lpid`` is invalid.
665*4882a593Smuzhiyun	* U_INVALID	if VM is not secure.
666*4882a593Smuzhiyun	* U_PERMISSION  if not called from a Hypervisor context.
667*4882a593Smuzhiyun
668*4882a593SmuzhiyunDescription
669*4882a593Smuzhiyun~~~~~~~~~~~
670*4882a593Smuzhiyun
671*4882a593Smuzhiyun    Terminate an SVM and release all its resources.
672*4882a593Smuzhiyun
673*4882a593SmuzhiyunUse cases
674*4882a593Smuzhiyun~~~~~~~~~
675*4882a593Smuzhiyun
676*4882a593Smuzhiyun    #. Called by Hypervisor when terminating an SVM.
677*4882a593Smuzhiyun
678*4882a593Smuzhiyun
679*4882a593SmuzhiyunUltracalls used by SVM
680*4882a593Smuzhiyun======================
681*4882a593Smuzhiyun
682*4882a593SmuzhiyunUV_SHARE_PAGE
683*4882a593Smuzhiyun-------------
684*4882a593Smuzhiyun
685*4882a593Smuzhiyun    Share a set of guest physical pages with the Hypervisor.
686*4882a593Smuzhiyun
687*4882a593SmuzhiyunSyntax
688*4882a593Smuzhiyun~~~~~~
689*4882a593Smuzhiyun
690*4882a593Smuzhiyun.. code-block:: c
691*4882a593Smuzhiyun
692*4882a593Smuzhiyun	uint64_t ultracall(const uint64_t UV_SHARE_PAGE,
693*4882a593Smuzhiyun		uint64_t gfn,	/* guest page frame number */
694*4882a593Smuzhiyun		uint64_t num)	/* number of pages of size PAGE_SIZE */
695*4882a593Smuzhiyun
696*4882a593SmuzhiyunReturn values
697*4882a593Smuzhiyun~~~~~~~~~~~~~
698*4882a593Smuzhiyun
699*4882a593Smuzhiyun    One of the following values:
700*4882a593Smuzhiyun
701*4882a593Smuzhiyun	* U_SUCCESS	on success.
702*4882a593Smuzhiyun	* U_FUNCTION	if functionality is not supported.
703*4882a593Smuzhiyun	* U_INVALID	if the VM is not secure.
704*4882a593Smuzhiyun	* U_PARAMETER	if ``gfn`` is invalid.
705*4882a593Smuzhiyun	* U_P2 		if ``num`` is invalid.
706*4882a593Smuzhiyun
707*4882a593SmuzhiyunDescription
708*4882a593Smuzhiyun~~~~~~~~~~~
709*4882a593Smuzhiyun
710*4882a593Smuzhiyun    Share the ``num`` pages starting at guest physical frame number ``gfn``
711*4882a593Smuzhiyun    with the Hypervisor. Assume page size is PAGE_SIZE bytes. Zero the
712*4882a593Smuzhiyun    pages before returning.
713*4882a593Smuzhiyun
714*4882a593Smuzhiyun    If the address is already backed by a secure page, unmap the page and
715*4882a593Smuzhiyun    back it with an insecure page, with the help of the Hypervisor. If it
716*4882a593Smuzhiyun    is not backed by any page yet, mark the PTE as insecure and back it
717*4882a593Smuzhiyun    with an insecure page when the address is accessed. If it is already
718*4882a593Smuzhiyun    backed by an insecure page, zero the page and return.
719*4882a593Smuzhiyun
720*4882a593SmuzhiyunUse cases
721*4882a593Smuzhiyun~~~~~~~~~
722*4882a593Smuzhiyun
723*4882a593Smuzhiyun    #. The Hypervisor cannot access the SVM pages since they are backed by
724*4882a593Smuzhiyun       secure pages. Hence an SVM must explicitly request Ultravisor for
725*4882a593Smuzhiyun       pages it can share with Hypervisor.
726*4882a593Smuzhiyun
727*4882a593Smuzhiyun    #. Shared pages are needed to support virtio and Virtual Processor Area
728*4882a593Smuzhiyun       (VPA) in SVMs.
729*4882a593Smuzhiyun
730*4882a593Smuzhiyun
731*4882a593SmuzhiyunUV_UNSHARE_PAGE
732*4882a593Smuzhiyun---------------
733*4882a593Smuzhiyun
734*4882a593Smuzhiyun    Restore a shared SVM page to its initial state.
735*4882a593Smuzhiyun
736*4882a593SmuzhiyunSyntax
737*4882a593Smuzhiyun~~~~~~
738*4882a593Smuzhiyun
739*4882a593Smuzhiyun.. code-block:: c
740*4882a593Smuzhiyun
741*4882a593Smuzhiyun	uint64_t ultracall(const uint64_t UV_UNSHARE_PAGE,
742*4882a593Smuzhiyun		uint64_t gfn,	/* guest page frame number */
743*4882a593Smuzhiyun		uint73 num)	/* number of pages of size PAGE_SIZE*/
744*4882a593Smuzhiyun
745*4882a593SmuzhiyunReturn values
746*4882a593Smuzhiyun~~~~~~~~~~~~~
747*4882a593Smuzhiyun
748*4882a593Smuzhiyun    One of the following values:
749*4882a593Smuzhiyun
750*4882a593Smuzhiyun	* U_SUCCESS	on success.
751*4882a593Smuzhiyun	* U_FUNCTION	if functionality is not supported.
752*4882a593Smuzhiyun	* U_INVALID	if VM is not secure.
753*4882a593Smuzhiyun	* U_PARAMETER	if ``gfn`` is invalid.
754*4882a593Smuzhiyun	* U_P2 		if ``num`` is invalid.
755*4882a593Smuzhiyun
756*4882a593SmuzhiyunDescription
757*4882a593Smuzhiyun~~~~~~~~~~~
758*4882a593Smuzhiyun
759*4882a593Smuzhiyun    Stop sharing ``num`` pages starting at ``gfn`` with the Hypervisor.
760*4882a593Smuzhiyun    Assume that the page size is PAGE_SIZE. Zero the pages before
761*4882a593Smuzhiyun    returning.
762*4882a593Smuzhiyun
763*4882a593Smuzhiyun    If the address is already backed by an insecure page, unmap the page
764*4882a593Smuzhiyun    and back it with a secure page. Inform the Hypervisor to release
765*4882a593Smuzhiyun    reference to its shared page. If the address is not backed by a page
766*4882a593Smuzhiyun    yet, mark the PTE as secure and back it with a secure page when that
767*4882a593Smuzhiyun    address is accessed. If it is already backed by an secure page zero
768*4882a593Smuzhiyun    the page and return.
769*4882a593Smuzhiyun
770*4882a593SmuzhiyunUse cases
771*4882a593Smuzhiyun~~~~~~~~~
772*4882a593Smuzhiyun
773*4882a593Smuzhiyun    #. The SVM may decide to unshare a page from the Hypervisor.
774*4882a593Smuzhiyun
775*4882a593Smuzhiyun
776*4882a593SmuzhiyunUV_UNSHARE_ALL_PAGES
777*4882a593Smuzhiyun--------------------
778*4882a593Smuzhiyun
779*4882a593Smuzhiyun    Unshare all pages the SVM has shared with Hypervisor.
780*4882a593Smuzhiyun
781*4882a593SmuzhiyunSyntax
782*4882a593Smuzhiyun~~~~~~
783*4882a593Smuzhiyun
784*4882a593Smuzhiyun.. code-block:: c
785*4882a593Smuzhiyun
786*4882a593Smuzhiyun	uint64_t ultracall(const uint64_t UV_UNSHARE_ALL_PAGES)
787*4882a593Smuzhiyun
788*4882a593SmuzhiyunReturn values
789*4882a593Smuzhiyun~~~~~~~~~~~~~
790*4882a593Smuzhiyun
791*4882a593Smuzhiyun    One of the following values:
792*4882a593Smuzhiyun
793*4882a593Smuzhiyun	* U_SUCCESS	on success.
794*4882a593Smuzhiyun	* U_FUNCTION	if functionality is not supported.
795*4882a593Smuzhiyun	* U_INVAL	if VM is not secure.
796*4882a593Smuzhiyun
797*4882a593SmuzhiyunDescription
798*4882a593Smuzhiyun~~~~~~~~~~~
799*4882a593Smuzhiyun
800*4882a593Smuzhiyun    Unshare all shared pages from the Hypervisor. All unshared pages are
801*4882a593Smuzhiyun    zeroed on return. Only pages explicitly shared by the SVM with the
802*4882a593Smuzhiyun    Hypervisor (using UV_SHARE_PAGE ultracall) are unshared. Ultravisor
803*4882a593Smuzhiyun    may internally share some pages with the Hypervisor without explicit
804*4882a593Smuzhiyun    request from the SVM.  These pages will not be unshared by this
805*4882a593Smuzhiyun    ultracall.
806*4882a593Smuzhiyun
807*4882a593SmuzhiyunUse cases
808*4882a593Smuzhiyun~~~~~~~~~
809*4882a593Smuzhiyun
810*4882a593Smuzhiyun    #. This call is needed when ``kexec`` is used to boot a different
811*4882a593Smuzhiyun       kernel. It may also be needed during SVM reset.
812*4882a593Smuzhiyun
813*4882a593SmuzhiyunUV_ESM
814*4882a593Smuzhiyun------
815*4882a593Smuzhiyun
816*4882a593Smuzhiyun    Secure the virtual machine (*enter secure mode*).
817*4882a593Smuzhiyun
818*4882a593SmuzhiyunSyntax
819*4882a593Smuzhiyun~~~~~~
820*4882a593Smuzhiyun
821*4882a593Smuzhiyun.. code-block:: c
822*4882a593Smuzhiyun
823*4882a593Smuzhiyun	uint64_t ultracall(const uint64_t UV_ESM,
824*4882a593Smuzhiyun		uint64_t esm_blob_addr,	/* location of the ESM blob */
825*4882a593Smuzhiyun		unint64_t fdt)		/* Flattened device tree */
826*4882a593Smuzhiyun
827*4882a593SmuzhiyunReturn values
828*4882a593Smuzhiyun~~~~~~~~~~~~~
829*4882a593Smuzhiyun
830*4882a593Smuzhiyun    One of the following values:
831*4882a593Smuzhiyun
832*4882a593Smuzhiyun	* U_SUCCESS	on success (including if VM is already secure).
833*4882a593Smuzhiyun	* U_FUNCTION	if functionality is not supported.
834*4882a593Smuzhiyun	* U_INVALID	if VM is not secure.
835*4882a593Smuzhiyun	* U_PARAMETER	if ``esm_blob_addr`` is invalid.
836*4882a593Smuzhiyun	* U_P2 		if ``fdt`` is invalid.
837*4882a593Smuzhiyun	* U_PERMISSION	if any integrity checks fail.
838*4882a593Smuzhiyun	* U_RETRY	insufficient memory to create SVM.
839*4882a593Smuzhiyun	* U_NO_KEY	symmetric key unavailable.
840*4882a593Smuzhiyun
841*4882a593SmuzhiyunDescription
842*4882a593Smuzhiyun~~~~~~~~~~~
843*4882a593Smuzhiyun
844*4882a593Smuzhiyun    Secure the virtual machine. On successful completion, return
845*4882a593Smuzhiyun    control to the virtual machine at the address specified in the
846*4882a593Smuzhiyun    ESM blob.
847*4882a593Smuzhiyun
848*4882a593SmuzhiyunUse cases
849*4882a593Smuzhiyun~~~~~~~~~
850*4882a593Smuzhiyun
851*4882a593Smuzhiyun    #. A normal virtual machine can choose to switch to a secure mode.
852*4882a593Smuzhiyun
853*4882a593SmuzhiyunHypervisor Calls API
854*4882a593Smuzhiyun####################
855*4882a593Smuzhiyun
856*4882a593Smuzhiyun    This document describes the Hypervisor calls (hypercalls) that are
857*4882a593Smuzhiyun    needed to support the Ultravisor. Hypercalls are services provided by
858*4882a593Smuzhiyun    the Hypervisor to virtual machines and Ultravisor.
859*4882a593Smuzhiyun
860*4882a593Smuzhiyun    Register usage for these hypercalls is identical to that of the other
861*4882a593Smuzhiyun    hypercalls defined in the Power Architecture Platform Reference (PAPR)
862*4882a593Smuzhiyun    document.  i.e on input, register R3 identifies the specific service
863*4882a593Smuzhiyun    that is being requested and registers R4 through R11 contain
864*4882a593Smuzhiyun    additional parameters to the hypercall, if any. On output, register
865*4882a593Smuzhiyun    R3 contains the return value and registers R4 through R9 contain any
866*4882a593Smuzhiyun    other output values from the hypercall.
867*4882a593Smuzhiyun
868*4882a593Smuzhiyun    This document only covers hypercalls currently implemented/planned
869*4882a593Smuzhiyun    for Ultravisor usage but others can be added here when it makes sense.
870*4882a593Smuzhiyun
871*4882a593Smuzhiyun    The full specification for all hypercalls/ultracalls will eventually
872*4882a593Smuzhiyun    be made available in the public/OpenPower version of the PAPR
873*4882a593Smuzhiyun    specification.
874*4882a593Smuzhiyun
875*4882a593SmuzhiyunHypervisor calls to support Ultravisor
876*4882a593Smuzhiyun======================================
877*4882a593Smuzhiyun
878*4882a593Smuzhiyun    Following are the set of hypercalls needed to support Ultravisor.
879*4882a593Smuzhiyun
880*4882a593SmuzhiyunH_SVM_INIT_START
881*4882a593Smuzhiyun----------------
882*4882a593Smuzhiyun
883*4882a593Smuzhiyun    Begin the process of converting a normal virtual machine into an SVM.
884*4882a593Smuzhiyun
885*4882a593SmuzhiyunSyntax
886*4882a593Smuzhiyun~~~~~~
887*4882a593Smuzhiyun
888*4882a593Smuzhiyun.. code-block:: c
889*4882a593Smuzhiyun
890*4882a593Smuzhiyun	uint64_t hypercall(const uint64_t H_SVM_INIT_START)
891*4882a593Smuzhiyun
892*4882a593SmuzhiyunReturn values
893*4882a593Smuzhiyun~~~~~~~~~~~~~
894*4882a593Smuzhiyun
895*4882a593Smuzhiyun    One of the following values:
896*4882a593Smuzhiyun
897*4882a593Smuzhiyun	* H_SUCCESS	 on success.
898*4882a593Smuzhiyun        * H_STATE        if the VM is not in a position to switch to secure.
899*4882a593Smuzhiyun
900*4882a593SmuzhiyunDescription
901*4882a593Smuzhiyun~~~~~~~~~~~
902*4882a593Smuzhiyun
903*4882a593Smuzhiyun    Initiate the process of securing a virtual machine. This involves
904*4882a593Smuzhiyun    coordinating with the Ultravisor, using ultracalls, to allocate
905*4882a593Smuzhiyun    resources in the Ultravisor for the new SVM, transferring the VM's
906*4882a593Smuzhiyun    pages from normal to secure memory etc. When the process is
907*4882a593Smuzhiyun    completed, Ultravisor issues the H_SVM_INIT_DONE hypercall.
908*4882a593Smuzhiyun
909*4882a593SmuzhiyunUse cases
910*4882a593Smuzhiyun~~~~~~~~~
911*4882a593Smuzhiyun
912*4882a593Smuzhiyun     #. Ultravisor uses this hypercall to inform Hypervisor that a VM
913*4882a593Smuzhiyun        has initiated the process of switching to secure mode.
914*4882a593Smuzhiyun
915*4882a593Smuzhiyun
916*4882a593SmuzhiyunH_SVM_INIT_DONE
917*4882a593Smuzhiyun---------------
918*4882a593Smuzhiyun
919*4882a593Smuzhiyun    Complete the process of securing an SVM.
920*4882a593Smuzhiyun
921*4882a593SmuzhiyunSyntax
922*4882a593Smuzhiyun~~~~~~
923*4882a593Smuzhiyun
924*4882a593Smuzhiyun.. code-block:: c
925*4882a593Smuzhiyun
926*4882a593Smuzhiyun	uint64_t hypercall(const uint64_t H_SVM_INIT_DONE)
927*4882a593Smuzhiyun
928*4882a593SmuzhiyunReturn values
929*4882a593Smuzhiyun~~~~~~~~~~~~~
930*4882a593Smuzhiyun
931*4882a593Smuzhiyun    One of the following values:
932*4882a593Smuzhiyun
933*4882a593Smuzhiyun	* H_SUCCESS 		on success.
934*4882a593Smuzhiyun	* H_UNSUPPORTED		if called from the wrong context (e.g.
935*4882a593Smuzhiyun				from an SVM or before an H_SVM_INIT_START
936*4882a593Smuzhiyun				hypercall).
937*4882a593Smuzhiyun	* H_STATE		if the hypervisor could not successfully
938*4882a593Smuzhiyun                                transition the VM to Secure VM.
939*4882a593Smuzhiyun
940*4882a593SmuzhiyunDescription
941*4882a593Smuzhiyun~~~~~~~~~~~
942*4882a593Smuzhiyun
943*4882a593Smuzhiyun    Complete the process of securing a virtual machine. This call must
944*4882a593Smuzhiyun    be made after a prior call to ``H_SVM_INIT_START`` hypercall.
945*4882a593Smuzhiyun
946*4882a593SmuzhiyunUse cases
947*4882a593Smuzhiyun~~~~~~~~~
948*4882a593Smuzhiyun
949*4882a593Smuzhiyun    On successfully securing a virtual machine, the Ultravisor informs
950*4882a593Smuzhiyun    Hypervisor about it. Hypervisor can use this call to finish setting
951*4882a593Smuzhiyun    up its internal state for this virtual machine.
952*4882a593Smuzhiyun
953*4882a593Smuzhiyun
954*4882a593SmuzhiyunH_SVM_INIT_ABORT
955*4882a593Smuzhiyun----------------
956*4882a593Smuzhiyun
957*4882a593Smuzhiyun    Abort the process of securing an SVM.
958*4882a593Smuzhiyun
959*4882a593SmuzhiyunSyntax
960*4882a593Smuzhiyun~~~~~~
961*4882a593Smuzhiyun
962*4882a593Smuzhiyun.. code-block:: c
963*4882a593Smuzhiyun
964*4882a593Smuzhiyun	uint64_t hypercall(const uint64_t H_SVM_INIT_ABORT)
965*4882a593Smuzhiyun
966*4882a593SmuzhiyunReturn values
967*4882a593Smuzhiyun~~~~~~~~~~~~~
968*4882a593Smuzhiyun
969*4882a593Smuzhiyun    One of the following values:
970*4882a593Smuzhiyun
971*4882a593Smuzhiyun	* H_PARAMETER 		on successfully cleaning up the state,
972*4882a593Smuzhiyun				Hypervisor will return this value to the
973*4882a593Smuzhiyun				**guest**, to indicate that the underlying
974*4882a593Smuzhiyun				UV_ESM ultracall failed.
975*4882a593Smuzhiyun
976*4882a593Smuzhiyun	* H_STATE		if called after a VM has gone secure (i.e
977*4882a593Smuzhiyun				H_SVM_INIT_DONE hypercall was successful).
978*4882a593Smuzhiyun
979*4882a593Smuzhiyun	* H_UNSUPPORTED		if called from a wrong context (e.g. from a
980*4882a593Smuzhiyun				normal VM).
981*4882a593Smuzhiyun
982*4882a593SmuzhiyunDescription
983*4882a593Smuzhiyun~~~~~~~~~~~
984*4882a593Smuzhiyun
985*4882a593Smuzhiyun    Abort the process of securing a virtual machine. This call must
986*4882a593Smuzhiyun    be made after a prior call to ``H_SVM_INIT_START`` hypercall and
987*4882a593Smuzhiyun    before a call to ``H_SVM_INIT_DONE``.
988*4882a593Smuzhiyun
989*4882a593Smuzhiyun    On entry into this hypercall the non-volatile GPRs and FPRs are
990*4882a593Smuzhiyun    expected to contain the values they had at the time the VM issued
991*4882a593Smuzhiyun    the UV_ESM ultracall. Further ``SRR0`` is expected to contain the
992*4882a593Smuzhiyun    address of the instruction after the ``UV_ESM`` ultracall and ``SRR1``
993*4882a593Smuzhiyun    the MSR value with which to return to the VM.
994*4882a593Smuzhiyun
995*4882a593Smuzhiyun    This hypercall will cleanup any partial state that was established for
996*4882a593Smuzhiyun    the VM since the prior ``H_SVM_INIT_START`` hypercall, including paging
997*4882a593Smuzhiyun    out pages that were paged-into secure memory, and issue the
998*4882a593Smuzhiyun    ``UV_SVM_TERMINATE`` ultracall to terminate the VM.
999*4882a593Smuzhiyun
1000*4882a593Smuzhiyun    After the partial state is cleaned up, control returns to the VM
1001*4882a593Smuzhiyun    (**not Ultravisor**), at the address specified in ``SRR0`` with the
1002*4882a593Smuzhiyun    MSR values set to the value in ``SRR1``.
1003*4882a593Smuzhiyun
1004*4882a593SmuzhiyunUse cases
1005*4882a593Smuzhiyun~~~~~~~~~
1006*4882a593Smuzhiyun
1007*4882a593Smuzhiyun    If after a successful call to ``H_SVM_INIT_START``, the Ultravisor
1008*4882a593Smuzhiyun    encounters an error while securing a virtual machine, either due
1009*4882a593Smuzhiyun    to lack of resources or because the VM's security information could
1010*4882a593Smuzhiyun    not be validated, Ultravisor informs the Hypervisor about it.
1011*4882a593Smuzhiyun    Hypervisor should use this call to clean up any internal state for
1012*4882a593Smuzhiyun    this virtual machine and return to the VM.
1013*4882a593Smuzhiyun
1014*4882a593SmuzhiyunH_SVM_PAGE_IN
1015*4882a593Smuzhiyun-------------
1016*4882a593Smuzhiyun
1017*4882a593Smuzhiyun    Move the contents of a page from normal memory to secure memory.
1018*4882a593Smuzhiyun
1019*4882a593SmuzhiyunSyntax
1020*4882a593Smuzhiyun~~~~~~
1021*4882a593Smuzhiyun
1022*4882a593Smuzhiyun.. code-block:: c
1023*4882a593Smuzhiyun
1024*4882a593Smuzhiyun	uint64_t hypercall(const uint64_t H_SVM_PAGE_IN,
1025*4882a593Smuzhiyun		uint64_t guest_pa,	/* guest-physical-address */
1026*4882a593Smuzhiyun		uint64_t flags,		/* flags */
1027*4882a593Smuzhiyun		uint64_t order)		/* page size order */
1028*4882a593Smuzhiyun
1029*4882a593SmuzhiyunReturn values
1030*4882a593Smuzhiyun~~~~~~~~~~~~~
1031*4882a593Smuzhiyun
1032*4882a593Smuzhiyun    One of the following values:
1033*4882a593Smuzhiyun
1034*4882a593Smuzhiyun	* H_SUCCESS	on success.
1035*4882a593Smuzhiyun	* H_PARAMETER	if ``guest_pa`` is invalid.
1036*4882a593Smuzhiyun	* H_P2		if ``flags`` is invalid.
1037*4882a593Smuzhiyun	* H_P3		if ``order`` of page is invalid.
1038*4882a593Smuzhiyun
1039*4882a593SmuzhiyunDescription
1040*4882a593Smuzhiyun~~~~~~~~~~~
1041*4882a593Smuzhiyun
1042*4882a593Smuzhiyun    Retrieve the content of the page, belonging to the VM at the specified
1043*4882a593Smuzhiyun    guest physical address.
1044*4882a593Smuzhiyun
1045*4882a593Smuzhiyun    Only valid value(s) in ``flags`` are:
1046*4882a593Smuzhiyun
1047*4882a593Smuzhiyun        * H_PAGE_IN_SHARED which indicates that the page is to be shared
1048*4882a593Smuzhiyun	  with the Ultravisor.
1049*4882a593Smuzhiyun
1050*4882a593Smuzhiyun	* H_PAGE_IN_NONSHARED indicates that the UV is not anymore
1051*4882a593Smuzhiyun          interested in the page. Applicable if the page is a shared page.
1052*4882a593Smuzhiyun
1053*4882a593Smuzhiyun    The ``order`` parameter must correspond to the configured page size.
1054*4882a593Smuzhiyun
1055*4882a593SmuzhiyunUse cases
1056*4882a593Smuzhiyun~~~~~~~~~
1057*4882a593Smuzhiyun
1058*4882a593Smuzhiyun    #. When a normal VM becomes a secure VM (using the UV_ESM ultracall),
1059*4882a593Smuzhiyun       the Ultravisor uses this hypercall to move contents of each page of
1060*4882a593Smuzhiyun       the VM from normal memory to secure memory.
1061*4882a593Smuzhiyun
1062*4882a593Smuzhiyun    #. Ultravisor uses this hypercall to ask Hypervisor to provide a page
1063*4882a593Smuzhiyun       in normal memory that can be shared between the SVM and Hypervisor.
1064*4882a593Smuzhiyun
1065*4882a593Smuzhiyun    #. Ultravisor uses this hypercall to page-in a paged-out page. This
1066*4882a593Smuzhiyun       can happen when the SVM touches a paged-out page.
1067*4882a593Smuzhiyun
1068*4882a593Smuzhiyun    #. If SVM wants to disable sharing of pages with Hypervisor, it can
1069*4882a593Smuzhiyun       inform Ultravisor to do so. Ultravisor will then use this hypercall
1070*4882a593Smuzhiyun       and inform Hypervisor that it has released access to the normal
1071*4882a593Smuzhiyun       page.
1072*4882a593Smuzhiyun
1073*4882a593SmuzhiyunH_SVM_PAGE_OUT
1074*4882a593Smuzhiyun---------------
1075*4882a593Smuzhiyun
1076*4882a593Smuzhiyun    Move the contents of the page to normal memory.
1077*4882a593Smuzhiyun
1078*4882a593SmuzhiyunSyntax
1079*4882a593Smuzhiyun~~~~~~
1080*4882a593Smuzhiyun
1081*4882a593Smuzhiyun.. code-block:: c
1082*4882a593Smuzhiyun
1083*4882a593Smuzhiyun	uint64_t hypercall(const uint64_t H_SVM_PAGE_OUT,
1084*4882a593Smuzhiyun		uint64_t guest_pa,	/* guest-physical-address */
1085*4882a593Smuzhiyun		uint64_t flags,		/* flags (currently none) */
1086*4882a593Smuzhiyun		uint64_t order)		/* page size order */
1087*4882a593Smuzhiyun
1088*4882a593SmuzhiyunReturn values
1089*4882a593Smuzhiyun~~~~~~~~~~~~~
1090*4882a593Smuzhiyun
1091*4882a593Smuzhiyun    One of the following values:
1092*4882a593Smuzhiyun
1093*4882a593Smuzhiyun	* H_SUCCESS	on success.
1094*4882a593Smuzhiyun	* H_PARAMETER	if ``guest_pa`` is invalid.
1095*4882a593Smuzhiyun	* H_P2		if ``flags`` is invalid.
1096*4882a593Smuzhiyun	* H_P3		if ``order`` is invalid.
1097*4882a593Smuzhiyun
1098*4882a593SmuzhiyunDescription
1099*4882a593Smuzhiyun~~~~~~~~~~~
1100*4882a593Smuzhiyun
1101*4882a593Smuzhiyun    Move the contents of the page identified by ``guest_pa`` to normal
1102*4882a593Smuzhiyun    memory.
1103*4882a593Smuzhiyun
1104*4882a593Smuzhiyun    Currently ``flags`` is unused and must be set to 0. The ``order``
1105*4882a593Smuzhiyun    parameter must correspond to the configured page size.
1106*4882a593Smuzhiyun
1107*4882a593SmuzhiyunUse cases
1108*4882a593Smuzhiyun~~~~~~~~~
1109*4882a593Smuzhiyun
1110*4882a593Smuzhiyun    #. If Ultravisor is running low on secure pages, it can move the
1111*4882a593Smuzhiyun       contents of some secure pages, into normal pages using this
1112*4882a593Smuzhiyun       hypercall. The content will be encrypted.
1113*4882a593Smuzhiyun
1114*4882a593SmuzhiyunReferences
1115*4882a593Smuzhiyun##########
1116*4882a593Smuzhiyun
1117*4882a593Smuzhiyun- `Supporting Protected Computing on IBM Power Architecture <https://developer.ibm.com/articles/l-support-protected-computing/>`_
1118