Skip to contentSkip to conversation

RDMA/srp: Do not call scsi_done() from srp_abort()

PATCH Applied Bart Van Assche 3 participants 5 messages Aug 23, 2023 – Sep 11, 2023

Subsystems (2)
lore
Share & tools
lore

Bart Van Assche

author maintainer
#0 lore raw

PATCH 1/1 RDMA/srp: Do not call scsi_done() from srp_abort()

After scmd_eh_abort_handler() has called the SCSI LLD eh_abort_handler callback, it performs one of the following actions:
* Call scsi_queue_insert().
* Call scsi_finish_command().
* Call scsi_eh_scmd_add().
Hence, SCSI abort handlers must not call scsi_done(). Otherwise all the above actions would trigger a use-after-free. Hence remove the scsi_done() call from srp_abort(). Keep the srp_free_req() call before returning SUCCESS because we may not see the command again if SUCCESS is returned.

Cc Bob Pearson <[email protected]>
Cc Shinichiro Kawasaki <[email protected]>
Fixes d8536670916a ("IB/srp: Avoid having aborted requests hang")
---
 drivers/infiniband/ulp/srp/ib_srp.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)
drivers/infiniband/ulp/srp/ib_srp.c +5 -11
index 0e513a7e5ac8..be003fa0168c 100644
@@ -2788,7 +2788,6 @@ static int srp_abort(struct scsi_cmnd *scmnd)
 	u32 tag;
 	u16 ch_idx;
 	struct srp_rdma_ch *ch;
-	int ret;
 
 	shost_printk(KERN_ERR, target->scsi_host, "SRP abort called\n");
 
@@ -2802,19 +2801,14 @@ static int srp_abort(struct scsi_cmnd *scmnd)
 	shost_printk(KERN_ERR, target->scsi_host,
 		     "Sending SRP abort for tag %#x\n", tag);
 	if (srp_send_tsk_mgmt(ch, tag, scmnd->device->lun,
-			      SRP_TSK_ABORT_TASK, NULL) == 0)
-		ret = SUCCESS;
-	else if (target->rport->state == SRP_RPORT_LOST)
-		ret = FAST_IO_FAIL;
-	else
-		ret = FAILED;
-	if (ret == SUCCESS) {
+			      SRP_TSK_ABORT_TASK, NULL) == 0) {
 		srp_free_req(ch, req, scmnd, 0);
-		scmnd->result = DID_ABORT << 16;
-		scsi_done(scmnd);
+		return SUCCESS;
 	}
+	if (target->rport->state == SRP_RPORT_LOST)
+		return FAST_IO_FAIL;
 
-	return ret;
+	return FAILED;
 }
 
 static int srp_reset_device(struct scsi_cmnd *scmnd)
#1 lore raw
Quoted 11 lines · Bart Van Assche

After scmd_eh_abort_handler() has called the SCSI LLD eh_abort_handler callback, it performs one of the following actions:
* Call scsi_queue_insert().
* Call scsi_finish_command().
* Call scsi_eh_scmd_add().
Hence, SCSI abort handlers must not call scsi_done(). Otherwise all the above actions would trigger a use-after-free. Hence remove the scsi_done() call from srp_abort(). Keep the srp_free_req() call before returning SUCCESS because we may not see the command again if SUCCESS is returned.

Quoted 4 lines
Cc Bob Pearson <[email protected]>
Cc Shinichiro Kawasaki <[email protected]>
Fixes d8536670916a ("IB/srp: Avoid having aborted requests hang")

Thanks Bart. Do you think this patch fixes the hangs at blktests srp/002 and srp/011? I tried this patch and still see the hang at srp/002, but the hang at srp/011 looks disappearing.

author maintainer
#2 lore raw
Quoted 12 lines · Shinichiro Kawasaki
Quoted 11 lines · Bart Van Assche

After scmd_eh_abort_handler() has called the SCSI LLD eh_abort_handler callback, it performs one of the following actions:
* Call scsi_queue_insert().
* Call scsi_finish_command().
* Call scsi_eh_scmd_add().
Hence, SCSI abort handlers must not call scsi_done(). Otherwise all the above actions would trigger a use-after-free. Hence remove the scsi_done() call from srp_abort(). Keep the srp_free_req() call before returning SUCCESS because we may not see the command again if SUCCESS is returned.

Quoted 8 lines
Quoted 4 lines
Cc Bob Pearson <[email protected]>
Cc Shinichiro Kawasaki <[email protected]>
Fixes d8536670916a ("IB/srp: Avoid having aborted requests hang")

Thanks Bart. Do you think this patch fixes the hangs at blktests srp/002 and srp/011? I tried this patch and still see the hang at srp/002, but the hang at srp/011 looks disappearing.

I have not yet tried to verify whether the above patch affects any blktests. The above patch is a patch that I developed a few weeks ago but that had not yet been published on the linux-rdma mailing list.

Thanks,

Bart.

#3 lore raw
Quoted 18 lines · Bart Van Assche
Quoted 17 lines · Shinichiro Kawasaki
Quoted 15 lines · Bart Van Assche

After scmd_eh_abort_handler() has called the SCSI LLD eh_abort_handler callback, it performs one of the following actions:
* Call scsi_queue_insert().
* Call scsi_finish_command().
* Call scsi_eh_scmd_add().
Hence, SCSI abort handlers must not call scsi_done(). Otherwise all the above actions would trigger a use-after-free. Hence remove the scsi_done() call from srp_abort(). Keep the srp_free_req() call before returning SUCCESS because we may not see the command again if SUCCESS is returned.

Cc Bob Pearson <[email protected]>
Cc Shinichiro Kawasaki <[email protected]>
Fixes d8536670916a ("IB/srp: Avoid having aborted requests hang")
Quoted 7 lines
Quoted 3 lines

Thanks Bart. Do you think this patch fixes the hangs at blktests srp/002 and srp/011? I tried this patch and still see the hang at srp/002, but the hang at srp/011 looks disappearing.

I have not yet tried to verify whether the above patch affects any blktests. The above patch is a patch that I developed a few weeks ago but that had not yet been published on the linux-rdma mailing list.

Thanks for the explanation. I do not observe regression with this patch on my blktests test runs. It looks good that it avoids the srp/011 hang, but not sure why it avoids it.

#4 lore raw
In reply to Bart Van Assche
Quoted 11 lines · Bart Van Assche

After scmd_eh_abort_handler() has called the SCSI LLD eh_abort_handler callback, it performs one of the following actions:
* Call scsi_queue_insert().
* Call scsi_finish_command().
* Call scsi_eh_scmd_add().
Hence, SCSI abort handlers must not call scsi_done(). Otherwise all the above actions would trigger a use-after-free. Hence remove the scsi_done() call from srp_abort(). Keep the srp_free_req() call before returning SUCCESS because we may not see the command again if SUCCESS is returned.

Quoted 1 line

[...]

Applied, thanks!

[1/1] RDMA/srp: Do not call scsi_done() from srp_abort()

      https://git.kernel.org/rdma/rdma/c/e193b7955dfad6

Best regards,

Signature · 1 line
Leon Romanovsky <[email protected]>