The patch titled Subject: kvm/book3s: drop mmap_sem now that locked_vm is atomic has been added to the -mm tree. Its filename is kvm-book3s-drop-mmap_sem-now-that-locked_vm-is-atomic.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/kvm-book3s-drop-mmap_sem-now-that-locked_vm-is-atomic.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/kvm-book3s-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: kvm/book3s: 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-7-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@xxxxxxxxxx> 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@xxxxxxxxx> Cc: Wu Hao <hao.wu@xxxxxxxxx> Cc: Mark Rutland <mark.rutland@xxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- arch/powerpc/kvm/book3s_64_vio.c | 34 ++++++++++------------------- 1 file changed, 12 insertions(+), 22 deletions(-) --- a/arch/powerpc/kvm/book3s_64_vio.c~kvm-book3s-drop-mmap_sem-now-that-locked_vm-is-atomic +++ a/arch/powerpc/kvm/book3s_64_vio.c @@ -56,7 +56,7 @@ static unsigned long kvmppc_stt_pages(un return tce_pages + ALIGN(stt_bytes, PAGE_SIZE) / PAGE_SIZE; } -static long kvmppc_account_memlimit(unsigned long stt_pages, bool inc) +static long kvmppc_account_memlimit(unsigned long pages, bool inc) { long ret = 0; s64 locked_vm; @@ -64,33 +64,23 @@ static long kvmppc_account_memlimit(unsi if (!current || !current->mm) return ret; /* process exited */ - down_write(¤t->mm->mmap_sem); - - locked_vm = atomic64_read(¤t->mm->locked_vm); if (inc) { - unsigned long locked, lock_limit; + unsigned long lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT; - locked = locked_vm + stt_pages; - lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT; - if (locked > lock_limit && !capable(CAP_IPC_LOCK)) + locked_vm = atomic64_add_return(pages, ¤t->mm->locked_vm); + if (locked_vm > lock_limit && !capable(CAP_IPC_LOCK)) { ret = -ENOMEM; - else - atomic64_add(stt_pages, ¤t->mm->locked_vm); + atomic64_sub(pages, ¤t->mm->locked_vm); + } } else { - if (WARN_ON_ONCE(stt_pages > locked_vm)) - stt_pages = locked_vm; - - atomic64_sub(stt_pages, ¤t->mm->locked_vm); + locked_vm = atomic64_sub_return(pages, ¤t->mm->locked_vm); + WARN_ON_ONCE(locked_vm < 0); } - pr_debug("[%d] RLIMIT_MEMLOCK KVM %c%ld %ld/%ld%s\n", current->pid, - inc ? '+' : '-', - stt_pages << PAGE_SHIFT, - atomic64_read(¤t->mm->locked_vm) << PAGE_SHIFT, - rlimit(RLIMIT_MEMLOCK), - ret ? " - exceeded" : ""); - - up_write(¤t->mm->mmap_sem); + pr_debug("[%d] RLIMIT_MEMLOCK KVM %c%lu %lld/%lu%s\n", current->pid, + inc ? '+' : '-', pages << PAGE_SHIFT, + locked_vm << PAGE_SHIFT, + rlimit(RLIMIT_MEMLOCK), ret ? " - exceeded" : ""); 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