18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci 38c2ecf20Sopenharmony_ci=================== 48c2ecf20Sopenharmony_ciLinux KVM Hypercall 58c2ecf20Sopenharmony_ci=================== 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ciX86: 88c2ecf20Sopenharmony_ci KVM Hypercalls have a three-byte sequence of either the vmcall or the vmmcall 98c2ecf20Sopenharmony_ci instruction. The hypervisor can replace it with instructions that are 108c2ecf20Sopenharmony_ci guaranteed to be supported. 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci Up to four arguments may be passed in rbx, rcx, rdx, and rsi respectively. 138c2ecf20Sopenharmony_ci The hypercall number should be placed in rax and the return value will be 148c2ecf20Sopenharmony_ci placed in rax. No other registers will be clobbered unless explicitly stated 158c2ecf20Sopenharmony_ci by the particular hypercall. 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ciS390: 188c2ecf20Sopenharmony_ci R2-R7 are used for parameters 1-6. In addition, R1 is used for hypercall 198c2ecf20Sopenharmony_ci number. The return value is written to R2. 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci S390 uses diagnose instruction as hypercall (0x500) along with hypercall 228c2ecf20Sopenharmony_ci number in R1. 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci For further information on the S390 diagnose call as supported by KVM, 258c2ecf20Sopenharmony_ci refer to Documentation/virt/kvm/s390-diag.rst. 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ciPowerPC: 288c2ecf20Sopenharmony_ci It uses R3-R10 and hypercall number in R11. R4-R11 are used as output registers. 298c2ecf20Sopenharmony_ci Return value is placed in R3. 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci KVM hypercalls uses 4 byte opcode, that are patched with 'hypercall-instructions' 328c2ecf20Sopenharmony_ci property inside the device tree's /hypervisor node. 338c2ecf20Sopenharmony_ci For more information refer to Documentation/virt/kvm/ppc-pv.rst 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ciMIPS: 368c2ecf20Sopenharmony_ci KVM hypercalls use the HYPCALL instruction with code 0 and the hypercall 378c2ecf20Sopenharmony_ci number in $2 (v0). Up to four arguments may be placed in $4-$7 (a0-a3) and 388c2ecf20Sopenharmony_ci the return value is placed in $2 (v0). 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ciKVM Hypercalls Documentation 418c2ecf20Sopenharmony_ci============================ 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ciThe template for each hypercall is: 448c2ecf20Sopenharmony_ci1. Hypercall name. 458c2ecf20Sopenharmony_ci2. Architecture(s) 468c2ecf20Sopenharmony_ci3. Status (deprecated, obsolete, active) 478c2ecf20Sopenharmony_ci4. Purpose 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci1. KVM_HC_VAPIC_POLL_IRQ 508c2ecf20Sopenharmony_ci------------------------ 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci:Architecture: x86 538c2ecf20Sopenharmony_ci:Status: active 548c2ecf20Sopenharmony_ci:Purpose: Trigger guest exit so that the host can check for pending 558c2ecf20Sopenharmony_ci interrupts on reentry. 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci2. KVM_HC_MMU_OP 588c2ecf20Sopenharmony_ci---------------- 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci:Architecture: x86 618c2ecf20Sopenharmony_ci:Status: deprecated. 628c2ecf20Sopenharmony_ci:Purpose: Support MMU operations such as writing to PTE, 638c2ecf20Sopenharmony_ci flushing TLB, release PT. 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci3. KVM_HC_FEATURES 668c2ecf20Sopenharmony_ci------------------ 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci:Architecture: PPC 698c2ecf20Sopenharmony_ci:Status: active 708c2ecf20Sopenharmony_ci:Purpose: Expose hypercall availability to the guest. On x86 platforms, cpuid 718c2ecf20Sopenharmony_ci used to enumerate which hypercalls are available. On PPC, either 728c2ecf20Sopenharmony_ci device tree based lookup ( which is also what EPAPR dictates) 738c2ecf20Sopenharmony_ci OR KVM specific enumeration mechanism (which is this hypercall) 748c2ecf20Sopenharmony_ci can be used. 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci4. KVM_HC_PPC_MAP_MAGIC_PAGE 778c2ecf20Sopenharmony_ci---------------------------- 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci:Architecture: PPC 808c2ecf20Sopenharmony_ci:Status: active 818c2ecf20Sopenharmony_ci:Purpose: To enable communication between the hypervisor and guest there is a 828c2ecf20Sopenharmony_ci shared page that contains parts of supervisor visible register state. 838c2ecf20Sopenharmony_ci The guest can map this shared page to access its supervisor register 848c2ecf20Sopenharmony_ci through memory using this hypercall. 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci5. KVM_HC_KICK_CPU 878c2ecf20Sopenharmony_ci------------------ 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci:Architecture: x86 908c2ecf20Sopenharmony_ci:Status: active 918c2ecf20Sopenharmony_ci:Purpose: Hypercall used to wakeup a vcpu from HLT state 928c2ecf20Sopenharmony_ci:Usage example: 938c2ecf20Sopenharmony_ci A vcpu of a paravirtualized guest that is busywaiting in guest 948c2ecf20Sopenharmony_ci kernel mode for an event to occur (ex: a spinlock to become available) can 958c2ecf20Sopenharmony_ci execute HLT instruction once it has busy-waited for more than a threshold 968c2ecf20Sopenharmony_ci time-interval. Execution of HLT instruction would cause the hypervisor to put 978c2ecf20Sopenharmony_ci the vcpu to sleep until occurrence of an appropriate event. Another vcpu of the 988c2ecf20Sopenharmony_ci same guest can wakeup the sleeping vcpu by issuing KVM_HC_KICK_CPU hypercall, 998c2ecf20Sopenharmony_ci specifying APIC ID (a1) of the vcpu to be woken up. An additional argument (a0) 1008c2ecf20Sopenharmony_ci is used in the hypercall for future use. 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci6. KVM_HC_CLOCK_PAIRING 1048c2ecf20Sopenharmony_ci----------------------- 1058c2ecf20Sopenharmony_ci:Architecture: x86 1068c2ecf20Sopenharmony_ci:Status: active 1078c2ecf20Sopenharmony_ci:Purpose: Hypercall used to synchronize host and guest clocks. 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ciUsage: 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_cia0: guest physical address where host copies 1128c2ecf20Sopenharmony_ci"struct kvm_clock_offset" structure. 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_cia1: clock_type, ATM only KVM_CLOCK_PAIRING_WALLCLOCK (0) 1158c2ecf20Sopenharmony_ciis supported (corresponding to the host's CLOCK_REALTIME clock). 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci :: 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci struct kvm_clock_pairing { 1208c2ecf20Sopenharmony_ci __s64 sec; 1218c2ecf20Sopenharmony_ci __s64 nsec; 1228c2ecf20Sopenharmony_ci __u64 tsc; 1238c2ecf20Sopenharmony_ci __u32 flags; 1248c2ecf20Sopenharmony_ci __u32 pad[9]; 1258c2ecf20Sopenharmony_ci }; 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci Where: 1288c2ecf20Sopenharmony_ci * sec: seconds from clock_type clock. 1298c2ecf20Sopenharmony_ci * nsec: nanoseconds from clock_type clock. 1308c2ecf20Sopenharmony_ci * tsc: guest TSC value used to calculate sec/nsec pair 1318c2ecf20Sopenharmony_ci * flags: flags, unused (0) at the moment. 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ciThe hypercall lets a guest compute a precise timestamp across 1348c2ecf20Sopenharmony_cihost and guest. The guest can use the returned TSC value to 1358c2ecf20Sopenharmony_cicompute the CLOCK_REALTIME for its clock, at the same instant. 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ciReturns KVM_EOPNOTSUPP if the host does not use TSC clocksource, 1388c2ecf20Sopenharmony_cior if clock type is different than KVM_CLOCK_PAIRING_WALLCLOCK. 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci6. KVM_HC_SEND_IPI 1418c2ecf20Sopenharmony_ci------------------ 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci:Architecture: x86 1448c2ecf20Sopenharmony_ci:Status: active 1458c2ecf20Sopenharmony_ci:Purpose: Send IPIs to multiple vCPUs. 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci- a0: lower part of the bitmap of destination APIC IDs 1488c2ecf20Sopenharmony_ci- a1: higher part of the bitmap of destination APIC IDs 1498c2ecf20Sopenharmony_ci- a2: the lowest APIC ID in bitmap 1508c2ecf20Sopenharmony_ci- a3: APIC ICR 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ciThe hypercall lets a guest send multicast IPIs, with at most 128 1538c2ecf20Sopenharmony_ci128 destinations per hypercall in 64-bit mode and 64 vCPUs per 1548c2ecf20Sopenharmony_cihypercall in 32-bit mode. The destinations are represented by a 1558c2ecf20Sopenharmony_cibitmap contained in the first two arguments (a0 and a1). Bit 0 of 1568c2ecf20Sopenharmony_cia0 corresponds to the APIC ID in the third argument (a2), bit 1 1578c2ecf20Sopenharmony_cicorresponds to the APIC ID a2+1, and so on. 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ciReturns the number of CPUs to which the IPIs were delivered successfully. 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ci7. KVM_HC_SCHED_YIELD 1628c2ecf20Sopenharmony_ci--------------------- 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci:Architecture: x86 1658c2ecf20Sopenharmony_ci:Status: active 1668c2ecf20Sopenharmony_ci:Purpose: Hypercall used to yield if the IPI target vCPU is preempted 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_cia0: destination APIC ID 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci:Usage example: When sending a call-function IPI-many to vCPUs, yield if 1718c2ecf20Sopenharmony_ci any of the IPI target vCPUs was preempted. 172