Skip to content

Commit

Permalink
KVM: Kill off the old hva-based MMU notifier callbacks
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Christopherson <[email protected]>
  • Loading branch information
sean-jc committed Mar 19, 2021
1 parent 862b51d commit 1628380
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 99 deletions.
1 change: 0 additions & 1 deletion arch/arm64/include/asm/kvm_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,6 @@ int __kvm_arm_vcpu_set_events(struct kvm_vcpu *vcpu,
struct kvm_vcpu_events *events);

#define KVM_ARCH_WANT_MMU_NOTIFIER
#define KVM_ARCH_WANT_NEW_MMU_NOTIFIER_APIS

void kvm_arm_halt_guest(struct kvm *kvm);
void kvm_arm_resume_guest(struct kvm *kvm);
Expand Down
1 change: 0 additions & 1 deletion arch/mips/include/asm/kvm_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,6 @@ enum kvm_mips_fault_result kvm_trap_emul_gva_fault(struct kvm_vcpu *vcpu,
bool write);

#define KVM_ARCH_WANT_MMU_NOTIFIER
#define KVM_ARCH_WANT_NEW_MMU_NOTIFIER_APIS

/* Emulation */
int kvm_get_inst(u32 *opc, struct kvm_vcpu *vcpu, u32 *out);
Expand Down
1 change: 0 additions & 1 deletion arch/powerpc/include/asm/kvm_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
#include <linux/mmu_notifier.h>

#define KVM_ARCH_WANT_MMU_NOTIFIER
#define KVM_ARCH_WANT_NEW_MMU_NOTIFIER_APIS

#define HPTEG_CACHE_NUM (1 << 15)
#define HPTEG_HASH_BITS_PTE 13
Expand Down
1 change: 0 additions & 1 deletion arch/x86/include/asm/kvm_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -1718,7 +1718,6 @@ asmlinkage void kvm_spurious_fault(void);
_ASM_EXTABLE(666b, 667b)

#define KVM_ARCH_WANT_MMU_NOTIFIER
#define KVM_ARCH_WANT_NEW_MMU_NOTIFIER_APIS

int kvm_cpu_has_injectable_intr(struct kvm_vcpu *v);
int kvm_cpu_has_interrupt(struct kvm_vcpu *vcpu);
Expand Down
8 changes: 0 additions & 8 deletions include/linux/kvm_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ int kvm_async_pf_wakeup_all(struct kvm_vcpu *vcpu);
#endif

#ifdef KVM_ARCH_WANT_MMU_NOTIFIER
#ifdef KVM_ARCH_WANT_NEW_MMU_NOTIFIER_APIS
struct kvm_gfn_info {
struct kvm_memory_slot *slot;
gfn_t start;
Expand All @@ -231,13 +230,6 @@ bool kvm_unmap_gfn_range(struct kvm *kvm, struct kvm_gfn_info *info);
bool kvm_age_gfn(struct kvm *kvm, struct kvm_gfn_info *info);
bool kvm_test_age_gfn(struct kvm *kvm, struct kvm_gfn_info *info);
bool kvm_set_spte_gfn(struct kvm *kvm, struct kvm_gfn_info *info);
#else
int kvm_unmap_hva_range(struct kvm *kvm,
unsigned long start, unsigned long end, unsigned flags);
int kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte);
int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end);
int kvm_test_age_hva(struct kvm *kvm, unsigned long hva);
#endif /* KVM_ARCH_WANT_NEW_MMU_NOTIFIER_APIS */
#endif

