Skip to content

Commit eaa74ec

Browse files
Bart Van Asschedledford
authored andcommitted
IB/core: Make rdma_rw_ctx_init() initialize all used fields
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: a060b56 ("IB/core: generic RDMA READ/WRITE API") Signed-off-by: Bart Van Assche <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Tested-by: Steve Wise <[email protected]> Tested-by: Laurence Oberman <[email protected]> Cc: Parav Pandit <[email protected]> Cc: Nicholas Bellinger <[email protected]> Cc: <[email protected]> #v4.7+ Signed-off-by: Doug Ledford <[email protected]>
1 parent 523d939 commit eaa74ec

File tree

1 file changed

+9
-5
lines changed
  • drivers/infiniband/core

1 file changed

+9
-5
lines changed

drivers/infiniband/core/rw.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ static inline u32 rdma_rw_fr_page_list_len(struct ib_device *dev)
7171
return min_t(u32, dev->attrs.max_fast_reg_page_list_len, 256);
7272
}
7373

74+
/* Caller must have zero-initialized *reg. */
7475
static int rdma_rw_init_one_mr(struct ib_qp *qp, u8 port_num,
7576
struct rdma_rw_reg_ctx *reg, struct scatterlist *sg,
7677
u32 sg_cnt, u32 offset)
@@ -114,6 +115,7 @@ static int rdma_rw_init_mr_wrs(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
114115
u8 port_num, struct scatterlist *sg, u32 sg_cnt, u32 offset,
115116
u64 remote_addr, u32 rkey, enum dma_data_direction dir)
116117
{
118+
struct rdma_rw_reg_ctx *prev = NULL;
117119
u32 pages_per_mr = rdma_rw_fr_page_list_len(qp->pd->device);
118120
int i, j, ret = 0, count = 0;
119121

@@ -125,7 +127,6 @@ static int rdma_rw_init_mr_wrs(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
125127
}
126128

127129
for (i = 0; i < ctx->nr_ops; i++) {
128-
struct rdma_rw_reg_ctx *prev = i ? &ctx->reg[i - 1] : NULL;
129130
struct rdma_rw_reg_ctx *reg = &ctx->reg[i];
130131
u32 nents = min(sg_cnt, pages_per_mr);
131132

@@ -162,9 +163,13 @@ static int rdma_rw_init_mr_wrs(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
162163
sg_cnt -= nents;
163164
for (j = 0; j < nents; j++)
164165
sg = sg_next(sg);
166+
prev = reg;
165167
offset = 0;
166168
}
167169

170+
if (prev)
171+
prev->wr.wr.next = NULL;
172+
168173
ctx->type = RDMA_RW_MR;
169174
return count;
170175

@@ -205,11 +210,10 @@ static int rdma_rw_init_map_wrs(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
205210
rdma_wr->wr.opcode = IB_WR_RDMA_READ;
206211
rdma_wr->remote_addr = remote_addr + total_len;
207212
rdma_wr->rkey = rkey;
213+
rdma_wr->wr.num_sge = nr_sge;
208214
rdma_wr->wr.sg_list = sge;
209215

210216
for (j = 0; j < nr_sge; j++, sg = sg_next(sg)) {
211-
rdma_wr->wr.num_sge++;
212-
213217
sge->addr = ib_sg_dma_address(dev, sg) + offset;
214218
sge->length = ib_sg_dma_len(dev, sg) - offset;
215219
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,
220224
offset = 0;
221225
}
222226

223-
if (i + 1 < ctx->nr_ops)
224-
rdma_wr->wr.next = &ctx->map.wrs[i + 1].wr;
227+
rdma_wr->wr.next = i + 1 < ctx->nr_ops ?
228+
&ctx->map.wrs[i + 1].wr : NULL;
225229
}
226230

227231
ctx->type = RDMA_RW_MULTI_WR;

0 commit comments

Comments
 (0)