msr.txt 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. Availability of this MSR must be checked via bit 3 in 0x4000001 cpuid
  86. leaf prior to usage.
  87. MSR_KVM_WALL_CLOCK: 0x11
  88. data and functioning: same as MSR_KVM_WALL_CLOCK_NEW. Use that instead.
  89. This MSR falls outside the reserved KVM range and may be removed in the
  90. future. Its usage is deprecated.
  91. Availability of this MSR must be checked via bit 0 in 0x4000001 cpuid
  92. leaf prior to usage.
  93. MSR_KVM_SYSTEM_TIME: 0x12
  94. data and functioning: same as MSR_KVM_SYSTEM_TIME_NEW. Use that instead.
  95. This MSR falls outside the reserved KVM range and may be removed in the
  96. future. Its usage is deprecated.
  97. Availability of this MSR must be checked via bit 0 in 0x4000001 cpuid
  98. leaf prior to usage.
  99. The suggested algorithm for detecting kvmclock presence is then:
  100. if (!kvm_para_available()) /* refer to cpuid.txt */
  101. return NON_PRESENT;
  102. flags = cpuid_eax(0x40000001);
  103. if (flags & 3) {
  104. msr_kvm_system_time = MSR_KVM_SYSTEM_TIME_NEW;
  105. msr_kvm_wall_clock = MSR_KVM_WALL_CLOCK_NEW;
  106. return PRESENT;
  107. } else if (flags & 0) {
  108. msr_kvm_system_time = MSR_KVM_SYSTEM_TIME;
  109. msr_kvm_wall_clock = MSR_KVM_WALL_CLOCK;
  110. return PRESENT;
  111. } else
  112. return NON_PRESENT;
  113. MSR_KVM_ASYNC_PF_EN: 0x4b564d02
  114. data: Bits 63-6 hold 64-byte aligned physical address of a
  115. 64 byte memory area which must be in guest RAM and must be
  116. zeroed. Bits 5-2 are reserved and should be zero. Bit 0 is 1
  117. when asynchronous page faults are enabled on the vcpu 0 when
  118. disabled. Bit 2 is 1 if asynchronous page faults can be injected
  119. when vcpu is in cpl == 0.
  120. First 4 byte of 64 byte memory location will be written to by
  121. the hypervisor at the time of asynchronous page fault (APF)
  122. injection to indicate type of asynchronous page fault. Value
  123. of 1 means that the page referred to by the page fault is not
  124. present. Value 2 means that the page is now available. Disabling
  125. interrupt inhibits APFs. Guest must not enable interrupt
  126. before the reason is read, or it may be overwritten by another
  127. APF. Since APF uses the same exception vector as regular page
  128. fault guest must reset the reason to 0 before it does
  129. something that can generate normal page fault. If during page
  130. fault APF reason is 0 it means that this is regular page
  131. fault.
  132. During delivery of type 1 APF cr2 contains a token that will
  133. be used to notify a guest when missing page becomes
  134. available. When page becomes available type 2 APF is sent with
  135. cr2 set to the token associated with the page. There is special
  136. kind of token 0xffffffff which tells vcpu that it should wake
  137. up all processes waiting for APFs and no individual type 2 APFs
  138. will be sent.
  139. If APF is disabled while there are outstanding APFs, they will
  140. not be delivered.
  141. Currently type 2 APF will be always delivered on the same vcpu as
  142. type 1 was, but guest should not rely on that.