linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH for-next 0/3] Use the right sg_cnt after ib_dma_map_sg
@ 2022-08-18 10:53 Md Haris Iqbal
  2022-08-18 10:53 ` [PATCH for-next 1/3] RDMA/rtrs-clt: Output sg index when warning on Md Haris Iqbal
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Md Haris Iqbal @ 2022-08-18 10:53 UTC (permalink / raw)
  To: linux-rdma; +Cc: leon, jgg, haris.iqbal, jinpu.wang

Hi Jason, hi Leon,

Please consider to include following changes to the next merge window.

The patchset is organized as follows:
1: Add output for debug purposes
2: Use correct count returned form ib_dma_map_sg for rtrs-clt
3: Use correct count returned form ib_dma_map_sg for rtrs-srv

Jack Wang (3):
  RDMA/rtrs-clt: Output sg index when warning on
  RDMA/rtrs-clt: Use the right sg_cnt after ib_dma_map_sg
  RDMA/rtrs-srv: Pass the correct number of entries for dma mapped SGL

 drivers/infiniband/ulp/rtrs/rtrs-clt.c |  9 +++++----
 drivers/infiniband/ulp/rtrs/rtrs-srv.c | 14 +++++++-------
 drivers/infiniband/ulp/rtrs/rtrs.c     |  2 +-
 3 files changed, 13 insertions(+), 12 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH for-next 1/3] RDMA/rtrs-clt: Output sg index when warning on
  2022-08-18 10:53 [PATCH for-next 0/3] Use the right sg_cnt after ib_dma_map_sg Md Haris Iqbal
@ 2022-08-18 10:53 ` Md Haris Iqbal
  2022-08-18 10:53 ` [PATCH for-next 2/3] RDMA/rtrs-clt: Use the right sg_cnt after ib_dma_map_sg Md Haris Iqbal
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Md Haris Iqbal @ 2022-08-18 10:53 UTC (permalink / raw)
  To: linux-rdma; +Cc: leon, jgg, haris.iqbal, jinpu.wang, Aleksei Marov

From: Jack Wang <jinpu.wang@ionos.com>

Output the sg index, so it's a bit easier for debug.

Signed-off-by: Jack Wang <jinpu.wang@ionos.com>
Reviewed-by: Aleksei Marov <aleksei.marov@ionos.com>
---
 drivers/infiniband/ulp/rtrs/rtrs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/infiniband/ulp/rtrs/rtrs.c b/drivers/infiniband/ulp/rtrs/rtrs.c
index 60fa0b0160f4..ed324b47d93a 100644
--- a/drivers/infiniband/ulp/rtrs/rtrs.c
+++ b/drivers/infiniband/ulp/rtrs/rtrs.c
@@ -175,7 +175,7 @@ int rtrs_iu_post_rdma_write_imm(struct rtrs_con *con, struct rtrs_iu *iu,
 	 * length error
 	 */
 	for (i = 0; i < num_sge; i++)
-		if (WARN_ON(sge[i].length == 0))
+		if (WARN_ONCE(sge[i].length == 0, "sg %d is zero length\n", i))
 			return -EINVAL;
 
 	return rtrs_post_send(con->qp, head, &wr.wr, tail);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH for-next 2/3] RDMA/rtrs-clt: Use the right sg_cnt after ib_dma_map_sg
  2022-08-18 10:53 [PATCH for-next 0/3] Use the right sg_cnt after ib_dma_map_sg Md Haris Iqbal
  2022-08-18 10:53 ` [PATCH for-next 1/3] RDMA/rtrs-clt: Output sg index when warning on Md Haris Iqbal
