Skip to content

Commit a4e63bc

Browse files
committed
RDMA/odp: Ensure the mm is still alive before creating an implicit child
Registration of a mmu_notifier requires the caller to hold a mmget() on the mm as registration is not permitted to race with exit_mmap(). There is a BUG_ON inside the mmu_notifier to guard against this. Normally creating a umem is done against current which implicitly holds the mmget(), however an implicit ODP child is created from a pagefault work queue and is not guaranteed to have a mmget(). Call mmget() around this registration and abort faulting if the MM has gone to exit_mmap(). Before the patch below the notifier was registered when the implicit ODP parent was created, so there was no chance to register a notifier outside of current. Fixes: c571fec ("RDMA/odp: use mmu_notifier_get/put for 'struct ib_ucontext_per_mm'") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent e38b55e commit a4e63bc

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

drivers/infiniband/core/umem_odp.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,28 @@ ib_umem_odp_alloc_child(struct ib_umem_odp *root, unsigned long addr,
181181
odp_data->page_shift = PAGE_SHIFT;
182182
odp_data->notifier.ops = ops;
183183

184+
/*
185+
* A mmget must be held when registering a notifier, the owming_mm only
186+
* has a mm_grab at this point.
187+
*/
188+
if (!mmget_not_zero(umem->owning_mm)) {
189+
ret = -EFAULT;
190+
goto out_free;
191+
}
192+
184193
odp_data->tgid = get_pid(root->tgid);
185194
ret = ib_init_umem_odp(odp_data, ops);
186-
if (ret) {
187-
put_pid(odp_data->tgid);
188-
kfree(odp_data);
189-
return ERR_PTR(ret);
190-
}
195+
if (ret)
196+
goto out_tgid;
197+
mmput(umem->owning_mm);
191198
return odp_data;
199+
200+
out_tgid:
201+
put_pid(odp_data->tgid);
202+
mmput(umem->owning_mm);
203+
out_free:
204+
kfree(odp_data);
205+
return ERR_PTR(ret);
192206
}
193207
EXPORT_SYMBOL(ib_umem_odp_alloc_child);
194208

0 commit comments

Comments
 (0)