1.. SPDX-License-Identifier: GPL-2.0 2 3=============================================== 4KVM/arm64-specific hypercalls exposed to guests 5=============================================== 6 7This file documents the KVM/arm64-specific hypercalls which may be 8exposed by KVM/arm64 to guest operating systems. These hypercalls are 9issued using the HVC instruction according to version 1.1 of the Arm SMC 10Calling Convention (DEN0028/C): 11 12https://developer.arm.com/docs/den0028/c 13 14All KVM/arm64-specific hypercalls are allocated within the "Vendor 15Specific Hypervisor Service Call" range with a UID of 16``28b46fb6-2ec5-11e9-a9ca-4b564d003a74``. This UID should be queried by the 17guest using the standard "Call UID" function for the service range in 18order to determine that the KVM/arm64-specific hypercalls are available. 19 20``ARM_SMCCC_KVM_FUNC_FEATURES`` 21--------------------------------------------- 22 23Provides a discovery mechanism for other KVM/arm64 hypercalls. 24 25+---------------------+-------------------------------------------------------------+ 26| Presence: | Mandatory for the KVM/arm64 UID | 27+---------------------+-------------------------------------------------------------+ 28| Calling convention: | HVC32 | 29+---------------------+----------+--------------------------------------------------+ 30| Function ID: | (uint32) | 0x86000000 | 31+---------------------+----------+--------------------------------------------------+ 32| Arguments: | None | 33+---------------------+----------+----+---------------------------------------------+ 34| Return Values: | (uint32) | R0 | Bitmap of available function numbers 0-31 | 35| +----------+----+---------------------------------------------+ 36| | (uint32) | R1 | Bitmap of available function numbers 32-63 | 37| +----------+----+---------------------------------------------+ 38| | (uint32) | R2 | Bitmap of available function numbers 64-95 | 39| +----------+----+---------------------------------------------+ 40| | (uint32) | R3 | Bitmap of available function numbers 96-127 | 41+---------------------+----------+----+---------------------------------------------+ 42 43``ARM_SMCCC_KVM_FUNC_PTP`` 44---------------------------------------- 45 46See ptp_kvm.rst 47 48``ARM_SMCCC_KVM_FUNC_HYP_MEMINFO`` 49---------------------------------- 50 51Query the memory protection parameters for a pKVM protected virtual machine. 52 53+---------------------+-------------------------------------------------------------+ 54| Presence: | Optional; pKVM protected guests only. | 55+---------------------+-------------------------------------------------------------+ 56| Calling convention: | HVC64 | 57+---------------------+----------+--------------------------------------------------+ 58| Function ID: | (uint32) | 0xC6000002 | 59+---------------------+----------+----+---------------------------------------------+ 60| Arguments: | (uint64) | R1 | Reserved / Must be zero | 61| +----------+----+---------------------------------------------+ 62| | (uint64) | R2 | Reserved / Must be zero | 63| +----------+----+---------------------------------------------+ 64| | (uint64) | R3 | Reserved / Must be zero | 65+---------------------+----------+----+---------------------------------------------+ 66| Return Values: | (int64) | R0 | ``INVALID_PARAMETER (-3)`` on error, else | 67| | | | memory protection granule in bytes | 68| +----------+----+---------------------------------------------+ 69| | (int64) | R1 | ``KVM_FUNC_HAS_RANGE (1)`` if MEM_SHARE and | 70| | | | MEM_UNSHARE take a range argument. | 71+---------------------+----------+----+---------------------------------------------+ 72 73``ARM_SMCCC_KVM_FUNC_MEM_SHARE`` 74-------------------------------- 75 76Share a region of memory with the KVM host, granting it read, write and execute 77permissions. The size of the region is equal to the memory protection granule 78advertised by ``ARM_SMCCC_KVM_FUNC_HYP_MEMINFO`` times the number of granules 79set in R2. See the ``KVM_FUNC_HAS_RANGE`` paragraph for more details about this 80argument. 81 82+---------------------+-------------------------------------------------------------+ 83| Presence: | Optional; pKVM protected guests only. | 84+---------------------+-------------------------------------------------------------+ 85| Calling convention: | HVC64 | 86+---------------------+----------+--------------------------------------------------+ 87| Function ID: | (uint32) | 0xC6000003 | 88+---------------------+----------+----+---------------------------------------------+ 89| Arguments: | (uint64) | R1 | Base IPA of memory region to share | 90| +----------+----+---------------------------------------------+ 91| | (uint64) | R2 | Number of granules to share | 92| +----------+----+---------------------------------------------+ 93| | (uint64) | R3 | Reserved / Must be zero | 94+---------------------+----------+----+---------------------------------------------+ 95| Return Values: | (int64) | R0 | ``SUCCESS (0)`` | 96| | | +---------------------------------------------+ 97| | | | ``INVALID_PARAMETER (-3)`` | 98| +----------+----+---------------------------------------------+ 99| | (uint64) | R1 | Number of shared granules | 100+---------------------+----------+----+---------------------------------------------+ 101 102``ARM_SMCCC_KVM_FUNC_MEM_UNSHARE`` 103---------------------------------- 104 105Revoke access permission from the KVM host to a memory region previously shared 106with ``ARM_SMCCC_KVM_FUNC_MEM_SHARE``. The size of the region is equal to the 107memory protection granule advertised by ``ARM_SMCCC_KVM_FUNC_HYP_MEMINFO`` times 108the number of granules set in R2. See the ``KVM_FUNC_HAS_RANGE`` paragraph for 109more details about this argument. 110 111+---------------------+-------------------------------------------------------------+ 112| Presence: | Optional; pKVM protected guests only. | 113+---------------------+-------------------------------------------------------------+ 114| Calling convention: | HVC64 | 115+---------------------+----------+--------------------------------------------------+ 116| Function ID: | (uint32) | 0xC6000004 | 117+---------------------+----------+----+---------------------------------------------+ 118| Arguments: | (uint64) | R1 | Base IPA of memory region to unshare | 119| +----------+----+---------------------------------------------+ 120| | (uint64) | R2 | Number of granules to unshare | 121| +----------+----+---------------------------------------------+ 122| | (uint64) | R3 | Reserved / Must be zero | 123+---------------------+----------+----+---------------------------------------------+ 124| Return Values: | (int64) | R0 | ``SUCCESS (0)`` | 125| | | +---------------------------------------------+ 126| | | | ``INVALID_PARAMETER (-3)`` | 127| +----------+----+---------------------------------------------+ 128| | (uint64) | R1 | Number of unshared granules | 129+---------------------+----------+----+---------------------------------------------+ 130 131``ARM_SMCCC_KVM_FUNC_MMIO_GUARD`` 132---------------------------------- 133 134Request that a given memory region is handled as MMIO by the hypervisor, 135allowing accesses to this region to be emulated by the KVM host. The size of the 136region is equal to the memory protection granule advertised by 137``ARM_SMCCC_KVM_FUNC_HYP_MEMINFO``. 138 139+---------------------+-------------------------------------------------------------+ 140| Presence: | Optional; pKVM protected guests only. | 141+---------------------+-------------------------------------------------------------+ 142| Calling convention: | HVC64 | 143+---------------------+----------+--------------------------------------------------+ 144| Function ID: | (uint32) | 0xC6000007 | 145+---------------------+----------+----+---------------------------------------------+ 146| Arguments: | (uint64) | R1 | Base IPA of MMIO memory region | 147| +----------+----+---------------------------------------------+ 148| | (uint64) | R2 | Reserved / Must be zero | 149| +----------+----+---------------------------------------------+ 150| | (uint64) | R3 | Reserved / Must be zero | 151+---------------------+----------+----+---------------------------------------------+ 152| Return Values: | (int64) | R0 | ``SUCCESS (0)`` | 153| | | +---------------------------------------------+ 154| | | | ``INVALID_PARAMETER (-3)`` | 155+---------------------+----------+----+---------------------------------------------+ 156 157``ARM_SMCCC_KVM_FUNC_MEM_RELINQUISH`` 158-------------------------------------- 159 160Cooperatively relinquish ownership of a memory region. The size of the 161region is equal to the memory protection granule advertised by 162``ARM_SMCCC_KVM_FUNC_HYP_MEMINFO``. If this hypercall is advertised 163then it is mandatory to call it before freeing memory via, for 164example, virtio balloon. If the caller is a protected VM, it is 165guaranteed that the memory region will be completely cleared before 166becoming visible to another VM. 167 168+---------------------+-------------------------------------------------------------+ 169| Presence: | Optional. | 170+---------------------+-------------------------------------------------------------+ 171| Calling convention: | HVC64 | 172+---------------------+----------+--------------------------------------------------+ 173| Function ID: | (uint32) | 0xC6000009 | 174+---------------------+----------+----+---------------------------------------------+ 175| Arguments: | (uint64) | R1 | Base IPA of memory region to relinquish | 176| +----------+----+---------------------------------------------+ 177| | (uint64) | R2 | Reserved / Must be zero | 178| +----------+----+---------------------------------------------+ 179| | (uint64) | R3 | Reserved / Must be zero | 180+---------------------+----------+----+---------------------------------------------+ 181| Return Values: | (int64) | R0 | ``SUCCESS (0)`` | 182| | | +---------------------------------------------+ 183| | | | ``INVALID_PARAMETER (-3)`` | 184+---------------------+----------+----+---------------------------------------------+ 185 186``ARM_SMCCC_KVM_FUNC_MMIO_GUARD_*`` 187----------------------------------- 188 189See mmio-guard.rst 190 191``KVM_FUNC_HAS_RANGE`` 192---------------------- 193 194This flag, when set in ARM_SMCCC_KVM_FUNC_HYP_MEMINFO, indicates the guest can 195pass a number of granules as an argument to: 196 197 * ARM_SMCCC_KVM_FUNC_MEM_SHARE 198 * ARM_SMCCC_KVM_FUNC_MEM_UNSHARE 199 200In order to support legacy guests, the kernel still accepts ``0`` as a value. In 201that case a single granule is shared/unshared. 202 203When set in ARM_SMCCC_KVM_FUNC_MMIO_GUARD_INFO, indicates the guest can call the 204HVCs: 205 206 * ARM_SMCCC_KVM_FUNC_MMIO_RGUARD_MAP 207 * ARM_SMCCC_KVM_FUNC_MMIO_RGUARD_UNMAP 208 209For all those HVCs, the hypervisor is free to stop the process at any time 210either because the range isn't physically contiguous or to limit the time spent 211at EL2. In such case, the number of actually shared granules is returned (R1) 212and the caller can start again where it stopped, that is, the base IPA + (Number 213of processed granules * protection granule size). 214 215If the number of processed granules returned is zero (R1), an error (R0) will be 216set. 217 218``ARM_SMCCC_KVM_FUNC_DEV_REQ_MMIO`` 219-------------------------------------- 220 221Verify a device MMIO region matches the host description in the firmware 222tables for a physical device passthrough to a protected virtual machine. 223 224Called per page as defined by ``ARM_SMCCC_KVM_FUNC_HYP_MEMINFO`` using the 225IPA of the resource. 226 227Must be called after one of the following for the same IPA, which indicates 228that this IPA range is MMIO: 229 * ``ARM_SMCCC_KVM_FUNC_MMIO_RGUARD_MAP`` 230 * ``ARM_SMCCC_KVM_FUNC_MMIO_RGUARD_UNMAP`` 231 232Returns a token that can be used to verify the IPA page, the VM 233typically have access to a trusted description of the device containing 234the tokens. Where it can compare both. 235 236Must be called before any MMIO access for protected virtual machines. 237Ideally from the protected vm firmware. 238 239After this call succeeds, access to this IPA would be through stage-2 and won't 240exit to the host. 241 242+---------------------+-------------------------------------------------------------+ 243| Presence: | Optional. | 244+---------------------+-------------------------------------------------------------+ 245| Calling convention: | HVC64 | 246+---------------------+----------+--------------------------------------------------+ 247| Function ID: | (uint32) | 0xC6000003F | 248+---------------------+----------+----+---------------------------------------------+ 249| Arguments: | (uint64) | R1 | Base IPA of MMIO region | 250| +----------+----+---------------------------------------------+ 251| | (uint64) | R2 | Reserved / Must be zero | 252| +----------+----+---------------------------------------------+ 253| | (uint64) | R3 | Reserved / Must be zero | 254+---------------------+----------+----+---------------------------------------------+ 255| Return Values: | (int64) | R0 | ``SUCCESS (0)`` | 256| | | +---------------------------------------------+ 257| | | | ``INVALID_PARAMETER (-3)`` | 258| +----------+----+---------------------------------------------+ 259| | (uint64) | R1 | Token used to represent the page which | 260| | | | can be used to verify it. | 261+---------------------+----------+----+---------------------------------------------+ 262 263``ARM_SMCCC_KVM_FUNC_DEV_REQ_DMA`` 264-------------------------------------- 265 266See pviommu.rst 267 268``ARM_SMCCC_VENDOR_HYP_KVM_PVIOMMU_OP_FUNC_ID`` 269-------------------------------------- 270 271See pviommu.rst