Message ID | 20230130032407.259855-1-yanjun.zhu@intel.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Jason Gunthorpe |
Headers | show |
Series | [PATCHv2,for-next,1/1] RDMA/irdma: Add support for dmabuf pin memory regions | expand |
On Mon, Jan 30, 2023 at 11:24:07AM +0800, Zhu Yanjun wrote: > From: Zhu Yanjun <yanjun.zhu@linux.dev> > > This is a followup to the EFA dmabuf[1]. Irdma driver currently does > not support on-demand-paging(ODP). So it uses habanalabs as the > dmabuf exporter, and irdma as the importer to allow for peer2peer > access through libibverbs. > > In this commit, the function ib_umem_dmabuf_get_pinned() is used. > This function is introduced in EFA dmabuf[1] which allows the driver > to get a dmabuf umem which is pinned and does not require move_notify > callback implementation. The returned umem is pinned and DMA mapped > like standard cpu umems, and is released through ib_umem_release(). > > [1]https://lore.kernel.org/lkml/20211007114018.GD2688930@ziepe.ca/t/ > > Signed-off-by: Zhu Yanjun <yanjun.zhu@linux.dev> > --- > V1->V2: Thanks Shiraz Saleem, he gave me a lot of good suggestions. > This commit is based on the shared functions from refactored > irdma_reg_user_mr. > --- > drivers/infiniband/hw/irdma/verbs.c | 43 +++++++++++++++++++++++++++++ > 1 file changed, 43 insertions(+) > > diff --git a/drivers/infiniband/hw/irdma/verbs.c b/drivers/infiniband/hw/irdma/verbs.c > index 6982f38596c8..a638861689c2 100644 > --- a/drivers/infiniband/hw/irdma/verbs.c > +++ b/drivers/infiniband/hw/irdma/verbs.c > @@ -2977,6 +2977,48 @@ static struct ib_mr *irdma_reg_user_mr(struct ib_pd *pd, u64 start, u64 len, > return ERR_PTR(err); > } > > +static struct ib_mr *irdma_reg_user_mr_dmabuf(struct ib_pd *pd, u64 start, > + u64 len, u64 virt, > + int fd, int access, > + struct ib_udata *udata) > +{ > + struct irdma_device *iwdev = to_iwdev(pd->device); > + struct ib_umem_dmabuf *umem_dmabuf = NULL; > + struct irdma_mr *iwmr = NULL; No reason to null initialize these > + int err; > + > + if (len > iwdev->rf->sc_dev.hw_attrs.max_mr_size) > + return ERR_PTR(-EINVAL); > + > + if (udata->inlen < IRDMA_MEM_REG_MIN_REQ_LEN) > + return ERR_PTR(-EINVAL); > + > + umem_dmabuf = ib_umem_dmabuf_get_pinned(pd->device, start, len, fd, access); > + if (IS_ERR(umem_dmabuf)) { > + err = PTR_ERR(umem_dmabuf); > + ibdev_dbg(&iwdev->ibdev, "Failed to get dmabuf umem[%d]\n", err); > + return ERR_PTR(err); > + } > + > + iwmr = irdma_alloc_iwmr(&umem_dmabuf->umem, pd, virt, IRDMA_MEMREG_TYPE_MEM); > + if (IS_ERR(iwmr)) { > + ib_umem_release(&umem_dmabuf->umem); > + return (struct ib_mr *)iwmr; err = PTR_ERR(iwmr); goto err_release; > + } > + > + err = irdma_reg_user_mr_type_mem(iwmr, access); > + if (err) > + goto error; > + > + return &iwmr->ibmr; > + > +error: err_iwmr: > + irdma_free_iwmr(iwmr); err_release: > + ib_umem_release(&umem_dmabuf->umem); > + > + return ERR_PTR(err); > +} Jason
在 2023/1/31 22:42, Jason Gunthorpe 写道: > On Mon, Jan 30, 2023 at 11:24:07AM +0800, Zhu Yanjun wrote: >> From: Zhu Yanjun <yanjun.zhu@linux.dev> >> >> This is a followup to the EFA dmabuf[1]. Irdma driver currently does >> not support on-demand-paging(ODP). So it uses habanalabs as the >> dmabuf exporter, and irdma as the importer to allow for peer2peer >> access through libibverbs. >> >> In this commit, the function ib_umem_dmabuf_get_pinned() is used. >> This function is introduced in EFA dmabuf[1] which allows the driver >> to get a dmabuf umem which is pinned and does not require move_notify >> callback implementation. The returned umem is pinned and DMA mapped >> like standard cpu umems, and is released through ib_umem_release(). >> >> [1]https://lore.kernel.org/lkml/20211007114018.GD2688930@ziepe.ca/t/ >> >> Signed-off-by: Zhu Yanjun <yanjun.zhu@linux.dev> >> --- >> V1->V2: Thanks Shiraz Saleem, he gave me a lot of good suggestions. >> This commit is based on the shared functions from refactored >> irdma_reg_user_mr. >> --- >> drivers/infiniband/hw/irdma/verbs.c | 43 +++++++++++++++++++++++++++++ >> 1 file changed, 43 insertions(+) >> >> diff --git a/drivers/infiniband/hw/irdma/verbs.c b/drivers/infiniband/hw/irdma/verbs.c >> index 6982f38596c8..a638861689c2 100644 >> --- a/drivers/infiniband/hw/irdma/verbs.c >> +++ b/drivers/infiniband/hw/irdma/verbs.c >> @@ -2977,6 +2977,48 @@ static struct ib_mr *irdma_reg_user_mr(struct ib_pd *pd, u64 start, u64 len, >> return ERR_PTR(err); >> } >> >> +static struct ib_mr *irdma_reg_user_mr_dmabuf(struct ib_pd *pd, u64 start, >> + u64 len, u64 virt, >> + int fd, int access, >> + struct ib_udata *udata) >> +{ >> + struct irdma_device *iwdev = to_iwdev(pd->device); >> + struct ib_umem_dmabuf *umem_dmabuf = NULL; >> + struct irdma_mr *iwmr = NULL; > No reason to null initialize these Got it. > >> + int err; >> + >> + if (len > iwdev->rf->sc_dev.hw_attrs.max_mr_size) >> + return ERR_PTR(-EINVAL); >> + >> + if (udata->inlen < IRDMA_MEM_REG_MIN_REQ_LEN) >> + return ERR_PTR(-EINVAL); >> + >> + umem_dmabuf = ib_umem_dmabuf_get_pinned(pd->device, start, len, fd, access); >> + if (IS_ERR(umem_dmabuf)) { >> + err = PTR_ERR(umem_dmabuf); >> + ibdev_dbg(&iwdev->ibdev, "Failed to get dmabuf umem[%d]\n", err); >> + return ERR_PTR(err); >> + } >> + >> + iwmr = irdma_alloc_iwmr(&umem_dmabuf->umem, pd, virt, IRDMA_MEMREG_TYPE_MEM); >> + if (IS_ERR(iwmr)) { >> + ib_umem_release(&umem_dmabuf->umem); >> + return (struct ib_mr *)iwmr; > err = PTR_ERR(iwmr); > goto err_release; Got it. > >> + } >> + >> + err = irdma_reg_user_mr_type_mem(iwmr, access); >> + if (err) >> + goto error; >> + >> + return &iwmr->ibmr; >> + >> +error: > err_iwmr: >> + irdma_free_iwmr(iwmr); > err_release: Got it. I will send the latest commit very soon. Zhu Yanjun > >> + ib_umem_release(&umem_dmabuf->umem); >> + >> + return ERR_PTR(err); >> +} > Jason
diff --git a/drivers/infiniband/hw/irdma/verbs.c b/drivers/infiniband/hw/irdma/verbs.c index 6982f38596c8..a638861689c2 100644 --- a/drivers/infiniband/hw/irdma/verbs.c +++ b/drivers/infiniband/hw/irdma/verbs.c @@ -2977,6 +2977,48 @@ static struct ib_mr *irdma_reg_user_mr(struct ib_pd *pd, u64 start, u64 len, return ERR_PTR(err); } +static struct ib_mr *irdma_reg_user_mr_dmabuf(struct ib_pd *pd, u64 start, + u64 len, u64 virt, + int fd, int access, + struct ib_udata *udata) +{ + struct irdma_device *iwdev = to_iwdev(pd->device); + struct ib_umem_dmabuf *umem_dmabuf = NULL; + struct irdma_mr *iwmr = NULL; + int err; + + if (len > iwdev->rf->sc_dev.hw_attrs.max_mr_size) + return ERR_PTR(-EINVAL); + + if (udata->inlen < IRDMA_MEM_REG_MIN_REQ_LEN) + return ERR_PTR(-EINVAL); + + umem_dmabuf = ib_umem_dmabuf_get_pinned(pd->device, start, len, fd, access); + if (IS_ERR(umem_dmabuf)) { + err = PTR_ERR(umem_dmabuf); + ibdev_dbg(&iwdev->ibdev, "Failed to get dmabuf umem[%d]\n", err); + return ERR_PTR(err); + } + + iwmr = irdma_alloc_iwmr(&umem_dmabuf->umem, pd, virt, IRDMA_MEMREG_TYPE_MEM); + if (IS_ERR(iwmr)) { + ib_umem_release(&umem_dmabuf->umem); + return (struct ib_mr *)iwmr; + } + + err = irdma_reg_user_mr_type_mem(iwmr, access); + if (err) + goto error; + + return &iwmr->ibmr; + +error: + irdma_free_iwmr(iwmr); + ib_umem_release(&umem_dmabuf->umem); + + return ERR_PTR(err); +} + /** * irdma_reg_phys_mr - register kernel physical memory * @pd: ibpd pointer @@ -4483,6 +4525,7 @@ static const struct ib_device_ops irdma_dev_ops = { .query_port = irdma_query_port, .query_qp = irdma_query_qp, .reg_user_mr = irdma_reg_user_mr, + .reg_user_mr_dmabuf = irdma_reg_user_mr_dmabuf, .req_notify_cq = irdma_req_notify_cq, .resize_cq = irdma_resize_cq, INIT_RDMA_OBJ_SIZE(ib_pd, irdma_pd, ibpd),