xref: /linux/arch/x86/kvm/vmx/hyperv.h (revision 4b132aacb0768ac1e652cf517097ea6f237214b9)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __KVM_X86_VMX_HYPERV_H
3 #define __KVM_X86_VMX_HYPERV_H
4 
5 #include <linux/kvm_host.h>
6 #include "vmcs12.h"
7 #include "vmx.h"
8 
9 #define EVMPTR_INVALID (-1ULL)
10 #define EVMPTR_MAP_PENDING (-2ULL)
11 
12 enum nested_evmptrld_status {
13 	EVMPTRLD_DISABLED,
14 	EVMPTRLD_SUCCEEDED,
15 	EVMPTRLD_VMFAIL,
16 	EVMPTRLD_ERROR,
17 };
18 
19 #ifdef CONFIG_KVM_HYPERV
20 static inline bool evmptr_is_valid(u64 evmptr)
21 {
22 	return evmptr != EVMPTR_INVALID && evmptr != EVMPTR_MAP_PENDING;
23 }
24 
25 static inline bool nested_vmx_is_evmptr12_valid(struct vcpu_vmx *vmx)
26 {
27 	return evmptr_is_valid(vmx->nested.hv_evmcs_vmptr);
28 }
29 
30 static inline bool evmptr_is_set(u64 evmptr)
31 {
32 	return evmptr != EVMPTR_INVALID;
33 }
34 
35 static inline bool nested_vmx_is_evmptr12_set(struct vcpu_vmx *vmx)
36 {
37 	return evmptr_is_set(vmx->nested.hv_evmcs_vmptr);
38 }
39 
40 static inline struct hv_enlightened_vmcs *nested_vmx_evmcs(struct vcpu_vmx *vmx)
41 {
42 	return vmx->nested.hv_evmcs;
43 }
44 
45 static inline bool guest_cpuid_has_evmcs(struct kvm_vcpu *vcpu)
46 {
47 	/*
48 	 * eVMCS is exposed to the guest if Hyper-V is enabled in CPUID and
49 	 * eVMCS has been explicitly enabled by userspace.
50 	 */
51 	return vcpu->arch.hyperv_enabled &&
52 	       to_vmx(vcpu)->nested.enlightened_vmcs_enabled;
53 }
54 
55 u64 nested_get_evmptr(struct kvm_vcpu *vcpu);
56 uint16_t nested_get_evmcs_version(struct kvm_vcpu *vcpu);
57 int nested_enable_evmcs(struct kvm_vcpu *vcpu,
58 			uint16_t *vmcs_version);
59 void nested_evmcs_filter_control_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata);
60 int nested_evmcs_check_controls(struct vmcs12 *vmcs12);
61 bool nested_evmcs_l2_tlb_flush_enabled(struct kvm_vcpu *vcpu);
62 void vmx_hv_inject_synthetic_vmexit_post_tlb_flush(struct kvm_vcpu *vcpu);
63 #else
64 static inline bool evmptr_is_valid(u64 evmptr)
65 {
66 	return false;
67 }
68 
69 static inline bool nested_vmx_is_evmptr12_valid(struct vcpu_vmx *vmx)
70 {
71 	return false;
72 }
73 
74 static inline bool evmptr_is_set(u64 evmptr)
75 {
76 	return false;
77 }
78 
79 static inline bool nested_vmx_is_evmptr12_set(struct vcpu_vmx *vmx)
80 {
81 	return false;
82 }
83 
84 static inline struct hv_enlightened_vmcs *nested_vmx_evmcs(struct vcpu_vmx *vmx)
85 {
86 	return NULL;
87 }
88 #endif
89 
90 #endif /* __KVM_X86_VMX_HYPERV_H */
91