From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD3A1CA9EB5 for ; Mon, 4 Nov 2019 20:25:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 87AC120848 for ; Mon, 4 Nov 2019 20:25:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="a8hSItnO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 87AC120848 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 22D766B0003; Mon, 4 Nov 2019 15:25:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1DD756B0005; Mon, 4 Nov 2019 15:25:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0CDEE6B0006; Mon, 4 Nov 2019 15:25:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0191.hostedemail.com [216.40.44.191]) by kanga.kvack.org (Postfix) with ESMTP id E9A6D6B0003 for ; Mon, 4 Nov 2019 15:25:02 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id A7D29282D for ; Mon, 4 Nov 2019 20:25:02 +0000 (UTC) X-FDA: 76119724044.20.name85_ee3aa2b7ce1f X-HE-Tag: name85_ee3aa2b7ce1f X-Filterd-Recvd-Size: 6322 Received: from mail-qk1-f194.google.com (mail-qk1-f194.google.com [209.85.222.194]) by imf37.hostedemail.com (Postfix) with ESMTP for ; Mon, 4 Nov 2019 20:25:02 +0000 (UTC) Received: by mail-qk1-f194.google.com with SMTP id a194so18919978qkg.10 for ; Mon, 04 Nov 2019 12:25:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=wfX7MWPK2mXvXsnlqpoXJ9gVTBzlydNtygslKz1zYXc=; b=a8hSItnOZbtn6sMoihfhZuCetsEimfTI974lkvFhLKCg3HejeAO31tVnnKuLf8OBzG 4cchusxnrVjItFjaeoTqIrOvpcpNtbGL4HmtHSBYgaxArSbGCtmfHGie9wUvHBWBFCtR XDyhVJbgXG8KzNN7ekl9KMw5ZH7nR9fuIHVYFo3h/exFmvg9P24/oLAxyHrpy4Es/45s IqMUO7VIWM6EhQ7FH+tMQqucsVqJZJSx1KHeKTBcdhQbCjPwSIYCdzJN/likNaHlaSTx mvtuSLMteIPqZ8UG6y1xP8DW5n0eiCDpBRZvheCN9DH/7l9lUG76EBGzGGsVNnXnrdNf AnxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=wfX7MWPK2mXvXsnlqpoXJ9gVTBzlydNtygslKz1zYXc=; b=dO+sTXo/1rdQtfR6J6bg0gJnJ0tc3ZzggesAVMc6wYZ/ensBjpNPAjbnkpIN4pvbKE xbv9PJK67M7loWEmcIfFRZXDf4FcK/uMORg8YndAnDDZWWD9W83dhQPo78nkbKQ232pP sSj4Fu3rGaxHazETUz0KO0qQrkPfhtEr/RkBuTopuy3rWGTYxlge6w76S3sPdMDkTngK O4WnApP86tvMkOCqhqPi8Fry4Duz0IYq5+oCna9E+PBTEIf3Gu7gZ6rQz3itt6Qey1rh m2ptG7WH+w+xzoTOMqukJJ9gPPzH3xZWQPnmz3Mk+AvjCEyOGRXwumZ0EiP9Wim9sdIz EwQA== X-Gm-Message-State: APjAAAU4DoG4neWSvQbrGka1Kdp2Mv5J6ueJvRX/qzt+U1zo6VkoK1th 5ML4eHUX3T3QHASEenWUeS2EHA== X-Google-Smtp-Source: APXvYqxgNGF3cXksanX/E/C8HqgGn5+TVBnu52RjRVopu16Kv6kjyL+U9vqqnb2baD1bHGbzMrjKsA== X-Received: by 2002:a37:94e:: with SMTP id 75mr15364499qkj.49.1572899101609; Mon, 04 Nov 2019 12:25:01 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-142-162-113-180.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.162.113.180]) by smtp.gmail.com with ESMTPSA id d2sm9640372qkg.77.2019.11.04.12.25.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 04 Nov 2019 12:25:01 -0800 (PST) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1iRiuK-00055e-9y; Mon, 04 Nov 2019 16:25:00 -0400 Date: Mon, 4 Nov 2019 16:25:00 -0400 From: Jason Gunthorpe To: Jerome Glisse , Ralph Campbell , John Hubbard , Felix.Kuehling@amd.com Cc: linux-rdma@vger.kernel.org, linux-mm@kvack.org, Andrea Arcangeli , dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, Ben Skeggs Subject: Re: [PATCH hmm 05/15] RDMA/odp: Use mmu_range_notifier_insert() Message-ID: <20191104202500.GA19383@ziepe.ca> References: <20191015181242.8343-1-jgg@ziepe.ca> <20191015181242.8343-6-jgg@ziepe.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191015181242.8343-6-jgg@ziepe.ca> User-Agent: Mutt/1.9.4 (2018-02-28) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Oct 15, 2019 at 03:12:32PM -0300, Jason Gunthorpe wrote: > @@ -250,26 +85,15 @@ static inline int ib_init_umem_odp(struct ib_umem_odp *umem_odp) > ret = -ENOMEM; > goto out_page_list; > } > - } > > - mn = mmu_notifier_get(&ib_umem_notifiers, umem_odp->umem.owning_mm); > - if (IS_ERR(mn)) { > - ret = PTR_ERR(mn); > - goto out_dma_list; > - } > - umem_odp->per_mm = per_mm = > - container_of(mn, struct ib_ucontext_per_mm, mn); > - > - mutex_init(&umem_odp->umem_mutex); > - init_completion(&umem_odp->notifier_completion); > + ret = mmu_range_notifier_insert(&umem_odp->notifier, start, > + end - start, current->mm); > + if (ret) > + goto out_dma_list; It turns out 'current' can't be used here as this can be called from the page fault work queue and should be 'umem_odp->umem.owning_mm' The same problem applies to the tgid a few lines below It also seems there is a pre-existing problem here as this code doesn't guarentee to have a mmget() on the mm for the non-current case when it called mmu_notifier_get() or now mmu_range_notifier_insert(). I'll fix this in a dedicated patch. This incremental sorts it out, I'll squash it into this patch: diff --git a/drivers/infiniband/core/umem_odp.c b/drivers/infiniband/core/umem_odp.c index 6132b8127e8435..0768bb60ce1662 100644 --- a/drivers/infiniband/core/umem_odp.c +++ b/drivers/infiniband/core/umem_odp.c @@ -87,12 +87,10 @@ static inline int ib_init_umem_odp(struct ib_umem_odp *umem_odp) } ret = mmu_range_notifier_insert(&umem_odp->notifier, start, - end - start, current->mm); + end - start, + umem_odp->umem.owning_mm); if (ret) goto out_dma_list; - - umem_odp->tgid = - get_task_pid(current->group_leader, PIDTYPE_PID); } return 0; @@ -140,8 +138,10 @@ ib_umem_odp_alloc_implicit(struct ib_udata *udata, int access) umem_odp->is_implicit_odp = 1; umem_odp->page_shift = PAGE_SHIFT; + umem_odp->tgid = get_task_pid(current->group_leader, PIDTYPE_PID); ret = ib_init_umem_odp(umem_odp); if (ret) { + put_pid(umem_odp->tgid); kfree(umem_odp); return ERR_PTR(ret); } @@ -185,8 +185,10 @@ ib_umem_odp_alloc_child(struct ib_umem_odp *root, unsigned long addr, odp_data->page_shift = PAGE_SHIFT; odp_data->notifier.ops = ops; + odp_data->tgid = get_pid(root->tgid); ret = ib_init_umem_odp(odp_data); if (ret) { + put_pid(odp_data->tgid); kfree(odp_data); return ERR_PTR(ret); } @@ -254,11 +256,14 @@ struct ib_umem_odp *ib_umem_odp_get(struct ib_udata *udata, unsigned long addr, up_read(&mm->mmap_sem); } + umem_odp->tgid = get_task_pid(current->group_leader, PIDTYPE_PID); ret = ib_init_umem_odp(umem_odp); if (ret) - goto err_free; + goto err_put_pid; return umem_odp; +err_put_pid: + put_pid(umem_odp->tgid); err_free: kfree(umem_odp); return ERR_PTR(ret);