[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20181105165558.11698-9-daniel.m.jordan@oracle.com>
Date: Mon, 5 Nov 2018 11:55:53 -0500
From: Daniel Jordan <daniel.m.jordan@...cle.com>
To: linux-mm@...ck.org, kvm@...r.kernel.org,
linux-kernel@...r.kernel.org
Cc: aarcange@...hat.com, aaron.lu@...el.com, akpm@...ux-foundation.org,
alex.williamson@...hat.com, bsd@...hat.com,
daniel.m.jordan@...cle.com, darrick.wong@...cle.com,
dave.hansen@...ux.intel.com, jgg@...lanox.com, jwadams@...gle.com,
jiangshanlai@...il.com, mhocko@...nel.org, mike.kravetz@...cle.com,
Pavel.Tatashin@...rosoft.com, prasad.singamsetty@...cle.com,
rdunlap@...radead.org, steven.sistare@...cle.com,
tim.c.chen@...el.com, tj@...nel.org, vbabka@...e.cz
Subject: [RFC PATCH v4 08/13] vfio: remove unnecessary mmap_sem writer acquisition around locked_vm
Now that mmap_sem is no longer required for modifying locked_vm, remove
it in the VFIO code.
[XXX Can be sent separately, along with similar conversions in the other
places mmap_sem was taken for locked_vm. While at it, could make
similar changes to pinned_vm.]
Signed-off-by: Daniel Jordan <daniel.m.jordan@...cle.com>
---
drivers/vfio/vfio_iommu_type1.c | 26 +++++++++-----------------
1 file changed, 9 insertions(+), 17 deletions(-)
diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index f307dc9d5e19..9e52a24eb45b 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -258,7 +258,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;
+ long locked_vm;
+ int ret = 0;
if (!npage)
return 0;
@@ -267,24 +268,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) {
- unsigned long limit;
-
- limit = task_rlimit(dma->task,
- RLIMIT_MEMLOCK) >> PAGE_SHIFT;
+ locked_vm = atomic_long_add_return(npage, &mm->locked_vm);
- if (atomic_long_read(&mm->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) {
+ atomic_long_sub(npage, &mm->locked_vm);
+ ret = -ENOMEM;
}
-
- if (!ret)
- atomic_long_add(npage, &mm->locked_vm);
-
- up_write(&mm->mmap_sem);
}
if (async)
--
2.19.1
Powered by blists - more mailing lists