The patch titled Subject: powerpc/mmu: drop mmap_sem now that locked_vm is atomic has been added to the -mm tree. Its filename is powerpc-mmu-drop-mmap_sem-now-that-locked_vm-is-atomic.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/powerpc-mmu-drop-mmap_sem-now-that-locked_vm-is-atomic.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/powerpc-mmu-drop-mmap_sem-now-that-locked_vm-is-atomic.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Daniel Jordan <daniel.m.jordan@xxxxxxxxxx> Subject: powerpc/mmu: drop mmap_sem now that locked_vm is atomic With locked_vm now an atomic, there is no need to take mmap_sem as writer. Delete and refactor accordingly. Link: http://lkml.kernel.org/r/20190402204158.27582-6-daniel.m.jordan@xxxxxxxxxx Signed-off-by: Daniel Jordan <daniel.m.jordan@xxxxxxxxxx> Cc: Alexey Kardashevskiy <aik@xxxxxxxxx> Cc: Benjamin Herrenschmidt <benh@xxxxxxxxxxxxxxxxxxx> Cc: Christoph Lameter <cl@xxxxxxxxx> Cc: Davidlohr Bueso <dave@xxxxxxxxxxxx> Cc: Michael Ellerman <mpe@xxxxxxxxxxxxxx> Cc: Paul Mackerras <paulus@xxxxxxxxx> Cc: Alan Tull <atull@xxxxxxxxxx> Cc: Alex Williamson <alex.williamson@xxxxxxxxxx> Cc: Ira Weiny <ira.weiny@xxxxxxxxx> Cc: Jason Gunthorpe <jgg@xxxxxxxxxxxx> Cc: Moritz Fischer <mdf@xxxxxxxxxx> Cc: Paul Mackerras <paulus@xxxxxxxxxx> Cc: Wu Hao <hao.wu@xxxxxxxxx> Cc: Mark Rutland <mark.rutland@xxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- arch/powerpc/mm/mmu_context_iommu.c | 27 ++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) --- a/arch/powerpc/mm/mmu_context_iommu.c~powerpc-mmu-drop-mmap_sem-now-that-locked_vm-is-atomic +++ a/arch/powerpc/mm/mmu_context_iommu.c @@ -54,34 +54,29 @@ struct mm_iommu_table_group_mem_t { static long mm_iommu_adjust_locked_vm(struct mm_struct *mm, unsigned long npages, bool incr) { - long ret = 0, locked, lock_limit; + long ret = 0; + unsigned long lock_limit; s64 locked_vm; if (!npages) return 0; - down_write(&mm->mmap_sem); - locked_vm = atomic64_read(&mm->locked_vm); if (incr) { - locked = locked_vm + npages; lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT; - if (locked > lock_limit && !capable(CAP_IPC_LOCK)) + locked_vm = atomic64_add_return(npages, &mm->locked_vm); + if (locked_vm > lock_limit && !capable(CAP_IPC_LOCK)) { ret = -ENOMEM; - else - atomic64_add(npages, &mm->locked_vm); + atomic64_sub(npages, &mm->locked_vm); + } } else { - if (WARN_ON_ONCE(npages > locked_vm)) - npages = locked_vm; - atomic64_sub(npages, &mm->locked_vm); + locked_vm = atomic64_sub_return(npages, &mm->locked_vm); + WARN_ON_ONCE(locked_vm < 0); } - pr_debug("[%d] RLIMIT_MEMLOCK HASH64 %c%ld %ld/%ld\n", - current ? current->pid : 0, - incr ? '+' : '-', - npages << PAGE_SHIFT, - atomic64_read(&mm->locked_vm) << PAGE_SHIFT, + pr_debug("[%d] RLIMIT_MEMLOCK HASH64 %c%lu %lld/%lu\n", + current ? current->pid : 0, incr ? '+' : '-', + npages << PAGE_SHIFT, locked_vm << PAGE_SHIFT, rlimit(RLIMIT_MEMLOCK)); - up_write(&mm->mmap_sem); return ret; } _ Patches currently in -mm which might be from daniel.m.jordan@xxxxxxxxxx are mm-change-locked_vms-type-from-unsigned-long-to-atomic64_t.patch vfio-type1-drop-mmap_sem-now-that-locked_vm-is-atomic.patch vfio-spapr_tce-drop-mmap_sem-now-that-locked_vm-is-atomic.patch fpga-dlf-afu-drop-mmap_sem-now-that-locked_vm-is-atomic.patch powerpc-mmu-drop-mmap_sem-now-that-locked_vm-is-atomic.patch kvm-book3s-drop-mmap_sem-now-that-locked_vm-is-atomic.patch