diff mbox

[1/5] IB/core: Make rdma_rw_ctx_init() initialize all used fields

Message ID 91e53f7b-fdb6-bd66-ada6-982c641c2048@sandisk.com (mailing list archive)
State Superseded
Headers show

Commit Message

Bart Van Assche June 28, 2016, 11:25 a.m. UTC
Some but not all callers of rdma_rw_ctx_init() zero-initialize
struct rdma_rw_ctx. Hence make rdma_rw_ctx_init() initialize all
work request fields that will be read by ib_post_send().

Fixes: b99f8e4d7bcd ("IB/srpt: convert to the generic RDMA READ/WRITE API")
Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
Cc: <stable@vger.kernel.org> #v4.7+
Cc: Christoph Hellwig <hch@lst.de>
Cc: Sagi Grimberg <sagi@grimberg.me>
Cc: Nicholas Bellinger <nab@linux-iscsi.org>
Cc: Parav Pandit <pandit.parav@gmail.com>
Cc: Laurence Oberman <loberman@redhat.com>
---
 drivers/infiniband/core/rw.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

Comments

Christoph Hellwig June 28, 2016, 11:51 a.m. UTC | #1
On Tue, Jun 28, 2016 at 01:25:15PM +0200, Bart Van Assche wrote:
> Some but not all callers of rdma_rw_ctx_init() zero-initialize
> struct rdma_rw_ctx. Hence make rdma_rw_ctx_init() initialize all
> work request fields that will be read by ib_post_send().
> 
> Fixes: b99f8e4d7bcd ("IB/srpt: convert to the generic RDMA READ/WRITE API")
> Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
> Cc: <stable@vger.kernel.org> #v4.7+
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Sagi Grimberg <sagi@grimberg.me>
> Cc: Nicholas Bellinger <nab@linux-iscsi.org>
> Cc: Parav Pandit <pandit.parav@gmail.com>
> Cc: Laurence Oberman <loberman@redhat.com>
> ---
>  drivers/infiniband/core/rw.c | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/infiniband/core/rw.c b/drivers/infiniband/core/rw.c
> index 1eb9b12..13d4067 100644
> --- a/drivers/infiniband/core/rw.c
> +++ b/drivers/infiniband/core/rw.c
> @@ -99,6 +99,7 @@ static int rdma_rw_init_one_mr(struct ib_qp *qp, u8 port_num,
>  	}
>  
>  	reg->reg_wr.wr.opcode = IB_WR_REG_MR;
> +	reg->reg_wr.wr.next = NULL;

This one is always set up by the callers of the function.

