hypercalls.rst 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ===================
  3. Linux KVM Hypercall
  4. ===================
  5. X86:
  6. KVM Hypercalls have a three-byte sequence of either the vmcall or the vmmcall
  7. instruction. The hypervisor can replace it with instructions that are
  8. guaranteed to be supported.
  9. Up to four arguments may be passed in rbx, rcx, rdx, and rsi respectively.
  10. The hypercall number should be placed in rax and the return value will be
  11. placed in rax. No other registers will be clobbered unless explicitly stated
  12. by the particular hypercall.
  13. S390:
  14. R2-R7 are used for parameters 1-6. In addition, R1 is used for hypercall
  15. number. The return value is written to R2.
  16. S390 uses diagnose instruction as hypercall (0x500) along with hypercall
  17. number in R1.
  18. For further information on the S390 diagnose call as supported by KVM,
  19. refer to Documentation/virt/kvm/s390/s390-diag.rst.
  20. PowerPC:
  21. It uses R3-R10 and hypercall number in R11. R4-R11 are used as output registers.
  22. Return value is placed in R3.
  23. KVM hypercalls uses 4 byte opcode, that are patched with 'hypercall-instructions'
  24. property inside the device tree's /hypervisor node.
  25. For more information refer to Documentation/virt/kvm/ppc-pv.rst
  26. MIPS:
  27. KVM hypercalls use the HYPCALL instruction with code 0 and the hypercall
  28. number in $2 (v0). Up to four arguments may be placed in $4-$7 (a0-a3) and
  29. the return value is placed in $2 (v0).
  30. KVM Hypercalls Documentation
  31. ============================
  32. The template for each hypercall is:
  33. 1. Hypercall name.
  34. 2. Architecture(s)
  35. 3. Status (deprecated, obsolete, active)
  36. 4. Purpose
  37. 1. KVM_HC_VAPIC_POLL_IRQ
  38. ------------------------
  39. :Architecture: x86
  40. :Status: active
  41. :Purpose: Trigger guest exit so that the host can check for pending
  42. interrupts on reentry.
  43. 2. KVM_HC_MMU_OP
  44. ----------------
  45. :Architecture: x86
  46. :Status: deprecated.
  47. :Purpose: Support MMU operations such as writing to PTE,
  48. flushing TLB, release PT.
  49. 3. KVM_HC_FEATURES
  50. ------------------
  51. :Architecture: PPC
  52. :Status: active
  53. :Purpose: Expose hypercall availability to the guest. On x86 platforms, cpuid
  54. used to enumerate which hypercalls are available. On PPC, either
  55. device tree based lookup ( which is also what EPAPR dictates)
  56. OR KVM specific enumeration mechanism (which is this hypercall)
  57. can be used.
  58. 4. KVM_HC_PPC_MAP_MAGIC_PAGE
  59. ----------------------------
  60. :Architecture: PPC
  61. :Status: active
  62. :Purpose: To enable communication between the hypervisor and guest there is a
  63. shared page that contains parts of supervisor visible register state.
  64. The guest can map this shared page to access its supervisor register
  65. through memory using this hypercall.
  66. 5. KVM_HC_KICK_CPU
  67. ------------------
  68. :Architecture: x86
  69. :Status: active
  70. :Purpose: Hypercall used to wakeup a vcpu from HLT state
  71. :Usage example:
  72. A vcpu of a paravirtualized guest that is busywaiting in guest
  73. kernel mode for an event to occur (ex: a spinlock to become available) can
  74. execute HLT instruction once it has busy-waited for more than a threshold
  75. time-interval. Execution of HLT instruction would cause the hypervisor to put
  76. the vcpu to sleep until occurrence of an appropriate event. Another vcpu of the
  77. same guest can wakeup the sleeping vcpu by issuing KVM_HC_KICK_CPU hypercall,
  78. specifying APIC ID (a1) of the vcpu to be woken up. An additional argument (a0)
  79. is used in the hypercall for future use.
  80. 6. KVM_HC_CLOCK_PAIRING
  81. -----------------------
  82. :Architecture: x86
  83. :Status: active
  84. :Purpose: Hypercall used to synchronize host and guest clocks.
  85. Usage:
  86. a0: guest physical address where host copies
  87. "struct kvm_clock_offset" structure.
  88. a1: clock_type, ATM only KVM_CLOCK_PAIRING_WALLCLOCK (0)
  89. is supported (corresponding to the host's CLOCK_REALTIME clock).
  90. ::
  91. struct kvm_clock_pairing {
  92. __s64 sec;
  93. __s64 nsec;
  94. __u64 tsc;
  95. __u32 flags;
  96. __u32 pad[9];
  97. };
  98. Where:
  99. * sec: seconds from clock_type clock.
  100. * nsec: nanoseconds from clock_type clock.
  101. * tsc: guest TSC value used to calculate sec/nsec pair
  102. * flags: flags, unused (0) at the moment.
  103. The hypercall lets a guest compute a precise timestamp across
  104. host and guest. The guest can use the returned TSC value to
  105. compute the CLOCK_REALTIME for its clock, at the same instant.
  106. Returns KVM_EOPNOTSUPP if the host does not use TSC clocksource,
  107. or if clock type is different than KVM_CLOCK_PAIRING_WALLCLOCK.
  108. 6. KVM_HC_SEND_IPI
  109. ------------------
  110. :Architecture: x86
  111. :Status: active
  112. :Purpose: Send IPIs to multiple vCPUs.
  113. - a0: lower part of the bitmap of destination APIC IDs
  114. - a1: higher part of the bitmap of destination APIC IDs
  115. - a2: the lowest APIC ID in bitmap
  116. - a3: APIC ICR
  117. The hypercall lets a guest send multicast IPIs, with at most 128
  118. 128 destinations per hypercall in 64-bit mode and 64 vCPUs per
  119. hypercall in 32-bit mode. The destinations are represented by a
  120. bitmap contained in the first two arguments (a0 and a1). Bit 0 of
  121. a0 corresponds to the APIC ID in the third argument (a2), bit 1
  122. corresponds to the APIC ID a2+1, and so on.
  123. Returns the number of CPUs to which the IPIs were delivered successfully.
  124. 7. KVM_HC_SCHED_YIELD
  125. ---------------------
  126. :Architecture: x86
  127. :Status: active
  128. :Purpose: Hypercall used to yield if the IPI target vCPU is preempted
  129. a0: destination APIC ID
  130. :Usage example: When sending a call-function IPI-many to vCPUs, yield if
  131. any of the IPI target vCPUs was preempted.
  132. 8. KVM_HC_MAP_GPA_RANGE
  133. -------------------------
  134. :Architecture: x86
  135. :Status: active
  136. :Purpose: Request KVM to map a GPA range with the specified attributes.
  137. a0: the guest physical address of the start page
  138. a1: the number of (4kb) pages (must be contiguous in GPA space)
  139. a2: attributes
  140. Where 'attributes' :
  141. * bits 3:0 - preferred page size encoding 0 = 4kb, 1 = 2mb, 2 = 1gb, etc...
  142. * bit 4 - plaintext = 0, encrypted = 1
  143. * bits 63:5 - reserved (must be zero)
  144. **Implementation note**: this hypercall is implemented in userspace via
  145. the KVM_CAP_EXIT_HYPERCALL capability. Userspace must enable that capability
  146. before advertising KVM_FEATURE_HC_MAP_GPA_RANGE in the guest CPUID. In
  147. addition, if the guest supports KVM_FEATURE_MIGRATION_CONTROL, userspace
  148. must also set up an MSR filter to process writes to MSR_KVM_MIGRATION_CONTROL.