[PATCH 2/3] KVM: MMU: unconditionally clear MMIO cache on root rebuild
From: Paolo Bonzini
Date: Thu Jun 04 2026 - 12:17:04 EST
Upon changing CR3, the MMIO cache becomes invalid because the
GVA->GPA mapping has changed. However, kvm_load_new_pgd() calls
vcpu_clear_mmio_info() call only if the fast switch succeeded.
The early-return path instead leaves the root invalid; the next entry
then calls kvm_mmu_reload() and from there kvm_mmu_load().
kvm_mmu_load() calls kvm_mmu_sync_roots(), which clears the MMIO
cache, but one combination that falls through is root_role.direct==1,
i.e. CR0.PG=0, for which kvm_mmu_sync_roots() bails before reaching the
call to vcpu_clear_mmio_info().
That combination is barely reachable: a valid direct root is pretty much
always a fast-switch success because it does not check the PGD for a
match. The early return for a direct root thus requires the current root
to already be invalid, and kvm_mmu_unload() itself clears the MMIO cache.
That said, doing an independent clear in the style of kvm_mmu_new_pgd()
is more obviously correct and basically free, so harden it.
Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
---
arch/x86/kvm/mmu/mmu.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c
index f8aa7eda661e..6689c9f8ae16 100644
--- a/arch/x86/kvm/mmu/mmu.c
+++ b/arch/x86/kvm/mmu/mmu.c
@@ -6138,6 +6138,7 @@ int kvm_mmu_load(struct kvm_vcpu *vcpu)
if (r)
goto out;
+ vcpu_clear_mmio_info(vcpu, MMIO_GVA_ANY);
kvm_mmu_sync_roots(vcpu);
kvm_mmu_load_pgd(vcpu);
--
2.52.0