hvhdk.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Type definitions for the Microsoft hypervisor.
  4. */
  5. #ifndef _HV_HVHDK_H
  6. #define _HV_HVHDK_H
  7. #include <linux/build_bug.h>
  8. #include "hvhdk_mini.h"
  9. #include "hvgdk.h"
  10. /*
  11. * Hypervisor statistics page format
  12. */
  13. struct hv_stats_page {
  14. u64 data[HV_HYP_PAGE_SIZE / sizeof(u64)];
  15. } __packed;
  16. /* Bits for dirty mask of hv_vp_register_page */
  17. #define HV_X64_REGISTER_CLASS_GENERAL 0
  18. #define HV_X64_REGISTER_CLASS_IP 1
  19. #define HV_X64_REGISTER_CLASS_XMM 2
  20. #define HV_X64_REGISTER_CLASS_SEGMENT 3
  21. #define HV_X64_REGISTER_CLASS_FLAGS 4
  22. #define HV_VP_REGISTER_PAGE_VERSION_1 1u
  23. #define HV_VP_REGISTER_PAGE_MAX_VECTOR_COUNT 7
  24. union hv_vp_register_page_interrupt_vectors {
  25. u64 as_uint64;
  26. struct {
  27. u8 vector_count;
  28. u8 vector[HV_VP_REGISTER_PAGE_MAX_VECTOR_COUNT];
  29. } __packed;
  30. };
  31. struct hv_vp_register_page {
  32. u16 version;
  33. u8 isvalid;
  34. u8 rsvdz;
  35. u32 dirty;
  36. #if IS_ENABLED(CONFIG_X86)
  37. union {
  38. struct {
  39. /* General purpose registers
  40. * (HV_X64_REGISTER_CLASS_GENERAL)
  41. */
  42. union {
  43. struct {
  44. u64 rax;
  45. u64 rcx;
  46. u64 rdx;
  47. u64 rbx;
  48. u64 rsp;
  49. u64 rbp;
  50. u64 rsi;
  51. u64 rdi;
  52. u64 r8;
  53. u64 r9;
  54. u64 r10;
  55. u64 r11;
  56. u64 r12;
  57. u64 r13;
  58. u64 r14;
  59. u64 r15;
  60. } __packed;
  61. u64 gp_registers[16];
  62. };
  63. /* Instruction pointer (HV_X64_REGISTER_CLASS_IP) */
  64. u64 rip;
  65. /* Flags (HV_X64_REGISTER_CLASS_FLAGS) */
  66. u64 rflags;
  67. } __packed;
  68. u64 registers[18];
  69. };
  70. /* Volatile XMM registers (HV_X64_REGISTER_CLASS_XMM) */
  71. union {
  72. struct {
  73. struct hv_u128 xmm0;
  74. struct hv_u128 xmm1;
  75. struct hv_u128 xmm2;
  76. struct hv_u128 xmm3;
  77. struct hv_u128 xmm4;
  78. struct hv_u128 xmm5;
  79. } __packed;
  80. struct hv_u128 xmm_registers[6];
  81. };
  82. /* Segment registers (HV_X64_REGISTER_CLASS_SEGMENT) */
  83. union {
  84. struct {
  85. struct hv_x64_segment_register es;
  86. struct hv_x64_segment_register cs;
  87. struct hv_x64_segment_register ss;
  88. struct hv_x64_segment_register ds;
  89. struct hv_x64_segment_register fs;
  90. struct hv_x64_segment_register gs;
  91. } __packed;
  92. struct hv_x64_segment_register segment_registers[6];
  93. };
  94. /* Misc. control registers (cannot be set via this interface) */
  95. u64 cr0;
  96. u64 cr3;
  97. u64 cr4;
  98. u64 cr8;
  99. u64 efer;
  100. u64 dr7;
  101. union hv_x64_pending_interruption_register pending_interruption;
  102. union hv_x64_interrupt_state_register interrupt_state;
  103. u64 instruction_emulation_hints;
  104. u64 xfem;
  105. /*
  106. * Fields from this point are not included in the register page save chunk.
  107. * The reserved field is intended to maintain alignment for unsaved fields.
  108. */
  109. u8 reserved1[0x100];
  110. /*
  111. * Interrupts injected as part of HvCallDispatchVp.
  112. */
  113. union hv_vp_register_page_interrupt_vectors interrupt_vectors;
  114. #elif IS_ENABLED(CONFIG_ARM64)
  115. /* Not yet supported in ARM */
  116. #endif
  117. } __packed;
  118. #define HV_PARTITION_PROCESSOR_FEATURES_BANKS 2
  119. union hv_partition_processor_features {
  120. u64 as_uint64[HV_PARTITION_PROCESSOR_FEATURES_BANKS];
  121. struct {
  122. u64 sse3_support : 1;
  123. u64 lahf_sahf_support : 1;
  124. u64 ssse3_support : 1;
  125. u64 sse4_1_support : 1;
  126. u64 sse4_2_support : 1;
  127. u64 sse4a_support : 1;
  128. u64 xop_support : 1;
  129. u64 pop_cnt_support : 1;
  130. u64 cmpxchg16b_support : 1;
  131. u64 altmovcr8_support : 1;
  132. u64 lzcnt_support : 1;
  133. u64 mis_align_sse_support : 1;
  134. u64 mmx_ext_support : 1;
  135. u64 amd3dnow_support : 1;
  136. u64 extended_amd3dnow_support : 1;
  137. u64 page_1gb_support : 1;
  138. u64 aes_support : 1;
  139. u64 pclmulqdq_support : 1;
  140. u64 pcid_support : 1;
  141. u64 fma4_support : 1;
  142. u64 f16c_support : 1;
  143. u64 rd_rand_support : 1;
  144. u64 rd_wr_fs_gs_support : 1;
  145. u64 smep_support : 1;
  146. u64 enhanced_fast_string_support : 1;
  147. u64 bmi1_support : 1;
  148. u64 bmi2_support : 1;
  149. u64 hle_support_deprecated : 1;
  150. u64 rtm_support_deprecated : 1;
  151. u64 movbe_support : 1;
  152. u64 npiep1_support : 1;
  153. u64 dep_x87_fpu_save_support : 1;
  154. u64 rd_seed_support : 1;
  155. u64 adx_support : 1;
  156. u64 intel_prefetch_support : 1;
  157. u64 smap_support : 1;
  158. u64 hle_support : 1;
  159. u64 rtm_support : 1;
  160. u64 rdtscp_support : 1;
  161. u64 clflushopt_support : 1;
  162. u64 clwb_support : 1;
  163. u64 sha_support : 1;
  164. u64 x87_pointers_saved_support : 1;
  165. u64 invpcid_support : 1;
  166. u64 ibrs_support : 1;
  167. u64 stibp_support : 1;
  168. u64 ibpb_support: 1;
  169. u64 unrestricted_guest_support : 1;
  170. u64 mdd_support : 1;
  171. u64 fast_short_rep_mov_support : 1;
  172. u64 l1dcache_flush_support : 1;
  173. u64 rdcl_no_support : 1;
  174. u64 ibrs_all_support : 1;
  175. u64 skip_l1df_support : 1;
  176. u64 ssb_no_support : 1;
  177. u64 rsb_a_no_support : 1;
  178. u64 virt_spec_ctrl_support : 1;
  179. u64 rd_pid_support : 1;
  180. u64 umip_support : 1;
  181. u64 mbs_no_support : 1;
  182. u64 mb_clear_support : 1;
  183. u64 taa_no_support : 1;
  184. u64 tsx_ctrl_support : 1;
  185. /*
  186. * N.B. The final processor feature bit in bank 0 is reserved to
  187. * simplify potential downlevel backports.
  188. */
  189. u64 reserved_bank0 : 1;
  190. /* N.B. Begin bank 1 processor features. */
  191. u64 acount_mcount_support : 1;
  192. u64 tsc_invariant_support : 1;
  193. u64 cl_zero_support : 1;
  194. u64 rdpru_support : 1;
  195. u64 la57_support : 1;
  196. u64 mbec_support : 1;
  197. u64 nested_virt_support : 1;
  198. u64 psfd_support : 1;
  199. u64 cet_ss_support : 1;
  200. u64 cet_ibt_support : 1;
  201. u64 vmx_exception_inject_support : 1;
  202. u64 enqcmd_support : 1;
  203. u64 umwait_tpause_support : 1;
  204. u64 movdiri_support : 1;
  205. u64 movdir64b_support : 1;
  206. u64 cldemote_support : 1;
  207. u64 serialize_support : 1;
  208. u64 tsc_deadline_tmr_support : 1;
  209. u64 tsc_adjust_support : 1;
  210. u64 fzlrep_movsb : 1;
  211. u64 fsrep_stosb : 1;
  212. u64 fsrep_cmpsb : 1;
  213. u64 reserved_bank1 : 42;
  214. } __packed;
  215. };
  216. union hv_partition_processor_xsave_features {
  217. struct {
  218. u64 xsave_support : 1;
  219. u64 xsaveopt_support : 1;
  220. u64 avx_support : 1;
  221. u64 reserved1 : 61;
  222. } __packed;
  223. u64 as_uint64;
  224. };
  225. struct hv_partition_creation_properties {
  226. union hv_partition_processor_features disabled_processor_features;
  227. union hv_partition_processor_xsave_features
  228. disabled_processor_xsave_features;
  229. } __packed;
  230. #define HV_PARTITION_SYNTHETIC_PROCESSOR_FEATURES_BANKS 1
  231. union hv_partition_synthetic_processor_features {
  232. u64 as_uint64[HV_PARTITION_SYNTHETIC_PROCESSOR_FEATURES_BANKS];
  233. struct {
  234. u64 hypervisor_present : 1;
  235. /* Support for HV#1: (CPUID leaves 0x40000000 - 0x40000006)*/
  236. u64 hv1 : 1;
  237. u64 access_vp_run_time_reg : 1; /* HV_X64_MSR_VP_RUNTIME */
  238. u64 access_partition_reference_counter : 1; /* HV_X64_MSR_TIME_REF_COUNT */
  239. u64 access_synic_regs : 1; /* SINT-related registers */
  240. /*
  241. * Access to HV_X64_MSR_STIMER0_CONFIG through
  242. * HV_X64_MSR_STIMER3_COUNT.
  243. */
  244. u64 access_synthetic_timer_regs : 1;
  245. u64 access_intr_ctrl_regs : 1; /* APIC MSRs and VP assist page*/
  246. /* HV_X64_MSR_GUEST_OS_ID and HV_X64_MSR_HYPERCALL */
  247. u64 access_hypercall_regs : 1;
  248. u64 access_vp_index : 1;
  249. u64 access_partition_reference_tsc : 1;
  250. u64 access_guest_idle_reg : 1;
  251. u64 access_frequency_regs : 1;
  252. u64 reserved_z12 : 1;
  253. u64 reserved_z13 : 1;
  254. u64 reserved_z14 : 1;
  255. u64 enable_extended_gva_ranges_for_flush_virtual_address_list : 1;
  256. u64 reserved_z16 : 1;
  257. u64 reserved_z17 : 1;
  258. /* Use fast hypercall output. Corresponds to privilege. */
  259. u64 fast_hypercall_output : 1;
  260. u64 reserved_z19 : 1;
  261. u64 start_virtual_processor : 1; /* Can start VPs */
  262. u64 reserved_z21 : 1;
  263. /* Synthetic timers in direct mode. */
  264. u64 direct_synthetic_timers : 1;
  265. u64 reserved_z23 : 1;
  266. u64 extended_processor_masks : 1;
  267. /* Enable various hypercalls */
  268. u64 tb_flush_hypercalls : 1;
  269. u64 synthetic_cluster_ipi : 1;
  270. u64 notify_long_spin_wait : 1;
  271. u64 query_numa_distance : 1;
  272. u64 signal_events : 1;
  273. u64 retarget_device_interrupt : 1;
  274. u64 restore_time : 1;
  275. /* EnlightenedVmcs nested enlightenment is supported. */
  276. u64 enlightened_vmcs : 1;
  277. u64 reserved : 31;
  278. } __packed;
  279. };
  280. #define HV_MAKE_COMPATIBILITY_VERSION(major_, minor_) \
  281. ((u32)((major_) << 8 | (minor_)))
  282. #define HV_COMPATIBILITY_21_H2 HV_MAKE_COMPATIBILITY_VERSION(0X6, 0X9)
  283. union hv_partition_isolation_properties {
  284. u64 as_uint64;
  285. struct {
  286. u64 isolation_type: 5;
  287. u64 isolation_host_type : 2;
  288. u64 rsvd_z: 5;
  289. u64 shared_gpa_boundary_page_number: 52;
  290. } __packed;
  291. };
  292. /*
  293. * Various isolation types supported by MSHV.
  294. */
  295. #define HV_PARTITION_ISOLATION_TYPE_NONE 0
  296. #define HV_PARTITION_ISOLATION_TYPE_SNP 2
  297. #define HV_PARTITION_ISOLATION_TYPE_TDX 3
  298. /*
  299. * Various host isolation types supported by MSHV.
  300. */
  301. #define HV_PARTITION_ISOLATION_HOST_TYPE_NONE 0x0
  302. #define HV_PARTITION_ISOLATION_HOST_TYPE_HARDWARE 0x1
  303. #define HV_PARTITION_ISOLATION_HOST_TYPE_RESERVED 0x2
  304. /* Note: Exo partition is enabled by default */
  305. #define HV_PARTITION_CREATION_FLAG_SMT_ENABLED_GUEST BIT(0)
  306. #define HV_PARTITION_CREATION_FLAG_NESTED_VIRTUALIZATION_CAPABLE BIT(1)
  307. #define HV_PARTITION_CREATION_FLAG_GPA_SUPER_PAGES_ENABLED BIT(4)
  308. #define HV_PARTITION_CREATION_FLAG_EXO_PARTITION BIT(8)
  309. #define HV_PARTITION_CREATION_FLAG_LAPIC_ENABLED BIT(13)
  310. #define HV_PARTITION_CREATION_FLAG_INTERCEPT_MESSAGE_PAGE_ENABLED BIT(19)
  311. #define HV_PARTITION_CREATION_FLAG_X2APIC_CAPABLE BIT(22)
  312. struct hv_input_create_partition {
  313. u64 flags;
  314. struct hv_proximity_domain_info proximity_domain_info;
  315. u32 compatibility_version;
  316. u32 padding;
  317. struct hv_partition_creation_properties partition_creation_properties;
  318. union hv_partition_isolation_properties isolation_properties;
  319. } __packed;
  320. struct hv_output_create_partition {
  321. u64 partition_id;
  322. } __packed;
  323. struct hv_input_initialize_partition {
  324. u64 partition_id;
  325. } __packed;
  326. struct hv_input_finalize_partition {
  327. u64 partition_id;
  328. } __packed;
  329. struct hv_input_delete_partition {
  330. u64 partition_id;
  331. } __packed;
  332. struct hv_input_get_partition_property {
  333. u64 partition_id;
  334. u32 property_code; /* enum hv_partition_property_code */
  335. u32 padding;
  336. } __packed;
  337. struct hv_output_get_partition_property {
  338. u64 property_value;
  339. } __packed;
  340. struct hv_input_set_partition_property {
  341. u64 partition_id;
  342. u32 property_code; /* enum hv_partition_property_code */
  343. u32 padding;
  344. u64 property_value;
  345. } __packed;
  346. union hv_partition_property_arg {
  347. u64 as_uint64;
  348. struct {
  349. union {
  350. u32 arg;
  351. u32 vp_index;
  352. };
  353. u16 reserved0;
  354. u8 reserved1;
  355. u8 object_type;
  356. } __packed;
  357. };
  358. struct hv_input_get_partition_property_ex {
  359. u64 partition_id;
  360. u32 property_code; /* enum hv_partition_property_code */
  361. u32 padding;
  362. union {
  363. union hv_partition_property_arg arg_data;
  364. u64 arg;
  365. };
  366. } __packed;
  367. /*
  368. * NOTE: Should use hv_input_set_partition_property_ex_header to compute this
  369. * size, but hv_input_get_partition_property_ex is identical so it suffices
  370. */
  371. #define HV_PARTITION_PROPERTY_EX_MAX_VAR_SIZE \
  372. (HV_HYP_PAGE_SIZE - sizeof(struct hv_input_get_partition_property_ex))
  373. union hv_partition_property_ex {
  374. u8 buffer[HV_PARTITION_PROPERTY_EX_MAX_VAR_SIZE];
  375. struct hv_partition_property_vmm_capabilities vmm_capabilities;
  376. /* More fields to be filled in when needed */
  377. };
  378. struct hv_output_get_partition_property_ex {
  379. union hv_partition_property_ex property_value;
  380. } __packed;
  381. enum hv_vp_state_page_type {
  382. HV_VP_STATE_PAGE_REGISTERS = 0,
  383. HV_VP_STATE_PAGE_INTERCEPT_MESSAGE = 1,
  384. HV_VP_STATE_PAGE_GHCB = 2,
  385. HV_VP_STATE_PAGE_COUNT
  386. };
  387. struct hv_input_map_vp_state_page {
  388. u64 partition_id;
  389. u32 vp_index;
  390. u16 type; /* enum hv_vp_state_page_type */
  391. union hv_input_vtl input_vtl;
  392. union {
  393. u8 as_uint8;
  394. struct {
  395. u8 map_location_provided : 1;
  396. u8 reserved : 7;
  397. };
  398. } flags;
  399. u64 requested_map_location;
  400. } __packed;
  401. struct hv_output_map_vp_state_page {
  402. u64 map_location; /* GPA page number */
  403. } __packed;
  404. struct hv_input_unmap_vp_state_page {
  405. u64 partition_id;
  406. u32 vp_index;
  407. u16 type; /* enum hv_vp_state_page_type */
  408. union hv_input_vtl input_vtl;
  409. u8 reserved0;
  410. } __packed;
  411. struct hv_x64_apic_eoi_message {
  412. u32 vp_index;
  413. u32 interrupt_vector;
  414. } __packed;
  415. struct hv_opaque_intercept_message {
  416. u32 vp_index;
  417. } __packed;
  418. enum hv_port_type {
  419. HV_PORT_TYPE_MESSAGE = 1,
  420. HV_PORT_TYPE_EVENT = 2,
  421. HV_PORT_TYPE_MONITOR = 3,
  422. HV_PORT_TYPE_DOORBELL = 4 /* Root Partition only */
  423. };
  424. struct hv_port_info {
  425. u32 port_type; /* enum hv_port_type */
  426. u32 padding;
  427. union {
  428. struct {
  429. u32 target_sint;
  430. u32 target_vp;
  431. u64 rsvdz;
  432. } message_port_info;
  433. struct {
  434. u32 target_sint;
  435. u32 target_vp;
  436. u16 base_flag_number;
  437. u16 flag_count;
  438. u32 rsvdz;
  439. } event_port_info;
  440. struct {
  441. u64 monitor_address;
  442. u64 rsvdz;
  443. } monitor_port_info;
  444. struct {
  445. u32 target_sint;
  446. u32 target_vp;
  447. u64 rsvdz;
  448. } doorbell_port_info;
  449. };
  450. } __packed;
  451. struct hv_connection_info {
  452. u32 port_type;
  453. u32 padding;
  454. union {
  455. struct {
  456. u64 rsvdz;
  457. } message_connection_info;
  458. struct {
  459. u64 rsvdz;
  460. } event_connection_info;
  461. struct {
  462. u64 monitor_address;
  463. } monitor_connection_info;
  464. struct {
  465. u64 gpa;
  466. u64 trigger_value;
  467. u64 flags;
  468. } doorbell_connection_info;
  469. };
  470. } __packed;
  471. /* Define synthetic interrupt controller flag constants. */
  472. #define HV_EVENT_FLAGS_COUNT (256 * 8)
  473. #define HV_EVENT_FLAGS_BYTE_COUNT (256)
  474. #define HV_EVENT_FLAGS32_COUNT (256 / sizeof(u32))
  475. /* linux side we create long version of flags to use long bit ops on flags */
  476. #define HV_EVENT_FLAGS_UL_COUNT (256 / sizeof(ulong))
  477. /* Define the synthetic interrupt controller event flags format. */
  478. union hv_synic_event_flags {
  479. unsigned char flags8[HV_EVENT_FLAGS_BYTE_COUNT];
  480. u32 flags32[HV_EVENT_FLAGS32_COUNT];
  481. ulong flags[HV_EVENT_FLAGS_UL_COUNT]; /* linux only */
  482. };
  483. struct hv_synic_event_flags_page {
  484. volatile union hv_synic_event_flags event_flags[HV_SYNIC_SINT_COUNT];
  485. };
  486. #define HV_SYNIC_EVENT_RING_MESSAGE_COUNT 63
  487. struct hv_synic_event_ring {
  488. u8 signal_masked;
  489. u8 ring_full;
  490. u16 reserved_z;
  491. u32 data[HV_SYNIC_EVENT_RING_MESSAGE_COUNT];
  492. } __packed;
  493. struct hv_synic_event_ring_page {
  494. struct hv_synic_event_ring sint_event_ring[HV_SYNIC_SINT_COUNT];
  495. };
  496. /* Define SynIC control register. */
  497. union hv_synic_scontrol {
  498. u64 as_uint64;
  499. struct {
  500. u64 enable : 1;
  501. u64 reserved : 63;
  502. } __packed;
  503. };
  504. /* Define the format of the SIEFP register */
  505. union hv_synic_siefp {
  506. u64 as_uint64;
  507. struct {
  508. u64 siefp_enabled : 1;
  509. u64 preserved : 11;
  510. u64 base_siefp_gpa : 52;
  511. } __packed;
  512. };
  513. union hv_synic_sirbp {
  514. u64 as_uint64;
  515. struct {
  516. u64 sirbp_enabled : 1;
  517. u64 preserved : 11;
  518. u64 base_sirbp_gpa : 52;
  519. } __packed;
  520. };
  521. union hv_interrupt_control {
  522. u64 as_uint64;
  523. struct {
  524. u32 interrupt_type; /* enum hv_interrupt_type */
  525. #if IS_ENABLED(CONFIG_X86)
  526. u32 level_triggered : 1;
  527. u32 logical_dest_mode : 1;
  528. u32 rsvd : 30;
  529. #elif IS_ENABLED(CONFIG_ARM64)
  530. u32 rsvd1 : 2;
  531. u32 asserted : 1;
  532. u32 rsvd2 : 29;
  533. #endif
  534. } __packed;
  535. };
  536. struct hv_stimer_state {
  537. struct {
  538. u32 undelivered_msg_pending : 1;
  539. u32 reserved : 31;
  540. } __packed flags;
  541. u32 resvd;
  542. u64 config;
  543. u64 count;
  544. u64 adjustment;
  545. u64 undelivered_exp_time;
  546. } __packed;
  547. struct hv_synthetic_timers_state {
  548. struct hv_stimer_state timers[HV_SYNIC_STIMER_COUNT];
  549. u64 reserved[5];
  550. } __packed;
  551. struct hv_async_completion_message_payload {
  552. u64 partition_id;
  553. u32 status;
  554. u32 completion_count;
  555. u64 sub_status;
  556. } __packed;
  557. union hv_input_delete_vp {
  558. u64 as_uint64[2];
  559. struct {
  560. u64 partition_id;
  561. u32 vp_index;
  562. u8 reserved[4];
  563. } __packed;
  564. } __packed;
  565. struct hv_input_assert_virtual_interrupt {
  566. u64 partition_id;
  567. union hv_interrupt_control control;
  568. u64 dest_addr; /* cpu's apic id */
  569. u32 vector;
  570. u8 target_vtl;
  571. u8 rsvd_z0;
  572. u16 rsvd_z1;
  573. } __packed;
  574. struct hv_input_create_port {
  575. u64 port_partition_id;
  576. union hv_port_id port_id;
  577. u8 port_vtl;
  578. u8 min_connection_vtl;
  579. u16 padding;
  580. u64 connection_partition_id;
  581. struct hv_port_info port_info;
  582. struct hv_proximity_domain_info proximity_domain_info;
  583. } __packed;
  584. union hv_input_delete_port {
  585. u64 as_uint64[2];
  586. struct {
  587. u64 port_partition_id;
  588. union hv_port_id port_id;
  589. u32 reserved;
  590. };
  591. } __packed;
  592. struct hv_input_connect_port {
  593. u64 connection_partition_id;
  594. union hv_connection_id connection_id;
  595. u8 connection_vtl;
  596. u8 rsvdz0;
  597. u16 rsvdz1;
  598. u64 port_partition_id;
  599. union hv_port_id port_id;
  600. u32 reserved2;
  601. struct hv_connection_info connection_info;
  602. struct hv_proximity_domain_info proximity_domain_info;
  603. } __packed;
  604. union hv_input_disconnect_port {
  605. u64 as_uint64[2];
  606. struct {
  607. u64 connection_partition_id;
  608. union hv_connection_id connection_id;
  609. u32 is_doorbell: 1;
  610. u32 reserved: 31;
  611. } __packed;
  612. } __packed;
  613. union hv_input_notify_port_ring_empty {
  614. u64 as_uint64;
  615. struct {
  616. u32 sint_index;
  617. u32 reserved;
  618. };
  619. } __packed;
  620. struct hv_vp_state_data_xsave {
  621. u64 flags;
  622. union hv_x64_xsave_xfem_register states;
  623. } __packed;
  624. /*
  625. * For getting and setting VP state, there are two options based on the state type:
  626. *
  627. * 1.) Data that is accessed by PFNs in the input hypercall page. This is used
  628. * for state which may not fit into the hypercall pages.
  629. * 2.) Data that is accessed directly in the input\output hypercall pages.
  630. * This is used for state that will always fit into the hypercall pages.
  631. *
  632. * In the future this could be dynamic based on the size if needed.
  633. *
  634. * Note these hypercalls have an 8-byte aligned variable header size as per the tlfs
  635. */
  636. #define HV_GET_SET_VP_STATE_TYPE_PFN BIT(31)
  637. enum hv_get_set_vp_state_type {
  638. /* HvGetSetVpStateLocalInterruptControllerState - APIC/GIC state */
  639. HV_GET_SET_VP_STATE_LAPIC_STATE = 0 | HV_GET_SET_VP_STATE_TYPE_PFN,
  640. HV_GET_SET_VP_STATE_XSAVE = 1 | HV_GET_SET_VP_STATE_TYPE_PFN,
  641. HV_GET_SET_VP_STATE_SIM_PAGE = 2 | HV_GET_SET_VP_STATE_TYPE_PFN,
  642. HV_GET_SET_VP_STATE_SIEF_PAGE = 3 | HV_GET_SET_VP_STATE_TYPE_PFN,
  643. HV_GET_SET_VP_STATE_SYNTHETIC_TIMERS = 4,
  644. };
  645. struct hv_vp_state_data {
  646. u32 type;
  647. u32 rsvd;
  648. struct hv_vp_state_data_xsave xsave;
  649. } __packed;
  650. struct hv_input_get_vp_state {
  651. u64 partition_id;
  652. u32 vp_index;
  653. u8 input_vtl;
  654. u8 rsvd0;
  655. u16 rsvd1;
  656. struct hv_vp_state_data state_data;
  657. u64 output_data_pfns[];
  658. } __packed;
  659. union hv_output_get_vp_state {
  660. struct hv_synthetic_timers_state synthetic_timers_state;
  661. } __packed;
  662. union hv_input_set_vp_state_data {
  663. u64 pfns;
  664. u8 bytes;
  665. } __packed;
  666. struct hv_input_set_vp_state {
  667. u64 partition_id;
  668. u32 vp_index;
  669. u8 input_vtl;
  670. u8 rsvd0;
  671. u16 rsvd1;
  672. struct hv_vp_state_data state_data;
  673. union hv_input_set_vp_state_data data[];
  674. } __packed;
  675. union hv_x64_vp_execution_state {
  676. u16 as_uint16;
  677. struct {
  678. u16 cpl:2;
  679. u16 cr0_pe:1;
  680. u16 cr0_am:1;
  681. u16 efer_lma:1;
  682. u16 debug_active:1;
  683. u16 interruption_pending:1;
  684. u16 vtl:4;
  685. u16 enclave_mode:1;
  686. u16 interrupt_shadow:1;
  687. u16 virtualization_fault_active:1;
  688. u16 reserved:2;
  689. } __packed;
  690. };
  691. struct hv_x64_intercept_message_header {
  692. u32 vp_index;
  693. u8 instruction_length:4;
  694. u8 cr8:4; /* Only set for exo partitions */
  695. u8 intercept_access_type; /* enum hv_intercept_access_type */
  696. union hv_x64_vp_execution_state execution_state;
  697. struct hv_x64_segment_register cs_segment;
  698. u64 rip;
  699. u64 rflags;
  700. } __packed;
  701. union hv_x64_memory_access_info {
  702. u8 as_uint8;
  703. struct {
  704. u8 gva_valid:1;
  705. u8 gva_gpa_valid:1;
  706. u8 hypercall_output_pending:1;
  707. u8 tlb_locked_no_overlay:1;
  708. u8 reserved:4;
  709. } __packed;
  710. };
  711. struct hv_x64_memory_intercept_message {
  712. struct hv_x64_intercept_message_header header;
  713. u32 cache_type; /* enum hv_cache_type */
  714. u8 instruction_byte_count;
  715. union hv_x64_memory_access_info memory_access_info;
  716. u8 tpr_priority;
  717. u8 reserved1;
  718. u64 guest_virtual_address;
  719. u64 guest_physical_address;
  720. u8 instruction_bytes[16];
  721. } __packed;
  722. #if IS_ENABLED(CONFIG_ARM64)
  723. union hv_arm64_vp_execution_state {
  724. u16 as_uint16;
  725. struct {
  726. u16 cpl:2; /* Exception Level (EL) */
  727. u16 debug_active:1;
  728. u16 interruption_pending:1;
  729. u16 vtl:4;
  730. u16 virtualization_fault_active:1;
  731. u16 reserved:7;
  732. } __packed;
  733. };
  734. struct hv_arm64_intercept_message_header {
  735. u32 vp_index;
  736. u8 instruction_length;
  737. u8 intercept_access_type; /* enum hv_intercept_access_type */
  738. union hv_arm64_vp_execution_state execution_state;
  739. u64 pc;
  740. u64 cpsr;
  741. } __packed;
  742. union hv_arm64_memory_access_info {
  743. u8 as_uint8;
  744. struct {
  745. u8 gva_valid:1;
  746. u8 gva_gpa_valid:1;
  747. u8 hypercall_output_pending:1;
  748. u8 reserved:5;
  749. } __packed;
  750. };
  751. struct hv_arm64_memory_intercept_message {
  752. struct hv_arm64_intercept_message_header header;
  753. u32 cache_type; /* enum hv_cache_type */
  754. u8 instruction_byte_count;
  755. union hv_arm64_memory_access_info memory_access_info;
  756. u16 reserved1;
  757. u8 instruction_bytes[4];
  758. u32 reserved2;
  759. u64 guest_virtual_address;
  760. u64 guest_physical_address;
  761. u64 syndrome;
  762. } __packed;
  763. #endif /* CONFIG_ARM64 */
  764. /*
  765. * Dispatch state for the VP communicated by the hypervisor to the
  766. * VP-dispatching thread in the root on return from HVCALL_DISPATCH_VP.
  767. */
  768. enum hv_vp_dispatch_state {
  769. HV_VP_DISPATCH_STATE_INVALID = 0,
  770. HV_VP_DISPATCH_STATE_BLOCKED = 1,
  771. HV_VP_DISPATCH_STATE_READY = 2,
  772. };
  773. /*
  774. * Dispatch event that caused the current dispatch state on return from
  775. * HVCALL_DISPATCH_VP.
  776. */
  777. enum hv_vp_dispatch_event {
  778. HV_VP_DISPATCH_EVENT_INVALID = 0x00000000,
  779. HV_VP_DISPATCH_EVENT_SUSPEND = 0x00000001,
  780. HV_VP_DISPATCH_EVENT_INTERCEPT = 0x00000002,
  781. };
  782. #define HV_ROOT_SCHEDULER_MAX_VPS_PER_CHILD_PARTITION 1024
  783. /* The maximum array size of HV_GENERIC_SET (vp_set) buffer */
  784. #define HV_GENERIC_SET_QWORD_COUNT(max) (((((max) - 1) >> 6) + 1) + 2)
  785. struct hv_vp_signal_bitset_scheduler_message {
  786. u64 partition_id;
  787. u32 overflow_count;
  788. u16 vp_count;
  789. u16 reserved;
  790. #define BITSET_BUFFER_SIZE \
  791. HV_GENERIC_SET_QWORD_COUNT(HV_ROOT_SCHEDULER_MAX_VPS_PER_CHILD_PARTITION)
  792. union {
  793. struct hv_vpset bitset;
  794. u64 bitset_buffer[BITSET_BUFFER_SIZE];
  795. } vp_bitset;
  796. #undef BITSET_BUFFER_SIZE
  797. } __packed;
  798. static_assert(sizeof(struct hv_vp_signal_bitset_scheduler_message) <=
  799. (sizeof(struct hv_message) - sizeof(struct hv_message_header)));
  800. #define HV_MESSAGE_MAX_PARTITION_VP_PAIR_COUNT \
  801. (((sizeof(struct hv_message) - sizeof(struct hv_message_header)) / \
  802. (sizeof(u64 /* partition id */) + sizeof(u32 /* vp index */))) - 1)
  803. struct hv_vp_signal_pair_scheduler_message {
  804. u32 overflow_count;
  805. u8 vp_count;
  806. u8 reserved1[3];
  807. u64 partition_ids[HV_MESSAGE_MAX_PARTITION_VP_PAIR_COUNT];
  808. u32 vp_indexes[HV_MESSAGE_MAX_PARTITION_VP_PAIR_COUNT];
  809. u8 reserved2[4];
  810. } __packed;
  811. static_assert(sizeof(struct hv_vp_signal_pair_scheduler_message) ==
  812. (sizeof(struct hv_message) - sizeof(struct hv_message_header)));
  813. /* Input and output structures for HVCALL_DISPATCH_VP */
  814. #define HV_DISPATCH_VP_FLAG_CLEAR_INTERCEPT_SUSPEND 0x1
  815. #define HV_DISPATCH_VP_FLAG_ENABLE_CALLER_INTERRUPTS 0x2
  816. #define HV_DISPATCH_VP_FLAG_SET_CALLER_SPEC_CTRL 0x4
  817. #define HV_DISPATCH_VP_FLAG_SKIP_VP_SPEC_FLUSH 0x8
  818. #define HV_DISPATCH_VP_FLAG_SKIP_CALLER_SPEC_FLUSH 0x10
  819. #define HV_DISPATCH_VP_FLAG_SKIP_CALLER_USER_SPEC_FLUSH 0x20
  820. #define HV_DISPATCH_VP_FLAG_SCAN_INTERRUPT_INJECTION 0x40
  821. struct hv_input_dispatch_vp {
  822. u64 partition_id;
  823. u32 vp_index;
  824. u32 flags;
  825. u64 time_slice; /* in 100ns */
  826. u64 spec_ctrl;
  827. } __packed;
  828. struct hv_output_dispatch_vp {
  829. u32 dispatch_state; /* enum hv_vp_dispatch_state */
  830. u32 dispatch_event; /* enum hv_vp_dispatch_event */
  831. } __packed;
  832. struct hv_input_modify_sparse_spa_page_host_access {
  833. u32 host_access : 2;
  834. u32 reserved : 30;
  835. u32 flags;
  836. u64 partition_id;
  837. u64 spa_page_list[];
  838. } __packed;
  839. /* hv_input_modify_sparse_spa_page_host_access flags */
  840. #define HV_MODIFY_SPA_PAGE_HOST_ACCESS_MAKE_EXCLUSIVE 0x1
  841. #define HV_MODIFY_SPA_PAGE_HOST_ACCESS_MAKE_SHARED 0x2
  842. #define HV_MODIFY_SPA_PAGE_HOST_ACCESS_LARGE_PAGE 0x4
  843. #define HV_MODIFY_SPA_PAGE_HOST_ACCESS_HUGE_PAGE 0x8
  844. #endif /* _HV_HVHDK_H */