@ 2022-08-18 10:53 ` Md Haris Iqbal
  2022-08-18 10:53 ` [PATCH for-next 3/3] RDMA/rtrs-srv: Pass the correct number of entries for dma mapped SGL Md Haris Iqbal
  2022-08-21  9:27 ` [PATCH for-next 0/3] Use the right sg_cnt after ib_dma_map_sg Leon Romanovsky
  3 siblings, 0 replies; 5+ messages in thread
From: Md Haris Iqbal @ 2022-08-18 10:53 UTC (permalink / raw)
  To: linux-rdma; +Cc: leon, jgg, haris.iqbal, jinpu.wang, Aleksei Marov

From: Jack Wang <jinpu.wang@ionos.com>

When iommu is enabled, we hit warnings like this:
WARNING: at rtrs/rtrs.c:178 rtrs_iu_post_rdma_write_imm+0x9b/0x110

rtrs warn on one sge entry length is 0, which is unexpected.

The problem is ib_dma_map_sg augments the SGL into a 'dma mapped SGL'.
This process may change the number of entries and the lengths of each
entry.

Code that touches dma_address is iterating over the 'dma mapped SGL'
and must use dma_nents which returned from ib_dma_map_sg().
So pass the count return from ib_dma_map_sg.

Fixes: 6a98d71daea1 ("RDMA/rtrs: client: main functionality")
Signed-off-by: Jack Wang <jinpu.wang@ionos.com>
Reviewed-by: Aleksei Marov <aleksei.marov@ionos.com>
---
 drivers/infiniband/ulp/rtrs/rtrs-clt.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.c b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
index 5219bb10777a..5d0df186e937 100644
--- a/drivers/infiniband/ulp/rtrs/rtrs-clt.c
+++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
@@ -1007,7 +1007,8 @@ rtrs_clt_get_copy_req(struct rtrs_clt_path *alive_path,
 static int rtrs_post_rdma_write_sg(struct rtrs_clt_con *con,
 				   struct rtrs_clt_io_req *req,
 				   struct rtrs_rbuf *rbuf, bool fr_en,
-				   u32 size, u32 imm, struct ib_send_wr *wr,
+				   u32 count, u32 size, u32 imm,
+				   struct ib_send_wr *wr,
 				   struct ib_send_wr *tail)
 {
 	struct rtrs_clt_path *clt_path = to_clt_path(con->c.path);
@@ -1027,12 +1028,12 @@ static int rtrs_post_rdma_write_sg(struct rtrs_clt_con *con,
 		num_sge = 2;
 		ptail = tail;
 	} else {
-		for_each_sg(req->sglist, sg, req->sg_cnt, i) {
+		for_each_sg(req->sglist, sg, count, i) {
 			sge[i].addr   = sg_dma_address(sg);
 			sge[i].length = sg_dma_len(sg);
 			sge[i].lkey   = clt_path->s.dev->ib_pd->local_dma_lkey;
 		}
-		num_sge = 1 + req->sg_cnt;
+		num_sge = 1 + count;
 	}
 	sge[i].addr   = req->iu->dma_addr;
 	sge[i].length = size;
@@ -1145,7 +1146,7 @@ static int rtrs_clt_write_req(struct rtrs_clt_io_req *req)
 	 */
 	rtrs_clt_update_all_stats(req, WRITE);
 
-	ret = rtrs_post_rdma_write_sg(req->con, req, rbuf, fr_en,
+	ret = rtrs_post_rdma_write_sg(req->con, req, rbuf, fr_en, count,
 				      req->usr_len + sizeof(*msg),
 				      imm, wr, &inv_wr);
 	if (ret) {
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH for-next 3/3] RDMA/rtrs-srv: Pass the correct number of entries for dma mapped SGL
  2022-08-18 10:53 [PATCH for-next 0/3] Use the right sg_cnt after ib_dma_map_sg Md Haris Iqbal
  2022-08-18 10:53 ` [PATCH for-next 1/3] RDMA/rtrs-clt: Output sg index when warning on Md Haris Iqbal
  2022-08-18 10:53 ` [PATCH for-next 2/3] RDMA/rtrs-clt: Use the right sg_cnt after ib_dma_map_sg Md Haris Iqbal
@ 2022-08-18 10:53 ` Md Haris Iqbal
  2022-08-21  9:27 ` [PATCH for-next 0/3] Use the right sg_cnt after ib_dma_map_sg Leon Romanovsky
  3 siblings, 0 replies; 5+ messages in thread
From: Md Haris Iqbal @ 2022-08-18 10:53 UTC (permalink / raw)
  To: linux-rdma; +Cc: leon, jgg, haris.iqbal, jinpu.wang, Aleksei Marov

From: Jack Wang <jinpu.wang@ionos.com>

ib_dma_map_sg() augments the SGL into a 'dma mapped SGL'. This process
may change the number of entries and the lengths of each entry.

Code that touches dma_address is iterating over the 'dma mapped SGL'
and must use dma_nents which returned from ib_dma_map_sg().

We should use the return count from ib_dma_map_sg for futher usage.

Fixes: 9cb837480424e ("RDMA/rtrs: server: main functionality")
Signed-off-by: Jack Wang <jinpu.wang@ionos.com>
Reviewed-by: Aleksei Marov <aleksei.marov@ionos.com>
---
 drivers/infiniband/ulp/rtrs/rtrs-srv.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/infiniband/ulp/rtrs/rtrs-srv.c b/drivers/infiniband/ulp/rtrs/rtrs-srv.c
index 22e6f991946c..aa259b4c6f89 100644
--- a/drivers/infiniband/ulp/rtrs/rtrs-srv.c
+++ b/drivers/infiniband/ulp/rtrs/rtrs-srv.c
@@ -593,7 +593,7 @@ static int map_cont_bufs(struct rtrs_srv_path *srv_path)
 		struct sg_table *sgt = &srv_mr->sgt;
 		struct scatterlist *s;
 		struct ib_mr *mr;
-		int nr, chunks;
+		int nr, nr_sgt, chunks;
 
 		chunks = chunks_per_mr * mri;
 		if (!always_invalidate)
@@ -608,19 +608,19 @@ static int map_cont_bufs(struct rtrs_srv_path *srv_path)
 			sg_set_page(s, srv->chunks[chunks + i],
 				    max_chunk_size, 0);
 
-		nr = ib_dma_map_sg(srv_path->s.dev->ib_dev, sgt->sgl,
+		nr_sgt = ib_dma_map_sg(srv_path->s.dev->ib_dev, sgt->sgl,
 				   sgt->nents, DMA_BIDIRECTIONAL);
-		if (nr < sgt->nents) {
-			err = nr < 0 ? nr : -EINVAL;
+		if (!nr_sgt) {
+			err = -EINVAL;
 			goto free_sg;
 		}
 		mr = ib_alloc_mr(srv_path->s.dev->ib_pd, IB_MR_TYPE_MEM_REG,
-				 sgt->nents);
+				 nr_sgt);
 		if (IS_ERR(mr)) {
 			err = PTR_ERR(mr);
 			goto unmap_sg;
 		}
-		nr = ib_map_mr_sg(mr, sgt->sgl, sgt->nents,
+		nr = ib_map_mr_sg(mr, sgt->sgl, nr_sgt,
 				  NULL, max_chunk_size);
 		if (nr < 0 || nr < sgt->nents) {
 			err = nr < 0 ? nr : -EINVAL;
@@ -639,7 +639,7 @@ static int map_cont_bufs(struct rtrs_srv_path *srv_path)
 			}
 		}
 		/* Eventually dma addr for each chunk can be cached */
-		for_each_sg(sgt->sgl, s, sgt->orig_nents, i)
+		for_each_sg(sgt->sgl, s, nr_sgt, i)
 			srv_path->dma_addr[chunks + i] = sg_dma_address(s);
 
 		ib_update_fast_reg_key(mr, ib_inc_rkey(mr->rkey));
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH for-next 0/3] Use the right sg_cnt after ib_dma_map_sg
  2022-08-18 10:53 [PATCH for-next 0/3] Use the right sg_cnt after ib_dma_map_sg Md Haris Iqbal
                   ` (2 preceding siblings ...)
  2022-08-18 10:53 ` [PATCH for-next 3/3] RDMA/rtrs-srv: Pass the correct number of entries for dma mapped SGL Md Haris Iqbal
@ 2022-08-21  9:27 ` Leon Romanovsky
  3 siblings, 0 replies; 5+ messages in thread
