18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci 38c2ecf20Sopenharmony_ci======================================= 48c2ecf20Sopenharmony_ciInternal ABI between the kernel and HYP 58c2ecf20Sopenharmony_ci======================================= 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ciThis file documents the interaction between the Linux kernel and the 88c2ecf20Sopenharmony_cihypervisor layer when running Linux as a hypervisor (for example 98c2ecf20Sopenharmony_ciKVM). It doesn't cover the interaction of the kernel with the 108c2ecf20Sopenharmony_cihypervisor when running as a guest (under Xen, KVM or any other 118c2ecf20Sopenharmony_cihypervisor), or any hypervisor-specific interaction when the kernel is 128c2ecf20Sopenharmony_ciused as a host. 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ciNote: KVM/arm has been removed from the kernel. The API described 158c2ecf20Sopenharmony_cihere is still valid though, as it allows the kernel to kexec when 168c2ecf20Sopenharmony_cibooted at HYP. It can also be used by a hypervisor other than KVM 178c2ecf20Sopenharmony_ciif necessary. 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ciOn arm and arm64 (without VHE), the kernel doesn't run in hypervisor 208c2ecf20Sopenharmony_cimode, but still needs to interact with it, allowing a built-in 218c2ecf20Sopenharmony_cihypervisor to be either installed or torn down. 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ciIn order to achieve this, the kernel must be booted at HYP (arm) or 248c2ecf20Sopenharmony_ciEL2 (arm64), allowing it to install a set of stubs before dropping to 258c2ecf20Sopenharmony_ciSVC/EL1. These stubs are accessible by using a 'hvc #0' instruction, 268c2ecf20Sopenharmony_ciand only act on individual CPUs. 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ciUnless specified otherwise, any built-in hypervisor must implement 298c2ecf20Sopenharmony_cithese functions (see arch/arm{,64}/include/asm/virt.h): 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci* :: 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci r0/x0 = HVC_SET_VECTORS 348c2ecf20Sopenharmony_ci r1/x1 = vectors 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci Set HVBAR/VBAR_EL2 to 'vectors' to enable a hypervisor. 'vectors' 378c2ecf20Sopenharmony_ci must be a physical address, and respect the alignment requirements 388c2ecf20Sopenharmony_ci of the architecture. Only implemented by the initial stubs, not by 398c2ecf20Sopenharmony_ci Linux hypervisors. 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci* :: 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci r0/x0 = HVC_RESET_VECTORS 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci Turn HYP/EL2 MMU off, and reset HVBAR/VBAR_EL2 to the initials 468c2ecf20Sopenharmony_ci stubs' exception vector value. This effectively disables an existing 478c2ecf20Sopenharmony_ci hypervisor. 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci* :: 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci r0/x0 = HVC_SOFT_RESTART 528c2ecf20Sopenharmony_ci r1/x1 = restart address 538c2ecf20Sopenharmony_ci x2 = x0's value when entering the next payload (arm64) 548c2ecf20Sopenharmony_ci x3 = x1's value when entering the next payload (arm64) 558c2ecf20Sopenharmony_ci x4 = x2's value when entering the next payload (arm64) 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci Mask all exceptions, disable the MMU, clear I+D bits, move the arguments 588c2ecf20Sopenharmony_ci into place (arm64 only), and jump to the restart address while at HYP/EL2. 598c2ecf20Sopenharmony_ci This hypercall is not expected to return to its caller. 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ciAny other value of r0/x0 triggers a hypervisor-specific handling, 628c2ecf20Sopenharmony_ciwhich is not documented here. 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ciThe return value of a stub hypercall is held by r0/x0, and is 0 on 658c2ecf20Sopenharmony_cisuccess, and HVC_STUB_ERR on error. A stub hypercall is allowed to 668c2ecf20Sopenharmony_ciclobber any of the caller-saved registers (x0-x18 on arm64, r0-r3 and 678c2ecf20Sopenharmony_ciip on arm). It is thus recommended to use a function call to perform 688c2ecf20Sopenharmony_cithe hypercall. 69