Skip to content

Commit 8e907ed

Browse files
jemmy858585jgunthorpe
authored andcommitted
IB/umem: Use the correct mm during ib_umem_release
User-space may invoke ibv_reg_mr and ibv_dereg_mr in different threads. If ibv_dereg_mr is called after the thread which invoked ibv_reg_mr has exited, get_pid_task will return NULL and ib_umem_release will not decrease mm->pinned_vm. Instead of using threads to locate the mm, use the overall tgid from the ib_ucontext struct instead. This matches the behavior of ODP and disassociate in handling the mm of the process that called ibv_reg_mr. Cc: <[email protected]> Fixes: 87773dd ("IB: ib_umem_release() should decrement mm->pinned_vm from ib_umem_get") Signed-off-by: Lidong Chen <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 3d69191 commit 8e907ed

File tree

2 files changed

+1
-7
lines changed

2 files changed

+1
-7
lines changed

drivers/infiniband/core/umem.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
119119
umem->length = size;
120120
umem->address = addr;
121121
umem->page_shift = PAGE_SHIFT;
122-
umem->pid = get_task_pid(current, PIDTYPE_PID);
123122
/*
124123
* We ask for writable memory if any of the following
125124
* access flags are set. "Local write" and "remote write"
@@ -132,7 +131,6 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
132131
IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_MW_BIND));
133132

134133
if (access & IB_ACCESS_ON_DEMAND) {
135-
put_pid(umem->pid);
136134
ret = ib_umem_odp_get(context, umem, access);
137135
if (ret) {
138136
kfree(umem);
@@ -148,7 +146,6 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
148146

149147
page_list = (struct page **) __get_free_page(GFP_KERNEL);
150148
if (!page_list) {
151-
put_pid(umem->pid);
152149
kfree(umem);
153150
return ERR_PTR(-ENOMEM);
154151
}
@@ -231,7 +228,6 @@ struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
231228
if (ret < 0) {
232229
if (need_release)
233230
__ib_umem_release(context->device, umem, 0);
234-
put_pid(umem->pid);
235231
kfree(umem);
236232
} else
237233
current->mm->pinned_vm = locked;
@@ -274,8 +270,7 @@ void ib_umem_release(struct ib_umem *umem)
274270

275271
__ib_umem_release(umem->context->device, umem, 1);
276272

277-
task = get_pid_task(umem->pid, PIDTYPE_PID);
278-
put_pid(umem->pid);
273+
task = get_pid_task(umem->context->tgid, PIDTYPE_PID);
279274
if (!task)
280275
goto out;
281276
mm = get_task_mm(task);

include/rdma/ib_umem.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ struct ib_umem {
4848
int writable;
4949
int hugetlb;
5050
struct work_struct work;
51-
struct pid *pid;
5251
struct mm_struct *mm;
5352
unsigned long diff;
5453
struct ib_umem_odp *odp_data;

0 commit comments

Comments
 (0)