hvgdk.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Type definitions for the Microsoft Hypervisor.
  4. */
  5. #ifndef _HV_HVGDK_H
  6. #define _HV_HVGDK_H
  7. #include "hvgdk_mini.h"
  8. #include "hvgdk_ext.h"
  9. /*
  10. * The guest OS needs to register the guest ID with the hypervisor.
  11. * The guest ID is a 64 bit entity and the structure of this ID is
  12. * specified in the Hyper-V TLFS specification.
  13. *
  14. * While the current guideline does not specify how Linux guest ID(s)
  15. * need to be generated, our plan is to publish the guidelines for
  16. * Linux and other guest operating systems that currently are hosted
  17. * on Hyper-V. The implementation here conforms to this yet
  18. * unpublished guidelines.
  19. *
  20. * Bit(s)
  21. * 63 - Indicates if the OS is Open Source or not; 1 is Open Source
  22. * 62:56 - Os Type; Linux is 0x100
  23. * 55:48 - Distro specific identification
  24. * 47:16 - Linux kernel version number
  25. * 15:0 - Distro specific identification
  26. */
  27. #define HV_LINUX_VENDOR_ID 0x8100
  28. /* HV_VMX_ENLIGHTENED_VMCS */
  29. struct hv_enlightened_vmcs {
  30. u32 revision_id;
  31. u32 abort;
  32. u16 host_es_selector;
  33. u16 host_cs_selector;
  34. u16 host_ss_selector;
  35. u16 host_ds_selector;
  36. u16 host_fs_selector;
  37. u16 host_gs_selector;
  38. u16 host_tr_selector;
  39. u16 padding16_1;
  40. u64 host_ia32_pat;
  41. u64 host_ia32_efer;
  42. u64 host_cr0;
  43. u64 host_cr3;
  44. u64 host_cr4;
  45. u64 host_ia32_sysenter_esp;
  46. u64 host_ia32_sysenter_eip;
  47. u64 host_rip;
  48. u32 host_ia32_sysenter_cs;
  49. u32 pin_based_vm_exec_control;
  50. u32 vm_exit_controls;
  51. u32 secondary_vm_exec_control;
  52. u64 io_bitmap_a;
  53. u64 io_bitmap_b;
  54. u64 msr_bitmap;
  55. u16 guest_es_selector;
  56. u16 guest_cs_selector;
  57. u16 guest_ss_selector;
  58. u16 guest_ds_selector;
  59. u16 guest_fs_selector;
  60. u16 guest_gs_selector;
  61. u16 guest_ldtr_selector;
  62. u16 guest_tr_selector;
  63. u32 guest_es_limit;
  64. u32 guest_cs_limit;
  65. u32 guest_ss_limit;
  66. u32 guest_ds_limit;
  67. u32 guest_fs_limit;
  68. u32 guest_gs_limit;
  69. u32 guest_ldtr_limit;
  70. u32 guest_tr_limit;
  71. u32 guest_gdtr_limit;
  72. u32 guest_idtr_limit;
  73. u32 guest_es_ar_bytes;
  74. u32 guest_cs_ar_bytes;
  75. u32 guest_ss_ar_bytes;
  76. u32 guest_ds_ar_bytes;
  77. u32 guest_fs_ar_bytes;
  78. u32 guest_gs_ar_bytes;
  79. u32 guest_ldtr_ar_bytes;
  80. u32 guest_tr_ar_bytes;
  81. u64 guest_es_base;
  82. u64 guest_cs_base;
  83. u64 guest_ss_base;
  84. u64 guest_ds_base;
  85. u64 guest_fs_base;
  86. u64 guest_gs_base;
  87. u64 guest_ldtr_base;
  88. u64 guest_tr_base;
  89. u64 guest_gdtr_base;
  90. u64 guest_idtr_base;
  91. u64 padding64_1[3];
  92. u64 vm_exit_msr_store_addr;
  93. u64 vm_exit_msr_load_addr;
  94. u64 vm_entry_msr_load_addr;
  95. u64 cr3_target_value0;
  96. u64 cr3_target_value1;
  97. u64 cr3_target_value2;
  98. u64 cr3_target_value3;
  99. u32 page_fault_error_code_mask;
  100. u32 page_fault_error_code_match;
  101. u32 cr3_target_count;
  102. u32 vm_exit_msr_store_count;
  103. u32 vm_exit_msr_load_count;
  104. u32 vm_entry_msr_load_count;
  105. u64 tsc_offset;
  106. u64 virtual_apic_page_addr;
  107. u64 vmcs_link_pointer;
  108. u64 guest_ia32_debugctl;
  109. u64 guest_ia32_pat;
  110. u64 guest_ia32_efer;
  111. u64 guest_pdptr0;
  112. u64 guest_pdptr1;
  113. u64 guest_pdptr2;
  114. u64 guest_pdptr3;
  115. u64 guest_pending_dbg_exceptions;
  116. u64 guest_sysenter_esp;
  117. u64 guest_sysenter_eip;
  118. u32 guest_activity_state;
  119. u32 guest_sysenter_cs;
  120. u64 cr0_guest_host_mask;
  121. u64 cr4_guest_host_mask;
  122. u64 cr0_read_shadow;
  123. u64 cr4_read_shadow;
  124. u64 guest_cr0;
  125. u64 guest_cr3;
  126. u64 guest_cr4;
  127. u64 guest_dr7;
  128. u64 host_fs_base;
  129. u64 host_gs_base;
  130. u64 host_tr_base;
  131. u64 host_gdtr_base;
  132. u64 host_idtr_base;
  133. u64 host_rsp;
  134. u64 ept_pointer;
  135. u16 virtual_processor_id;
  136. u16 padding16_2[3];
  137. u64 padding64_2[5];
  138. u64 guest_physical_address;
  139. u32 vm_instruction_error;
  140. u32 vm_exit_reason;
  141. u32 vm_exit_intr_info;
  142. u32 vm_exit_intr_error_code;
  143. u32 idt_vectoring_info_field;
  144. u32 idt_vectoring_error_code;
  145. u32 vm_exit_instruction_len;
  146. u32 vmx_instruction_info;
  147. u64 exit_qualification;
  148. u64 exit_io_instruction_ecx;
  149. u64 exit_io_instruction_esi;
  150. u64 exit_io_instruction_edi;
  151. u64 exit_io_instruction_eip;
  152. u64 guest_linear_address;
  153. u64 guest_rsp;
  154. u64 guest_rflags;
  155. u32 guest_interruptibility_info;
  156. u32 cpu_based_vm_exec_control;
  157. u32 exception_bitmap;
  158. u32 vm_entry_controls;
  159. u32 vm_entry_intr_info_field;
  160. u32 vm_entry_exception_error_code;
  161. u32 vm_entry_instruction_len;
  162. u32 tpr_threshold;
  163. u64 guest_rip;
  164. u32 hv_clean_fields;
  165. u32 padding32_1;
  166. u32 hv_synthetic_controls;
  167. struct {
  168. u32 nested_flush_hypercall:1;
  169. u32 msr_bitmap:1;
  170. u32 reserved:30;
  171. } __packed hv_enlightenments_control;
  172. u32 hv_vp_id;
  173. u32 padding32_2;
  174. u64 hv_vm_id;
  175. u64 partition_assist_page;
  176. u64 padding64_4[4];
  177. u64 guest_bndcfgs;
  178. u64 guest_ia32_perf_global_ctrl;
  179. u64 guest_ia32_s_cet;
  180. u64 guest_ssp;
  181. u64 guest_ia32_int_ssp_table_addr;
  182. u64 guest_ia32_lbr_ctl;
  183. u64 padding64_5[2];
  184. u64 xss_exit_bitmap;
  185. u64 encls_exiting_bitmap;
  186. u64 host_ia32_perf_global_ctrl;
  187. u64 tsc_multiplier;
  188. u64 host_ia32_s_cet;
  189. u64 host_ssp;
  190. u64 host_ia32_int_ssp_table_addr;
  191. u64 padding64_6;
  192. } __packed;
  193. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE 0
  194. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_IO_BITMAP BIT(0)
  195. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_MSR_BITMAP BIT(1)
  196. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP2 BIT(2)
  197. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP1 BIT(3)
  198. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_PROC BIT(4)
  199. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_EVENT BIT(5)
  200. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_ENTRY BIT(6)
  201. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_EXCPN BIT(7)
  202. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_CRDR BIT(8)
  203. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_XLAT BIT(9)
  204. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_BASIC BIT(10)
  205. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1 BIT(11)
  206. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP2 BIT(12)
  207. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_POINTER BIT(13)
  208. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1 BIT(14)
  209. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_ENLIGHTENMENTSCONTROL BIT(15)
  210. #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_ALL 0xFFFF
  211. /*
  212. * Note, Hyper-V isn't actually stealing bit 28 from Intel, just abusing it by
  213. * pairing it with architecturally impossible exit reasons. Bit 28 is set only
  214. * on SMI exits to a SMI transfer monitor (STM) and if and only if a MTF VM-Exit
  215. * is pending. I.e. it will never be set by hardware for non-SMI exits (there
  216. * are only three), nor will it ever be set unless the VMM is an STM.
  217. */
  218. #define HV_VMX_SYNTHETIC_EXIT_REASON_TRAP_AFTER_FLUSH 0x10000031
  219. /*
  220. * Hyper-V uses the software reserved 32 bytes in VMCB control area to expose
  221. * SVM enlightenments to guests. This is documented in the TLFS doc.
  222. * Note on naming: SVM_NESTED_ENLIGHTENED_VMCB_FIELDS
  223. */
  224. struct hv_vmcb_enlightenments {
  225. struct __packed hv_enlightenments_control {
  226. u32 nested_flush_hypercall : 1;
  227. u32 msr_bitmap : 1;
  228. u32 enlightened_npt_tlb: 1;
  229. u32 reserved : 29;
  230. } __packed hv_enlightenments_control;
  231. u32 hv_vp_id;
  232. u64 hv_vm_id;
  233. u64 partition_assist_page;
  234. u64 reserved;
  235. } __packed;
  236. /*
  237. * Hyper-V uses the software reserved clean bit in VMCB.
  238. */
  239. #define HV_VMCB_NESTED_ENLIGHTENMENTS 31
  240. /* Synthetic VM-Exit */
  241. #define HV_SVM_EXITCODE_ENL 0xf0000000ull
  242. #define HV_SVM_ENL_EXITCODE_TRAP_AFTER_FLUSH (1)
  243. /* VM_PARTITION_ASSIST_PAGE */
  244. struct hv_partition_assist_pg {
  245. u32 tlb_lock_count;
  246. };
  247. /* Define connection identifier type. */
  248. union hv_connection_id {
  249. u32 asu32;
  250. struct {
  251. u32 id : 24;
  252. u32 reserved : 8;
  253. } __packed u;
  254. };
  255. struct hv_input_unmap_gpa_pages {
  256. u64 target_partition_id;
  257. u64 target_gpa_base;
  258. u32 unmap_flags;
  259. u32 padding;
  260. } __packed;
  261. #endif /* #ifndef _HV_HVGDK_H */