1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * KVM L1 hypervisor optimizations on Hyper-V for SVM.
6 #ifndef __ARCH_X86_KVM_SVM_ONHYPERV_H__
7 #define __ARCH_X86_KVM_SVM_ONHYPERV_H__
9 #if IS_ENABLED(CONFIG_HYPERV)
11 #include "kvm_onhyperv.h"
12 #include "svm/hyperv.h"
14 static struct kvm_x86_ops svm_x86_ops;
16 int svm_hv_enable_direct_tlbflush(struct kvm_vcpu *vcpu);
18 static inline void svm_hv_init_vmcb(struct vmcb *vmcb)
20 struct hv_enlightenments *hve =
21 (struct hv_enlightenments *)vmcb->control.reserved_sw;
24 ms_hyperv.nested_features & HV_X64_NESTED_ENLIGHTENED_TLB)
25 hve->hv_enlightenments_control.enlightened_npt_tlb = 1;
27 if (ms_hyperv.nested_features & HV_X64_NESTED_MSR_BITMAP)
28 hve->hv_enlightenments_control.msr_bitmap = 1;
31 static inline void svm_hv_hardware_setup(void)
34 ms_hyperv.nested_features & HV_X64_NESTED_ENLIGHTENED_TLB) {
35 pr_info("kvm: Hyper-V enlightened NPT TLB flush enabled\n");
36 svm_x86_ops.tlb_remote_flush = hv_remote_flush_tlb;
37 svm_x86_ops.tlb_remote_flush_with_range =
38 hv_remote_flush_tlb_with_range;
41 if (ms_hyperv.nested_features & HV_X64_NESTED_DIRECT_FLUSH) {
44 pr_info("kvm: Hyper-V Direct TLB Flush enabled\n");
45 for_each_online_cpu(cpu) {
46 struct hv_vp_assist_page *vp_ap =
47 hv_get_vp_assist_page(cpu);
52 vp_ap->nested_control.features.directhypercall = 1;
54 svm_x86_ops.enable_direct_tlbflush =
55 svm_hv_enable_direct_tlbflush;
59 static inline void svm_hv_vmcb_dirty_nested_enlightenments(
60 struct kvm_vcpu *vcpu)
62 struct vmcb *vmcb = to_svm(vcpu)->vmcb;
63 struct hv_enlightenments *hve =
64 (struct hv_enlightenments *)vmcb->control.reserved_sw;
66 if (hve->hv_enlightenments_control.msr_bitmap)
67 vmcb_mark_dirty(vmcb, VMCB_HV_NESTED_ENLIGHTENMENTS);
70 static inline void svm_hv_update_vp_id(struct vmcb *vmcb,
71 struct kvm_vcpu *vcpu)
73 struct hv_enlightenments *hve =
74 (struct hv_enlightenments *)vmcb->control.reserved_sw;
75 u32 vp_index = kvm_hv_get_vpindex(vcpu);
77 if (hve->hv_vp_id != vp_index) {
78 hve->hv_vp_id = vp_index;
79 vmcb_mark_dirty(vmcb, VMCB_HV_NESTED_ENLIGHTENMENTS);
84 static inline void svm_hv_init_vmcb(struct vmcb *vmcb)
88 static inline void svm_hv_hardware_setup(void)
92 static inline void svm_hv_vmcb_dirty_nested_enlightenments(
93 struct kvm_vcpu *vcpu)
97 static inline void svm_hv_update_vp_id(struct vmcb *vmcb,
98 struct kvm_vcpu *vcpu)
101 #endif /* CONFIG_HYPERV */
103 #endif /* __ARCH_X86_KVM_SVM_ONHYPERV_H__ */