[PATCH 6.6.y 06/17] KVM: x86/mmu: Flush all TLB entries, not a precise range, when yielding
From: Paolo Bonzini
Date: Fri Dec 04 2026 - 13:05:48 EST
From: Kyle Zeng <kylebot@xxxxxxxxxx>
[ Upstream commit dc3709f44c9617c9fa6d5d0e71dc5b82f47a57b7 ]
Flush *all* TLB entries, not just the currently visible range of GFNs, when
yielding and dropping mmu_lock the shadow MMU, as a pending flush may cover
a bigger range than what is currently in scope, e.g. from a different
memslot or from a different page-table level. Flushing only the range of
GFNs that are directly relevant to the current slot+level result in KVM
failing to TLB flush entries for previously-zapped SPTEs when running on
Hyper-V (the only time the range-based flushing is used).
Fixes: f285c633cb6d ("kvm: mmu: Used range based flushing in slot_handle_level_range")
Cc: stable@xxxxxxxxxxxxxxx
Reported-by: Kevin Liu <kevin.liu@xxxxxxxxxx>
Reported-by: Stefan Teodorescu <fane@xxxxxxxxxx>
Reported-by: Ulfar Erlingsson <ulfar@xxxxxxxxxx>
Signed-off-by: Kyle Zeng <kylebot@xxxxxxxxxx>
[sean: split to separate patch, write changelog, rewrite comment, add more reporters]
Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
Link: https://patch.msgid.link/20261119172647.64295-4-seanjc@xxxxxxxxxx
Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
---
arch/x86/kvm/mmu/mmu.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index b79f937dd59e..b0ed5c2f1086 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -5954,8 +5954,12 @@ static __always_inline bool __walk_slot_rmaps(struct kvm *kvm,
if (need_resched() || rwlock_needbreak(&kvm->mmu_lock)) {
if (flush && flush_on_yield) {
- kvm_flush_remote_tlbs_range(kvm, start_gfn,
- iterator.gfn - start_gfn + 1);
+ /*
+ * DO NOT do a range-based flush, as the caller
+ * may be zapping a range greater than what is
+ * visible here!
+ */
+ kvm_flush_remote_tlbs(kvm);
flush = false;
}
cond_resched_rwlock_write(&kvm->mmu_lock);
--
2.56.1