From: Moshe Lazer Date: Tue, 5 Aug 2014 15:16:46 +0000 (+0300) Subject: IB/mlx4: Mark user mr as writable if actual virtual memory is writable X-Git-Tag: v4.1.12-92~293^2~1^2~25 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=420baded7776cec075b0485d6d9b618422347491;p=users%2Fjedix%2Flinux-maple.git IB/mlx4: Mark user mr as writable if actual virtual memory is writable To allow rereg mr (from read only mr to writablemr) without using get_user_pages again, we need to define the initial mr as writable. We shouldn't do this in case that user virtual memory is not writable (e.g. const memory) Signed-off-by: Moshe Lazer (Ported from Mellanox OFED 2.4) Signed-off-by: Mukesh Kacker --- diff --git a/drivers/infiniband/hw/mlx4/mr.c b/drivers/infiniband/hw/mlx4/mr.c index 8e4889d447a43..1cb08bd30072f 100644 --- a/drivers/infiniband/hw/mlx4/mr.c +++ b/drivers/infiniband/hw/mlx4/mr.c @@ -391,15 +391,25 @@ struct ib_mr *mlx4_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length, int shift; int err; int n; + struct vm_area_struct *vma; + int umem_flags = access_flags; mr = kmalloc(sizeof *mr, GFP_KERNEL); if (!mr) return ERR_PTR(-ENOMEM); - /* Force registering the memory as writable. */ + /* If actual memory is writable, force registering the memory as writable. */ /* Used for memory re-registeration. HCA protects the access */ + if (!(umem_flags & IB_ACCESS_LOCAL_WRITE)) { + down_read(¤t->mm->mmap_sem); + vma = find_vma(current->mm, start); + if (vma && (vma->vm_end >= start + length) && + (vma->vm_start <= start) && (vma->vm_flags & VM_WRITE)) + umem_flags |= IB_ACCESS_LOCAL_WRITE; + up_read(¤t->mm->mmap_sem); + } mr->umem = ib_umem_get(pd->uobject->context, start, length, - access_flags | IB_ACCESS_LOCAL_WRITE, 0); + umem_flags, 0); if (IS_ERR(mr->umem)) { err = PTR_ERR(mr->umem); goto err_free;