1609363cfSSean Christopherson /* SPDX-License-Identifier: GPL-2.0 */
2609363cfSSean Christopherson #ifndef __KVM_X86_VMX_VMCS12_H
3609363cfSSean Christopherson #define __KVM_X86_VMX_VMCS12_H
4609363cfSSean Christopherson
5609363cfSSean Christopherson #include <linux/build_bug.h>
6609363cfSSean Christopherson
7609363cfSSean Christopherson #include "vmcs.h"
8609363cfSSean Christopherson
9609363cfSSean Christopherson /*
10609363cfSSean Christopherson * struct vmcs12 describes the state that our guest hypervisor (L1) keeps for a
11609363cfSSean Christopherson * single nested guest (L2), hence the name vmcs12. Any VMX implementation has
12609363cfSSean Christopherson * a VMCS structure, and vmcs12 is our emulated VMX's VMCS. This structure is
13609363cfSSean Christopherson * stored in guest memory specified by VMPTRLD, but is opaque to the guest,
14609363cfSSean Christopherson * which must access it using VMREAD/VMWRITE/VMCLEAR instructions.
15609363cfSSean Christopherson * More than one of these structures may exist, if L1 runs multiple L2 guests.
16609363cfSSean Christopherson * nested_vmx_run() will use the data here to build the vmcs02: a VMCS for the
17609363cfSSean Christopherson * underlying hardware which will be used to run L2.
18609363cfSSean Christopherson * This structure is packed to ensure that its layout is identical across
19609363cfSSean Christopherson * machines (necessary for live migration).
20609363cfSSean Christopherson *
21609363cfSSean Christopherson * IMPORTANT: Changing the layout of existing fields in this structure
22609363cfSSean Christopherson * will break save/restore compatibility with older kvm releases. When
23609363cfSSean Christopherson * adding new fields, either use space in the reserved padding* arrays
24609363cfSSean Christopherson * or add the new fields to the end of the structure.
25609363cfSSean Christopherson */
26609363cfSSean Christopherson typedef u64 natural_width;
27609363cfSSean Christopherson struct __packed vmcs12 {
28609363cfSSean Christopherson /* According to the Intel spec, a VMCS region must start with the
29609363cfSSean Christopherson * following two fields. Then follow implementation-specific data.
30609363cfSSean Christopherson */
31609363cfSSean Christopherson struct vmcs_hdr hdr;
32609363cfSSean Christopherson u32 abort;
33609363cfSSean Christopherson
34609363cfSSean Christopherson u32 launch_state; /* set to 0 by VMCLEAR, to 1 by VMLAUNCH */
35609363cfSSean Christopherson u32 padding[7]; /* room for future expansion */
36609363cfSSean Christopherson
37609363cfSSean Christopherson u64 io_bitmap_a;
38609363cfSSean Christopherson u64 io_bitmap_b;
39609363cfSSean Christopherson u64 msr_bitmap;
40609363cfSSean Christopherson u64 vm_exit_msr_store_addr;
41609363cfSSean Christopherson u64 vm_exit_msr_load_addr;
42609363cfSSean Christopherson u64 vm_entry_msr_load_addr;
43609363cfSSean Christopherson u64 tsc_offset;
44609363cfSSean Christopherson u64 virtual_apic_page_addr;
45609363cfSSean Christopherson u64 apic_access_addr;
46609363cfSSean Christopherson u64 posted_intr_desc_addr;
47609363cfSSean Christopherson u64 ept_pointer;
48609363cfSSean Christopherson u64 eoi_exit_bitmap0;
49609363cfSSean Christopherson u64 eoi_exit_bitmap1;
50609363cfSSean Christopherson u64 eoi_exit_bitmap2;
51609363cfSSean Christopherson u64 eoi_exit_bitmap3;
52609363cfSSean Christopherson u64 xss_exit_bitmap;
53609363cfSSean Christopherson u64 guest_physical_address;
54609363cfSSean Christopherson u64 vmcs_link_pointer;
55609363cfSSean Christopherson u64 guest_ia32_debugctl;
56609363cfSSean Christopherson u64 guest_ia32_pat;
57609363cfSSean Christopherson u64 guest_ia32_efer;
58609363cfSSean Christopherson u64 guest_ia32_perf_global_ctrl;
59609363cfSSean Christopherson u64 guest_pdptr0;
60609363cfSSean Christopherson u64 guest_pdptr1;
61609363cfSSean Christopherson u64 guest_pdptr2;
62609363cfSSean Christopherson u64 guest_pdptr3;
63609363cfSSean Christopherson u64 guest_bndcfgs;
64609363cfSSean Christopherson u64 host_ia32_pat;
65609363cfSSean Christopherson u64 host_ia32_efer;
66609363cfSSean Christopherson u64 host_ia32_perf_global_ctrl;
67609363cfSSean Christopherson u64 vmread_bitmap;
68609363cfSSean Christopherson u64 vmwrite_bitmap;
69609363cfSSean Christopherson u64 vm_function_control;
70609363cfSSean Christopherson u64 eptp_list_address;
71609363cfSSean Christopherson u64 pml_address;
7272add915SSean Christopherson u64 encls_exiting_bitmap;
733c0f9936SIlias Stamatis u64 tsc_multiplier;
743c0f9936SIlias Stamatis u64 padding64[1]; /* room for future expansion */
75609363cfSSean Christopherson /*
76609363cfSSean Christopherson * To allow migration of L1 (complete with its L2 guests) between
77609363cfSSean Christopherson * machines of different natural widths (32 or 64 bit), we cannot have
78609363cfSSean Christopherson * unsigned long fields with no explicit size. We use u64 (aliased
79609363cfSSean Christopherson * natural_width) instead. Luckily, x86 is little-endian.
80609363cfSSean Christopherson */
81609363cfSSean Christopherson natural_width cr0_guest_host_mask;
82609363cfSSean Christopherson natural_width cr4_guest_host_mask;
83609363cfSSean Christopherson natural_width cr0_read_shadow;
84609363cfSSean Christopherson natural_width cr4_read_shadow;
85b8d295f9SSean Christopherson natural_width dead_space[4]; /* Last remnants of cr3_target_value[0-3]. */
86609363cfSSean Christopherson natural_width exit_qualification;
87609363cfSSean Christopherson natural_width guest_linear_address;
88609363cfSSean Christopherson natural_width guest_cr0;
89609363cfSSean Christopherson natural_width guest_cr3;
90609363cfSSean Christopherson natural_width guest_cr4;
91609363cfSSean Christopherson natural_width guest_es_base;
92609363cfSSean Christopherson natural_width guest_cs_base;
93609363cfSSean Christopherson natural_width guest_ss_base;
94609363cfSSean Christopherson natural_width guest_ds_base;
95609363cfSSean Christopherson natural_width guest_fs_base;
96609363cfSSean Christopherson natural_width guest_gs_base;
97609363cfSSean Christopherson natural_width guest_ldtr_base;
98609363cfSSean Christopherson natural_width guest_tr_base;
99609363cfSSean Christopherson natural_width guest_gdtr_base;
100609363cfSSean Christopherson natural_width guest_idtr_base;
101609363cfSSean Christopherson natural_width guest_dr7;
102609363cfSSean Christopherson natural_width guest_rsp;
103609363cfSSean Christopherson natural_width guest_rip;
104609363cfSSean Christopherson natural_width guest_rflags;
105609363cfSSean Christopherson natural_width guest_pending_dbg_exceptions;
106609363cfSSean Christopherson natural_width guest_sysenter_esp;
107609363cfSSean Christopherson natural_width guest_sysenter_eip;
108609363cfSSean Christopherson natural_width host_cr0;
109609363cfSSean Christopherson natural_width host_cr3;
110609363cfSSean Christopherson natural_width host_cr4;
111609363cfSSean Christopherson natural_width host_fs_base;
112609363cfSSean Christopherson natural_width host_gs_base;
113609363cfSSean Christopherson natural_width host_tr_base;
114609363cfSSean Christopherson natural_width host_gdtr_base;
115609363cfSSean Christopherson natural_width host_idtr_base;
116609363cfSSean Christopherson natural_width host_ia32_sysenter_esp;
117609363cfSSean Christopherson natural_width host_ia32_sysenter_eip;
118609363cfSSean Christopherson natural_width host_rsp;
119609363cfSSean Christopherson natural_width host_rip;
120609363cfSSean Christopherson natural_width paddingl[8]; /* room for future expansion */
121609363cfSSean Christopherson u32 pin_based_vm_exec_control;
122609363cfSSean Christopherson u32 cpu_based_vm_exec_control;
123609363cfSSean Christopherson u32 exception_bitmap;
124609363cfSSean Christopherson u32 page_fault_error_code_mask;
125609363cfSSean Christopherson u32 page_fault_error_code_match;
126609363cfSSean Christopherson u32 cr3_target_count;
127609363cfSSean Christopherson u32 vm_exit_controls;
128609363cfSSean Christopherson u32 vm_exit_msr_store_count;
129609363cfSSean Christopherson u32 vm_exit_msr_load_count;
130609363cfSSean Christopherson u32 vm_entry_controls;
131609363cfSSean Christopherson u32 vm_entry_msr_load_count;
132609363cfSSean Christopherson u32 vm_entry_intr_info_field;
133609363cfSSean Christopherson u32 vm_entry_exception_error_code;
134609363cfSSean Christopherson u32 vm_entry_instruction_len;
135609363cfSSean Christopherson u32 tpr_threshold;
136609363cfSSean Christopherson u32 secondary_vm_exec_control;
137609363cfSSean Christopherson u32 vm_instruction_error;
138609363cfSSean Christopherson u32 vm_exit_reason;
139609363cfSSean Christopherson u32 vm_exit_intr_info;
140609363cfSSean Christopherson u32 vm_exit_intr_error_code;
141609363cfSSean Christopherson u32 idt_vectoring_info_field;
142609363cfSSean Christopherson u32 idt_vectoring_error_code;
143609363cfSSean Christopherson u32 vm_exit_instruction_len;
144609363cfSSean Christopherson u32 vmx_instruction_info;
145609363cfSSean Christopherson u32 guest_es_limit;
146609363cfSSean Christopherson u32 guest_cs_limit;
147609363cfSSean Christopherson u32 guest_ss_limit;
148609363cfSSean Christopherson u32 guest_ds_limit;
149609363cfSSean Christopherson u32 guest_fs_limit;
150609363cfSSean Christopherson u32 guest_gs_limit;
151609363cfSSean Christopherson u32 guest_ldtr_limit;
152609363cfSSean Christopherson u32 guest_tr_limit;
153609363cfSSean Christopherson u32 guest_gdtr_limit;
154609363cfSSean Christopherson u32 guest_idtr_limit;
155609363cfSSean Christopherson u32 guest_es_ar_bytes;
156609363cfSSean Christopherson u32 guest_cs_ar_bytes;
157609363cfSSean Christopherson u32 guest_ss_ar_bytes;
158609363cfSSean Christopherson u32 guest_ds_ar_bytes;
159609363cfSSean Christopherson u32 guest_fs_ar_bytes;
160609363cfSSean Christopherson u32 guest_gs_ar_bytes;
161609363cfSSean Christopherson u32 guest_ldtr_ar_bytes;
162609363cfSSean Christopherson u32 guest_tr_ar_bytes;
163609363cfSSean Christopherson u32 guest_interruptibility_info;
164609363cfSSean Christopherson u32 guest_activity_state;
165609363cfSSean Christopherson u32 guest_sysenter_cs;
166609363cfSSean Christopherson u32 host_ia32_sysenter_cs;
167609363cfSSean Christopherson u32 vmx_preemption_timer_value;
168609363cfSSean Christopherson u32 padding32[7]; /* room for future expansion */
169609363cfSSean Christopherson u16 virtual_processor_id;
170609363cfSSean Christopherson u16 posted_intr_nv;
171609363cfSSean Christopherson u16 guest_es_selector;
172609363cfSSean Christopherson u16 guest_cs_selector;
173609363cfSSean Christopherson u16 guest_ss_selector;
174609363cfSSean Christopherson u16 guest_ds_selector;
175609363cfSSean Christopherson u16 guest_fs_selector;
176609363cfSSean Christopherson u16 guest_gs_selector;
177609363cfSSean Christopherson u16 guest_ldtr_selector;
178609363cfSSean Christopherson u16 guest_tr_selector;
179609363cfSSean Christopherson u16 guest_intr_status;
180609363cfSSean Christopherson u16 host_es_selector;
181609363cfSSean Christopherson u16 host_cs_selector;
182609363cfSSean Christopherson u16 host_ss_selector;
183609363cfSSean Christopherson u16 host_ds_selector;
184609363cfSSean Christopherson u16 host_fs_selector;
185609363cfSSean Christopherson u16 host_gs_selector;
186609363cfSSean Christopherson u16 host_tr_selector;
187609363cfSSean Christopherson u16 guest_pml_index;
188609363cfSSean Christopherson };
189609363cfSSean Christopherson
190609363cfSSean Christopherson /*
191609363cfSSean Christopherson * VMCS12_REVISION is an arbitrary id that should be changed if the content or
192609363cfSSean Christopherson * layout of struct vmcs12 is changed. MSR_IA32_VMX_BASIC returns this id, and
193609363cfSSean Christopherson * VMPTRLD verifies that the VMCS region that L1 is loading contains this id.
194609363cfSSean Christopherson *
195609363cfSSean Christopherson * IMPORTANT: Changing this value will break save/restore compatibility with
196609363cfSSean Christopherson * older kvm releases.
197609363cfSSean Christopherson */
198609363cfSSean Christopherson #define VMCS12_REVISION 0x11e57ed0
199609363cfSSean Christopherson
200609363cfSSean Christopherson /*
201609363cfSSean Christopherson * VMCS12_SIZE is the number of bytes L1 should allocate for the VMXON region
202609363cfSSean Christopherson * and any VMCS region. Although only sizeof(struct vmcs12) are used by the
2036ca00dfaSLiran Alon * current implementation, 4K are reserved to avoid future complications and
2046ca00dfaSLiran Alon * to preserve userspace ABI.
205609363cfSSean Christopherson */
2066ca00dfaSLiran Alon #define VMCS12_SIZE KVM_STATE_NESTED_VMX_VMCS_SIZE
207609363cfSSean Christopherson
208609363cfSSean Christopherson /*
209609363cfSSean Christopherson * For save/restore compatibility, the vmcs12 field offsets must not change.
210609363cfSSean Christopherson */
211609363cfSSean Christopherson #define CHECK_OFFSET(field, loc) \
212*07a368b3SMaxim Levitsky ASSERT_STRUCT_OFFSET(struct vmcs12, field, loc)
213609363cfSSean Christopherson
vmx_check_vmcs12_offsets(void)214609363cfSSean Christopherson static inline void vmx_check_vmcs12_offsets(void)
215609363cfSSean Christopherson {
216609363cfSSean Christopherson CHECK_OFFSET(hdr, 0);
217609363cfSSean Christopherson CHECK_OFFSET(abort, 4);
218609363cfSSean Christopherson CHECK_OFFSET(launch_state, 8);
219609363cfSSean Christopherson CHECK_OFFSET(io_bitmap_a, 40);
220609363cfSSean Christopherson CHECK_OFFSET(io_bitmap_b, 48);
221609363cfSSean Christopherson CHECK_OFFSET(msr_bitmap, 56);
222609363cfSSean Christopherson CHECK_OFFSET(vm_exit_msr_store_addr, 64);
223609363cfSSean Christopherson CHECK_OFFSET(vm_exit_msr_load_addr, 72);
224609363cfSSean Christopherson CHECK_OFFSET(vm_entry_msr_load_addr, 80);
225609363cfSSean Christopherson CHECK_OFFSET(tsc_offset, 88);
226609363cfSSean Christopherson CHECK_OFFSET(virtual_apic_page_addr, 96);
227609363cfSSean Christopherson CHECK_OFFSET(apic_access_addr, 104);
228609363cfSSean Christopherson CHECK_OFFSET(posted_intr_desc_addr, 112);
229609363cfSSean Christopherson CHECK_OFFSET(ept_pointer, 120);
230609363cfSSean Christopherson CHECK_OFFSET(eoi_exit_bitmap0, 128);
231609363cfSSean Christopherson CHECK_OFFSET(eoi_exit_bitmap1, 136);
232609363cfSSean Christopherson CHECK_OFFSET(eoi_exit_bitmap2, 144);
233609363cfSSean Christopherson CHECK_OFFSET(eoi_exit_bitmap3, 152);
234609363cfSSean Christopherson CHECK_OFFSET(xss_exit_bitmap, 160);
235609363cfSSean Christopherson CHECK_OFFSET(guest_physical_address, 168);
236609363cfSSean Christopherson CHECK_OFFSET(vmcs_link_pointer, 176);
237609363cfSSean Christopherson CHECK_OFFSET(guest_ia32_debugctl, 184);
238609363cfSSean Christopherson CHECK_OFFSET(guest_ia32_pat, 192);
239609363cfSSean Christopherson CHECK_OFFSET(guest_ia32_efer, 200);
240609363cfSSean Christopherson CHECK_OFFSET(guest_ia32_perf_global_ctrl, 208);
241609363cfSSean Christopherson CHECK_OFFSET(guest_pdptr0, 216);
242609363cfSSean Christopherson CHECK_OFFSET(guest_pdptr1, 224);
243609363cfSSean Christopherson CHECK_OFFSET(guest_pdptr2, 232);
244609363cfSSean Christopherson CHECK_OFFSET(guest_pdptr3, 240);
245609363cfSSean Christopherson CHECK_OFFSET(guest_bndcfgs, 248);
246609363cfSSean Christopherson CHECK_OFFSET(host_ia32_pat, 256);
247609363cfSSean Christopherson CHECK_OFFSET(host_ia32_efer, 264);
248609363cfSSean Christopherson CHECK_OFFSET(host_ia32_perf_global_ctrl, 272);
249609363cfSSean Christopherson CHECK_OFFSET(vmread_bitmap, 280);
250609363cfSSean Christopherson CHECK_OFFSET(vmwrite_bitmap, 288);
251609363cfSSean Christopherson CHECK_OFFSET(vm_function_control, 296);
252609363cfSSean Christopherson CHECK_OFFSET(eptp_list_address, 304);
253609363cfSSean Christopherson CHECK_OFFSET(pml_address, 312);
25472add915SSean Christopherson CHECK_OFFSET(encls_exiting_bitmap, 320);
2553c0f9936SIlias Stamatis CHECK_OFFSET(tsc_multiplier, 328);
256609363cfSSean Christopherson CHECK_OFFSET(cr0_guest_host_mask, 344);
257609363cfSSean Christopherson CHECK_OFFSET(cr4_guest_host_mask, 352);
258609363cfSSean Christopherson CHECK_OFFSET(cr0_read_shadow, 360);
259609363cfSSean Christopherson CHECK_OFFSET(cr4_read_shadow, 368);
260b8d295f9SSean Christopherson CHECK_OFFSET(dead_space, 376);
261609363cfSSean Christopherson CHECK_OFFSET(exit_qualification, 408);
262609363cfSSean Christopherson CHECK_OFFSET(guest_linear_address, 416);
263609363cfSSean Christopherson CHECK_OFFSET(guest_cr0, 424);
264609363cfSSean Christopherson CHECK_OFFSET(guest_cr3, 432);
265609363cfSSean Christopherson CHECK_OFFSET(guest_cr4, 440);
266609363cfSSean Christopherson CHECK_OFFSET(guest_es_base, 448);
267609363cfSSean Christopherson CHECK_OFFSET(guest_cs_base, 456);
268609363cfSSean Christopherson CHECK_OFFSET(guest_ss_base, 464);
269609363cfSSean Christopherson CHECK_OFFSET(guest_ds_base, 472);
270609363cfSSean Christopherson CHECK_OFFSET(guest_fs_base, 480);
271609363cfSSean Christopherson CHECK_OFFSET(guest_gs_base, 488);
272609363cfSSean Christopherson CHECK_OFFSET(guest_ldtr_base, 496);
273609363cfSSean Christopherson CHECK_OFFSET(guest_tr_base, 504);
274609363cfSSean Christopherson CHECK_OFFSET(guest_gdtr_base, 512);
275609363cfSSean Christopherson CHECK_OFFSET(guest_idtr_base, 520);
276609363cfSSean Christopherson CHECK_OFFSET(guest_dr7, 528);
277609363cfSSean Christopherson CHECK_OFFSET(guest_rsp, 536);
278609363cfSSean Christopherson CHECK_OFFSET(guest_rip, 544);
279609363cfSSean Christopherson CHECK_OFFSET(guest_rflags, 552);
280609363cfSSean Christopherson CHECK_OFFSET(guest_pending_dbg_exceptions, 560);
281609363cfSSean Christopherson CHECK_OFFSET(guest_sysenter_esp, 568);
282609363cfSSean Christopherson CHECK_OFFSET(guest_sysenter_eip, 576);
283609363cfSSean Christopherson CHECK_OFFSET(host_cr0, 584);
284609363cfSSean Christopherson CHECK_OFFSET(host_cr3, 592);
285609363cfSSean Christopherson CHECK_OFFSET(host_cr4, 600);
286609363cfSSean Christopherson CHECK_OFFSET(host_fs_base, 608);
287609363cfSSean Christopherson CHECK_OFFSET(host_gs_base, 616);
288609363cfSSean Christopherson CHECK_OFFSET(host_tr_base, 624);
289609363cfSSean Christopherson CHECK_OFFSET(host_gdtr_base, 632);
290609363cfSSean Christopherson CHECK_OFFSET(host_idtr_base, 640);
291609363cfSSean Christopherson CHECK_OFFSET(host_ia32_sysenter_esp, 648);
292609363cfSSean Christopherson CHECK_OFFSET(host_ia32_sysenter_eip, 656);
293609363cfSSean Christopherson CHECK_OFFSET(host_rsp, 664);
294609363cfSSean Christopherson CHECK_OFFSET(host_rip, 672);
295609363cfSSean Christopherson CHECK_OFFSET(pin_based_vm_exec_control, 744);
296609363cfSSean Christopherson CHECK_OFFSET(cpu_based_vm_exec_control, 748);
297609363cfSSean Christopherson CHECK_OFFSET(exception_bitmap, 752);
298609363cfSSean Christopherson CHECK_OFFSET(page_fault_error_code_mask, 756);
299609363cfSSean Christopherson CHECK_OFFSET(page_fault_error_code_match, 760);
300609363cfSSean Christopherson CHECK_OFFSET(cr3_target_count, 764);
301609363cfSSean Christopherson CHECK_OFFSET(vm_exit_controls, 768);
302609363cfSSean Christopherson CHECK_OFFSET(vm_exit_msr_store_count, 772);
303609363cfSSean Christopherson CHECK_OFFSET(vm_exit_msr_load_count, 776);
304609363cfSSean Christopherson CHECK_OFFSET(vm_entry_controls, 780);
305609363cfSSean Christopherson CHECK_OFFSET(vm_entry_msr_load_count, 784);
306609363cfSSean Christopherson CHECK_OFFSET(vm_entry_intr_info_field, 788);
307609363cfSSean Christopherson CHECK_OFFSET(vm_entry_exception_error_code, 792);
308609363cfSSean Christopherson CHECK_OFFSET(vm_entry_instruction_len, 796);
309609363cfSSean Christopherson CHECK_OFFSET(tpr_threshold, 800);
310609363cfSSean Christopherson CHECK_OFFSET(secondary_vm_exec_control, 804);
311609363cfSSean Christopherson CHECK_OFFSET(vm_instruction_error, 808);
312609363cfSSean Christopherson CHECK_OFFSET(vm_exit_reason, 812);
313609363cfSSean Christopherson CHECK_OFFSET(vm_exit_intr_info, 816);
314609363cfSSean Christopherson CHECK_OFFSET(vm_exit_intr_error_code, 820);
315609363cfSSean Christopherson CHECK_OFFSET(idt_vectoring_info_field, 824);
316609363cfSSean Christopherson CHECK_OFFSET(idt_vectoring_error_code, 828);
317609363cfSSean Christopherson CHECK_OFFSET(vm_exit_instruction_len, 832);
318609363cfSSean Christopherson CHECK_OFFSET(vmx_instruction_info, 836);
319609363cfSSean Christopherson CHECK_OFFSET(guest_es_limit, 840);
320609363cfSSean Christopherson CHECK_OFFSET(guest_cs_limit, 844);
321609363cfSSean Christopherson CHECK_OFFSET(guest_ss_limit, 848);
322609363cfSSean Christopherson CHECK_OFFSET(guest_ds_limit, 852);
323609363cfSSean Christopherson CHECK_OFFSET(guest_fs_limit, 856);
324609363cfSSean Christopherson CHECK_OFFSET(guest_gs_limit, 860);
325609363cfSSean Christopherson CHECK_OFFSET(guest_ldtr_limit, 864);
326609363cfSSean Christopherson CHECK_OFFSET(guest_tr_limit, 868);
327609363cfSSean Christopherson CHECK_OFFSET(guest_gdtr_limit, 872);
328609363cfSSean Christopherson CHECK_OFFSET(guest_idtr_limit, 876);
329609363cfSSean Christopherson CHECK_OFFSET(guest_es_ar_bytes, 880);
330609363cfSSean Christopherson CHECK_OFFSET(guest_cs_ar_bytes, 884);
331609363cfSSean Christopherson CHECK_OFFSET(guest_ss_ar_bytes, 888);
332609363cfSSean Christopherson CHECK_OFFSET(guest_ds_ar_bytes, 892);
333609363cfSSean Christopherson CHECK_OFFSET(guest_fs_ar_bytes, 896);
334609363cfSSean Christopherson CHECK_OFFSET(guest_gs_ar_bytes, 900);
335609363cfSSean Christopherson CHECK_OFFSET(guest_ldtr_ar_bytes, 904);
336609363cfSSean Christopherson CHECK_OFFSET(guest_tr_ar_bytes, 908);
337609363cfSSean Christopherson CHECK_OFFSET(guest_interruptibility_info, 912);
338609363cfSSean Christopherson CHECK_OFFSET(guest_activity_state, 916);
339609363cfSSean Christopherson CHECK_OFFSET(guest_sysenter_cs, 920);
340609363cfSSean Christopherson CHECK_OFFSET(host_ia32_sysenter_cs, 924);
341609363cfSSean Christopherson CHECK_OFFSET(vmx_preemption_timer_value, 928);
342609363cfSSean Christopherson CHECK_OFFSET(virtual_processor_id, 960);
343609363cfSSean Christopherson CHECK_OFFSET(posted_intr_nv, 962);
344609363cfSSean Christopherson CHECK_OFFSET(guest_es_selector, 964);
345609363cfSSean Christopherson CHECK_OFFSET(guest_cs_selector, 966);
346609363cfSSean Christopherson CHECK_OFFSET(guest_ss_selector, 968);
347609363cfSSean Christopherson CHECK_OFFSET(guest_ds_selector, 970);
348609363cfSSean Christopherson CHECK_OFFSET(guest_fs_selector, 972);
349609363cfSSean Christopherson CHECK_OFFSET(guest_gs_selector, 974);
350609363cfSSean Christopherson CHECK_OFFSET(guest_ldtr_selector, 976);
351609363cfSSean Christopherson CHECK_OFFSET(guest_tr_selector, 978);
352609363cfSSean Christopherson CHECK_OFFSET(guest_intr_status, 980);
353609363cfSSean Christopherson CHECK_OFFSET(host_es_selector, 982);
354609363cfSSean Christopherson CHECK_OFFSET(host_cs_selector, 984);
355609363cfSSean Christopherson CHECK_OFFSET(host_ss_selector, 986);
356609363cfSSean Christopherson CHECK_OFFSET(host_ds_selector, 988);
357609363cfSSean Christopherson CHECK_OFFSET(host_fs_selector, 990);
358609363cfSSean Christopherson CHECK_OFFSET(host_gs_selector, 992);
359609363cfSSean Christopherson CHECK_OFFSET(host_tr_selector, 994);
360609363cfSSean Christopherson CHECK_OFFSET(guest_pml_index, 996);
361609363cfSSean Christopherson }
362609363cfSSean Christopherson
3632423a4c0SVitaly Kuznetsov extern const unsigned short vmcs12_field_offsets[];
364609363cfSSean Christopherson extern const unsigned int nr_vmcs12_fields;
365609363cfSSean Christopherson
get_vmcs12_field_offset(unsigned long field)3662423a4c0SVitaly Kuznetsov static inline short get_vmcs12_field_offset(unsigned long field)
367609363cfSSean Christopherson {
368609363cfSSean Christopherson unsigned short offset;
369609363cfSSean Christopherson unsigned int index;
370609363cfSSean Christopherson
371609363cfSSean Christopherson if (field >> 15)
372609363cfSSean Christopherson return -ENOENT;
373609363cfSSean Christopherson
374609363cfSSean Christopherson index = ROL16(field, 6);
375609363cfSSean Christopherson if (index >= nr_vmcs12_fields)
376609363cfSSean Christopherson return -ENOENT;
377609363cfSSean Christopherson
378609363cfSSean Christopherson index = array_index_nospec(index, nr_vmcs12_fields);
3792423a4c0SVitaly Kuznetsov offset = vmcs12_field_offsets[index];
380609363cfSSean Christopherson if (offset == 0)
381609363cfSSean Christopherson return -ENOENT;
382609363cfSSean Christopherson return offset;
383609363cfSSean Christopherson }
384609363cfSSean Christopherson
vmcs12_read_any(struct vmcs12 * vmcs12,unsigned long field,u16 offset)3851c6f0b47SSean Christopherson static inline u64 vmcs12_read_any(struct vmcs12 *vmcs12, unsigned long field,
3861c6f0b47SSean Christopherson u16 offset)
387609363cfSSean Christopherson {
3881c6f0b47SSean Christopherson char *p = (char *)vmcs12 + offset;
389609363cfSSean Christopherson
390609363cfSSean Christopherson switch (vmcs_field_width(field)) {
391609363cfSSean Christopherson case VMCS_FIELD_WIDTH_NATURAL_WIDTH:
3921c6f0b47SSean Christopherson return *((natural_width *)p);
393609363cfSSean Christopherson case VMCS_FIELD_WIDTH_U16:
3941c6f0b47SSean Christopherson return *((u16 *)p);
395609363cfSSean Christopherson case VMCS_FIELD_WIDTH_U32:
3961c6f0b47SSean Christopherson return *((u32 *)p);
397609363cfSSean Christopherson case VMCS_FIELD_WIDTH_U64:
3981c6f0b47SSean Christopherson return *((u64 *)p);
399609363cfSSean Christopherson default:
4001c6f0b47SSean Christopherson WARN_ON_ONCE(1);
4011c6f0b47SSean Christopherson return -1;
402609363cfSSean Christopherson }
403609363cfSSean Christopherson }
404609363cfSSean Christopherson
vmcs12_write_any(struct vmcs12 * vmcs12,unsigned long field,u16 offset,u64 field_value)4051c6f0b47SSean Christopherson static inline void vmcs12_write_any(struct vmcs12 *vmcs12, unsigned long field,
4061c6f0b47SSean Christopherson u16 offset, u64 field_value)
4071c6f0b47SSean Christopherson {
408609363cfSSean Christopherson char *p = (char *)vmcs12 + offset;
409609363cfSSean Christopherson
410609363cfSSean Christopherson switch (vmcs_field_width(field)) {
411609363cfSSean Christopherson case VMCS_FIELD_WIDTH_U16:
412609363cfSSean Christopherson *(u16 *)p = field_value;
4131c6f0b47SSean Christopherson break;
414609363cfSSean Christopherson case VMCS_FIELD_WIDTH_U32:
415609363cfSSean Christopherson *(u32 *)p = field_value;
4161c6f0b47SSean Christopherson break;
417609363cfSSean Christopherson case VMCS_FIELD_WIDTH_U64:
418609363cfSSean Christopherson *(u64 *)p = field_value;
4191c6f0b47SSean Christopherson break;
420609363cfSSean Christopherson case VMCS_FIELD_WIDTH_NATURAL_WIDTH:
421609363cfSSean Christopherson *(natural_width *)p = field_value;
4221c6f0b47SSean Christopherson break;
423609363cfSSean Christopherson default:
4241c6f0b47SSean Christopherson WARN_ON_ONCE(1);
4251c6f0b47SSean Christopherson break;
426609363cfSSean Christopherson }
427609363cfSSean Christopherson }
428609363cfSSean Christopherson
429609363cfSSean Christopherson #endif /* __KVM_X86_VMX_VMCS12_H */
430