> @@ -114,6 +115,7 @@ static int rdma_rw_init_mr_wrs(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
>  		u8 port_num, struct scatterlist *sg, u32 sg_cnt, u32 offset,
>  		u64 remote_addr, u32 rkey, enum dma_data_direction dir)
>  {
> +	struct rdma_rw_reg_ctx *prev = NULL;
>  	u32 pages_per_mr = rdma_rw_fr_page_list_len(qp->pd->device);
>  	int i, j, ret = 0, count = 0;
>  
> @@ -125,7 +127,6 @@ static int rdma_rw_init_mr_wrs(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
>  	}
>  
>  	for (i = 0; i < ctx->nr_ops; i++) {
> -		struct rdma_rw_reg_ctx *prev = i ? &ctx->reg[i - 1] : NULL;
>  		struct rdma_rw_reg_ctx *reg = &ctx->reg[i];
>  		u32 nents = min(sg_cnt, pages_per_mr);
>  
> @@ -162,9 +163,13 @@ static int rdma_rw_init_mr_wrs(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
>  		sg_cnt -= nents;
>  		for (j = 0; j < nents; j++)
>  			sg = sg_next(sg);
> +		prev = reg;
>  		offset = 0;
>  	}
>  
> +	if (prev)
> +		prev->wr.wr.next = NULL;
> +
>  	ctx->type = RDMA_RW_MR;
>  	return count;

I think the right fix here is to set last_wr->next to NULL for
the !chain_wr case in rdma_rw_ctx_wrs, or in fact maybe just simplify
the end of rdma_rw_ctx_wrs to:

	last_wr->next = chain_wr;
	if (!chain_wr) {
		last_wr->wr_cqe = cqe;
		last_wr->send_flags |= IB_SEND_SIGNALED;
	}

> @@ -205,11 +210,10 @@ static int rdma_rw_init_map_wrs(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
>  			rdma_wr->wr.opcode = IB_WR_RDMA_READ;
>  		rdma_wr->remote_addr = remote_addr + total_len;
>  		rdma_wr->rkey = rkey;
> +		rdma_wr->wr.num_sge = nr_sge;
>  		rdma_wr->wr.sg_list = sge;
>  
>  		for (j = 0; j < nr_sge; j++, sg = sg_next(sg)) {
> -			rdma_wr->wr.num_sge++;
> -

This parts looks fine.

> -		if (i + 1 < ctx->nr_ops)
> -			rdma_wr->wr.next = &ctx->map.wrs[i + 1].wr;
> +		rdma_wr->wr.next = i + 1 < ctx->nr_ops ?
> +			&ctx->map.wrs[i + 1].wr : NULL;

I think the rdma_rw_ctx_wrs should take care of this as well.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Bart Van Assche June 28, 2016, 1:04 p.m. UTC | #2
On 06/28/2016 01:51 PM, Christoph Hellwig wrote:
> On Tue, Jun 28, 2016 at 01:25:15PM +0200, Bart Van Assche wrote:
>> -		if (i + 1 < ctx->nr_ops)
>> -			rdma_wr->wr.next = &ctx->map.wrs[i + 1].wr;
>> +		rdma_wr->wr.next = i + 1 < ctx->nr_ops ?
>> +			&ctx->map.wrs[i + 1].wr : NULL;
>
> I think the rdma_rw_ctx_wrs should take care of this as well.

I agree that it is possible to let rdma_rw_ctx_wrs() initialize wr.next 
of the last WR. But if we chose that approach then drivers that call 
rdma_rw_ctx_init() but not rdma_rw_ctx_wrs(), e.g. ib_isert, can end up 
with a last wr.next field that has not been initialized. Hence my 
preference for performing that initialization in rdma_rw_init_mr_wrs() 
and rdma_rw_init_map_wrs().

Bart.


--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/infiniband/core/rw.c b/drivers/infiniband/core/rw.c
index 1eb9b12..13d4067 100644
--- a/drivers/infiniband/core/rw.c
+++ b/drivers/infiniband/core/rw.c
@@ -99,6 +99,7 @@  static int rdma_rw_init_one_mr(struct ib_qp *qp, u8 port_num,
 	}
 
 	reg->reg_wr.wr.opcode = IB_WR_REG_MR;
+	reg->reg_wr.wr.next = NULL;
 	reg->reg_wr.mr = reg->mr;
 	reg->reg_wr.access = IB_ACCESS_LOCAL_WRITE;
 	if (rdma_protocol_iwarp(qp->device, port_num))
@@ -114,6 +115,7 @@  static int rdma_rw_init_mr_wrs(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
 		u8 port_num, struct scatterlist *sg, u32 sg_cnt, u32 offset,
 		u64 remote_addr, u32 rkey, enum dma_data_direction dir)
 {
+	struct rdma_rw_reg_ctx *prev = NULL;
 	u32 pages_per_mr = rdma_rw_fr_page_list_len(qp->pd->device);
 	int i, j, ret = 0, count = 0;
 
@@ -125,7 +127,6 @@  static int rdma_rw_init_mr_wrs(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
 	}
 
 	for (i = 0; i < ctx->nr_ops; i++) {
-		struct rdma_rw_reg_ctx *prev = i ? &ctx->reg[i - 1] : NULL;
 		struct rdma_rw_reg_ctx *reg = &ctx->reg[i];
 		u32 nents = min(sg_cnt, pages_per_mr);
 
@@ -162,9 +163,13 @@  static int rdma_rw_init_mr_wrs(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
 		sg_cnt -= nents;
 		for (j = 0; j < nents; j++)
 			sg = sg_next(sg);
+		prev = reg;
 		offset = 0;
 	}
 
+	if (prev)
+		prev->wr.wr.next = NULL;
+
 	ctx->type = RDMA_RW_MR;
 	return count;
 
@@ -205,11 +210,10 @@  static int rdma_rw_init_map_wrs(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
 			rdma_wr->wr.opcode = IB_WR_RDMA_READ;
 		rdma_wr->remote_addr = remote_addr + total_len;
 		rdma_wr->rkey = rkey;
+		rdma_wr->wr.num_sge = nr_sge;
 		rdma_wr->wr.sg_list = sge;
 
 		for (j = 0; j < nr_sge; j++, sg = sg_next(sg)) {
-			rdma_wr->wr.num_sge++;
-
 			sge->addr = ib_sg_dma_address(dev, sg) + offset;
 			sge->length = ib_sg_dma_len(dev, sg) - offset;
 			sge->lkey = qp->pd->local_dma_lkey;
@@ -220,8 +224,8 @@  static int rdma_rw_init_map_wrs(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
 			offset = 0;
 		}
 
-		if (i + 1 < ctx->nr_ops)
-			rdma_wr->wr.next = &ctx->map.wrs[i + 1].wr;
+		rdma_wr->wr.next = i + 1 < ctx->nr_ops ?
+			&ctx->map.wrs[i + 1].wr : NULL;
 	}
 
 	ctx->type = RDMA_RW_MULTI_WR;