enum {
Expand Down
91 changes: 4 additions & 87 deletions virt/kvm/kvm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,6 @@ static void kvm_mmu_notifier_invalidate_range(struct mmu_notifier *mn,
srcu_read_unlock(&kvm->srcu, idx);
}

#ifdef KVM_ARCH_WANT_NEW_MMU_NOTIFIER_APIS
typedef bool (*hva_handler_t)(struct kvm *kvm, struct kvm_gfn_info *info);

static __always_inline int __kvm_handle_hva_range(struct kvm *kvm,
Expand Down Expand Up @@ -541,50 +540,24 @@ static __always_inline int kvm_handle_hva_range_no_flush(struct mmu_notifier *mn

return ret;
}
#endif /* KVM_ARCH_WANT_NEW_MMU_NOTIFIER_APIS */

static void kvm_mmu_notifier_change_pte(struct mmu_notifier *mn,
struct mm_struct *mm,
unsigned long address,
pte_t pte)
{
#ifdef KVM_ARCH_WANT_NEW_MMU_NOTIFIER_APIS
kvm_handle_hva_range(mn, address, address + 1, pte, kvm_set_spte_gfn);
#else
struct kvm *kvm = mmu_notifier_to_kvm(mn);
int idx;

trace_kvm_set_spte_hva(address);

idx = srcu_read_lock(&kvm->srcu);

KVM_MMU_LOCK(kvm);

kvm->mmu_notifier_seq++;

if (kvm_set_spte_hva(kvm, address, pte))
kvm_flush_remote_tlbs(kvm);

KVM_MMU_UNLOCK(kvm);
srcu_read_unlock(&kvm->srcu, idx);
#endif
kvm_handle_hva_range(mn, address, address + 1, pte, kvm_set_spte_gfn);
}

static int kvm_mmu_notifier_invalidate_range_start(struct mmu_notifier *mn,
const struct mmu_notifier_range *range)
{
#ifdef KVM_ARCH_WANT_NEW_MMU_NOTIFIER_APIS
bool blockable = mmu_notifier_range_blockable(range);
#endif
struct kvm *kvm = mmu_notifier_to_kvm(mn);
#ifndef KVM_ARCH_WANT_NEW_MMU_NOTIFIER_APIS
int need_tlb_flush = 0, idx;

trace_kvm_unmap_hva_range(range->start, range->end);

idx = srcu_read_lock(&kvm->srcu);
#endif

KVM_MMU_LOCK(kvm);
/*
* The count increase must become visible at unlock time as no
Expand All @@ -611,21 +584,10 @@ static int kvm_mmu_notifier_invalidate_range_start(struct mmu_notifier *mn,
max(kvm->mmu_notifier_range_end, range->end);
}

#ifdef KVM_ARCH_WANT_NEW_MMU_NOTIFIER_APIS
__kvm_handle_hva_range(kvm, range->start, range->end, __pte(0),
kvm_unmap_gfn_range, true, blockable);
#else
need_tlb_flush = kvm_unmap_hva_range(kvm, range->start, range->end,
range->flags);
/* we've to flush the tlb before the pages can be freed */
if (need_tlb_flush || kvm->tlbs_dirty)
kvm_flush_remote_tlbs(kvm);
#endif

KVM_MMU_UNLOCK(kvm);
#ifndef KVM_ARCH_WANT_NEW_MMU_NOTIFIER_APIS
srcu_read_unlock(&kvm->srcu, idx);
#endif

return 0;
}
Expand Down Expand Up @@ -659,42 +621,18 @@ static int kvm_mmu_notifier_clear_flush_young(struct mmu_notifier *mn,
unsigned long start,
unsigned long end)
{
#ifdef KVM_ARCH_WANT_NEW_MMU_NOTIFIER_APIS
return kvm_handle_hva_range(mn, start, end, __pte(0), kvm_age_gfn);
#else
struct kvm *kvm = mmu_notifier_to_kvm(mn);
int young, idx;

trace_kvm_age_hva(start, end);

idx = srcu_read_lock(&kvm->srcu);
KVM_MMU_LOCK(kvm);

young = kvm_age_hva(kvm, start, end);
if (young)
kvm_flush_remote_tlbs(kvm);

KVM_MMU_UNLOCK(kvm);
srcu_read_unlock(&kvm->srcu, idx);

return young;
#endif
return kvm_handle_hva_range(mn, start, end, __pte(0), kvm_age_gfn);
}

static int kvm_mmu_notifier_clear_young(struct mmu_notifier *mn,
struct mm_struct *mm,
unsigned long start,
unsigned long end)
{
#ifndef KVM_ARCH_WANT_NEW_MMU_NOTIFIER_APIS
struct kvm *kvm = mmu_notifier_to_kvm(mn);
int young, idx;

trace_kvm_age_hva(start, end);

idx = srcu_read_lock(&kvm->srcu);
KVM_MMU_LOCK(kvm);
#endif
/*
* Even though we do not flush TLB, this will still adversely
* affect performance on pre-Haswell Intel EPT, where there is
Expand All @@ -708,38 +646,17 @@ static int kvm_mmu_notifier_clear_young(struct mmu_notifier *mn,
* cadence. If we find this inaccurate, we might come up with a
* more sophisticated heuristic later.
*/
#ifdef KVM_ARCH_WANT_NEW_MMU_NOTIFIER_APIS
return kvm_handle_hva_range_no_flush(mn, start, end, kvm_age_gfn);
#else
young = kvm_age_hva(kvm, start, end);
KVM_MMU_UNLOCK(kvm);
srcu_read_unlock(&kvm->srcu, idx);

return young;
#endif
}

static int kvm_mmu_notifier_test_young(struct mmu_notifier *mn,
struct mm_struct *mm,
unsigned long address)
{
#ifdef KVM_ARCH_WANT_NEW_MMU_NOTIFIER_APIS
return kvm_handle_hva_range_no_flush(mn, address, address + 1,
kvm_test_age_gfn);
#else
struct kvm *kvm = mmu_notifier_to_kvm(mn);
int young, idx;

trace_kvm_test_age_hva(address);

idx = srcu_read_lock(&kvm->srcu);
KVM_MMU_LOCK(kvm);
young = kvm_test_age_hva(kvm, address);
KVM_MMU_UNLOCK(kvm);
srcu_read_unlock(&kvm->srcu, idx);

return young;
#endif
return kvm_handle_hva_range_no_flush(mn, address, address + 1,
kvm_test_age_gfn);
}

static void kvm_mmu_notifier_release(struct mmu_notifier *mn,
Expand Down

0 comments on commit 1628380

Please sign in to comment.