Skip to content

Commit 72f3104

Browse files
author
Marc Zyngier
committed
arm/arm64: KVM: Take mmap_sem in kvm_arch_prepare_memory_region
We don't hold the mmap_sem while searching for VMAs (via find_vma), in kvm_arch_prepare_memory_region, which can end up in expected failures. Fixes: commit 8eef912 ("arm/arm64: KVM: map MMIO regions at creation time") Cc: Ard Biesheuvel <[email protected]> Cc: Eric Auger <[email protected]> Cc: [email protected] # v3.18+ Reviewed-by: Christoffer Dall <[email protected]> [ Handle dirty page logging failure case ] Signed-off-by: Suzuki K Poulose <[email protected]> Signed-off-by: Marc Zyngier <[email protected]>
1 parent 90f6e15 commit 72f3104

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

arch/arm/kvm/mmu.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,6 +1803,7 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
18031803
(KVM_PHYS_SIZE >> PAGE_SHIFT))
18041804
return -EFAULT;
18051805

1806+
down_read(&current->mm->mmap_sem);
18061807
/*
18071808
* A memory region could potentially cover multiple VMAs, and any holes
18081809
* between them, so iterate over all of them to find out if we can map
@@ -1846,8 +1847,10 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
18461847
pa += vm_start - vma->vm_start;
18471848

18481849
/* IO region dirty page logging not allowed */
1849-
if (memslot->flags & KVM_MEM_LOG_DIRTY_PAGES)
1850-
return -EINVAL;
1850+
if (memslot->flags & KVM_MEM_LOG_DIRTY_PAGES) {
1851+
ret = -EINVAL;
1852+
goto out;
1853+
}
18511854

18521855
ret = kvm_phys_addr_ioremap(kvm, gpa, pa,
18531856
vm_end - vm_start,
@@ -1859,14 +1862,16 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
18591862
} while (hva < reg_end);
18601863

18611864
if (change == KVM_MR_FLAGS_ONLY)
1862-
return ret;
1865+
goto out;
18631866

18641867
spin_lock(&kvm->mmu_lock);
18651868
if (ret)
18661869
unmap_stage2_range(kvm, mem->guest_phys_addr, mem->memory_size);
18671870
else
18681871
stage2_flush_memslot(kvm, memslot);
18691872
spin_unlock(&kvm->mmu_lock);
1873+
out:
1874+
up_read(&current->mm->mmap_sem);
18701875
return ret;
18711876
}
18721877

0 commit comments

Comments
 (0)