From 348acf74c966406457bc2d3ac5db3a99a01aaedb Mon Sep 17 00:00:00 2001 From: Yu Zhang Date: Sat, 27 Jan 2024 19:07:03 +0800 Subject: [PATCH] KVM: mmu: increase the mmu_notifier_count for legacy APIs Intel inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I8YDCS CVE: NA ---------------------------------------------------------------------- Fix kvm_mmu_notifier_invalidate_range_start(), which missed to increase the mmu_notifier_count. Otherwise BUG_ON() could be triggered later, by kvm_mmu_notifier_invalidate_range_end(), on platforms using legacy KVM MMU notifier APIs. Fixes: ac63cf0a8e38 ("KVM: Move MMU notifier's mmu_lock acquisition into common helper") Reported-by: xianglai li Signed-off-by: Yu Zhang --- virt/kvm/kvm_main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 4c63787c7b08..9166ef044bcf 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -662,6 +662,7 @@ static __always_inline int kvm_handle_hva_range_no_flush(struct mmu_notifier *mn return __kvm_handle_hva_range(kvm, &range); } +#endif /* KVM_ARCH_WANT_NEW_MMU_NOTIFIER_APIS */ static void kvm_inc_notifier_count(struct kvm *kvm, unsigned long start, unsigned long end) @@ -691,7 +692,6 @@ static void kvm_inc_notifier_count(struct kvm *kvm, unsigned long start, max(kvm->mmu_notifier_range_end, end); } } -#endif /* KVM_ARCH_WANT_NEW_MMU_NOTIFIER_APIS */ static void kvm_mmu_notifier_change_pte(struct mmu_notifier *mn, struct mm_struct *mm, @@ -748,6 +748,9 @@ static int kvm_mmu_notifier_invalidate_range_start(struct mmu_notifier *mn, #else idx = srcu_read_lock(&kvm->srcu); KVM_MMU_LOCK(kvm); + + kvm_inc_notifier_count(kvm, range->start, range->end); + 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 */ -- Gitee