| 1 |
.. SPDX-License-Identifier: CC-BY-4.0 |
| 2 |
|
| 3 |
Hypercall ABI |
| 4 |
============= |
| 5 |
|
| 6 |
Hypercalls are system calls to Xen. Two modes of guest operation are |
| 7 |
supported, and up to 5 individual parameters are supported. |
| 8 |
|
| 9 |
Hypercalls may only be issued by kernel-level software [#kern]_. |
| 10 |
|
| 11 |
Registers |
| 12 |
--------- |
| 13 |
|
| 14 |
The registers used for hypercalls depends on the operating mode of the guest. |
| 15 |
|
| 16 |
.. list-table:: |
| 17 |
:header-rows: 1 |
| 18 |
|
| 19 |
* - ABI |
| 20 |
- Hypercall Index |
| 21 |
- Parameters (1 - 5) [#params]_ |
| 22 |
- Result |
| 23 |
|
| 24 |
* - 64bit |
| 25 |
- RAX |
| 26 |
- RDI RSI RDX R10 R8 |
| 27 |
- RAX |
| 28 |
|
| 29 |
* - 32bit |
| 30 |
- EAX |
| 31 |
- EBX ECX EDX ESI EDI |
| 32 |
- EAX |
| 33 |
|
| 34 |
32 and 64bit PV guests have an ABI fixed by their guest type. The ABI for an |
| 35 |
HVM guest depends on whether the vCPU is operating in a 64bit segment or not |
| 36 |
[#mode]_. |
| 37 |
|
| 38 |
|
| 39 |
Parameters |
| 40 |
---------- |
| 41 |
|
| 42 |
Different hypercalls take a different number of parameters. Each hypercall |
| 43 |
potentially clobbers each of its parameter registers; a guest may not rely on |
| 44 |
the parameter registers staying the same. A debug build of Xen checks this by |
| 45 |
deliberately poisoning the parameter registers before returning back to the |
| 46 |
guest. |
| 47 |
|
| 48 |
|
| 49 |
Mode transfer |
| 50 |
------------- |
| 51 |
|
| 52 |
The exact sequence of instructions required to issue a hypercall differs |
| 53 |
between virtualisation mode and hardware vendor. |
| 54 |
|
| 55 |
.. list-table:: |
| 56 |
:header-rows: 1 |
| 57 |
|
| 58 |
* - Guest |
| 59 |
- Transfer instruction |
| 60 |
|
| 61 |
* - 32bit PV |
| 62 |
- INT 0x82 |
| 63 |
|
| 64 |
* - 64bit PV |
| 65 |
- SYSCALL |
| 66 |
|
| 67 |
* - Intel HVM |
| 68 |
- VMCALL |
| 69 |
|
| 70 |
* - AMD HVM |
| 71 |
- VMMCALL |
| 72 |
|
| 73 |
To abstract away the details, Xen implements an interface known as the |
| 74 |
Hypercall Page. This allows a guest to make a hypercall without needing to |
| 75 |
perform mode-specific or vendor-specific setup. |
| 76 |
|
| 77 |
|
| 78 |
Hypercall Page |
| 79 |
============== |
| 80 |
|
| 81 |
The hypercall page is a page of guest RAM into which Xen will write suitable |
| 82 |
transfer stubs. It is intended as a convenience for guests, but use of the |
| 83 |
hypercall page is not mandatory for making hypercalls to Xen. |
| 84 |
|
| 85 |
.. note:: |
| 86 |
|
| 87 |
There are cases where a hypercall page should not be used. It contains |
| 88 |
``ret`` instructions which are not compatible with certain speculative |
| 89 |
security techniques, and it does not contain ``endbr`` instructions which |
| 90 |
are necessary for certain Control-flow Integrity schemes. |
| 91 |
|
| 92 |
Creating a hypercall page is an isolated operation from Xen's point of view. |
| 93 |
It is the guests responsibility to ensure that the hypercall page, once |
| 94 |
written by Xen, is mapped with executable permissions so it may be used. |
| 95 |
Multiple hypercall pages may be created by the guest, if it wishes. |
| 96 |
|
| 97 |
The stubs are arranged by hypercall index, and start on 32-byte boundaries. |
| 98 |
To invoke a specific hypercall, ``call`` the relevant stub [#iret]_: |
| 99 |
|
| 100 |
.. code-block:: none |
| 101 |
|
| 102 |
call hypercall_page + index * 32 |
| 103 |
|
| 104 |
There result is an ABI which is invariant of the exact operating mode or |
| 105 |
hardware vendor. This is intended to simplify guest kernel interfaces by |
| 106 |
abstracting away the details of how it is currently running. |
| 107 |
|
| 108 |
|
| 109 |
Creating Hypercall Pages |
| 110 |
------------------------ |
| 111 |
|
| 112 |
Guests which are started using the PV boot protocol may set |
| 113 |
``XEN_ELFNOTE_HYPERCALL_PAGE`` to have the nominated page written as a |
| 114 |
hypercall page during construction. This mechanism is common for PV guests, |
| 115 |
and allows hypercalls to be issued with no additional setup. |
| 116 |
|
| 117 |
Any guest can locate the Xen CPUID leaves and read the *hypercall transfer |
| 118 |
page* information, which specifies an MSR that can be used to create |
| 119 |
additional hypercall pages. When a guest physical address is written to the |
| 120 |
MSR, Xen writes a hypercall page into the nominated guest page. This |
| 121 |
mechanism is common for HVM guests which are typically started via legacy |
| 122 |
means. |
| 123 |
|
| 124 |
|
| 125 |
.. rubric:: Footnotes |
| 126 |
|
| 127 |
.. [#kern] For HVM guests, ``HVMOP_guest_request_vm_event`` may be configured |
| 128 |
to be usable from userspace, but this behaviour is not default. |
| 129 |
|
| 130 |
.. [#params] Xen's ABI used to declare support for 6 hypercall arguments, |
| 131 |
using ``r9`` and ``ebp``. However, such an ABI clobbers the frame pointer |
| 132 |
in the 32bit code and does not interact nicely with guest-side debugging. |
| 133 |
``V4V``, the predecessor to ``HYPERCALL_argo_op`` was a 6-argument |
| 134 |
hypercall, but the ABI was intentionally altered when Argo was upstreamed |
| 135 |
(Xen 4.13) to be the 5-argument hypercall it now is. |
| 136 |
|
| 137 |
.. [#mode] While it is possible to use compatibility mode segments in a 64bit |
| 138 |
kernel, hypercalls issues from such a mode will be interpreted with the |
| 139 |
32bit ABI. Such a setup is not expected in production scenarios. |
| 140 |
|
| 141 |
.. [#iret] ``HYPERCALL_iret`` is special. It is only implemented for PV |
| 142 |
guests and takes all its parameters on the stack. This stub should be |
| 143 |
``jmp``'d to, rather than ``call``'d. HVM guests have this stub |
| 144 |
implemented as ``ud2a`` to prevent accidental use. |