KVM: SVM: Add a proper field for Hyper-V VMCB enlightenments
[platform/kernel/linux-starfive.git] / arch / x86 / kvm / svm / svm_onhyperv.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * KVM L1 hypervisor optimizations on Hyper-V for SVM.
4  */
5
6 #include <linux/kvm_host.h>
7
8 #include <asm/mshyperv.h>
9
10 #include "svm.h"
11 #include "svm_ops.h"
12
13 #include "hyperv.h"
14 #include "kvm_onhyperv.h"
15 #include "svm_onhyperv.h"
16
17 int svm_hv_enable_direct_tlbflush(struct kvm_vcpu *vcpu)
18 {
19         struct hv_enlightenments *hve;
20         struct hv_partition_assist_pg **p_hv_pa_pg =
21                         &to_kvm_hv(vcpu->kvm)->hv_pa_pg;
22
23         if (!*p_hv_pa_pg)
24                 *p_hv_pa_pg = kzalloc(PAGE_SIZE, GFP_KERNEL);
25
26         if (!*p_hv_pa_pg)
27                 return -ENOMEM;
28
29         hve = &to_svm(vcpu)->vmcb->control.hv_enlightenments;
30
31         hve->partition_assist_page = __pa(*p_hv_pa_pg);
32         hve->hv_vm_id = (unsigned long)vcpu->kvm;
33         if (!hve->hv_enlightenments_control.nested_flush_hypercall) {
34                 hve->hv_enlightenments_control.nested_flush_hypercall = 1;
35                 vmcb_mark_dirty(to_svm(vcpu)->vmcb, HV_VMCB_NESTED_ENLIGHTENMENTS);
36         }
37
38         return 0;
39 }
40