Track locked_vm per dma struct, and create a new subroutine, both for use in a subsequent patch. No functional change. Signed-off-by: Steve Sistare <steven.sistare@xxxxxxxxxx> --- drivers/vfio/vfio_iommu_type1.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 51bb687..3bd89d5 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -97,6 +97,7 @@ struct vfio_dma { struct rb_root pfn_list; /* Ex-user pinned pfn list */ unsigned long *bitmap; struct vfio_iommu *iommu; /* back pointer */ + uint64_t locked_vm; }; struct vfio_batch { @@ -407,6 +408,19 @@ static int vfio_iova_put_vfio_pfn(struct vfio_dma *dma, struct vfio_pfn *vpfn) return ret; } +static int mm_lock_vm(struct task_struct *task, struct mm_struct *mm, + bool lock_cap, long npage) +{ + int ret = mmap_write_lock_killable(mm); + + if (!ret) { + ret = __account_locked_vm(mm, abs(npage), npage > 0, task, + lock_cap); + mmap_write_unlock(mm); + } + return ret; +} + static int vfio_lock_acct(struct vfio_dma *dma, long npage, bool async) { struct task_struct *task = dma->iommu->task; @@ -429,12 +443,9 @@ static int vfio_lock_acct(struct vfio_dma *dma, long npage, bool async) if (!mm) return -ESRCH; /* process exited */ - ret = mmap_write_lock_killable(mm); - if (!ret) { - ret = __account_locked_vm(mm, abs(npage), npage > 0, task, - dma->lock_cap); - mmap_write_unlock(mm); - } + ret = mm_lock_vm(task, mm, dma->lock_cap, npage); + if (!ret) + dma->locked_vm += npage; if (async) mmput(mm); -- 1.8.3.1