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