Skip to contentSkip to conversation

scsi: core: run queues for all non-SDEV_DEL devices from scsi_run_host_queues

PATCH Applied David Jeffery 3 participants 3 messages May 15 – May 23 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 scsi: core: run queues for all non-SDEV_DEL devices from scsi_run_host_queues

While a scsi host is in a recovery state, scsi_mq_requeue_cmd will not set the requeue list for a requeued command to be kicked in the future. The expectation is a call to scsi_run_host_queues will kick all scsi devices once the recovery state is cleared.

However, scsi_run_host_queues uses shost_for_each_device which uses scsi_device_get and so will ignore devices in a partially removed state like SDEV_CANCEL. But these devices may also have requeued requests, leaving their requests stuck from not being kicked and causing the removal process of the device to hang.

scsi_run_host_queues needs to run against more devices than the macro shost_for_each_device allows. Instead of using the too limiting scsi_device_get state checks, only ignore devices in SDEV_DEL state or when unable to acquire a reference. Attempt to run the queues for all other devices when scsi_run_host_queues is called.

Fixes 8b566edbdbfb ("scsi: core: Only kick the requeue list if necessary")

---

Changes from V1:
Added a comment on why scsi_device_get cannot be used here.

 drivers/scsi/scsi_lib.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)
drivers/scsi/scsi_lib.c +25 -2
index 6e8c7a42603e..1b2809f1a096 100644
@@ -575,10 +575,33 @@ void scsi_requeue_run_queue(struct work_struct *work)
 
 void scsi_run_host_queues(struct Scsi_Host *shost)
 {
-	struct scsi_device *sdev;
+	struct scsi_device *sdev, *prev = NULL;
+	unsigned long flags;
 
-	shost_for_each_device(sdev, shost)
+	spin_lock_irqsave(shost->host_lock, flags);
+	__shost_for_each_device(sdev, shost) {
+		/*
+		 * Only skip devices so deep into removal they will never need
+		 * another kick to their queues. Thus scsi_device_get cannot
+		 * be used as it would skip devices in SDEV_CANCEL state which
+		 * may need a queue kick.
+		 */
+		if (sdev->sdev_state == SDEV_DEL ||
+		    !get_device(&sdev->sdev_gendev))
+			continue;
+		spin_unlock_irqrestore(shost->host_lock, flags);
+
+		if (prev)
+			put_device(&prev->sdev_gendev);
 		scsi_run_queue(sdev->request_queue);
+
+		prev = sdev;
+
+		spin_lock_irqsave(shost->host_lock, flags);
+	}
+	spin_unlock_irqrestore(shost->host_lock, flags);
+	if (prev)
+		put_device(&prev->sdev_gendev);
 }
 
 static void scsi_uninit_cmd(struct scsi_cmnd *cmd)
Signature · 1 line
2.53.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 11 lines · David Jeffery

While a scsi host is in a recovery state, scsi_mq_requeue_cmd will not set the requeue list for a requeued command to be kicked in the future. The expectation is a call to scsi_run_host_queues will kick all scsi devices once the recovery state is cleared.

However, scsi_run_host_queues uses shost_for_each_device which uses scsi_device_get and so will ignore devices in a partially removed state like SDEV_CANCEL. But these devices may also have requeued requests, leaving their requests stuck from not being kicked and causing the removal process of the device to hang.

Quoted 5 lines

scsi_run_host_queues needs to run against more devices than the macro shost_for_each_device allows. Instead of using the too limiting scsi_device_get state checks, only ignore devices in SDEV_DEL state or when unable to acquire a reference. Attempt to run the queues for all other devices when scsi_run_host_queues is called.

#2 lore raw
In reply to David Jeffery
Quoted 5 lines · David Jeffery

While a scsi host is in a recovery state, scsi_mq_requeue_cmd will not set the requeue list for a requeued command to be kicked in the future. The expectation is a call to scsi_run_host_queues will kick all scsi devices once the recovery state is cleared.

Quoted 7 lines

However, scsi_run_host_queues uses shost_for_each_device which uses scsi_device_get and so will ignore devices in a partially removed state like SDEV_CANCEL. But these devices may also have requeued requests, leaving their requests stuck from not being kicked and causing the removal process of the device to hang.

[...]

Applied to 7.1/scsi-fixes, thanks!

[1/1] scsi: core: run queues for all non-SDEV_DEL devices from scsi_run_host_queues

      https://git.kernel.org/mkp/scsi/c/7205b5870227
Signature · 1 line
Martin K. Petersen