Commit 3312d1c6 authored by Doug Ledford's avatar Doug Ledford Committed by Jason Gunthorpe

RDMA/umem: Minor optimizations

Noticed while reviewing commit d4b4dd1b ("RDMA/umem: Do not use
current->tgid to track the mm_struct") patch.  Why would we take a lock,
adjust a protected variable, drop the lock, and *then* check the input
into our protected variable adjustment?  Then we have to take the lock
again on our error unwind.  Let's just check the input early and skip
taking the locks needlessly if the input isn't valid.

It was also noticed that we set mm = current->mm, we then never modify
mm, but we still go back and reference current->mm a number of times
needlessly.  Be consistent in using the stored reference in mm.
Signed-off-by: default avatarDoug Ledford <dledford@redhat.com>
Reviewed-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent 1b571086
...@@ -152,6 +152,10 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr, ...@@ -152,6 +152,10 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
umem->hugetlb = 0; umem->hugetlb = 0;
npages = ib_umem_num_pages(umem); npages = ib_umem_num_pages(umem);
if (npages == 0 || npages > UINT_MAX) {
ret = -EINVAL;
goto out;
}
lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT; lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;
...@@ -166,11 +170,6 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr, ...@@ -166,11 +170,6 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
cur_base = addr & PAGE_MASK; cur_base = addr & PAGE_MASK;
if (npages == 0 || npages > UINT_MAX) {
ret = -EINVAL;
goto vma;
}
ret = sg_alloc_table(&umem->sg_head, npages, GFP_KERNEL); ret = sg_alloc_table(&umem->sg_head, npages, GFP_KERNEL);
if (ret) if (ret)
goto vma; goto vma;
...@@ -224,9 +223,9 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr, ...@@ -224,9 +223,9 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
umem_release: umem_release:
__ib_umem_release(context->device, umem, 0); __ib_umem_release(context->device, umem, 0);
vma: vma:
down_write(&current->mm->mmap_sem); down_write(&mm->mmap_sem);
current->mm->pinned_vm -= ib_umem_num_pages(umem); mm->pinned_vm -= ib_umem_num_pages(umem);
up_write(&current->mm->mmap_sem); up_write(&mm->mmap_sem);
out: out:
if (vma_list) if (vma_list)
free_page((unsigned long) vma_list); free_page((unsigned long) vma_list);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment