aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/infiniband/core/umem.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/infiniband/core/umem.c')
-rw-r--r--drivers/infiniband/core/umem.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/drivers/infiniband/core/umem.c b/drivers/infiniband/core/umem.c
index a3a2e9c1639b..df0c4f605a21 100644
--- a/drivers/infiniband/core/umem.c
+++ b/drivers/infiniband/core/umem.c
@@ -105,6 +105,7 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
105 umem->length = size; 105 umem->length = size;
106 umem->offset = addr & ~PAGE_MASK; 106 umem->offset = addr & ~PAGE_MASK;
107 umem->page_size = PAGE_SIZE; 107 umem->page_size = PAGE_SIZE;
108 umem->pid = get_task_pid(current, PIDTYPE_PID);
108 /* 109 /*
109 * We ask for writable memory if any access flags other than 110 * We ask for writable memory if any access flags other than
110 * "remote read" are set. "Local write" and "remote write" 111 * "remote read" are set. "Local write" and "remote write"
@@ -198,6 +199,7 @@ out:
198 if (ret < 0) { 199 if (ret < 0) {
199 if (need_release) 200 if (need_release)
200 __ib_umem_release(context->device, umem, 0); 201 __ib_umem_release(context->device, umem, 0);
202 put_pid(umem->pid);
201 kfree(umem); 203 kfree(umem);
202 } else 204 } else
203 current->mm->pinned_vm = locked; 205 current->mm->pinned_vm = locked;
@@ -230,15 +232,19 @@ void ib_umem_release(struct ib_umem *umem)
230{ 232{
231 struct ib_ucontext *context = umem->context; 233 struct ib_ucontext *context = umem->context;
232 struct mm_struct *mm; 234 struct mm_struct *mm;
235 struct task_struct *task;
233 unsigned long diff; 236 unsigned long diff;
234 237
235 __ib_umem_release(umem->context->device, umem, 1); 238 __ib_umem_release(umem->context->device, umem, 1);
236 239
237 mm = get_task_mm(current); 240 task = get_pid_task(umem->pid, PIDTYPE_PID);
238 if (!mm) { 241 put_pid(umem->pid);
239 kfree(umem); 242 if (!task)
240 return; 243 goto out;
241 } 244 mm = get_task_mm(task);
245 put_task_struct(task);
246 if (!mm)
247 goto out;
242 248
243 diff = PAGE_ALIGN(umem->length + umem->offset) >> PAGE_SHIFT; 249 diff = PAGE_ALIGN(umem->length + umem->offset) >> PAGE_SHIFT;
244 250
@@ -262,9 +268,10 @@ void ib_umem_release(struct ib_umem *umem)
262 } else 268 } else
263 down_write(&mm->mmap_sem); 269 down_write(&mm->mmap_sem);
264 270
265 current->mm->pinned_vm -= diff; 271 mm->pinned_vm -= diff;
266 up_write(&mm->mmap_sem); 272 up_write(&mm->mmap_sem);
267 mmput(mm); 273 mmput(mm);
274out:
268 kfree(umem); 275 kfree(umem);
269} 276}
270EXPORT_SYMBOL(ib_umem_release); 277EXPORT_SYMBOL(ib_umem_release);