Skip to content

Commit 2f18882

Browse files
SergeyGorenkojgunthorpe
authored andcommitted
IB/iser: Prevent invalidating wrong MR
The iser_reg_resources structure has two pointers to MR but only one mr_valid field. The implementation assumes that we use only *sig_mr when pi_enable is true. Otherwise, we use only *mr. However, it is only sometimes correct. Read commands without protection information occur even when pi_enble is true. For example, the following SCSI commands have a Data-In buffer but never have protection information: READ CAPACITY (16), INQUIRY, MODE SENSE(6), MAINTENANCE IN. So, we use *sig_mr for some SCSI commands and *mr for the other SCSI commands. In most cases, it works fine because the remote invalidation is applied. However, there are two cases when the remote invalidation is not applicable. 1. Small write commands when all data is sent as an immediate. 2. The target does not support the remote invalidation feature. The lazy invalidation is used if the remote invalidation is impossible. Since, at the lazy invalidation, we always invalidate the MR we want to use, the wrong MR may be invalidated. To fix the issue, we need a field per MR that indicates the MR needs invalidation. Since the ib_mr structure already has such a field, let's use ib_mr.need_inval instead of iser_reg_resources.mr_valid. Fixes: b76a439 ("IB/iser: Use IB_WR_REG_MR_INTEGRITY for PI handover") Link: https://lore.kernel.org/r/[email protected] Acked-by: Max Gurtovoy <[email protected]> Signed-off-by: Sergey Gorenko <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 63a43a6 commit 2f18882

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

drivers/infiniband/ulp/iser/iscsi_iser.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,10 @@ struct iser_device {
316316
*
317317
* @mr: memory region
318318
* @sig_mr: signature memory region
319-
* @mr_valid: is mr valid indicator
320319
*/
321320
struct iser_reg_resources {
322321
struct ib_mr *mr;
323322
struct ib_mr *sig_mr;
324-
u8 mr_valid:1;
325323
};
326324

327325
/**

drivers/infiniband/ulp/iser/iser_initiator.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,10 @@ static inline int iser_inv_desc(struct iser_fr_desc *desc, u32 rkey)
581581
return -EINVAL;
582582
}
583583

584-
desc->rsc.mr_valid = 0;
584+
if (desc->sig_protected)
585+
desc->rsc.sig_mr->need_inval = false;
586+
else
587+
desc->rsc.mr->need_inval = false;
585588

586589
return 0;
587590
}

drivers/infiniband/ulp/iser/iser_memory.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ static int iser_reg_sig_mr(struct iscsi_iser_task *iser_task,
264264

265265
iser_set_prot_checks(iser_task->sc, &sig_attrs->check_mask);
266266

267-
if (rsc->mr_valid)
267+
if (rsc->sig_mr->need_inval)
268268
iser_inv_rkey(&tx_desc->inv_wr, mr, cqe, &wr->wr);
269269

270270
ib_update_fast_reg_key(mr, ib_inc_rkey(mr->rkey));
@@ -288,7 +288,7 @@ static int iser_reg_sig_mr(struct iscsi_iser_task *iser_task,
288288
wr->access = IB_ACCESS_LOCAL_WRITE |
289289
IB_ACCESS_REMOTE_READ |
290290
IB_ACCESS_REMOTE_WRITE;
291-
rsc->mr_valid = 1;
291+
rsc->sig_mr->need_inval = true;
292292

293293
sig_reg->sge.lkey = mr->lkey;
294294
sig_reg->rkey = mr->rkey;
@@ -313,7 +313,7 @@ static int iser_fast_reg_mr(struct iscsi_iser_task *iser_task,
313313
struct ib_reg_wr *wr = &tx_desc->reg_wr;
314314
int n;
315315

316-
if (rsc->mr_valid)
316+
if (rsc->mr->need_inval)
317317
iser_inv_rkey(&tx_desc->inv_wr, mr, cqe, &wr->wr);
318318

319319
ib_update_fast_reg_key(mr, ib_inc_rkey(mr->rkey));
@@ -336,7 +336,7 @@ static int iser_fast_reg_mr(struct iscsi_iser_task *iser_task,
336336
IB_ACCESS_REMOTE_WRITE |
337337
IB_ACCESS_REMOTE_READ;
338338

339-
rsc->mr_valid = 1;
339+
rsc->mr->need_inval = true;
340340

341341
reg->sge.lkey = mr->lkey;
342342
reg->rkey = mr->rkey;

drivers/infiniband/ulp/iser/iser_verbs.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ iser_create_fastreg_desc(struct iser_device *device,
129129
goto err_alloc_mr_integrity;
130130
}
131131
}
132-
desc->rsc.mr_valid = 0;
133132

134133
return desc;
135134

0 commit comments

Comments
 (0)