* Re: [PATCHv3 for-next 1/1] RDMA/irdma: Add support for dmabuf pin memory regions
2023-01-05 22:37 [PATCHv3 for-next 1/1] RDMA/irdma: Add support for dmabuf pin memory regions Zhu Yanjun
@ 2023-01-05 13:37 ` Jason Gunthorpe
2023-01-07 6:22 ` Yanjun Zhu
0 siblings, 1 reply; 10+ messages in thread
From: Jason Gunthorpe @ 2023-01-05 13:37 UTC (permalink / raw)
To: Zhu Yanjun; +Cc: mustafa.ismail, shiraz.saleem, leon, linux-rdma, Zhu Yanjun
On Thu, Jan 05, 2023 at 05:37:10PM -0500, 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>
> ---
> V2->V3: Simplify the function by removing QP and CQ handling;
> V1->V2: Fix the build warning by adding a static;
> ---
> drivers/infiniband/hw/irdma/verbs.c | 97 +++++++++++++++++++++++++++++
> 1 file changed, 97 insertions(+)
>
> diff --git a/drivers/infiniband/hw/irdma/verbs.c b/drivers/infiniband/hw/irdma/verbs.c
> index f6973ea55eda..7028b8af87b9 100644
> --- a/drivers/infiniband/hw/irdma/verbs.c
> +++ b/drivers/infiniband/hw/irdma/verbs.c
> @@ -2912,6 +2912,102 @@ 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 irdma_pble_alloc *palloc;
> + struct irdma_pbl *iwpbl;
> + struct irdma_mr *iwmr;
> + u32 stag = 0;
> + bool use_pbles = false;
> + int err = -EINVAL;
> + struct ib_umem_dmabuf *umem_dmabuf;
> +
> + 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 = kzalloc(sizeof(*iwmr), GFP_KERNEL);
> + if (!iwmr) {
> + ib_umem_release(&umem_dmabuf->umem);
> + return ERR_PTR(-ENOMEM);
> + }
again, please don't duplicate all this code, refactor the mr code so
it can be shared.
Jason
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCHv3 for-next 1/1] RDMA/irdma: Add support for dmabuf pin memory regions
@ 2023-01-05 22:37 Zhu Yanjun
2023-01-05 13:37 ` Jason Gunthorpe
0 siblings, 1 reply; 10+ messages in thread
From: Zhu Yanjun @ 2023-01-05 22:37 UTC (permalink / raw)
To: mustafa.ismail, shiraz.saleem, jgg, leon, linux-rdma; +Cc: Zhu Yanjun
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>
---
V2->V3: Simplify the function by removing QP and CQ handling;
V1->V2: Fix the build warning by adding a static;
---
drivers/infiniband/hw/irdma/verbs.c | 97 +++++++++++++++++++++++++++++
1 file changed, 97 insertions(+)
diff --git a/drivers/infiniband/hw/irdma/verbs.c b/drivers/infiniband/hw/irdma/verbs.c
index f6973ea55eda..7028b8af87b9 100644
--- a/drivers/infiniband/hw/irdma/verbs.c
+++ b/drivers/infiniband/hw/irdma/verbs.c
@@ -2912,6 +2912,102 @@ 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 irdma_pble_alloc *palloc;
+ struct irdma_pbl *iwpbl;
+ struct irdma_mr *iwmr;
+ u32 stag = 0;
+ bool use_pbles = false;
+ int err = -EINVAL;
+ struct ib_umem_dmabuf *umem_dmabuf;
+
+ 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 = kzalloc(sizeof(*iwmr), GFP_KERNEL);
+ if (!iwmr) {
+ ib_umem_release(&umem_dmabuf->umem);
+ return ERR_PTR(-ENOMEM);
+ }
+
+ iwpbl = &iwmr->iwpbl;
+ iwpbl->iwmr = iwmr;
+ iwmr->region = &umem_dmabuf->umem;
+ iwmr->ibmr.pd = pd;
+ iwmr->ibmr.device = pd->device;
+ iwmr->ibmr.iova = virt;
+
+ iwmr->page_size = ib_umem_find_best_pgsz(iwmr->region,
+ iwdev->rf->sc_dev.hw_attrs.page_size_cap,
+ virt);
+ if (unlikely(!iwmr->page_size)) {
+ kfree(iwmr);
+ ib_umem_release(iwmr->region);
+ return ERR_PTR(-EOPNOTSUPP);
+ }
+
+ iwmr->len = iwmr->region->length;
+ iwpbl->user_base = virt;
+ palloc = &iwpbl->pble_alloc;
+ iwmr->type = IRDMA_MEMREG_TYPE_MEM;
+ iwmr->page_cnt = ib_umem_num_dma_blocks(iwmr->region, iwmr->page_size);
+
+ use_pbles = (iwmr->page_cnt != 1);
+
+ err = irdma_setup_pbles(iwdev->rf, iwmr, use_pbles, false);
+ if (err)
+ goto error;
+
+ if (use_pbles) {
+ err = irdma_check_mr_contiguous(palloc, iwmr->page_size);
+ if (err) {
+ irdma_free_pble(iwdev->rf->pble_rsrc, palloc);
+ iwpbl->pbl_allocated = false;
+ }
+ }
+
+ stag = irdma_create_stag(iwdev);
+ if (!stag) {
+ err = -ENOMEM;
+ goto error;
+ }
+
+ iwmr->stag = stag;
+ iwmr->ibmr.rkey = stag;
+ iwmr->ibmr.lkey = stag;
+ err = irdma_hwreg_mr(iwdev, iwmr, access);
+ if (err) {
+ irdma_free_stag(iwdev, stag);
+ goto error;
+ }
+
+ return &iwmr->ibmr;
+
+error:
+ if (palloc->level != PBLE_LEVEL_0 && iwpbl->pbl_allocated)
+ irdma_free_pble(iwdev->rf->pble_rsrc, palloc);
+ kfree(iwmr);
+ ib_umem_release(&umem_dmabuf->umem);
+
+ return ERR_PTR(err);
+}
+
/**
* irdma_reg_phys_mr - register kernel physical memory
* @pd: ibpd pointer
@@ -4418,6 +4514,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),
--
2.34.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCHv3 for-next 1/1] RDMA/irdma: Add support for dmabuf pin memory regions
2023-01-05 13:37 ` Jason Gunthorpe
@ 2023-01-07 6:22 ` Yanjun Zhu
0 siblings, 0 replies; 10+ messages in thread
From: Yanjun Zhu @ 2023-01-07 6:22 UTC (permalink / raw)
To: Jason Gunthorpe, Zhu Yanjun
Cc: mustafa.ismail, shiraz.saleem, leon, linux-rdma, Zhu Yanjun
在 2023/1/5 21:37, Jason Gunthorpe 写道:
> On Thu, Jan 05, 2023 at 05:37:10PM -0500, 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>
>> ---
>> V2->V3: Simplify the function by removing QP and CQ handling;
>> V1->V2: Fix the build warning by adding a static;
>> ---
>> drivers/infiniband/hw/irdma/verbs.c | 97 +++++++++++++++++++++++++++++
>> 1 file changed, 97 insertions(+)
>>
>> diff --git a/drivers/infiniband/hw/irdma/verbs.c b/drivers/infiniband/hw/irdma/verbs.c
>> index f6973ea55eda..7028b8af87b9 100644
>> --- a/drivers/infiniband/hw/irdma/verbs.c
>> +++ b/drivers/infiniband/hw/irdma/verbs.c
>> @@ -2912,6 +2912,102 @@ 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 irdma_pble_alloc *palloc;
>> + struct irdma_pbl *iwpbl;
>> + struct irdma_mr *iwmr;
>> + u32 stag = 0;
>> + bool use_pbles = false;
>> + int err = -EINVAL;
>> + struct ib_umem_dmabuf *umem_dmabuf;
>> +
>> + 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 = kzalloc(sizeof(*iwmr), GFP_KERNEL);
>> + if (!iwmr) {
>> + ib_umem_release(&umem_dmabuf->umem);
>> + return ERR_PTR(-ENOMEM);
>> + }
>
> again, please don't duplicate all this code, refactor the mr code so
> it can be shared.
Got it. I will refactor the mr code and split the shared code into
several helper functions. After the commits are merged, I will continue
to add the support of dmabuf with the helper functions.
Zhu Yanjun
>
> Jason
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCHv3 for-next 1/1] RDMA/irdma: Add support for dmabuf pin memory regions
@ 2023-02-01 3:21 Zhu Yanjun
2023-02-03 3:16 ` Zhu Yanjun
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Zhu Yanjun @ 2023-02-01 3:21 UTC (permalink / raw)
To: mustafa.ismail, shiraz.saleem, jgg, leon, linux-rdma; +Cc: Zhu Yanjun
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>
---
V2->V3: Remove unnecessary variable initialization;
Use error handler;
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 | 45 +++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/drivers/infiniband/hw/irdma/verbs.c b/drivers/infiniband/hw/irdma/verbs.c
index 6982f38596c8..7525f4cdf6fb 100644
--- a/drivers/infiniband/hw/irdma/verbs.c
+++ b/drivers/infiniband/hw/irdma/verbs.c
@@ -2977,6 +2977,50 @@ 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;
+ struct irdma_mr *iwmr;
+ 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)) {
+ err = PTR_ERR(iwmr);
+ goto err_release;
+ }
+
+ err = irdma_reg_user_mr_type_mem(iwmr, access);
+ if (err)
+ goto err_iwmr;
+
+ return &iwmr->ibmr;
+
+err_iwmr:
+ irdma_free_iwmr(iwmr);
+
+err_release:
+ ib_umem_release(&umem_dmabuf->umem);
+
+ return ERR_PTR(err);
+}
+
/**
* irdma_reg_phys_mr - register kernel physical memory
* @pd: ibpd pointer
@@ -4483,6 +4527,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),
--
2.27.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCHv3 for-next 1/1] RDMA/irdma: Add support for dmabuf pin memory regions
2023-02-01 3:21 Zhu Yanjun
@ 2023-02-03 3:16 ` Zhu Yanjun
2023-02-15 13:38 ` Saleem, Shiraz
2023-02-16 15:03 ` Jason Gunthorpe
2 siblings, 0 replies; 10+ messages in thread
From: Zhu Yanjun @ 2023-02-03 3:16 UTC (permalink / raw)
To: Zhu Yanjun, mustafa.ismail, shiraz.saleem, jgg, leon, linux-rdma
Cc: Zhu Yanjun
在 2023/2/1 11:21, Zhu Yanjun 写道:
> 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>
> ---
> V2->V3: Remove unnecessary variable initialization;
> Use error handler;
> 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.
Shiraz Saleem is on vacation and returning to office on Feb.13, 2023.
We can wait for him.
Zhu Yanjun
> ---
> drivers/infiniband/hw/irdma/verbs.c | 45 +++++++++++++++++++++++++++++
> 1 file changed, 45 insertions(+)
>
> diff --git a/drivers/infiniband/hw/irdma/verbs.c b/drivers/infiniband/hw/irdma/verbs.c
> index 6982f38596c8..7525f4cdf6fb 100644
> --- a/drivers/infiniband/hw/irdma/verbs.c
> +++ b/drivers/infiniband/hw/irdma/verbs.c
> @@ -2977,6 +2977,50 @@ 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;
> + struct irdma_mr *iwmr;
> + 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)) {
> + err = PTR_ERR(iwmr);
> + goto err_release;
> + }
> +
> + err = irdma_reg_user_mr_type_mem(iwmr, access);
> + if (err)
> + goto err_iwmr;
> +
> + return &iwmr->ibmr;
> +
> +err_iwmr:
> + irdma_free_iwmr(iwmr);
> +
> +err_release:
> + ib_umem_release(&umem_dmabuf->umem);
> +
> + return ERR_PTR(err);
> +}
> +
> /**
> * irdma_reg_phys_mr - register kernel physical memory
> * @pd: ibpd pointer
> @@ -4483,6 +4527,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),
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: [PATCHv3 for-next 1/1] RDMA/irdma: Add support for dmabuf pin memory regions
2023-02-01 3:21 Zhu Yanjun
2023-02-03 3:16 ` Zhu Yanjun
@ 2023-02-15 13:38 ` Saleem, Shiraz
2023-02-17 1:27 ` Zhu Yanjun
2023-02-16 15:03 ` Jason Gunthorpe
2 siblings, 1 reply; 10+ messages in thread
From: Saleem, Shiraz @ 2023-02-15 13:38 UTC (permalink / raw)
To: Zhu, Yanjun, Ismail, Mustafa, jgg@ziepe.ca, leon@kernel.org,
linux-rdma@vger.kernel.org
Cc: Zhu Yanjun
> Subject: [PATCHv3 for-next 1/1] RDMA/irdma: Add support for dmabuf pin
> memory regions
>
> 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>
> ---
> V2->V3: Remove unnecessary variable initialization;
> Use error handler;
> 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 | 45 +++++++++++++++++++++++++++++
> 1 file changed, 45 insertions(+)
>
> diff --git a/drivers/infiniband/hw/irdma/verbs.c b/drivers/infiniband/hw/irdma/verbs.c
> index 6982f38596c8..7525f4cdf6fb 100644
> --- a/drivers/infiniband/hw/irdma/verbs.c
> +++ b/drivers/infiniband/hw/irdma/verbs.c
> @@ -2977,6 +2977,50 @@ 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;
> + struct irdma_mr *iwmr;
> + 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);
Do we need this? we don't copy anything from udata. There is no info passed via ABI struct irdma_mem_reg_req.
> +
> + 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)) {
> + err = PTR_ERR(iwmr);
> + goto err_release;
> + }
> +
> + err = irdma_reg_user_mr_type_mem(iwmr, access);
> + if (err)
> + goto err_iwmr;
> +
> + return &iwmr->ibmr;
> +
> +err_iwmr:
> + irdma_free_iwmr(iwmr);
> +
> +err_release:
> + ib_umem_release(&umem_dmabuf->umem);
> +
> + return ERR_PTR(err);
> +}
> +
> /**
> * irdma_reg_phys_mr - register kernel physical memory
> * @pd: ibpd pointer
> @@ -4483,6 +4527,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),
> --
Reviewed-by: Shiraz Saleem <shiraz.saleem@intel.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCHv3 for-next 1/1] RDMA/irdma: Add support for dmabuf pin memory regions
2023-02-01 3:21 Zhu Yanjun
2023-02-03 3:16 ` Zhu Yanjun
2023-02-15 13:38 ` Saleem, Shiraz
@ 2023-02-16 15:03 ` Jason Gunthorpe
2023-02-17 0:46 ` Zhu Yanjun
2 siblings, 1 reply; 10+ messages in thread
From: Jason Gunthorpe @ 2023-02-16 15:03 UTC (permalink / raw)
To: Zhu Yanjun; +Cc: mustafa.ismail, shiraz.saleem, leon, linux-rdma, Zhu Yanjun
On Wed, Feb 01, 2023 at 11:21:15AM +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>
> Reviewed-by: Shiraz Saleem <shiraz.saleem@intel.com>
> ---
> V2->V3: Remove unnecessary variable initialization;
> Use error handler;
> 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 | 45 +++++++++++++++++++++++++++++
> 1 file changed, 45 insertions(+)
>
> diff --git a/drivers/infiniband/hw/irdma/verbs.c b/drivers/infiniband/hw/irdma/verbs.c
> index 6982f38596c8..7525f4cdf6fb 100644
> --- a/drivers/infiniband/hw/irdma/verbs.c
> +++ b/drivers/infiniband/hw/irdma/verbs.c
> @@ -2977,6 +2977,50 @@ 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;
> + struct irdma_mr *iwmr;
> + 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);
Shiraz is correct, I'm wondering how this even works. This is a new
style uAPI without UVERBS_ATTR_UHW so inlen should always be 0.
How did you manage to test this??
Jason
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCHv3 for-next 1/1] RDMA/irdma: Add support for dmabuf pin memory regions
2023-02-16 15:03 ` Jason Gunthorpe
@ 2023-02-17 0:46 ` Zhu Yanjun
2023-02-17 2:23 ` Jason Gunthorpe
0 siblings, 1 reply; 10+ messages in thread
From: Zhu Yanjun @ 2023-02-17 0:46 UTC (permalink / raw)
To: Jason Gunthorpe, Zhu Yanjun
Cc: mustafa.ismail, shiraz.saleem, leon, linux-rdma
在 2023/2/16 23:03, Jason Gunthorpe 写道:
> On Wed, Feb 01, 2023 at 11:21:15AM +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>
>> Reviewed-by: Shiraz Saleem <shiraz.saleem@intel.com>
>> ---
>> V2->V3: Remove unnecessary variable initialization;
>> Use error handler;
>> 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 | 45 +++++++++++++++++++++++++++++
>> 1 file changed, 45 insertions(+)
>>
>> diff --git a/drivers/infiniband/hw/irdma/verbs.c b/drivers/infiniband/hw/irdma/verbs.c
>> index 6982f38596c8..7525f4cdf6fb 100644
>> --- a/drivers/infiniband/hw/irdma/verbs.c
>> +++ b/drivers/infiniband/hw/irdma/verbs.c
>> @@ -2977,6 +2977,50 @@ 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;
>> + struct irdma_mr *iwmr;
>> + 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);
> Shiraz is correct, I'm wondering how this even works. This is a new
> style uAPI without UVERBS_ATTR_UHW so inlen should always be 0.
Got it. Thanks Shiraz and Jason.
I will remove the test of inlen in the latest commit.
Best Regards,
Zhu Yanjun
>
> How did you manage to test this??
>
> Jason
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCHv3 for-next 1/1] RDMA/irdma: Add support for dmabuf pin memory regions
2023-02-15 13:38 ` Saleem, Shiraz
@ 2023-02-17 1:27 ` Zhu Yanjun
0 siblings, 0 replies; 10+ messages in thread
From: Zhu Yanjun @ 2023-02-17 1:27 UTC (permalink / raw)
To: Saleem, Shiraz, Zhu, Yanjun, Ismail, Mustafa, jgg@ziepe.ca,
leon@kernel.org, linux-rdma@vger.kernel.org
在 2023/2/15 21:38, Saleem, Shiraz 写道:
>> Subject: [PATCHv3 for-next 1/1] RDMA/irdma: Add support for dmabuf pin
>> memory regions
>>
>> 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>
>> ---
>> V2->V3: Remove unnecessary variable initialization;
>> Use error handler;
>> 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 | 45 +++++++++++++++++++++++++++++
>> 1 file changed, 45 insertions(+)
>>
>> diff --git a/drivers/infiniband/hw/irdma/verbs.c b/drivers/infiniband/hw/irdma/verbs.c
>> index 6982f38596c8..7525f4cdf6fb 100644
>> --- a/drivers/infiniband/hw/irdma/verbs.c
>> +++ b/drivers/infiniband/hw/irdma/verbs.c
>> @@ -2977,6 +2977,50 @@ 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;
>> + struct irdma_mr *iwmr;
>> + 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);
> Do we need this? we don't copy anything from udata. There is no info passed via ABI struct irdma_mem_reg_req.
Got it. I will remove the inlen test and send a new commit out.
>
>> +
>> + 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)) {
>> + err = PTR_ERR(iwmr);
>> + goto err_release;
>> + }
>> +
>> + err = irdma_reg_user_mr_type_mem(iwmr, access);
>> + if (err)
>> + goto err_iwmr;
>> +
>> + return &iwmr->ibmr;
>> +
>> +err_iwmr:
>> + irdma_free_iwmr(iwmr);
>> +
>> +err_release:
>> + ib_umem_release(&umem_dmabuf->umem);
>> +
>> + return ERR_PTR(err);
>> +}
>> +
>> /**
>> * irdma_reg_phys_mr - register kernel physical memory
>> * @pd: ibpd pointer
>> @@ -4483,6 +4527,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),
>> --
> Reviewed-by: Shiraz Saleem <shiraz.saleem@intel.com>
Thanks.
Zhu Yanjun
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCHv3 for-next 1/1] RDMA/irdma: Add support for dmabuf pin memory regions
2023-02-17 0:46 ` Zhu Yanjun
@ 2023-02-17 2:23 ` Jason Gunthorpe
0 siblings, 0 replies; 10+ messages in thread
From: Jason Gunthorpe @ 2023-02-17 2:23 UTC (permalink / raw)
To: Zhu Yanjun; +Cc: Zhu Yanjun, mustafa.ismail, shiraz.saleem, leon, linux-rdma
On Fri, Feb 17, 2023 at 08:46:52AM +0800, Zhu Yanjun wrote:
>
> 在 2023/2/16 23:03, Jason Gunthorpe 写道:
> > On Wed, Feb 01, 2023 at 11:21:15AM +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>
> > > Reviewed-by: Shiraz Saleem <shiraz.saleem@intel.com>
> > > ---
> > > V2->V3: Remove unnecessary variable initialization;
> > > Use error handler;
> > > 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 | 45 +++++++++++++++++++++++++++++
> > > 1 file changed, 45 insertions(+)
> > >
> > > diff --git a/drivers/infiniband/hw/irdma/verbs.c b/drivers/infiniband/hw/irdma/verbs.c
> > > index 6982f38596c8..7525f4cdf6fb 100644
> > > --- a/drivers/infiniband/hw/irdma/verbs.c
> > > +++ b/drivers/infiniband/hw/irdma/verbs.c
> > > @@ -2977,6 +2977,50 @@ 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;
> > > + struct irdma_mr *iwmr;
> > > + 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);
> > Shiraz is correct, I'm wondering how this even works. This is a new
> > style uAPI without UVERBS_ATTR_UHW so inlen should always be 0.
>
> Got it. Thanks Shiraz and Jason.
>
> I will remove the test of inlen in the latest commit.
Please answer how did you manage to test this?
Jason
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2023-02-17 2:23 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-05 22:37 [PATCHv3 for-next 1/1] RDMA/irdma: Add support for dmabuf pin memory regions Zhu Yanjun
2023-01-05 13:37 ` Jason Gunthorpe
2023-01-07 6:22 ` Yanjun Zhu
-- strict thread matches above, loose matches on Subject: below --
2023-02-01 3:21 Zhu Yanjun
2023-02-03 3:16 ` Zhu Yanjun
2023-02-15 13:38 ` Saleem, Shiraz
2023-02-17 1:27 ` Zhu Yanjun
2023-02-16 15:03 ` Jason Gunthorpe
2023-02-17 0:46 ` Zhu Yanjun
2023-02-17 2:23 ` Jason Gunthorpe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).