Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/arch/x86/kvm/svm/svm_onhyperv.c
29524 views
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
static int svm_hv_enable_l2_tlb_flush(struct kvm_vcpu *vcpu)
19
{
20
struct hv_vmcb_enlightenments *hve;
21
hpa_t partition_assist_page = hv_get_partition_assist_page(vcpu);
22
23
if (partition_assist_page == INVALID_PAGE)
24
return -ENOMEM;
25
26
hve = &to_svm(vcpu)->vmcb->control.hv_enlightenments;
27
28
hve->partition_assist_page = partition_assist_page;
29
hve->hv_vm_id = (unsigned long)vcpu->kvm;
30
if (!hve->hv_enlightenments_control.nested_flush_hypercall) {
31
hve->hv_enlightenments_control.nested_flush_hypercall = 1;
32
vmcb_mark_dirty(to_svm(vcpu)->vmcb, HV_VMCB_NESTED_ENLIGHTENMENTS);
33
}
34
35
return 0;
36
}
37
38
__init void svm_hv_hardware_setup(void)
39
{
40
if (npt_enabled &&
41
ms_hyperv.nested_features & HV_X64_NESTED_ENLIGHTENED_TLB) {
42
pr_info(KBUILD_MODNAME ": Hyper-V enlightened NPT TLB flush enabled\n");
43
svm_x86_ops.flush_remote_tlbs = hv_flush_remote_tlbs;
44
svm_x86_ops.flush_remote_tlbs_range = hv_flush_remote_tlbs_range;
45
}
46
47
if (ms_hyperv.nested_features & HV_X64_NESTED_DIRECT_FLUSH) {
48
int cpu;
49
50
pr_info(KBUILD_MODNAME ": Hyper-V Direct TLB Flush enabled\n");
51
for_each_online_cpu(cpu) {
52
struct hv_vp_assist_page *vp_ap =
53
hv_get_vp_assist_page(cpu);
54
55
if (!vp_ap)
56
continue;
57
58
vp_ap->nested_control.features.directhypercall = 1;
59
}
60
svm_x86_ops.enable_l2_tlb_flush =
61
svm_hv_enable_l2_tlb_flush;
62
}
63
}
64
65