RDMA/odp: Ensure the mm is still alive before creating an implicit child
PATCH 1/1 RDMA/odp: Ensure the mm is still alive before creating an implicit child
From: Jason Gunthorpe <[email protected]>
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.
--- drivers/infiniband/core/umem_odp.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)
drivers/infiniband/core/umem_odp.c +18 -5
@@ -181,14 +181,27 @@ ib_umem_odp_alloc_child(struct ib_umem_odp *root, unsigned long addr, odp_data->page_shift =PAGE_SHIFT ; odp_data->notifier.ops = ops; +/* +* A mmget must be held when registering a notifier, the owming_mm only +* has a mm_grab at this point. +*/ +if (!mmget_not_zero (umem->owning_mm)) { + ret = -EFAULT ; + goto out_free; + } + odp_data->tgid =get_pid (root->tgid); ret =ib_init_umem_odp (odp_data, ops); -if (ret) { -put_pid (odp_data->tgid); -kfree (odp_data); -return ERR_PTR (ret); - } +if (ret) + goto out_mm; +mmput (umem->owning_mm);return odp_data; + +out_mm: +mmput (umem->owning_mm); +out_free: +kfree (odp_data); +return ERR_PTR (ret); }EXPORT_SYMBOL (ib_umem_odp_alloc_child);
Signature · 1 line
2.24.1
Quoted 35 lines · Leon Romanovsky
From: Jason Gunthorpe <[email protected]>
Registration of a
mmu_notifierrequires the caller to hold ammget()on the mm as registration is not permitted to race withexit_mmap(). There is aBUG_ONinside themmu_notifierto 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 ammget().Call
mmget()around this registration and abort faulting if the MM has gone toexit_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 c571feca2dc9 ("RDMA/odp: use mmu_notifier_get/put for 'struct ib_ucontext_per_mm'")Signed-off-by Jason Gunthorpe <[email protected]>Signed-off-by Leon Romanovsky <[email protected]>--- drivers/infiniband/core/umem_odp.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)drivers/infiniband/core/umem_odp.c +3
-0@@ -181,14 +181,27 @@ ib_umem_odp_alloc_child(struct ib_umem_odp *root, unsigned long addr, odp_data->page_shift =PAGE_SHIFT ; odp_data->notifier.ops = ops; +/* +* A mmget must be held when registering a notifier, the owming_mm only +* has a mm_grab at this point.
drivers/infiniband/core/umem_odp.c ib_umem_odp_alloc_child(struct ib_umem_odp *root, unsigned long addr, · line 187
Quoted 10 lines
drivers/infiniband/core/umem_odp.c +6
-2+*/ +if (!mmget_not_zero (umem->owning_mm)) { + ret = -EFAULT ; + goto out_free; + } + odp_data->tgid =get_pid (root->tgid); ret =ib_init_umem_odp (odp_data, ops); -if (ret) { -put_pid (odp_data->tgid);
This put_pid got lost, I put it back before applying to for-rc:
drivers/infiniband/core/umem_odp.c +19 -5
@@ -181,14 +181,28 @@ ib_umem_odp_alloc_child(struct ib_umem_odp *root, unsigned long addr, odp_data->page_shift =PAGE_SHIFT ; odp_data->notifier.ops = ops; +/* +* A mmget must be held when registering a notifier, the owming_mm only +* has a mm_grab at this point. +*/ +if (!mmget_not_zero (umem->owning_mm)) { + ret = -EFAULT ; + goto out_free; + } + odp_data->tgid =get_pid (root->tgid); ret =ib_init_umem_odp (odp_data, ops); -if (ret) { -put_pid (odp_data->tgid); -kfree (odp_data); -return ERR_PTR (ret); - } +if (ret) + goto out_tgid; +mmput (umem->owning_mm);return odp_data; + +out_tgid: +put_pid (odp_data->tgid); +mmput (umem->owning_mm); +out_free: +kfree (odp_data); +return ERR_PTR (ret); }EXPORT_SYMBOL (ib_umem_odp_alloc_child);