xref: /openbmc/linux/arch/x86/kvm/vmx/vmcs12.c (revision 8d20bd63)
1 // SPDX-License-Identifier: GPL-2.0
2 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
3 
4 #include "vmcs12.h"
5 
6 #define VMCS12_OFFSET(x) offsetof(struct vmcs12, x)
7 #define FIELD(number, name)	[ROL16(number, 6)] = VMCS12_OFFSET(name)
8 #define FIELD64(number, name)						\
9 	FIELD(number, name),						\
10 	[ROL16(number##_HIGH, 6)] = VMCS12_OFFSET(name) + sizeof(u32)
11 
12 const unsigned short vmcs12_field_offsets[] = {
13 	FIELD(VIRTUAL_PROCESSOR_ID, virtual_processor_id),
14 	FIELD(POSTED_INTR_NV, posted_intr_nv),
15 	FIELD(GUEST_ES_SELECTOR, guest_es_selector),
16 	FIELD(GUEST_CS_SELECTOR, guest_cs_selector),
17 	FIELD(GUEST_SS_SELECTOR, guest_ss_selector),
18 	FIELD(GUEST_DS_SELECTOR, guest_ds_selector),
19 	FIELD(GUEST_FS_SELECTOR, guest_fs_selector),
20 	FIELD(GUEST_GS_SELECTOR, guest_gs_selector),
21 	FIELD(GUEST_LDTR_SELECTOR, guest_ldtr_selector),
22 	FIELD(GUEST_TR_SELECTOR, guest_tr_selector),
23 	FIELD(GUEST_INTR_STATUS, guest_intr_status),
24 	FIELD(GUEST_PML_INDEX, guest_pml_index),
25 	FIELD(HOST_ES_SELECTOR, host_es_selector),
26 	FIELD(HOST_CS_SELECTOR, host_cs_selector),
27 	FIELD(HOST_SS_SELECTOR, host_ss_selector),
28 	FIELD(HOST_DS_SELECTOR, host_ds_selector),
29 	FIELD(HOST_FS_SELECTOR, host_fs_selector),
30 	FIELD(HOST_GS_SELECTOR, host_gs_selector),
31 	FIELD(HOST_TR_SELECTOR, host_tr_selector),
32 	FIELD64(IO_BITMAP_A, io_bitmap_a),
33 	FIELD64(IO_BITMAP_B, io_bitmap_b),
34 	FIELD64(MSR_BITMAP, msr_bitmap),
35 	FIELD64(VM_EXIT_MSR_STORE_ADDR, vm_exit_msr_store_addr),
36 	FIELD64(VM_EXIT_MSR_LOAD_ADDR, vm_exit_msr_load_addr),
37 	FIELD64(VM_ENTRY_MSR_LOAD_ADDR, vm_entry_msr_load_addr),
38 	FIELD64(PML_ADDRESS, pml_address),
39 	FIELD64(TSC_OFFSET, tsc_offset),
40 	FIELD64(TSC_MULTIPLIER, tsc_multiplier),
41 	FIELD64(VIRTUAL_APIC_PAGE_ADDR, virtual_apic_page_addr),
42 	FIELD64(APIC_ACCESS_ADDR, apic_access_addr),
43 	FIELD64(POSTED_INTR_DESC_ADDR, posted_intr_desc_addr),
44 	FIELD64(VM_FUNCTION_CONTROL, vm_function_control),
45 	FIELD64(EPT_POINTER, ept_pointer),
46 	FIELD64(EOI_EXIT_BITMAP0, eoi_exit_bitmap0),
47 	FIELD64(EOI_EXIT_BITMAP1, eoi_exit_bitmap1),
48 	FIELD64(EOI_EXIT_BITMAP2, eoi_exit_bitmap2),
49 	FIELD64(EOI_EXIT_BITMAP3, eoi_exit_bitmap3),
50 	FIELD64(EPTP_LIST_ADDRESS, eptp_list_address),
51 	FIELD64(VMREAD_BITMAP, vmread_bitmap),
52 	FIELD64(VMWRITE_BITMAP, vmwrite_bitmap),
53 	FIELD64(XSS_EXIT_BITMAP, xss_exit_bitmap),
54 	FIELD64(ENCLS_EXITING_BITMAP, encls_exiting_bitmap),
55 	FIELD64(GUEST_PHYSICAL_ADDRESS, guest_physical_address),
56 	FIELD64(VMCS_LINK_POINTER, vmcs_link_pointer),
57 	FIELD64(GUEST_IA32_DEBUGCTL, guest_ia32_debugctl),
58 	FIELD64(GUEST_IA32_PAT, guest_ia32_pat),
59 	FIELD64(GUEST_IA32_EFER, guest_ia32_efer),
60 	FIELD64(GUEST_IA32_PERF_GLOBAL_CTRL, guest_ia32_perf_global_ctrl),
61 	FIELD64(GUEST_PDPTR0, guest_pdptr0),
62 	FIELD64(GUEST_PDPTR1, guest_pdptr1),
63 	FIELD64(GUEST_PDPTR2, guest_pdptr2),
64 	FIELD64(GUEST_PDPTR3, guest_pdptr3),
65 	FIELD64(GUEST_BNDCFGS, guest_bndcfgs),
66 	FIELD64(HOST_IA32_PAT, host_ia32_pat),
67 	FIELD64(HOST_IA32_EFER, host_ia32_efer),
68 	FIELD64(HOST_IA32_PERF_GLOBAL_CTRL, host_ia32_perf_global_ctrl),
69 	FIELD(PIN_BASED_VM_EXEC_CONTROL, pin_based_vm_exec_control),
70 	FIELD(CPU_BASED_VM_EXEC_CONTROL, cpu_based_vm_exec_control),
71 	FIELD(EXCEPTION_BITMAP, exception_bitmap),
72 	FIELD(PAGE_FAULT_ERROR_CODE_MASK, page_fault_error_code_mask),
73 	FIELD(PAGE_FAULT_ERROR_CODE_MATCH, page_fault_error_code_match),
74 	FIELD(CR3_TARGET_COUNT, cr3_target_count),
75 	FIELD(VM_EXIT_CONTROLS, vm_exit_controls),
76 	FIELD(VM_EXIT_MSR_STORE_COUNT, vm_exit_msr_store_count),
77 	FIELD(VM_EXIT_MSR_LOAD_COUNT, vm_exit_msr_load_count),
78 	FIELD(VM_ENTRY_CONTROLS, vm_entry_controls),
79 	FIELD(VM_ENTRY_MSR_LOAD_COUNT, vm_entry_msr_load_count),
80 	FIELD(VM_ENTRY_INTR_INFO_FIELD, vm_entry_intr_info_field),
81 	FIELD(VM_ENTRY_EXCEPTION_ERROR_CODE, vm_entry_exception_error_code),
82 	FIELD(VM_ENTRY_INSTRUCTION_LEN, vm_entry_instruction_len),
83 	FIELD(TPR_THRESHOLD, tpr_threshold),
84 	FIELD(SECONDARY_VM_EXEC_CONTROL, secondary_vm_exec_control),
85 	FIELD(VM_INSTRUCTION_ERROR, vm_instruction_error),
86 	FIELD(VM_EXIT_REASON, vm_exit_reason),
87 	FIELD(VM_EXIT_INTR_INFO, vm_exit_intr_info),
88 	FIELD(VM_EXIT_INTR_ERROR_CODE, vm_exit_intr_error_code),
89 	FIELD(IDT_VECTORING_INFO_FIELD, idt_vectoring_info_field),
90 	FIELD(IDT_VECTORING_ERROR_CODE, idt_vectoring_error_code),
91 	FIELD(VM_EXIT_INSTRUCTION_LEN, vm_exit_instruction_len),
92 	FIELD(VMX_INSTRUCTION_INFO, vmx_instruction_info),
93 	FIELD(GUEST_ES_LIMIT, guest_es_limit),
94 	FIELD(GUEST_CS_LIMIT, guest_cs_limit),
95 	FIELD(GUEST_SS_LIMIT, guest_ss_limit),
96 	FIELD(GUEST_DS_LIMIT, guest_ds_limit),
97 	FIELD(GUEST_FS_LIMIT, guest_fs_limit),
98 	FIELD(GUEST_GS_LIMIT, guest_gs_limit),
99 	FIELD(GUEST_LDTR_LIMIT, guest_ldtr_limit),
100 	FIELD(GUEST_TR_LIMIT, guest_tr_limit),
101 	FIELD(GUEST_GDTR_LIMIT, guest_gdtr_limit),
102 	FIELD(GUEST_IDTR_LIMIT, guest_idtr_limit),
103 	FIELD(GUEST_ES_AR_BYTES, guest_es_ar_bytes),
104 	FIELD(GUEST_CS_AR_BYTES, guest_cs_ar_bytes),
105 	FIELD(GUEST_SS_AR_BYTES, guest_ss_ar_bytes),
106 	FIELD(GUEST_DS_AR_BYTES, guest_ds_ar_bytes),
107 	FIELD(GUEST_FS_AR_BYTES, guest_fs_ar_bytes),
108 	FIELD(GUEST_GS_AR_BYTES, guest_gs_ar_bytes),
109 	FIELD(GUEST_LDTR_AR_BYTES, guest_ldtr_ar_bytes),
110 	FIELD(GUEST_TR_AR_BYTES, guest_tr_ar_bytes),
111 	FIELD(GUEST_INTERRUPTIBILITY_INFO, guest_interruptibility_info),
112 	FIELD(GUEST_ACTIVITY_STATE, guest_activity_state),
113 	FIELD(GUEST_SYSENTER_CS, guest_sysenter_cs),
114 	FIELD(HOST_IA32_SYSENTER_CS, host_ia32_sysenter_cs),
115 	FIELD(VMX_PREEMPTION_TIMER_VALUE, vmx_preemption_timer_value),
116 	FIELD(CR0_GUEST_HOST_MASK, cr0_guest_host_mask),
117 	FIELD(CR4_GUEST_HOST_MASK, cr4_guest_host_mask),
118 	FIELD(CR0_READ_SHADOW, cr0_read_shadow),
119 	FIELD(CR4_READ_SHADOW, cr4_read_shadow),
120 	FIELD(EXIT_QUALIFICATION, exit_qualification),
121 	FIELD(GUEST_LINEAR_ADDRESS, guest_linear_address),
122 	FIELD(GUEST_CR0, guest_cr0),
123 	FIELD(GUEST_CR3, guest_cr3),
124 	FIELD(GUEST_CR4, guest_cr4),
125 	FIELD(GUEST_ES_BASE, guest_es_base),
126 	FIELD(GUEST_CS_BASE, guest_cs_base),
127 	FIELD(GUEST_SS_BASE, guest_ss_base),
128 	FIELD(GUEST_DS_BASE, guest_ds_base),
129 	FIELD(GUEST_FS_BASE, guest_fs_base),
130 	FIELD(GUEST_GS_BASE, guest_gs_base),
131 	FIELD(GUEST_LDTR_BASE, guest_ldtr_base),
132 	FIELD(GUEST_TR_BASE, guest_tr_base),
133 	FIELD(GUEST_GDTR_BASE, guest_gdtr_base),
134 	FIELD(GUEST_IDTR_BASE, guest_idtr_base),
135 	FIELD(GUEST_DR7, guest_dr7),
136 	FIELD(GUEST_RSP, guest_rsp),
137 	FIELD(GUEST_RIP, guest_rip),
138 	FIELD(GUEST_RFLAGS, guest_rflags),
139 	FIELD(GUEST_PENDING_DBG_EXCEPTIONS, guest_pending_dbg_exceptions),
140 	FIELD(GUEST_SYSENTER_ESP, guest_sysenter_esp),
141 	FIELD(GUEST_SYSENTER_EIP, guest_sysenter_eip),
142 	FIELD(HOST_CR0, host_cr0),
143 	FIELD(HOST_CR3, host_cr3),
144 	FIELD(HOST_CR4, host_cr4),
145 	FIELD(HOST_FS_BASE, host_fs_base),
146 	FIELD(HOST_GS_BASE, host_gs_base),
147 	FIELD(HOST_TR_BASE, host_tr_base),
148 	FIELD(HOST_GDTR_BASE, host_gdtr_base),
149 	FIELD(HOST_IDTR_BASE, host_idtr_base),
150 	FIELD(HOST_IA32_SYSENTER_ESP, host_ia32_sysenter_esp),
151 	FIELD(HOST_IA32_SYSENTER_EIP, host_ia32_sysenter_eip),
152 	FIELD(HOST_RSP, host_rsp),
153 	FIELD(HOST_RIP, host_rip),
154 };
155 const unsigned int nr_vmcs12_fields = ARRAY_SIZE(vmcs12_field_offsets);
156