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 = &vmcb->control.hv_enlightenments;
22 BUILD_BUG_ON(sizeof(vmcb->control.hv_enlightenments) !=
23 sizeof(vmcb->control.reserved_sw));
26 ms_hyperv.nested_features & HV_X64_NESTED_ENLIGHTENED_TLB)
27 hve->hv_enlightenments_control.enlightened_npt_tlb = 1;
29 if (ms_hyperv.nested_features & HV_X64_NESTED_MSR_BITMAP)
30 hve->hv_enlightenments_control.msr_bitmap = 1;
33 static inline __init void svm_hv_hardware_setup(void)
36 ms_hyperv.nested_features & HV_X64_NESTED_ENLIGHTENED_TLB) {
37 pr_info("kvm: Hyper-V enlightened NPT TLB flush enabled\n");
38 svm_x86_ops.tlb_remote_flush = hv_remote_flush_tlb;
39 svm_x86_ops.tlb_remote_flush_with_range =
40 hv_remote_flush_tlb_with_range;
43 if (ms_hyperv.nested_features & HV_X64_NESTED_DIRECT_FLUSH) {
46 pr_info("kvm: Hyper-V Direct TLB Flush enabled\n");
47 for_each_online_cpu(cpu) {
48 struct hv_vp_assist_page *vp_ap =
49 hv_get_vp_assist_page(cpu);
54 vp_ap->nested_control.features.directhypercall = 1;
56 svm_x86_ops.enable_direct_tlbflush =
57 svm_hv_enable_direct_tlbflush;
61 static inline void svm_hv_vmcb_dirty_nested_enlightenments(
62 struct kvm_vcpu *vcpu)
64 struct vmcb *vmcb = to_svm(vcpu)->vmcb;
65 struct hv_enlightenments *hve = &vmcb->control.hv_enlightenments;
67 if (hve->hv_enlightenments_control.msr_bitmap)
68 vmcb_mark_dirty(vmcb, HV_VMCB_NESTED_ENLIGHTENMENTS);
71 static inline void svm_hv_update_vp_id(struct vmcb *vmcb, struct kvm_vcpu *vcpu)
73 struct hv_enlightenments *hve = &vmcb->control.hv_enlightenments;
74 u32 vp_index = kvm_hv_get_vpindex(vcpu);
76 if (hve->hv_vp_id != vp_index) {
77 hve->hv_vp_id = vp_index;
78 vmcb_mark_dirty(vmcb, HV_VMCB_NESTED_ENLIGHTENMENTS);
83 static inline void svm_hv_init_vmcb(struct vmcb *vmcb)
87 static inline __init void svm_hv_hardware_setup(void)
91 static inline void svm_hv_vmcb_dirty_nested_enlightenments(
92 struct kvm_vcpu *vcpu)
96 static inline void svm_hv_update_vp_id(struct vmcb *vmcb,
97 struct kvm_vcpu *vcpu)
100 #endif /* CONFIG_HYPERV */
102 #endif /* __ARCH_X86_KVM_SVM_ONHYPERV_H__ */