From nobody Sun Nov 24 09:29:59 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4AEC126C0D; Sun, 10 Nov 2024 13:48:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731246510; cv=none; b=ktuYhIG483WvoCA20tWClRZ8RTEhjGZuqPKqdF51DZqkAdaPIg+/BynTGKzP2dZMGEeIrVxrbhvgGVserFH9A+yHjJXuOlpaIW2+Zfqogr29QfoLwcquR0LGrLV2VQRptE/9l4WQ1jbAk+Rov3MkQt/VNGOKvNYjXDH8Tz0aF6M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731246510; c=relaxed/simple; bh=faZKR+GLvGy07GeNnto8v510/6+S1UMSrHjOqNZtBkg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=byy5yYi01MrgV8O7bJ0RULd7szRAM4Vvb+6fTwKLFbk4oVvZEH7VRfdqO1cHsk60aiuHQv0sCRrrGExFB0mSRjbDpXXEhjvih2DWuUTo4lEV2TE1s0zSuV8bfUUZ/00e4uB/6uDeNw5JPCeNouBoGCMUtRS7u3VsOX21WWGkmi0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lZqOjdQd; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lZqOjdQd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F719C4CED0; Sun, 10 Nov 2024 13:48:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1731246509; bh=faZKR+GLvGy07GeNnto8v510/6+S1UMSrHjOqNZtBkg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lZqOjdQdeucnpQjwxEkZ3eHNOrLAHuPXqFA+rkeoPQNnbMEMED4/1APfMaS2VAkvl rLzo8I5d3cTWDyvtQAw6GetM/pXaLgdtyjkTbOMP04Gbpw7rebxfJIUG39XWZjAUHC JGWMb5rqS9GCk/zzg8r5kvegLt8mnOV9U3rhXtXKbNuaKlpOPReGPD1exn9r1CMgAr g8Ef0ettthz2D42h+w+IplD8y8ij8IGY4ZnR432YPo0BvhAwsvwE1dBDHfo85OWy2N x797zDgcIHKGYceA13Lx+R4ckiP9GOINwblEDprMsodj69+OGCPA0/pTz8sp3vKKJ9 2XFK1MUvbZZqA== From: Leon Romanovsky To: Jens Axboe , Jason Gunthorpe , Robin Murphy , Joerg Roedel , Will Deacon , Christoph Hellwig , Sagi Grimberg Cc: Leon Romanovsky , Keith Busch , Bjorn Helgaas , Logan Gunthorpe , Yishai Hadas , Shameer Kolothum , Kevin Tian , Alex Williamson , Marek Szyprowski , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Andrew Morton , Jonathan Corbet , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-rdma@vger.kernel.org, iommu@lists.linux.dev, linux-nvme@lists.infradead.org, linux-pci@vger.kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org, Randy Dunlap Subject: [PATCH v3 14/17] RDMA/umem: Separate implicit ODP initialization from explicit ODP Date: Sun, 10 Nov 2024 15:47:01 +0200 Message-ID: <1e5645ca12e94a74d8ec5e3aea75e38553ed6614.1731244445.git.leon@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Leon Romanovsky Create separate functions for the implicit ODP initialization which is different from the explicit ODP initialization. Signed-off-by: Leon Romanovsky --- drivers/infiniband/core/umem_odp.c | 91 +++++++++++++++--------------- 1 file changed, 46 insertions(+), 45 deletions(-) diff --git a/drivers/infiniband/core/umem_odp.c b/drivers/infiniband/core/u= mem_odp.c index 30cd8f353476..51d518989914 100644 --- a/drivers/infiniband/core/umem_odp.c +++ b/drivers/infiniband/core/umem_odp.c @@ -48,41 +48,44 @@ =20 #include "uverbs.h" =20 -static inline int ib_init_umem_odp(struct ib_umem_odp *umem_odp, - const struct mmu_interval_notifier_ops *ops) +static void ib_init_umem_implicit_odp(struct ib_umem_odp *umem_odp) +{ + umem_odp->is_implicit_odp =3D 1; + umem_odp->umem.is_odp =3D 1; + mutex_init(&umem_odp->umem_mutex); +} + +static int ib_init_umem_odp(struct ib_umem_odp *umem_odp, + const struct mmu_interval_notifier_ops *ops) { struct ib_device *dev =3D umem_odp->umem.ibdev; + size_t page_size =3D 1UL << umem_odp->page_shift; + unsigned long start; + unsigned long end; int ret; =20 umem_odp->umem.is_odp =3D 1; mutex_init(&umem_odp->umem_mutex); =20 - if (!umem_odp->is_implicit_odp) { - size_t page_size =3D 1UL << umem_odp->page_shift; - unsigned long start; - unsigned long end; - - start =3D ALIGN_DOWN(umem_odp->umem.address, page_size); - if (check_add_overflow(umem_odp->umem.address, - (unsigned long)umem_odp->umem.length, - &end)) - return -EOVERFLOW; - end =3D ALIGN(end, page_size); - if (unlikely(end < page_size)) - return -EOVERFLOW; - - ret =3D hmm_dma_map_alloc(dev->dma_device, &umem_odp->map, - (end - start) >> PAGE_SHIFT, - 1 << umem_odp->page_shift); - if (ret) - return ret; - - ret =3D mmu_interval_notifier_insert(&umem_odp->notifier, - umem_odp->umem.owning_mm, - start, end - start, ops); - if (ret) - goto out_free_map; - } + start =3D ALIGN_DOWN(umem_odp->umem.address, page_size); + if (check_add_overflow(umem_odp->umem.address, + (unsigned long)umem_odp->umem.length, &end)) + return -EOVERFLOW; + end =3D ALIGN(end, page_size); + if (unlikely(end < page_size)) + return -EOVERFLOW; + + ret =3D hmm_dma_map_alloc(dev->dma_device, &umem_odp->map, + (end - start) >> PAGE_SHIFT, + 1 << umem_odp->page_shift); + if (ret) + return ret; + + ret =3D mmu_interval_notifier_insert(&umem_odp->notifier, + umem_odp->umem.owning_mm, start, + end - start, ops); + if (ret) + goto out_free_map; =20 return 0; =20 @@ -106,7 +109,6 @@ struct ib_umem_odp *ib_umem_odp_alloc_implicit(struct i= b_device *device, { struct ib_umem *umem; struct ib_umem_odp *umem_odp; - int ret; =20 if (access & IB_ACCESS_HUGETLB) return ERR_PTR(-EINVAL); @@ -118,16 +120,10 @@ struct ib_umem_odp *ib_umem_odp_alloc_implicit(struct= ib_device *device, umem->ibdev =3D device; umem->writable =3D ib_access_writable(access); umem->owning_mm =3D current->mm; - umem_odp->is_implicit_odp =3D 1; umem_odp->page_shift =3D PAGE_SHIFT; =20 umem_odp->tgid =3D get_task_pid(current->group_leader, PIDTYPE_PID); - ret =3D ib_init_umem_odp(umem_odp, NULL); - if (ret) { - put_pid(umem_odp->tgid); - kfree(umem_odp); - return ERR_PTR(ret); - } + ib_init_umem_implicit_odp(umem_odp); return umem_odp; } EXPORT_SYMBOL(ib_umem_odp_alloc_implicit); @@ -248,7 +244,7 @@ struct ib_umem_odp *ib_umem_odp_get(struct ib_device *d= evice, } EXPORT_SYMBOL(ib_umem_odp_get); =20 -void ib_umem_odp_release(struct ib_umem_odp *umem_odp) +static void ib_umem_odp_free(struct ib_umem_odp *umem_odp) { struct ib_device *dev =3D umem_odp->umem.ibdev; =20 @@ -258,14 +254,19 @@ void ib_umem_odp_release(struct ib_umem_odp *umem_odp) * It is the driver's responsibility to ensure, before calling us, * that the hardware will not attempt to access the MR any more. */ - if (!umem_odp->is_implicit_odp) { - mutex_lock(&umem_odp->umem_mutex); - ib_umem_odp_unmap_dma_pages(umem_odp, ib_umem_start(umem_odp), - ib_umem_end(umem_odp)); - mutex_unlock(&umem_odp->umem_mutex); - mmu_interval_notifier_remove(&umem_odp->notifier); - hmm_dma_map_free(dev->dma_device, &umem_odp->map); - } + mutex_lock(&umem_odp->umem_mutex); + ib_umem_odp_unmap_dma_pages(umem_odp, ib_umem_start(umem_odp), + ib_umem_end(umem_odp)); + mutex_unlock(&umem_odp->umem_mutex); + mmu_interval_notifier_remove(&umem_odp->notifier); + hmm_dma_map_free(dev->dma_device, &umem_odp->map); +} + +void ib_umem_odp_release(struct ib_umem_odp *umem_odp) +{ + if (!umem_odp->is_implicit_odp) + ib_umem_odp_free(umem_odp); + put_pid(umem_odp->tgid); kfree(umem_odp); } --=20 2.47.0