[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20190402204158.27582-7-daniel.m.jordan@oracle.com>
Date: Tue, 2 Apr 2019 16:41:58 -0400
From: Daniel Jordan <daniel.m.jordan@...cle.com>
To: akpm@...ux-foundation.org
Cc: daniel.m.jordan@...cle.com, Alexey Kardashevskiy <aik@...abs.ru>,
Benjamin Herrenschmidt <benh@...nel.crashing.org>,
Christoph Lameter <cl@...ux.com>,
Davidlohr Bueso <dave@...olabs.net>,
Michael Ellerman <mpe@...erman.id.au>,
Paul Mackerras <paulus@...abs.org>, linux-mm@...ck.org,
kvm-ppc@...r.kernel.org, linuxppc-dev@...ts.ozlabs.org,
linux-kernel@...r.kernel.org
Subject: [PATCH 6/6] 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.
Signed-off-by: Daniel Jordan <daniel.m.jordan@...cle.com>
Cc: Alexey Kardashevskiy <aik@...abs.ru>
Cc: Andrew Morton <akpm@...ux-foundation.org>
Cc: Benjamin Herrenschmidt <benh@...nel.crashing.org>
Cc: Christoph Lameter <cl@...ux.com>
Cc: Davidlohr Bueso <dave@...olabs.net>
Cc: Michael Ellerman <mpe@...erman.id.au>
Cc: Paul Mackerras <paulus@...abs.org>
Cc: <linux-mm@...ck.org>
Cc: <kvm-ppc@...r.kernel.org>
Cc: <linuxppc-dev@...ts.ozlabs.org>
Cc: <linux-kernel@...r.kernel.org>
---
arch/powerpc/kvm/book3s_64_vio.c | 34 +++++++++++---------------------
1 file changed, 12 insertions(+), 22 deletions(-)
diff --git a/arch/powerpc/kvm/book3s_64_vio.c b/arch/powerpc/kvm/book3s_64_vio.c
index e7fdb6d10eeb..8e034c3a5d25 100644
--- a/arch/powerpc/kvm/book3s_64_vio.c
+++ b/arch/powerpc/kvm/book3s_64_vio.c
@@ -56,7 +56,7 @@ static unsigned long kvmppc_stt_pages(unsigned long tce_pages)
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(unsigned long stt_pages, bool inc)
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;
}
--
2.21.0
Powered by blists - more mailing lists