KVM: PPC: Book3S HV: Fix race between kvm_unmap_hva_range and MMU mode switch
Paul Mackerras
AppliedQuoted 17 lines · Paul Mackerras
Testing has revealed an occasional crash which appears to be caused by a race between
kvmppc_switch_mmu_to_hptandkvm_unmap_hva_range_hv. The symptom is a NULL pointer dereference in__find_linux_pte()called fromkvm_unmap_radix()withkvm->arch.pgtable= NULL.Looking at
kvmppc_switch_mmu_to_hpt(), it does indeed clearkvm->arch.pgtable(viakvmppc_free_radix()) before settingkvm->arch.radixto NULL, and there is nothing to preventkvm_unmap_hva_range_hv()or the other MMU callback functions from being called concurrently withkvmppc_switch_mmu_to_hpt()orkvmppc_switch_mmu_to_radix().This patch therefore adds calls to spin_lock/unlock on the
kvm->mmu_lockaround the assignments tokvm->arch.radix, and makes sure that the partition-scoped radix tree or HPT is only freed after changingkvm->arch.radix.
Quoted 6 lines
This also takes the
kvm->mmu_lockinkvmppc_rmap_reset()to make sure that the clearing of each rmap array (one per memslot) doesn't happen concurrently with use of the array in thekvm_unmap_hva_range_hv()or the other MMU callbacks.Signed-off-by Paul Mackerras <[email protected]>
Applied to my kvm-ppc-next branch.