projects/linux·blob master · refs

302 lines · 7.0 KiB

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