From: Daniel Jordan <daniel.m.jordan@oracle.com>
To: akpm@linux-foundation.org
Cc: daniel.m.jordan@oracle.com,
Alex Williamson <alex.williamson@redhat.com>,
Christoph Lameter <cl@linux.com>,
Davidlohr Bueso <dave@stgolabs.net>,
linux-mm@kvack.org, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 2/6] vfio/type1: drop mmap_sem now that locked_vm is atomic
Date: Tue, 2 Apr 2019 16:41:54 -0400 [thread overview]
Message-ID: <20190402204158.27582-3-daniel.m.jordan@oracle.com> (raw)
In-Reply-To: <20190402204158.27582-1-daniel.m.jordan@oracle.com>
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@oracle.com>
Cc: Alex Williamson <alex.williamson@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Christoph Lameter <cl@linux.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: <linux-mm@kvack.org>
Cc: <kvm@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>
---
drivers/vfio/vfio_iommu_type1.c | 27 +++++++++------------------
1 file changed, 9 insertions(+), 18 deletions(-)
diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index 5b2878697286..a227de6d9c4c 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -257,7 +257,8 @@ static int vfio_iova_put_vfio_pfn(struct vfio_dma *dma, struct vfio_pfn *vpfn)
static int vfio_lock_acct(struct vfio_dma *dma, long npage, bool async)
{
struct mm_struct *mm;
- int ret;
+ s64 locked_vm;
+ int ret = 0;
if (!npage)
return 0;
@@ -266,25 +267,15 @@ static int vfio_lock_acct(struct vfio_dma *dma, long npage, bool async)
if (!mm)
return -ESRCH; /* process exited */
- ret = down_write_killable(&mm->mmap_sem);
- if (!ret) {
- if (npage > 0) {
- if (!dma->lock_cap) {
- s64 locked_vm = atomic64_read(&mm->locked_vm);
- unsigned long limit;
-
- limit = task_rlimit(dma->task,
- RLIMIT_MEMLOCK) >> PAGE_SHIFT;
+ locked_vm = atomic64_add_return(npage, &mm->locked_vm);
- if (locked_vm + npage > limit)
- ret = -ENOMEM;
- }
+ if (npage > 0 && !dma->lock_cap) {
+ unsigned long limit = task_rlimit(dma->task, RLIMIT_MEMLOCK) >>
+ PAGE_SHIFT;
+ if (locked_vm > limit) {
+ atomic64_sub(npage, &mm->locked_vm);
+ ret = -ENOMEM;
}
-
- if (!ret)
- atomic64_add(npage, &mm->locked_vm);
-
- up_write(&mm->mmap_sem);
}
if (async)
--
2.21.0
next prev parent reply other threads:[~2019-04-03 0:01 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-02 20:41 [PATCH 0/6] convert locked_vm from unsigned long to atomic64_t Daniel Jordan
2019-04-02 20:41 ` [PATCH 1/6] mm: change locked_vm's type " Daniel Jordan
2019-04-02 22:04 ` Andrew Morton
2019-04-02 23:43 ` Davidlohr Bueso
2019-04-03 16:07 ` Daniel Jordan
2019-04-03 15:58 ` Daniel Jordan
2019-04-03 4:46 ` Christophe Leroy
2019-04-03 16:09 ` Daniel Jordan
2019-04-11 4:22 ` Alexey Kardashevskiy
2019-04-11 9:55 ` Mark Rutland
2019-04-11 20:28 ` Daniel Jordan
2019-04-16 23:33 ` Andrew Morton
2019-04-22 15:54 ` Daniel Jordan
2019-04-02 20:41 ` Daniel Jordan [this message]
2019-04-02 20:41 ` [PATCH 3/6] vfio/spapr_tce: drop mmap_sem now that locked_vm is atomic Daniel Jordan
2019-04-02 20:41 ` [PATCH 4/6] fpga/dlf/afu: " Daniel Jordan
2019-04-02 20:41 ` [PATCH 5/6] powerpc/mmu: " Daniel Jordan
2019-04-03 4:58 ` Christophe Leroy
2019-04-03 16:40 ` Daniel Jordan
2019-04-24 2:15 ` Davidlohr Bueso
2019-04-24 2:31 ` Davidlohr Bueso
2019-04-24 11:10 ` Jason Gunthorpe
2019-04-25 1:47 ` Daniel Jordan
2019-04-02 20:41 ` [PATCH 6/6] kvm/book3s: " Daniel Jordan
2019-04-03 12:51 ` [PATCH 0/6] convert locked_vm from unsigned long to atomic64_t Steven Sistare
2019-04-03 16:52 ` Daniel Jordan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190402204158.27582-3-daniel.m.jordan@oracle.com \
--to=daniel.m.jordan@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=alex.williamson@redhat.com \
--cc=cl@linux.com \
--cc=dave@stgolabs.net \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).