From: Leon Romanovsky @ 2022-08-21  9:27 UTC (permalink / raw)
  To: Md Haris Iqbal; +Cc: linux-rdma, jgg, jinpu.wang

On Thu, Aug 18, 2022 at 12:53:52PM +0200, Md Haris Iqbal wrote:
> Hi Jason, hi Leon,
> 
> Please consider to include following changes to the next merge window.
> 
> The patchset is organized as follows:
> 1: Add output for debug purposes
> 2: Use correct count returned form ib_dma_map_sg for rtrs-clt
> 3: Use correct count returned form ib_dma_map_sg for rtrs-srv
> 
> Jack Wang (3):
>   RDMA/rtrs-clt: Output sg index when warning on

Applied to -next.

>   RDMA/rtrs-clt: Use the right sg_cnt after ib_dma_map_sg
>   RDMA/rtrs-srv: Pass the correct number of entries for dma mapped SGL

Applied to -rc.

> 
>  drivers/infiniband/ulp/rtrs/rtrs-clt.c |  9 +++++----
>  drivers/infiniband/ulp/rtrs/rtrs-srv.c | 14 +++++++-------
>  drivers/infiniband/ulp/rtrs/rtrs.c     |  2 +-
>  3 files changed, 13 insertions(+), 12 deletions(-)
> 
> -- 
> 2.25.1
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-08-21  9:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-18 10:53 [PATCH for-next 0/3] Use the right sg_cnt after ib_dma_map_sg Md Haris Iqbal
2022-08-18 10:53 ` [PATCH for-next 1/3] RDMA/rtrs-clt: Output sg index when warning on Md Haris Iqbal
2022-08-18 10:53 ` [PATCH for-next 2/3] RDMA/rtrs-clt: Use the right sg_cnt after ib_dma_map_sg Md Haris Iqbal
2022-08-18 10:53 ` [PATCH for-next 3/3] RDMA/rtrs-srv: Pass the correct number of entries for dma mapped SGL Md Haris Iqbal
2022-08-21  9:27 ` [PATCH for-next 0/3] Use the right sg_cnt after ib_dma_map_sg Leon Romanovsky

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).