From: Jason Gunthorpe <jgg@ziepe.ca>
To: Leon Romanovsky <leon@kernel.org>
Cc: Doug Ledford <dledford@redhat.com>, linux-rdma@vger.kernel.org
Subject: Re: [PATCH rdma-rc] RDMA/odp: Ensure the mm is still alive before creating an implicit child
Date: Wed, 4 Mar 2020 14:04:35 -0400 [thread overview]
Message-ID: <20200304180435.GA16338@ziepe.ca> (raw)
In-Reply-To: <20200227114118.94736-1-leon@kernel.org>
On Thu, Feb 27, 2020 at 01:41:18PM +0200, Leon Romanovsky wrote:
> From: Jason Gunthorpe <jgg@mellanox.com>
>
> 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: c571feca2dc9 ("RDMA/odp: use mmu_notifier_get/put for 'struct ib_ucontext_per_mm'")
> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
> Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
> ---
> drivers/infiniband/core/umem_odp.c | 23 ++++++++++++++++++-----
> 1 file changed, 18 insertions(+), 5 deletions(-)
> diff --git a/drivers/infiniband/core/umem_odp.c b/drivers/infiniband/core/umem_odp.c
> index b8c657b28380..168f4f260c23 100644
> --- a/drivers/infiniband/core/umem_odp.c
> +++ b/drivers/infiniband/core/umem_odp.c
> @@ -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);
This put_pid got lost, I put it back before applying to for-rc:
diff --git a/drivers/infiniband/core/umem_odp.c b/drivers/infiniband/core/umem_odp.c
index b8c657b2838048..cd656ad4953bfc 100644
--- a/drivers/infiniband/core/umem_odp.c
+++ b/drivers/infiniband/core/umem_odp.c
@@ -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);
prev parent reply other threads:[~2020-03-04 18:04 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-27 11:41 [PATCH rdma-rc] RDMA/odp: Ensure the mm is still alive before creating an implicit child Leon Romanovsky
2020-03-04 18:04 ` Jason Gunthorpe [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200304180435.GA16338@ziepe.ca \
--to=jgg@ziepe.ca \
--cc=dledford@redhat.com \
--cc=leon@kernel.org \
--cc=linux-rdma@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.