]> www.infradead.org Git - users/hch/misc.git/commitdiff
KVM: arm64: Mark freed S2 MMUs as invalid
authorMarc Zyngier <maz@kernel.org>
Fri, 5 Sep 2025 07:28:59 +0000 (08:28 +0100)
committerOliver Upton <oliver.upton@linux.dev>
Fri, 5 Sep 2025 07:43:14 +0000 (00:43 -0700)
When freeing an S2 MMU, we free the associated pgd, but omit to
mark the structure as invalid. Subsequently, a call to
kvm_nested_s2_unmap() would pick these invalid S2 MMUs and
pass them down the teardown path.

This ends up with a nasty warning as we try to unmap an unallocated
set of page tables.

Fix this by making the S2 MMU invalid on freeing the pgd by calling
kvm_init_nested_s2_mmu().

Fixes: 4f128f8e1aaa ("KVM: arm64: nv: Support multiple nested Stage-2 mmu structures")
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20250905072859.211369-1-maz@kernel.org
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
arch/arm64/kvm/mmu.c

index 86f3d80daf37aff30e41ee0f244b0499acae3d2d..0f4271458a079e4d1b0845c4b2f7f3ed46175f36 100644 (file)
@@ -1106,6 +1106,10 @@ void kvm_free_stage2_pgd(struct kvm_s2_mmu *mmu)
                mmu->pgt = NULL;
                free_percpu(mmu->last_vcpu_ran);
        }
+
+       if (kvm_is_nested_s2_mmu(kvm, mmu))
+               kvm_init_nested_s2_mmu(mmu);
+
        write_unlock(&kvm->mmu_lock);
 
        if (pgt) {