hyperv-tlfs.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. /*
  3. * This file contains definitions from Hyper-V Hypervisor Top-Level Functional
  4. * Specification (TLFS):
  5. * https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/reference/tlfs
  6. */
  7. #ifndef _ASM_X86_HYPERV_TLFS_H
  8. #define _ASM_X86_HYPERV_TLFS_H
  9. #include <linux/types.h>
  10. /*
  11. * The below CPUID leaves are present if VersionAndFeatures.HypervisorPresent
  12. * is set by CPUID(HvCpuIdFunctionVersionAndFeatures).
  13. */
  14. #define HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS 0x40000000
  15. #define HYPERV_CPUID_INTERFACE 0x40000001
  16. #define HYPERV_CPUID_VERSION 0x40000002
  17. #define HYPERV_CPUID_FEATURES 0x40000003
  18. #define HYPERV_CPUID_ENLIGHTMENT_INFO 0x40000004
  19. #define HYPERV_CPUID_IMPLEMENT_LIMITS 0x40000005
  20. #define HYPERV_CPUID_NESTED_FEATURES 0x4000000A
  21. #define HYPERV_HYPERVISOR_PRESENT_BIT 0x80000000
  22. #define HYPERV_CPUID_MIN 0x40000005
  23. #define HYPERV_CPUID_MAX 0x4000ffff
  24. /*
  25. * Feature identification. EAX indicates which features are available
  26. * to the partition based upon the current partition privileges.
  27. */
  28. /* VP Runtime (HV_X64_MSR_VP_RUNTIME) available */
  29. #define HV_X64_MSR_VP_RUNTIME_AVAILABLE (1 << 0)
  30. /* Partition Reference Counter (HV_X64_MSR_TIME_REF_COUNT) available*/
  31. #define HV_MSR_TIME_REF_COUNT_AVAILABLE (1 << 1)
  32. /* Partition reference TSC MSR is available */
  33. #define HV_MSR_REFERENCE_TSC_AVAILABLE (1 << 9)
  34. /* A partition's reference time stamp counter (TSC) page */
  35. #define HV_X64_MSR_REFERENCE_TSC 0x40000021
  36. /*
  37. * There is a single feature flag that signifies if the partition has access
  38. * to MSRs with local APIC and TSC frequencies.
  39. */
  40. #define HV_X64_ACCESS_FREQUENCY_MSRS (1 << 11)
  41. /* AccessReenlightenmentControls privilege */
  42. #define HV_X64_ACCESS_REENLIGHTENMENT BIT(13)
  43. /*
  44. * Basic SynIC MSRs (HV_X64_MSR_SCONTROL through HV_X64_MSR_EOM
  45. * and HV_X64_MSR_SINT0 through HV_X64_MSR_SINT15) available
  46. */
  47. #define HV_X64_MSR_SYNIC_AVAILABLE (1 << 2)
  48. /*
  49. * Synthetic Timer MSRs (HV_X64_MSR_STIMER0_CONFIG through
  50. * HV_X64_MSR_STIMER3_COUNT) available
  51. */
  52. #define HV_MSR_SYNTIMER_AVAILABLE (1 << 3)
  53. /*
  54. * APIC access MSRs (HV_X64_MSR_EOI, HV_X64_MSR_ICR and HV_X64_MSR_TPR)
  55. * are available
  56. */
  57. #define HV_X64_MSR_APIC_ACCESS_AVAILABLE (1 << 4)
  58. /* Hypercall MSRs (HV_X64_MSR_GUEST_OS_ID and HV_X64_MSR_HYPERCALL) available*/
  59. #define HV_X64_MSR_HYPERCALL_AVAILABLE (1 << 5)
  60. /* Access virtual processor index MSR (HV_X64_MSR_VP_INDEX) available*/
  61. #define HV_X64_MSR_VP_INDEX_AVAILABLE (1 << 6)
  62. /* Virtual system reset MSR (HV_X64_MSR_RESET) is available*/
  63. #define HV_X64_MSR_RESET_AVAILABLE (1 << 7)
  64. /*
  65. * Access statistics pages MSRs (HV_X64_MSR_STATS_PARTITION_RETAIL_PAGE,
  66. * HV_X64_MSR_STATS_PARTITION_INTERNAL_PAGE, HV_X64_MSR_STATS_VP_RETAIL_PAGE,
  67. * HV_X64_MSR_STATS_VP_INTERNAL_PAGE) available
  68. */
  69. #define HV_X64_MSR_STAT_PAGES_AVAILABLE (1 << 8)
  70. /* Frequency MSRs available */
  71. #define HV_FEATURE_FREQUENCY_MSRS_AVAILABLE (1 << 8)
  72. /* Crash MSR available */
  73. #define HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE (1 << 10)
  74. /* stimer Direct Mode is available */
  75. #define HV_STIMER_DIRECT_MODE_AVAILABLE (1 << 19)
  76. /*
  77. * Feature identification: EBX indicates which flags were specified at
  78. * partition creation. The format is the same as the partition creation
  79. * flag structure defined in section Partition Creation Flags.
  80. */
  81. #define HV_X64_CREATE_PARTITIONS (1 << 0)
  82. #define HV_X64_ACCESS_PARTITION_ID (1 << 1)
  83. #define HV_X64_ACCESS_MEMORY_POOL (1 << 2)
  84. #define HV_X64_ADJUST_MESSAGE_BUFFERS (1 << 3)
  85. #define HV_X64_POST_MESSAGES (1 << 4)
  86. #define HV_X64_SIGNAL_EVENTS (1 << 5)
  87. #define HV_X64_CREATE_PORT (1 << 6)
  88. #define HV_X64_CONNECT_PORT (1 << 7)
  89. #define HV_X64_ACCESS_STATS (1 << 8)
  90. #define HV_X64_DEBUGGING (1 << 11)
  91. #define HV_X64_CPU_POWER_MANAGEMENT (1 << 12)
  92. #define HV_X64_CONFIGURE_PROFILER (1 << 13)
  93. /*
  94. * Feature identification. EDX indicates which miscellaneous features
  95. * are available to the partition.
  96. */
  97. /* The MWAIT instruction is available (per section MONITOR / MWAIT) */
  98. #define HV_X64_MWAIT_AVAILABLE (1 << 0)
  99. /* Guest debugging support is available */
  100. #define HV_X64_GUEST_DEBUGGING_AVAILABLE (1 << 1)
  101. /* Performance Monitor support is available*/
  102. #define HV_X64_PERF_MONITOR_AVAILABLE (1 << 2)
  103. /* Support for physical CPU dynamic partitioning events is available*/
  104. #define HV_X64_CPU_DYNAMIC_PARTITIONING_AVAILABLE (1 << 3)
  105. /*
  106. * Support for passing hypercall input parameter block via XMM
  107. * registers is available
  108. */
  109. #define HV_X64_HYPERCALL_PARAMS_XMM_AVAILABLE (1 << 4)
  110. /* Support for a virtual guest idle state is available */
  111. #define HV_X64_GUEST_IDLE_STATE_AVAILABLE (1 << 5)
  112. /* Guest crash data handler available */
  113. #define HV_X64_GUEST_CRASH_MSR_AVAILABLE (1 << 10)
  114. /*
  115. * Implementation recommendations. Indicates which behaviors the hypervisor
  116. * recommends the OS implement for optimal performance.
  117. */
  118. /*
  119. * Recommend using hypercall for address space switches rather
  120. * than MOV to CR3 instruction
  121. */
  122. #define HV_X64_AS_SWITCH_RECOMMENDED (1 << 0)
  123. /* Recommend using hypercall for local TLB flushes rather
  124. * than INVLPG or MOV to CR3 instructions */
  125. #define HV_X64_LOCAL_TLB_FLUSH_RECOMMENDED (1 << 1)
  126. /*
  127. * Recommend using hypercall for remote TLB flushes rather
  128. * than inter-processor interrupts
  129. */
  130. #define HV_X64_REMOTE_TLB_FLUSH_RECOMMENDED (1 << 2)
  131. /*
  132. * Recommend using MSRs for accessing APIC registers
  133. * EOI, ICR and TPR rather than their memory-mapped counterparts
  134. */
  135. #define HV_X64_APIC_ACCESS_RECOMMENDED (1 << 3)
  136. /* Recommend using the hypervisor-provided MSR to initiate a system RESET */
  137. #define HV_X64_SYSTEM_RESET_RECOMMENDED (1 << 4)
  138. /*
  139. * Recommend using relaxed timing for this partition. If used,
  140. * the VM should disable any watchdog timeouts that rely on the
  141. * timely delivery of external interrupts
  142. */
  143. #define HV_X64_RELAXED_TIMING_RECOMMENDED (1 << 5)
  144. /*
  145. * Recommend not using Auto End-Of-Interrupt feature
  146. */
  147. #define HV_DEPRECATING_AEOI_RECOMMENDED (1 << 9)
  148. /*
  149. * Recommend using cluster IPI hypercalls.
  150. */
  151. #define HV_X64_CLUSTER_IPI_RECOMMENDED (1 << 10)
  152. /* Recommend using the newer ExProcessorMasks interface */
  153. #define HV_X64_EX_PROCESSOR_MASKS_RECOMMENDED (1 << 11)
  154. /* Recommend using enlightened VMCS */
  155. #define HV_X64_ENLIGHTENED_VMCS_RECOMMENDED (1 << 14)
  156. /*
  157. * Crash notification flags.
  158. */
  159. #define HV_CRASH_CTL_CRASH_NOTIFY_MSG BIT_ULL(62)
  160. #define HV_CRASH_CTL_CRASH_NOTIFY BIT_ULL(63)
  161. /* MSR used to identify the guest OS. */
  162. #define HV_X64_MSR_GUEST_OS_ID 0x40000000
  163. /* MSR used to setup pages used to communicate with the hypervisor. */
  164. #define HV_X64_MSR_HYPERCALL 0x40000001
  165. /* MSR used to provide vcpu index */
  166. #define HV_X64_MSR_VP_INDEX 0x40000002
  167. /* MSR used to reset the guest OS. */
  168. #define HV_X64_MSR_RESET 0x40000003
  169. /* MSR used to provide vcpu runtime in 100ns units */
  170. #define HV_X64_MSR_VP_RUNTIME 0x40000010
  171. /* MSR used to read the per-partition time reference counter */
  172. #define HV_X64_MSR_TIME_REF_COUNT 0x40000020
  173. /* MSR used to retrieve the TSC frequency */
  174. #define HV_X64_MSR_TSC_FREQUENCY 0x40000022
  175. /* MSR used to retrieve the local APIC timer frequency */
  176. #define HV_X64_MSR_APIC_FREQUENCY 0x40000023
  177. /* Define the virtual APIC registers */
  178. #define HV_X64_MSR_EOI 0x40000070
  179. #define HV_X64_MSR_ICR 0x40000071
  180. #define HV_X64_MSR_TPR 0x40000072
  181. #define HV_X64_MSR_VP_ASSIST_PAGE 0x40000073
  182. /* Define synthetic interrupt controller model specific registers. */
  183. #define HV_X64_MSR_SCONTROL 0x40000080
  184. #define HV_X64_MSR_SVERSION 0x40000081
  185. #define HV_X64_MSR_SIEFP 0x40000082
  186. #define HV_X64_MSR_SIMP 0x40000083
  187. #define HV_X64_MSR_EOM 0x40000084
  188. #define HV_X64_MSR_SINT0 0x40000090
  189. #define HV_X64_MSR_SINT1 0x40000091
  190. #define HV_X64_MSR_SINT2 0x40000092
  191. #define HV_X64_MSR_SINT3 0x40000093
  192. #define HV_X64_MSR_SINT4 0x40000094
  193. #define HV_X64_MSR_SINT5 0x40000095
  194. #define HV_X64_MSR_SINT6 0x40000096
  195. #define HV_X64_MSR_SINT7 0x40000097
  196. #define HV_X64_MSR_SINT8 0x40000098
  197. #define HV_X64_MSR_SINT9 0x40000099
  198. #define HV_X64_MSR_SINT10 0x4000009A
  199. #define HV_X64_MSR_SINT11 0x4000009B
  200. #define HV_X64_MSR_SINT12 0x4000009C
  201. #define HV_X64_MSR_SINT13 0x4000009D
  202. #define HV_X64_MSR_SINT14 0x4000009E
  203. #define HV_X64_MSR_SINT15 0x4000009F
  204. /*
  205. * Synthetic Timer MSRs. Four timers per vcpu.
  206. */
  207. #define HV_X64_MSR_STIMER0_CONFIG 0x400000B0
  208. #define HV_X64_MSR_STIMER0_COUNT 0x400000B1
  209. #define HV_X64_MSR_STIMER1_CONFIG 0x400000B2
  210. #define HV_X64_MSR_STIMER1_COUNT 0x400000B3
  211. #define HV_X64_MSR_STIMER2_CONFIG 0x400000B4
  212. #define HV_X64_MSR_STIMER2_COUNT 0x400000B5
  213. #define HV_X64_MSR_STIMER3_CONFIG 0x400000B6
  214. #define HV_X64_MSR_STIMER3_COUNT 0x400000B7
  215. /* Hyper-V guest crash notification MSR's */
  216. #define HV_X64_MSR_CRASH_P0 0x40000100
  217. #define HV_X64_MSR_CRASH_P1 0x40000101
  218. #define HV_X64_MSR_CRASH_P2 0x40000102
  219. #define HV_X64_MSR_CRASH_P3 0x40000103
  220. #define HV_X64_MSR_CRASH_P4 0x40000104
  221. #define HV_X64_MSR_CRASH_CTL 0x40000105
  222. #define HV_X64_MSR_CRASH_CTL_NOTIFY (1ULL << 63)
  223. #define HV_X64_MSR_CRASH_PARAMS \
  224. (1 + (HV_X64_MSR_CRASH_P4 - HV_X64_MSR_CRASH_P0))
  225. /*
  226. * Declare the MSR used to setup pages used to communicate with the hypervisor.
  227. */
  228. union hv_x64_msr_hypercall_contents {
  229. u64 as_uint64;
  230. struct {
  231. u64 enable:1;
  232. u64 reserved:11;
  233. u64 guest_physical_address:52;
  234. };
  235. };
  236. /*
  237. * TSC page layout.
  238. */
  239. struct ms_hyperv_tsc_page {
  240. volatile u32 tsc_sequence;
  241. u32 reserved1;
  242. volatile u64 tsc_scale;
  243. volatile s64 tsc_offset;
  244. u64 reserved2[509];
  245. };
  246. /*
  247. * The guest OS needs to register the guest ID with the hypervisor.
  248. * The guest ID is a 64 bit entity and the structure of this ID is
  249. * specified in the Hyper-V specification:
  250. *
  251. * msdn.microsoft.com/en-us/library/windows/hardware/ff542653%28v=vs.85%29.aspx
  252. *
  253. * While the current guideline does not specify how Linux guest ID(s)
  254. * need to be generated, our plan is to publish the guidelines for
  255. * Linux and other guest operating systems that currently are hosted
  256. * on Hyper-V. The implementation here conforms to this yet
  257. * unpublished guidelines.
  258. *
  259. *
  260. * Bit(s)
  261. * 63 - Indicates if the OS is Open Source or not; 1 is Open Source
  262. * 62:56 - Os Type; Linux is 0x100
  263. * 55:48 - Distro specific identification
  264. * 47:16 - Linux kernel version number
  265. * 15:0 - Distro specific identification
  266. *
  267. *
  268. */
  269. #define HV_LINUX_VENDOR_ID 0x8100
  270. /* TSC emulation after migration */
  271. #define HV_X64_MSR_REENLIGHTENMENT_CONTROL 0x40000106
  272. /* Nested features (CPUID 0x4000000A) EAX */
  273. #define HV_X64_NESTED_GUEST_MAPPING_FLUSH BIT(18)
  274. #define HV_X64_NESTED_MSR_BITMAP BIT(19)
  275. struct hv_reenlightenment_control {
  276. __u64 vector:8;
  277. __u64 reserved1:8;
  278. __u64 enabled:1;
  279. __u64 reserved2:15;
  280. __u64 target_vp:32;
  281. };
  282. #define HV_X64_MSR_TSC_EMULATION_CONTROL 0x40000107
  283. #define HV_X64_MSR_TSC_EMULATION_STATUS 0x40000108
  284. struct hv_tsc_emulation_control {
  285. __u64 enabled:1;
  286. __u64 reserved:63;
  287. };
  288. struct hv_tsc_emulation_status {
  289. __u64 inprogress:1;
  290. __u64 reserved:63;
  291. };
  292. #define HV_X64_MSR_HYPERCALL_ENABLE 0x00000001
  293. #define HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT 12
  294. #define HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_MASK \
  295. (~((1ull << HV_X64_MSR_HYPERCALL_PAGE_ADDRESS_SHIFT) - 1))
  296. #define HV_IPI_LOW_VECTOR 0x10
  297. #define HV_IPI_HIGH_VECTOR 0xff
  298. /* Declare the various hypercall operations. */
  299. #define HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE 0x0002
  300. #define HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST 0x0003
  301. #define HVCALL_NOTIFY_LONG_SPIN_WAIT 0x0008
  302. #define HVCALL_SEND_IPI 0x000b
  303. #define HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE_EX 0x0013
  304. #define HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST_EX 0x0014
  305. #define HVCALL_SEND_IPI_EX 0x0015
  306. #define HVCALL_POST_MESSAGE 0x005c
  307. #define HVCALL_SIGNAL_EVENT 0x005d
  308. #define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE 0x00af
  309. #define HV_X64_MSR_VP_ASSIST_PAGE_ENABLE 0x00000001
  310. #define HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_SHIFT 12
  311. #define HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_MASK \
  312. (~((1ull << HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_SHIFT) - 1))
  313. /* Hyper-V Enlightened VMCS version mask in nested features CPUID */
  314. #define HV_X64_ENLIGHTENED_VMCS_VERSION 0xff
  315. #define HV_X64_MSR_TSC_REFERENCE_ENABLE 0x00000001
  316. #define HV_X64_MSR_TSC_REFERENCE_ADDRESS_SHIFT 12
  317. #define HV_PROCESSOR_POWER_STATE_C0 0
  318. #define HV_PROCESSOR_POWER_STATE_C1 1
  319. #define HV_PROCESSOR_POWER_STATE_C2 2
  320. #define HV_PROCESSOR_POWER_STATE_C3 3
  321. #define HV_FLUSH_ALL_PROCESSORS BIT(0)
  322. #define HV_FLUSH_ALL_VIRTUAL_ADDRESS_SPACES BIT(1)
  323. #define HV_FLUSH_NON_GLOBAL_MAPPINGS_ONLY BIT(2)
  324. #define HV_FLUSH_USE_EXTENDED_RANGE_FORMAT BIT(3)
  325. enum HV_GENERIC_SET_FORMAT {
  326. HV_GENERIC_SET_SPARSE_4K,
  327. HV_GENERIC_SET_ALL,
  328. };
  329. #define HV_HYPERCALL_RESULT_MASK GENMASK_ULL(15, 0)
  330. #define HV_HYPERCALL_FAST_BIT BIT(16)
  331. #define HV_HYPERCALL_VARHEAD_OFFSET 17
  332. #define HV_HYPERCALL_REP_COMP_OFFSET 32
  333. #define HV_HYPERCALL_REP_COMP_MASK GENMASK_ULL(43, 32)
  334. #define HV_HYPERCALL_REP_START_OFFSET 48
  335. #define HV_HYPERCALL_REP_START_MASK GENMASK_ULL(59, 48)
  336. /* hypercall status code */
  337. #define HV_STATUS_SUCCESS 0
  338. #define HV_STATUS_INVALID_HYPERCALL_CODE 2
  339. #define HV_STATUS_INVALID_HYPERCALL_INPUT 3
  340. #define HV_STATUS_INVALID_ALIGNMENT 4
  341. #define HV_STATUS_INVALID_PARAMETER 5
  342. #define HV_STATUS_INSUFFICIENT_MEMORY 11
  343. #define HV_STATUS_INVALID_PORT_ID 17
  344. #define HV_STATUS_INVALID_CONNECTION_ID 18
  345. #define HV_STATUS_INSUFFICIENT_BUFFERS 19
  346. typedef struct _HV_REFERENCE_TSC_PAGE {
  347. __u32 tsc_sequence;
  348. __u32 res1;
  349. __u64 tsc_scale;
  350. __s64 tsc_offset;
  351. } HV_REFERENCE_TSC_PAGE, *PHV_REFERENCE_TSC_PAGE;
  352. /* Define the number of synthetic interrupt sources. */
  353. #define HV_SYNIC_SINT_COUNT (16)
  354. /* Define the expected SynIC version. */
  355. #define HV_SYNIC_VERSION_1 (0x1)
  356. /* Valid SynIC vectors are 16-255. */
  357. #define HV_SYNIC_FIRST_VALID_VECTOR (16)
  358. #define HV_SYNIC_CONTROL_ENABLE (1ULL << 0)
  359. #define HV_SYNIC_SIMP_ENABLE (1ULL << 0)
  360. #define HV_SYNIC_SIEFP_ENABLE (1ULL << 0)
  361. #define HV_SYNIC_SINT_MASKED (1ULL << 16)
  362. #define HV_SYNIC_SINT_AUTO_EOI (1ULL << 17)
  363. #define HV_SYNIC_SINT_VECTOR_MASK (0xFF)
  364. #define HV_SYNIC_STIMER_COUNT (4)
  365. /* Define synthetic interrupt controller message constants. */
  366. #define HV_MESSAGE_SIZE (256)
  367. #define HV_MESSAGE_PAYLOAD_BYTE_COUNT (240)
  368. #define HV_MESSAGE_PAYLOAD_QWORD_COUNT (30)
  369. /* Define hypervisor message types. */
  370. enum hv_message_type {
  371. HVMSG_NONE = 0x00000000,
  372. /* Memory access messages. */
  373. HVMSG_UNMAPPED_GPA = 0x80000000,
  374. HVMSG_GPA_INTERCEPT = 0x80000001,
  375. /* Timer notification messages. */
  376. HVMSG_TIMER_EXPIRED = 0x80000010,
  377. /* Error messages. */
  378. HVMSG_INVALID_VP_REGISTER_VALUE = 0x80000020,
  379. HVMSG_UNRECOVERABLE_EXCEPTION = 0x80000021,
  380. HVMSG_UNSUPPORTED_FEATURE = 0x80000022,
  381. /* Trace buffer complete messages. */
  382. HVMSG_EVENTLOG_BUFFERCOMPLETE = 0x80000040,
  383. /* Platform-specific processor intercept messages. */
  384. HVMSG_X64_IOPORT_INTERCEPT = 0x80010000,
  385. HVMSG_X64_MSR_INTERCEPT = 0x80010001,
  386. HVMSG_X64_CPUID_INTERCEPT = 0x80010002,
  387. HVMSG_X64_EXCEPTION_INTERCEPT = 0x80010003,
  388. HVMSG_X64_APIC_EOI = 0x80010004,
  389. HVMSG_X64_LEGACY_FP_ERROR = 0x80010005
  390. };
  391. /* Define synthetic interrupt controller message flags. */
  392. union hv_message_flags {
  393. __u8 asu8;
  394. struct {
  395. __u8 msg_pending:1;
  396. __u8 reserved:7;
  397. };
  398. };
  399. /* Define port identifier type. */
  400. union hv_port_id {
  401. __u32 asu32;
  402. struct {
  403. __u32 id:24;
  404. __u32 reserved:8;
  405. } u;
  406. };
  407. /* Define synthetic interrupt controller message header. */
  408. struct hv_message_header {
  409. __u32 message_type;
  410. __u8 payload_size;
  411. union hv_message_flags message_flags;
  412. __u8 reserved[2];
  413. union {
  414. __u64 sender;
  415. union hv_port_id port;
  416. };
  417. };
  418. /* Define synthetic interrupt controller message format. */
  419. struct hv_message {
  420. struct hv_message_header header;
  421. union {
  422. __u64 payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT];
  423. } u;
  424. };
  425. /* Define the synthetic interrupt message page layout. */
  426. struct hv_message_page {
  427. struct hv_message sint_message[HV_SYNIC_SINT_COUNT];
  428. };
  429. /* Define timer message payload structure. */
  430. struct hv_timer_message_payload {
  431. __u32 timer_index;
  432. __u32 reserved;
  433. __u64 expiration_time; /* When the timer expired */
  434. __u64 delivery_time; /* When the message was delivered */
  435. };
  436. /* Define virtual processor assist page structure. */
  437. struct hv_vp_assist_page {
  438. __u32 apic_assist;
  439. __u32 reserved;
  440. __u64 vtl_control[2];
  441. __u64 nested_enlightenments_control[2];
  442. __u32 enlighten_vmentry;
  443. __u64 current_nested_vmcs;
  444. };
  445. struct hv_enlightened_vmcs {
  446. u32 revision_id;
  447. u32 abort;
  448. u16 host_es_selector;
  449. u16 host_cs_selector;
  450. u16 host_ss_selector;
  451. u16 host_ds_selector;
  452. u16 host_fs_selector;
  453. u16 host_gs_selector;
  454. u16 host_tr_selector;
  455. u64 host_ia32_pat;
  456. u64 host_ia32_efer;
  457. u64 host_cr0;
  458. u64 host_cr3;
  459. u64 host_cr4;
  460. u64 host_ia32_sysenter_esp;
  461. u64 host_ia32_sysenter_eip;
  462. u64 host_rip;
  463. u32 host_ia32_sysenter_cs;
  464. u32 pin_based_vm_exec_control;
  465. u32 vm_exit_controls;
  466. u32 secondary_vm_exec_control;
  467. u64 io_bitmap_a;
  468. u64 io_bitmap_b;
  469. u64 msr_bitmap;
  470. u16 guest_es_selector;
  471. u16 guest_cs_selector;
  472. u16 guest_ss_selector;
  473. u16 guest_ds_selector;
  474. u16 guest_fs_selector;
  475. u16 guest_gs_selector;
  476. u16 guest_ldtr_selector;
  477. u16 guest_tr_selector;
  478. u32 guest_es_limit;
  479. u32 guest_cs_limit;
  480. u32 guest_ss_limit;
  481. u32 guest_ds_limit;
  482. u32 guest_fs_limit;
  483. u32 guest_gs_limit;
  484. u32 guest_ldtr_limit;
  485. u32 guest_tr_limit;
  486. u32 guest_gdtr_limit;
  487. u32 guest_idtr_limit;
  488. u32 guest_es_ar_bytes;
  489. u32 guest_cs_ar_bytes;
  490. u32 guest_ss_ar_bytes;
  491. u32 guest_ds_ar_bytes;
  492. u32 guest_fs_ar_bytes;
  493. u32 guest_gs_ar_bytes;
  494. u32 guest_ldtr_ar_bytes;
  495. u32 guest_tr_ar_bytes;
  496. u64 guest_es_base;
  497. u64 guest_cs_base;
  498. u64 guest_ss_base;
  499. u64 guest_ds_base;
  500. u64 guest_fs_base;
  501. u64 guest_gs_base;
  502. u64 guest_ldtr_base;
  503. u64 guest_tr_base;
  504. u64 guest_gdtr_base;
  505. u64 guest_idtr_base;
  506. u64 padding64_1[3];
  507. u64 vm_exit_msr_store_addr;
  508. u64 vm_exit_msr_load_addr;
  509. u64 vm_entry_msr_load_addr;
  510. u64 cr3_target_value0;
  511. u64 cr3_target_value1;
  512. u64 cr3_target_value2;
  513. u64 cr3_target_value3;
  514. u32 page_fault_error_code_mask;
  515. u32 page_fault_error_code_match;
  516. u32 cr3_target_count;
  517. u32 vm_exit_msr_store_count;
  518. u32 vm_exit_msr_load_count;
  519. u32 vm_entry_msr_load_count;
  520. u64 tsc_offset;
  521. u64 virtual_apic_page_addr;
  522. u64 vmcs_link_pointer;
  523. u64 guest_ia32_debugctl;
  524. u64 guest_ia32_pat;
  525. u64 guest_ia32_efer;
  526. u64 guest_pdptr0;
  527. u64 guest_pdptr1;
  528. u64 guest_pdptr2;
  529. u64 guest_pdptr3;
  530. u64 guest_pending_dbg_exceptions;
  531. u64 guest_sysenter_esp;
  532. u64 guest_sysenter_eip;
  533. u32 guest_activity_state;
  534. u32 guest_sysenter_cs;
  535. u64 cr0_guest_host_mask;
  536. u64 cr4_guest_host_mask;
  537. u64 cr0_read_shadow;
  538. u64 cr4_read_shadow;
  539. u64 guest_cr0;
  540. u64 guest_cr3;
  541. u64 guest_cr4;
  542. u64 guest_dr7;
  543. u64 host_fs_base;
  544. u64 host_gs_base;
  545. u64 host_tr_base;
  546. u64 host_gdtr_base;
  547. u64 host_idtr_base;
  548. u64 host_rsp;
  549. u64 ept_pointer;
  550. u16 virtual_processor_id;
  551. u16 padding16[3];
  552. u64 padding64_2[5];
  553. u64 guest_physical_address;
  554. u32 vm_instruction_error;
  555. u32 vm_exit_reason;
  556. u32 vm_exit_intr_info;
  557. u32 vm_exit_intr_error_code;
  558. u32 idt_vectoring_info_field;
  559. u32 idt_vectoring_error_code;
  560. u32 vm_exit_instruction_len;
  561. u32 vmx_instruction_info;
  562. u64 exit_qualification;
  563. u64 exit_io_instruction_ecx;
  564. u64 exit_io_instruction_esi;
  565. u64 exit_io_instruction_edi;
  566. u64 exit_io_instruction_eip;
  567. u64 guest_linear_address;
  568. u64 guest_rsp;
  569. u64 guest_rflags;
  570. u32 guest_interruptibility_info;
  571. u32 cpu_based_vm_exec_control;
  572. u32 exception_bitmap;
  573. u32 vm_entry_controls;
  574. u32 vm_entry_intr_info_field;
  575. u32 vm_entry_exception_error_code;
  576. u32 vm_entry_instruction_len;
  577. u32 tpr_threshold;
  578. u64 guest_rip;
  579. u32 hv_clean_fields;
  580. u32 hv_padding_32;
  581. u32 hv_synthetic_controls;
  582. struct {
  583. u32 nested_flush_hypercall:1;
  584. u32 msr_bitmap:1;
  585. u32 reserved:30;
  586. } hv_enlightenments_control;
  587. u32 hv_vp_id;
  588. u64 hv_vm_id;
  589. u64 partition_assist_page;
  590. u64 padding64_4[4];
  591. u64 guest_bndcfgs;
  592. u64 padding64_5[7];
  593. u64 xss_exit_bitmap;
  594. u64 padding64_6[7];
  595. };
  596. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE 0
  597. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_IO_BITMAP BIT(0)
  598. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_MSR_BITMAP BIT(1)
  599. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP2 BIT(2)
  600. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP1 BIT(3)
  601. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_PROC BIT(4)
  602. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_EVENT BIT(5)
  603. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_ENTRY BIT(6)
  604. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_EXCPN BIT(7)
  605. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_CRDR BIT(8)
  606. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_XLAT BIT(9)
  607. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_BASIC BIT(10)
  608. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1 BIT(11)
  609. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2 BIT(12)
  610. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_POINTER BIT(13)
  611. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1 BIT(14)
  612. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_ENLIGHTENMENTSCONTROL BIT(15)
  613. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL 0xFFFF
  614. #define HV_STIMER_ENABLE (1ULL << 0)
  615. #define HV_STIMER_PERIODIC (1ULL << 1)
  616. #define HV_STIMER_LAZY (1ULL << 2)
  617. #define HV_STIMER_AUTOENABLE (1ULL << 3)
  618. #define HV_STIMER_SINT(config) (__u8)(((config) >> 16) & 0x0F)
  619. struct hv_vpset {
  620. u64 format;
  621. u64 valid_bank_mask;
  622. u64 bank_contents[];
  623. };
  624. /* HvCallSendSyntheticClusterIpi hypercall */
  625. struct hv_send_ipi {
  626. u32 vector;
  627. u32 reserved;
  628. u64 cpu_mask;
  629. };
  630. /* HvCallSendSyntheticClusterIpiEx hypercall */
  631. struct hv_send_ipi_ex {
  632. u32 vector;
  633. u32 reserved;
  634. struct hv_vpset vp_set;
  635. };
  636. /* HvFlushGuestPhysicalAddressSpace hypercalls */
  637. struct hv_guest_mapping_flush {
  638. u64 address_space;
  639. u64 flags;
  640. };
  641. /* HvFlushVirtualAddressSpace, HvFlushVirtualAddressList hypercalls */
  642. struct hv_tlb_flush {
  643. u64 address_space;
  644. u64 flags;
  645. u64 processor_mask;
  646. u64 gva_list[];
  647. };
  648. /* HvFlushVirtualAddressSpaceEx, HvFlushVirtualAddressListEx hypercalls */
  649. struct hv_tlb_flush_ex {
  650. u64 address_space;
  651. u64 flags;
  652. struct hv_vpset hv_vp_set;
  653. u64 gva_list[];
  654. };
  655. #endif