hypercalls.rst 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ===================================
  3. The LoongArch paravirtual interface
  4. ===================================
  5. KVM hypercalls use the HVCL instruction with code 0x100 and the hypercall
  6. number is put in a0. Up to five arguments may be placed in registers a1 - a5.
  7. The return value is placed in v0 (an alias of a0).
  8. Source code for this interface can be found in arch/loongarch/kvm*.
  9. Querying for existence
  10. ======================
  11. To determine if the host is running on KVM, we can utilize the cpucfg()
  12. function at index CPUCFG_KVM_BASE (0x40000000).
  13. The CPUCFG_KVM_BASE range, spanning from 0x40000000 to 0x400000FF, The
  14. CPUCFG_KVM_BASE range between 0x40000000 - 0x400000FF is marked as reserved.
  15. Consequently, all current and future processors will not implement any
  16. feature within this range.
  17. On a KVM-virtualized Linux system, a read operation on cpucfg() at index
  18. CPUCFG_KVM_BASE (0x40000000) returns the magic string 'KVM\0'.
  19. Once you have determined that your host is running on a paravirtualization-
  20. capable KVM, you may now use hypercalls as described below.
  21. KVM hypercall ABI
  22. =================
  23. The KVM hypercall ABI is simple, with one scratch register a0 (v0) and at most
  24. five generic registers (a1 - a5) used as input parameters. The FP (Floating-
  25. point) and vector registers are not utilized as input registers and must
  26. remain unmodified during a hypercall.
  27. Hypercall functions can be inlined as it only uses one scratch register.
  28. The parameters are as follows:
  29. ======== ================= ================
  30. Register IN OUT
  31. ======== ================= ================
  32. a0 function number Return code
  33. a1 1st parameter -
  34. a2 2nd parameter -
  35. a3 3rd parameter -
  36. a4 4th parameter -
  37. a5 5th parameter -
  38. ======== ================= ================
  39. The return codes may be one of the following:
  40. ==== =========================
  41. Code Meaning
  42. ==== =========================
  43. 0 Success
  44. -1 Hypercall not implemented
  45. -2 Bad Hypercall parameter
  46. ==== =========================
  47. KVM Hypercalls Documentation
  48. ============================
  49. The template for each hypercall is as follows:
  50. 1. Hypercall name
  51. 2. Purpose
  52. 1. KVM_HCALL_FUNC_IPI
  53. ------------------------
  54. :Purpose: Send IPIs to multiple vCPUs.
  55. - a0: KVM_HCALL_FUNC_IPI
  56. - a1: Lower part of the bitmap for destination physical CPUIDs
  57. - a2: Higher part of the bitmap for destination physical CPUIDs
  58. - a3: The lowest physical CPUID in the bitmap
  59. The hypercall lets a guest send multiple IPIs (Inter-Process Interrupts) with
  60. at most 128 destinations per hypercall. The destinations are represented in a
  61. bitmap contained in the first two input registers (a1 and a2).
  62. Bit 0 of a1 corresponds to the physical CPUID in the third input register (a3)
  63. and bit 1 corresponds to the physical CPUID in a3+1, and so on.
  64. PV IPI on LoongArch includes both PV IPI multicast sending and PV IPI receiving,
  65. and SWI is used for PV IPI inject since there is no VM-exits accessing SWI registers.