Skip to contentSkip to conversation

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

PATCH Superseded David Jeffery 2 participants 7 messages May 13 – May 15 SCSI

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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")
---
 drivers/scsi/scsi_lib.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
drivers/scsi/scsi_lib.c +19 -2
index 6e8c7a42603e..bb7281dc3633 100644
@@ -575,10 +575,27 @@ 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;
+
+	spin_lock_irqsave(shost->host_lock, flags);
+	__shost_for_each_device(sdev, shost) {
+		if (sdev->sdev_state == SDEV_DEL ||
+		    !get_device(&sdev->sdev_gendev))
+			continue;
+		spin_unlock_irqrestore(shost->host_lock, flags);
 
-	shost_for_each_device(sdev, shost)
+		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
#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.

From scsi_host.h:

static inline int scsi_host_in_recovery(struct Scsi_Host *shost)

{
	return shost->shost_state == SHOST_RECOVERY ||
		shost->shost_state == SHOST_CANCEL_RECOVERY ||
		shost->shost_state == SHOST_DEL_RECOVERY ||
		shost->tmf_in_progress;
}

This function returns false for the SDEV_CANCEL state. Hence, even with commit 8b566edbdbfb ("scsi: core: Only kick the requeue list if necessary") applied, the requeue list should still be kicked for SCSI hosts in the SDEV_CANCEL state, isn't it?

Thanks,

Bart.

#2 lore raw
Quoted 28 lines · Bart Van Assche
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.

From scsi_host.h:

static inline int scsi_host_in_recovery(struct Scsi_Host *shost)

{
        return shost->shost_state == SHOST_RECOVERY ||
                shost->shost_state == SHOST_CANCEL_RECOVERY ||
                shost->shost_state == SHOST_DEL_RECOVERY ||
                shost->tmf_in_progress;
}
Quoted 4 lines

This function returns false for the SDEV_CANCEL state. Hence, even with commit 8b566edbdbfb ("scsi: core: Only kick the requeue list if necessary") applied, the requeue list should still be kicked for SCSI hosts in the SDEV_CANCEL state, isn't it?

SDEV_CANCEL is a scsi_device state while the scsi_host_in_recovery macro is looking only at Scsi_Host state. An SDEV_CANCEL scsi_device is unrelated to the scsi_host_in_recovery return value.

I will note that looking at scsi_device state in scsi_mq_requeue_cmd in addition to the
scsi_host_in_recovery call does not fix the issue. The scsi_device can be in SDEV_RUNNING state at the time of request requeue with the attempted removal and transition of the scsi_device to SDEV_CANCEL occurring later while error handling is still unfinished.

David Jeffery

#3 lore raw
Quoted 10 lines · David Jeffery

SDEV_CANCEL is a scsi_device state while the scsi_host_in_recovery macro is looking only at Scsi_Host state. An SDEV_CANCEL scsi_device is unrelated to the scsi_host_in_recovery return value.

I will note that looking at scsi_device state in scsi_mq_requeue_cmd in addition to the
scsi_host_in_recovery call does not fix the issue. The scsi_device can be in SDEV_RUNNING state at the time of request requeue with the attempted removal and transition of the scsi_device to SDEV_CANCEL occurring later while error handling is still unfinished.

Oops, I got confused when I wrote my previous reply. Let me take another look at your patch.

Bart.

#4 lore raw
In reply to David Jeffery

drivers/scsi/scsi_lib.c void scsi_requeue_run_queue(struct work_struct *work) · line 585

Quoted 3 lines · David Jeffery
drivers/scsi/scsi_lib.c +3 -0
+		if (sdev->sdev_state == SDEV_DEL ||
+		    !get_device(&sdev->sdev_gendev))
+			continue;

A comment would be welcome above this statement that explains that get_device() is called instead of scsi_device_get() because the latter skips devices that are in the state SDEV_CANCEL state.

Thanks,

Bart.

#5 lore raw
Quoted 9 lines · Bart Van Assche

drivers/scsi/scsi_lib.c void scsi_requeue_run_queue(struct work_struct *work) · line 585

Quoted 3 lines · David Jeffery
drivers/scsi/scsi_lib.c +3 -0
+             if (sdev->sdev_state == SDEV_DEL ||
+                 !get_device(&sdev->sdev_gendev))
+                     continue;

A comment would be welcome above this statement that explains that get_device() is called instead of scsi_device_get() because the latter skips devices that are in the state SDEV_CANCEL state.

Would the wording:
/*
* 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.
*/

work for you? Thanks for the feedback.

David Jeffery

#6 lore raw
Quoted 19 lines · David Jeffery
Quoted 9 lines · Bart Van Assche

drivers/scsi/scsi_lib.c void scsi_requeue_run_queue(struct work_struct *work) · line 585

Quoted 3 lines · David Jeffery
drivers/scsi/scsi_lib.c +3 -0
+             if (sdev->sdev_state == SDEV_DEL ||
+                 !get_device(&sdev->sdev_gendev))
+                     continue;

A comment would be welcome above this statement that explains that get_device() is called instead of scsi_device_get() because the latter skips devices that are in the state SDEV_CANCEL state.

Would the wording:
/*
* 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.
*/

Quoted 1 line

work for you? Thanks for the feedback.

How about adding that other similar loops use scsi_device_get() and changing "scsi_device_get" into "scsi_device_get()"?

Thanks,

Bart.