msr.txt 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. KVM-specific MSRs.
  2. Glauber Costa <glommer@redhat.com>, Red Hat Inc, 2010
  3. =====================================================
  4. KVM makes use of some custom MSRs to service some requests.
  5. Custom MSRs have a range reserved for them, that goes from
  6. 0x4b564d00 to 0x4b564dff. There are MSRs outside this area,
  7. but they are deprecated and their use is discouraged.
  8. Custom MSR list
  9. --------
  10. The current supported Custom MSR list is:
  11. MSR_KVM_WALL_CLOCK_NEW: 0x4b564d00
  12. data: 4-byte alignment physical address of a memory area which must be
  13. in guest RAM. This memory is expected to hold a copy of the following
  14. structure:
  15. struct pvclock_wall_clock {
  16. u32 version;
  17. u32 sec;
  18. u32 nsec;
  19. } __attribute__((__packed__));
  20. whose data will be filled in by the hypervisor. The hypervisor is only
  21. guaranteed to update this data at the moment of MSR write.
  22. Users that want to reliably query this information more than once have
  23. to write more than once to this MSR. Fields have the following meanings:
  24. version: guest has to check version before and after grabbing
  25. time information and check that they are both equal and even.
  26. An odd version indicates an in-progress update.
  27. sec: number of seconds for wallclock.
  28. nsec: number of nanoseconds for wallclock.
  29. Note that although MSRs are per-CPU entities, the effect of this
  30. particular MSR is global.
  31. Availability of this MSR must be checked via bit 3 in 0x4000001 cpuid
  32. leaf prior to usage.
  33. MSR_KVM_SYSTEM_TIME_NEW: 0x4b564d01
  34. data: 4-byte aligned physical address of a memory area which must be in
  35. guest RAM, plus an enable bit in bit 0. This memory is expected to hold
  36. a copy of the following structure:
  37. struct pvclock_vcpu_time_info {
  38. u32 version;
  39. u32 pad0;
  40. u64 tsc_timestamp;
  41. u64 system_time;
  42. u32 tsc_to_system_mul;
  43. s8 tsc_shift;
  44. u8 flags;
  45. u8 pad[2];
  46. } __attribute__((__packed__)); /* 32 bytes */
  47. whose data will be filled in by the hypervisor periodically. Only one
  48. write, or registration, is needed for each VCPU. The interval between
  49. updates of this structure is arbitrary and implementation-dependent.
  50. The hypervisor may update this structure at any time it sees fit until
  51. anything with bit0 == 0 is written to it.
  52. Fields have the following meanings:
  53. version: guest has to check version before and after grabbing
  54. time information and check that they are both equal and even.
  55. An odd version indicates an in-progress update.
  56. tsc_timestamp: the tsc value at the current VCPU at the time
  57. of the update of this structure. Guests can subtract this value
  58. from current tsc to derive a notion of elapsed time since the
  59. structure update.
  60. system_time: a host notion of monotonic time, including sleep
  61. time at the time this structure was last updated. Unit is
  62. nanoseconds.
  63. tsc_to_system_mul: a function of the tsc frequency. One has
  64. to multiply any tsc-related quantity by this value to get
  65. a value in nanoseconds, besides dividing by 2^tsc_shift
  66. tsc_shift: cycle to nanosecond divider, as a power of two, to
  67. allow for shift rights. One has to shift right any tsc-related
  68. quantity by this value to get a value in nanoseconds, besides
  69. multiplying by tsc_to_system_mul.
  70. With this information, guests can derive per-CPU time by
  71. doing:
  72. time = (current_tsc - tsc_timestamp)
  73. time = (time * tsc_to_system_mul) >> tsc_shift
  74. time = time + system_time
  75. flags: bits in this field indicate extended capabilities
  76. coordinated between the guest and the hypervisor. Availability
  77. of specific flags has to be checked in 0x40000001 cpuid leaf.
  78. Current flags are:
  79. flag bit | cpuid bit | meaning
  80. -------------------------------------------------------------
  81. | | time measures taken across
  82. 0 | 24 | multiple cpus are guaranteed to
  83. | | be monotonic
  84. -------------------------------------------------------------
  85. | | guest vcpu has been paused by
  86. 1 | N/A | the host
  87. | | See 4.70 in api.txt
  88. -------------------------------------------------------------
  89. Availability of this MSR must be checked via bit 3 in 0x4000001 cpuid
  90. leaf prior to usage.
  91. MSR_KVM_WALL_CLOCK: 0x11
  92. data and functioning: same as MSR_KVM_WALL_CLOCK_NEW. Use that instead.
  93. This MSR falls outside the reserved KVM range and may be removed in the
  94. future. Its usage is deprecated.
  95. Availability of this MSR must be checked via bit 0 in 0x4000001 cpuid
  96. leaf prior to usage.
  97. MSR_KVM_SYSTEM_TIME: 0x12
  98. data and functioning: same as MSR_KVM_SYSTEM_TIME_NEW. Use that instead.
  99. This MSR falls outside the reserved KVM range and may be removed in the
  100. future. Its usage is deprecated.
  101. Availability of this MSR must be checked via bit 0 in 0x4000001 cpuid
  102. leaf prior to usage.
  103. The suggested algorithm for detecting kvmclock presence is then:
  104. if (!kvm_para_available()) /* refer to cpuid.txt */
  105. return NON_PRESENT;
  106. flags = cpuid_eax(0x40000001);
  107. if (flags & 3) {
  108. msr_kvm_system_time = MSR_KVM_SYSTEM_TIME_NEW;
  109. msr_kvm_wall_clock = MSR_KVM_WALL_CLOCK_NEW;
  110. return PRESENT;
  111. } else if (flags & 0) {
  112. msr_kvm_system_time = MSR_KVM_SYSTEM_TIME;
  113. msr_kvm_wall_clock = MSR_KVM_WALL_CLOCK;
  114. return PRESENT;
  115. } else
  116. return NON_PRESENT;
  117. MSR_KVM_ASYNC_PF_EN: 0x4b564d02
  118. data: Bits 63-6 hold 64-byte aligned physical address of a
  119. 64 byte memory area which must be in guest RAM and must be
  120. zeroed. Bits 5-2 are reserved and should be zero. Bit 0 is 1
  121. when asynchronous page faults are enabled on the vcpu 0 when
  122. disabled. Bit 2 is 1 if asynchronous page faults can be injected
  123. when vcpu is in cpl == 0.
  124. First 4 byte of 64 byte memory location will be written to by
  125. the hypervisor at the time of asynchronous page fault (APF)
  126. injection to indicate type of asynchronous page fault. Value
  127. of 1 means that the page referred to by the page fault is not
  128. present. Value 2 means that the page is now available. Disabling
  129. interrupt inhibits APFs. Guest must not enable interrupt
  130. before the reason is read, or it may be overwritten by another
  131. APF. Since APF uses the same exception vector as regular page
  132. fault guest must reset the reason to 0 before it does
  133. something that can generate normal page fault. If during page
  134. fault APF reason is 0 it means that this is regular page
  135. fault.
  136. During delivery of type 1 APF cr2 contains a token that will
  137. be used to notify a guest when missing page becomes
  138. available. When page becomes available type 2 APF is sent with
  139. cr2 set to the token associated with the page. There is special
  140. kind of token 0xffffffff which tells vcpu that it should wake
  141. up all processes waiting for APFs and no individual type 2 APFs
  142. will be sent.
  143. If APF is disabled while there are outstanding APFs, they will
  144. not be delivered.
  145. Currently type 2 APF will be always delivered on the same vcpu as
  146. type 1 was, but guest should not rely on that.
  147. MSR_KVM_STEAL_TIME: 0x4b564d03
  148. data: 64-byte alignment physical address of a memory area which must be
  149. in guest RAM, plus an enable bit in bit 0. This memory is expected to
  150. hold a copy of the following structure:
  151. struct kvm_steal_time {
  152. __u64 steal;
  153. __u32 version;
  154. __u32 flags;
  155. __u32 pad[12];
  156. }
  157. whose data will be filled in by the hypervisor periodically. Only one
  158. write, or registration, is needed for each VCPU. The interval between
  159. updates of this structure is arbitrary and implementation-dependent.
  160. The hypervisor may update this structure at any time it sees fit until
  161. anything with bit0 == 0 is written to it. Guest is required to make sure
  162. this structure is initialized to zero.
  163. Fields have the following meanings:
  164. version: a sequence counter. In other words, guest has to check
  165. this field before and after grabbing time information and make
  166. sure they are both equal and even. An odd version indicates an
  167. in-progress update.
  168. flags: At this point, always zero. May be used to indicate
  169. changes in this structure in the future.
  170. steal: the amount of time in which this vCPU did not run, in
  171. nanoseconds. Time during which the vcpu is idle, will not be
  172. reported as steal time.
  173. MSR_KVM_EOI_EN: 0x4b564d04
  174. data: Bit 0 is 1 when PV end of interrupt is enabled on the vcpu; 0
  175. when disabled. Bit 1 is reserved and must be zero. When PV end of
  176. interrupt is enabled (bit 0 set), bits 63-2 hold a 4-byte aligned
  177. physical address of a 4 byte memory area which must be in guest RAM and
  178. must be zeroed.
  179. The first, least significant bit of 4 byte memory location will be
  180. written to by the hypervisor, typically at the time of interrupt
  181. injection. Value of 1 means that guest can skip writing EOI to the apic
  182. (using MSR or MMIO write); instead, it is sufficient to signal
  183. EOI by clearing the bit in guest memory - this location will
  184. later be polled by the hypervisor.
  185. Value of 0 means that the EOI write is required.
  186. It is always safe for the guest to ignore the optimization and perform
  187. the APIC EOI write anyway.
  188. Hypervisor is guaranteed to only modify this least
  189. significant bit while in the current VCPU context, this means that
  190. guest does not need to use either lock prefix or memory ordering
  191. primitives to synchronise with the hypervisor.
  192. However, hypervisor can set and clear this memory bit at any time:
  193. therefore to make sure hypervisor does not interrupt the
  194. guest and clear the least significant bit in the memory area
  195. in the window between guest testing it to detect
  196. whether it can skip EOI apic write and between guest
  197. clearing it to signal EOI to the hypervisor,
  198. guest must both read the least significant bit in the memory area and
  199. clear it using a single CPU instruction, such as test and clear, or
  200. compare and exchange.