1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __KVM_X86_VMX_CAPS_H
3 #define __KVM_X86_VMX_CAPS_H
7 struct nested_vmx_msrs
{
9 * We only store the "true" versions of the VMX capability MSRs. We
10 * generate the "non-true" versions by setting the must-be-1 bits
11 * according to the SDM.
13 u32 procbased_ctls_low
;
14 u32 procbased_ctls_high
;
15 u32 secondary_ctls_low
;
16 u32 secondary_ctls_high
;
17 u32 pinbased_ctls_low
;
18 u32 pinbased_ctls_high
;
41 u32 pin_based_exec_ctrl
;
42 u32 cpu_based_exec_ctrl
;
43 u32 cpu_based_2nd_exec_ctrl
;
46 struct nested_vmx_msrs nested
;
48 extern struct vmcs_config vmcs_config
;
50 struct vmx_capability
{
54 extern struct vmx_capability vmx_capability
;
56 static inline bool cpu_has_vmx_basic_inout(void)
58 return (((u64
)vmcs_config
.basic_cap
<< 32) & VMX_BASIC_INOUT
);
61 static inline bool cpu_has_virtual_nmis(void)
63 return vmcs_config
.pin_based_exec_ctrl
& PIN_BASED_VIRTUAL_NMIS
;
66 static inline bool cpu_has_vmx_preemption_timer(void)
68 return vmcs_config
.pin_based_exec_ctrl
&
69 PIN_BASED_VMX_PREEMPTION_TIMER
;
72 static inline bool cpu_has_vmx_posted_intr(void)
74 return IS_ENABLED(CONFIG_X86_LOCAL_APIC
) &&
75 vmcs_config
.pin_based_exec_ctrl
& PIN_BASED_POSTED_INTR
;
78 static inline bool cpu_has_load_ia32_efer(void)
80 return (vmcs_config
.vmentry_ctrl
& VM_ENTRY_LOAD_IA32_EFER
) &&
81 (vmcs_config
.vmexit_ctrl
& VM_EXIT_LOAD_IA32_EFER
);
84 static inline bool cpu_has_load_perf_global_ctrl(void)
86 return (vmcs_config
.vmentry_ctrl
& VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL
) &&
87 (vmcs_config
.vmexit_ctrl
& VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL
);
90 static inline bool vmx_mpx_supported(void)
92 return (vmcs_config
.vmexit_ctrl
& VM_EXIT_CLEAR_BNDCFGS
) &&
93 (vmcs_config
.vmentry_ctrl
& VM_ENTRY_LOAD_BNDCFGS
);
96 static inline bool cpu_has_vmx_tpr_shadow(void)
98 return vmcs_config
.cpu_based_exec_ctrl
& CPU_BASED_TPR_SHADOW
;
101 static inline bool cpu_need_tpr_shadow(struct kvm_vcpu
*vcpu
)
103 return cpu_has_vmx_tpr_shadow() && lapic_in_kernel(vcpu
);
106 static inline bool cpu_has_vmx_msr_bitmap(void)
108 return vmcs_config
.cpu_based_exec_ctrl
& CPU_BASED_USE_MSR_BITMAPS
;
111 static inline bool cpu_has_secondary_exec_ctrls(void)
113 return vmcs_config
.cpu_based_exec_ctrl
&
114 CPU_BASED_ACTIVATE_SECONDARY_CONTROLS
;
117 static inline bool cpu_has_vmx_virtualize_apic_accesses(void)
119 return vmcs_config
.cpu_based_2nd_exec_ctrl
&
120 SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES
;
123 static inline bool cpu_has_vmx_ept(void)
125 return vmcs_config
.cpu_based_2nd_exec_ctrl
&
126 SECONDARY_EXEC_ENABLE_EPT
;
129 static inline bool vmx_umip_emulated(void)
131 return vmcs_config
.cpu_based_2nd_exec_ctrl
&
135 static inline bool cpu_has_vmx_rdtscp(void)
137 return vmcs_config
.cpu_based_2nd_exec_ctrl
&
138 SECONDARY_EXEC_RDTSCP
;
141 static inline bool cpu_has_vmx_virtualize_x2apic_mode(void)
143 return vmcs_config
.cpu_based_2nd_exec_ctrl
&
144 SECONDARY_EXEC_VIRTUALIZE_X2APIC_MODE
;
147 static inline bool cpu_has_vmx_vpid(void)
149 return vmcs_config
.cpu_based_2nd_exec_ctrl
&
150 SECONDARY_EXEC_ENABLE_VPID
;
153 static inline bool cpu_has_vmx_wbinvd_exit(void)
155 return vmcs_config
.cpu_based_2nd_exec_ctrl
&
156 SECONDARY_EXEC_WBINVD_EXITING
;
159 static inline bool cpu_has_vmx_unrestricted_guest(void)
161 return vmcs_config
.cpu_based_2nd_exec_ctrl
&
162 SECONDARY_EXEC_UNRESTRICTED_GUEST
;
165 static inline bool cpu_has_vmx_apic_register_virt(void)
167 return vmcs_config
.cpu_based_2nd_exec_ctrl
&
168 SECONDARY_EXEC_APIC_REGISTER_VIRT
;
171 static inline bool cpu_has_vmx_virtual_intr_delivery(void)
173 return vmcs_config
.cpu_based_2nd_exec_ctrl
&
174 SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY
;
177 static inline bool cpu_has_vmx_ple(void)
179 return vmcs_config
.cpu_based_2nd_exec_ctrl
&
180 SECONDARY_EXEC_PAUSE_LOOP_EXITING
;
183 static inline bool vmx_rdrand_supported(void)
185 return vmcs_config
.cpu_based_2nd_exec_ctrl
&
186 SECONDARY_EXEC_RDRAND_EXITING
;
189 static inline bool cpu_has_vmx_invpcid(void)
191 return vmcs_config
.cpu_based_2nd_exec_ctrl
&
192 SECONDARY_EXEC_ENABLE_INVPCID
;
195 static inline bool cpu_has_vmx_vmfunc(void)
197 return vmcs_config
.cpu_based_2nd_exec_ctrl
&
198 SECONDARY_EXEC_ENABLE_VMFUNC
;
201 static inline bool cpu_has_vmx_shadow_vmcs(void)
205 /* check if the cpu supports writing r/o exit information fields */
206 rdmsrl(MSR_IA32_VMX_MISC
, vmx_msr
);
207 if (!(vmx_msr
& MSR_IA32_VMX_MISC_VMWRITE_SHADOW_RO_FIELDS
))
210 return vmcs_config
.cpu_based_2nd_exec_ctrl
&
211 SECONDARY_EXEC_SHADOW_VMCS
;
214 static inline bool cpu_has_vmx_encls_vmexit(void)
216 return vmcs_config
.cpu_based_2nd_exec_ctrl
&
217 SECONDARY_EXEC_ENCLS_EXITING
;
220 static inline bool vmx_rdseed_supported(void)
222 return vmcs_config
.cpu_based_2nd_exec_ctrl
&
223 SECONDARY_EXEC_RDSEED_EXITING
;
226 static inline bool cpu_has_vmx_pml(void)
228 return vmcs_config
.cpu_based_2nd_exec_ctrl
& SECONDARY_EXEC_ENABLE_PML
;
231 static inline bool vmx_xsaves_supported(void)
233 return vmcs_config
.cpu_based_2nd_exec_ctrl
&
234 SECONDARY_EXEC_XSAVES
;
237 static inline bool cpu_has_vmx_tsc_scaling(void)
239 return vmcs_config
.cpu_based_2nd_exec_ctrl
&
240 SECONDARY_EXEC_TSC_SCALING
;
243 static inline bool cpu_has_vmx_apicv(void)
245 return cpu_has_vmx_apic_register_virt() &&
246 cpu_has_vmx_virtual_intr_delivery() &&
247 cpu_has_vmx_posted_intr();
250 static inline bool cpu_has_vmx_flexpriority(void)
252 return cpu_has_vmx_tpr_shadow() &&
253 cpu_has_vmx_virtualize_apic_accesses();
256 static inline bool cpu_has_vmx_ept_execute_only(void)
258 return vmx_capability
.ept
& VMX_EPT_EXECUTE_ONLY_BIT
;
261 static inline bool cpu_has_vmx_ept_4levels(void)
263 return vmx_capability
.ept
& VMX_EPT_PAGE_WALK_4_BIT
;
266 static inline bool cpu_has_vmx_ept_5levels(void)
268 return vmx_capability
.ept
& VMX_EPT_PAGE_WALK_5_BIT
;
271 static inline bool cpu_has_vmx_ept_mt_wb(void)
273 return vmx_capability
.ept
& VMX_EPTP_WB_BIT
;
276 static inline bool cpu_has_vmx_ept_2m_page(void)
278 return vmx_capability
.ept
& VMX_EPT_2MB_PAGE_BIT
;
281 static inline bool cpu_has_vmx_ept_1g_page(void)
283 return vmx_capability
.ept
& VMX_EPT_1GB_PAGE_BIT
;
286 static inline bool cpu_has_vmx_ept_ad_bits(void)
288 return vmx_capability
.ept
& VMX_EPT_AD_BIT
;
291 static inline bool cpu_has_vmx_invept_context(void)
293 return vmx_capability
.ept
& VMX_EPT_EXTENT_CONTEXT_BIT
;
296 static inline bool cpu_has_vmx_invept_global(void)
298 return vmx_capability
.ept
& VMX_EPT_EXTENT_GLOBAL_BIT
;
301 static inline bool cpu_has_vmx_invvpid(void)
303 return vmx_capability
.vpid
& VMX_VPID_INVVPID_BIT
;
306 static inline bool cpu_has_vmx_invvpid_individual_addr(void)
308 return vmx_capability
.vpid
& VMX_VPID_EXTENT_INDIVIDUAL_ADDR_BIT
;
311 static inline bool cpu_has_vmx_invvpid_single(void)
313 return vmx_capability
.vpid
& VMX_VPID_EXTENT_SINGLE_CONTEXT_BIT
;
316 static inline bool cpu_has_vmx_invvpid_global(void)
318 return vmx_capability
.vpid
& VMX_VPID_EXTENT_GLOBAL_CONTEXT_BIT
;
321 #endif /* __KVM_X86_VMX_CAPS_H */