Loading...
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * KVM L1 hypervisor optimizations on Hyper-V.
4 */
5
6#ifndef __ARCH_X86_KVM_KVM_ONHYPERV_H__
7#define __ARCH_X86_KVM_KVM_ONHYPERV_H__
8
9#if IS_ENABLED(CONFIG_HYPERV)
10int hv_flush_remote_tlbs_range(struct kvm *kvm, gfn_t gfn, gfn_t nr_pages);
11int hv_flush_remote_tlbs(struct kvm *kvm);
12void hv_track_root_tdp(struct kvm_vcpu *vcpu, hpa_t root_tdp);
13static inline hpa_t hv_get_partition_assist_page(struct kvm_vcpu *vcpu)
14{
15 /*
16 * Partition assist page is something which Hyper-V running in L0
17 * requires from KVM running in L1 before direct TLB flush for L2
18 * guests can be enabled. KVM doesn't currently use the page but to
19 * comply with TLFS it still needs to be allocated. For now, this
20 * is a single page shared among all vCPUs.
21 */
22 struct hv_partition_assist_pg **p_hv_pa_pg =
23 &vcpu->kvm->arch.hv_pa_pg;
24
25 if (!*p_hv_pa_pg)
26 *p_hv_pa_pg = kzalloc(PAGE_SIZE, GFP_KERNEL_ACCOUNT);
27
28 if (!*p_hv_pa_pg)
29 return INVALID_PAGE;
30
31 return __pa(*p_hv_pa_pg);
32}
33#else /* !CONFIG_HYPERV */
34static inline int hv_flush_remote_tlbs(struct kvm *kvm)
35{
36 return -EOPNOTSUPP;
37}
38
39static inline void hv_track_root_tdp(struct kvm_vcpu *vcpu, hpa_t root_tdp)
40{
41}
42#endif /* !CONFIG_HYPERV */
43
44#endif
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * KVM L1 hypervisor optimizations on Hyper-V.
4 */
5
6#ifndef __ARCH_X86_KVM_KVM_ONHYPERV_H__
7#define __ARCH_X86_KVM_KVM_ONHYPERV_H__
8
9#if IS_ENABLED(CONFIG_HYPERV)
10int hv_remote_flush_tlb_with_range(struct kvm *kvm,
11 struct kvm_tlb_range *range);
12int hv_remote_flush_tlb(struct kvm *kvm);
13
14static inline void hv_track_root_tdp(struct kvm_vcpu *vcpu, hpa_t root_tdp)
15{
16 struct kvm_arch *kvm_arch = &vcpu->kvm->arch;
17
18 if (kvm_x86_ops.tlb_remote_flush == hv_remote_flush_tlb) {
19 spin_lock(&kvm_arch->hv_root_tdp_lock);
20 vcpu->arch.hv_root_tdp = root_tdp;
21 if (root_tdp != kvm_arch->hv_root_tdp)
22 kvm_arch->hv_root_tdp = INVALID_PAGE;
23 spin_unlock(&kvm_arch->hv_root_tdp_lock);
24 }
25}
26#else /* !CONFIG_HYPERV */
27static inline void hv_track_root_tdp(struct kvm_vcpu *vcpu, hpa_t root_tdp)
28{
29}
30#endif /* !CONFIG_HYPERV */
31
32#endif