|
Lee Duncan |
89cf8b |
From: Bart Van Assche <bvanassche@acm.org>
|
|
Lee Duncan |
89cf8b |
Date: Thu, 30 Jun 2022 12:57:03 -0700
|
|
Lee Duncan |
89cf8b |
Subject: scsi: sd: Rework asynchronous resume support
|
|
Lee Duncan |
89cf8b |
Git-commit: 88f1669019bd62b3009a3cebf772fbaaa21b9f38
|
|
Lee Duncan |
89cf8b |
Patch-mainline: v6.0-rc1
|
|
Lee Duncan |
89cf8b |
References: git-fixes
|
|
Lee Duncan |
89cf8b |
|
|
Lee Duncan |
89cf8b |
For some technologies, e.g. an ATA bus, resuming can take multiple
|
|
Lee Duncan |
89cf8b |
seconds. Waiting for resume to finish can cause a very noticeable delay.
|
|
Lee Duncan |
89cf8b |
Hence this commit that restores the behavior from before "scsi: core: pm:
|
|
Lee Duncan |
89cf8b |
Rely on the device driver core for async power management" for most SCSI
|
|
Lee Duncan |
89cf8b |
devices.
|
|
Lee Duncan |
89cf8b |
|
|
Lee Duncan |
89cf8b |
This commit introduces a behavior change: if the START command fails, do
|
|
Lee Duncan |
89cf8b |
not consider this as a SCSI disk resume failure.
|
|
Lee Duncan |
89cf8b |
|
|
Lee Duncan |
89cf8b |
Link: https://bugzilla.kernel.org/show_bug.cgi?id=215880
|
|
Lee Duncan |
89cf8b |
Link: https://lore.kernel.org/r/20220630195703.10155-3-bvanassche@acm.org
|
|
Lee Duncan |
89cf8b |
Fixes: a19a93e4c6a9 ("scsi: core: pm: Rely on the device driver core for async power management")
|
|
Lee Duncan |
89cf8b |
Cc: Ming Lei <ming.lei@redhat.com>
|
|
Lee Duncan |
89cf8b |
Cc: Hannes Reinecke <hare@suse.de>
|
|
Lee Duncan |
89cf8b |
Cc: John Garry <john.garry@huawei.com>
|
|
Lee Duncan |
89cf8b |
Cc: ericspero@icloud.com
|
|
Lee Duncan |
89cf8b |
Cc: jason600.groome@gmail.com
|
|
Lee Duncan |
89cf8b |
Tested-by: jason600.groome@gmail.com
|
|
Lee Duncan |
89cf8b |
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
|
|
Lee Duncan |
89cf8b |
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
|
|
Lee Duncan |
89cf8b |
Acked-by: Lee Duncan <lduncan@suse.com>
|
|
Lee Duncan |
89cf8b |
---
|
|
Lee Duncan |
89cf8b |
drivers/scsi/sd.c | 84 +++++++++++++++++++++++++++++++++++++++++++------------
|
|
Lee Duncan |
89cf8b |
drivers/scsi/sd.h | 5 ++++
|
|
Lee Duncan |
89cf8b |
2 files changed, 71 insertions(+), 18 deletions(-)
|
|
Lee Duncan |
89cf8b |
|
|
Lee Duncan |
89cf8b |
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
|
|
Lee Duncan |
89cf8b |
index 895b56c8f25e..84696b3652ee 100644
|
|
Lee Duncan |
89cf8b |
--- a/drivers/scsi/sd.c
|
|
Lee Duncan |
89cf8b |
+++ b/drivers/scsi/sd.c
|
|
Lee Duncan |
89cf8b |
@@ -103,6 +103,7 @@ static void sd_config_discard(struct scsi_disk *, unsigned int);
|
|
Lee Duncan |
89cf8b |
static void sd_config_write_same(struct scsi_disk *);
|
|
Lee Duncan |
89cf8b |
static int sd_revalidate_disk(struct gendisk *);
|
|
Lee Duncan |
89cf8b |
static void sd_unlock_native_capacity(struct gendisk *disk);
|
|
Lee Duncan |
89cf8b |
+static void sd_start_done_work(struct work_struct *work);
|
|
Lee Duncan |
89cf8b |
static int sd_probe(struct device *);
|
|
Lee Duncan |
89cf8b |
static int sd_remove(struct device *);
|
|
Lee Duncan |
89cf8b |
static void sd_shutdown(struct device *);
|
|
Lee Duncan |
89cf8b |
@@ -3463,6 +3464,7 @@ static int sd_probe(struct device *dev)
|
|
Lee Duncan |
89cf8b |
sdkp->max_retries = SD_MAX_RETRIES;
|
|
Lee Duncan |
89cf8b |
atomic_set(&sdkp->openers, 0);
|
|
Lee Duncan |
89cf8b |
atomic_set(&sdkp->device->ioerr_cnt, 0);
|
|
Lee Duncan |
89cf8b |
+ INIT_WORK(&sdkp->start_done_work, sd_start_done_work);
|
|
Lee Duncan |
89cf8b |
|
|
Lee Duncan |
89cf8b |
if (!sdp->request_queue->rq_timeout) {
|
|
Lee Duncan |
89cf8b |
if (sdp->type != TYPE_MOD)
|
|
Lee Duncan |
89cf8b |
@@ -3585,12 +3587,69 @@ static void scsi_disk_release(struct device *dev)
|
|
Lee Duncan |
89cf8b |
kfree(sdkp);
|
|
Lee Duncan |
89cf8b |
}
|
|
Lee Duncan |
89cf8b |
|
|
Lee Duncan |
89cf8b |
+/* Process sense data after a START command finished. */
|
|
Lee Duncan |
89cf8b |
+static void sd_start_done_work(struct work_struct *work)
|
|
Lee Duncan |
89cf8b |
+{
|
|
Lee Duncan |
89cf8b |
+ struct scsi_disk *sdkp = container_of(work, typeof(*sdkp),
|
|
Lee Duncan |
89cf8b |
+ start_done_work);
|
|
Lee Duncan |
89cf8b |
+ struct scsi_sense_hdr sshdr;
|
|
Lee Duncan |
89cf8b |
+ int res = sdkp->start_result;
|
|
Lee Duncan |
89cf8b |
+
|
|
Lee Duncan |
89cf8b |
+ if (res == 0)
|
|
Lee Duncan |
89cf8b |
+ return;
|
|
Lee Duncan |
89cf8b |
+
|
|
Lee Duncan |
89cf8b |
+ sd_print_result(sdkp, "Start/Stop Unit failed", res);
|
|
Lee Duncan |
89cf8b |
+
|
|
Lee Duncan |
89cf8b |
+ if (res < 0)
|
|
Lee Duncan |
89cf8b |
+ return;
|
|
Lee Duncan |
89cf8b |
+
|
|
Lee Duncan |
89cf8b |
+ if (scsi_normalize_sense(sdkp->start_sense_buffer,
|
|
Lee Duncan |
89cf8b |
+ sdkp->start_sense_len, &sshdr))
|
|
Lee Duncan |
89cf8b |
+ sd_print_sense_hdr(sdkp, &sshdr);
|
|
Lee Duncan |
89cf8b |
+}
|
|
Lee Duncan |
89cf8b |
+
|
|
Lee Duncan |
89cf8b |
+/* A START command finished. May be called from interrupt context. */
|
|
Lee Duncan |
89cf8b |
+static void sd_start_done(struct request *req, blk_status_t status)
|
|
Lee Duncan |
89cf8b |
+{
|
|
Lee Duncan |
89cf8b |
+ const struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(req);
|
|
Lee Duncan |
89cf8b |
+ struct scsi_disk *sdkp = scsi_disk(req->q->disk);
|
|
Lee Duncan |
89cf8b |
+
|
|
Lee Duncan |
89cf8b |
+ sdkp->start_result = scmd->result;
|
|
Lee Duncan |
89cf8b |
+ WARN_ON_ONCE(scmd->sense_len > SCSI_SENSE_BUFFERSIZE);
|
|
Lee Duncan |
89cf8b |
+ sdkp->start_sense_len = scmd->sense_len;
|
|
Lee Duncan |
89cf8b |
+ memcpy(sdkp->start_sense_buffer, scmd->sense_buffer,
|
|
Lee Duncan |
89cf8b |
+ ARRAY_SIZE(sdkp->start_sense_buffer));
|
|
Lee Duncan |
89cf8b |
+ WARN_ON_ONCE(!schedule_work(&sdkp->start_done_work));
|
|
Lee Duncan |
89cf8b |
+}
|
|
Lee Duncan |
89cf8b |
+
|
|
Lee Duncan |
89cf8b |
+/* Submit a START command asynchronously. */
|
|
Lee Duncan |
89cf8b |
+static int sd_submit_start(struct scsi_disk *sdkp, u8 cmd[], u8 cmd_len)
|
|
Lee Duncan |
89cf8b |
+{
|
|
Lee Duncan |
89cf8b |
+ struct scsi_device *sdev = sdkp->device;
|
|
Lee Duncan |
89cf8b |
+ struct request_queue *q = sdev->request_queue;
|
|
Lee Duncan |
89cf8b |
+ struct request *req;
|
|
Lee Duncan |
89cf8b |
+ struct scsi_cmnd *scmd;
|
|
Lee Duncan |
89cf8b |
+
|
|
Lee Duncan |
89cf8b |
+ req = scsi_alloc_request(q, REQ_OP_DRV_IN, BLK_MQ_REQ_PM);
|
|
Lee Duncan |
89cf8b |
+ if (IS_ERR(req))
|
|
Lee Duncan |
89cf8b |
+ return PTR_ERR(req);
|
|
Lee Duncan |
89cf8b |
+
|
|
Lee Duncan |
89cf8b |
+ scmd = blk_mq_rq_to_pdu(req);
|
|
Lee Duncan |
89cf8b |
+ scmd->cmd_len = cmd_len;
|
|
Lee Duncan |
89cf8b |
+ memcpy(scmd->cmnd, cmd, cmd_len);
|
|
Lee Duncan |
89cf8b |
+ scmd->allowed = sdkp->max_retries;
|
|
Lee Duncan |
89cf8b |
+ req->timeout = SD_TIMEOUT;
|
|
Lee Duncan |
89cf8b |
+ req->rq_flags |= RQF_PM | RQF_QUIET;
|
|
Lee Duncan |
89cf8b |
+ req->end_io = sd_start_done;
|
|
Lee Duncan |
89cf8b |
+ blk_execute_rq_nowait(req, /*at_head=*/true);
|
|
Lee Duncan |
89cf8b |
+
|
|
Lee Duncan |
89cf8b |
+ return 0;
|
|
Lee Duncan |
89cf8b |
+}
|
|
Lee Duncan |
89cf8b |
+
|
|
Lee Duncan |
89cf8b |
static int sd_start_stop_device(struct scsi_disk *sdkp, int start)
|
|
Lee Duncan |
89cf8b |
{
|
|
Lee Duncan |
89cf8b |
unsigned char cmd[6] = { START_STOP }; /* START_VALID */
|
|
Lee Duncan |
89cf8b |
- struct scsi_sense_hdr sshdr;
|
|
Lee Duncan |
89cf8b |
struct scsi_device *sdp = sdkp->device;
|
|
Lee Duncan |
89cf8b |
- int res;
|
|
Lee Duncan |
89cf8b |
|
|
Lee Duncan |
89cf8b |
if (start)
|
|
Lee Duncan |
89cf8b |
cmd[4] |= 1; /* START */
|
|
Lee Duncan |
89cf8b |
@@ -3601,23 +3660,10 @@ static int sd_start_stop_device(struct scsi_disk *sdkp, int start)
|
|
Lee Duncan |
89cf8b |
if (!scsi_device_online(sdp))
|
|
Lee Duncan |
89cf8b |
return -ENODEV;
|
|
Lee Duncan |
89cf8b |
|
|
Lee Duncan |
89cf8b |
- res = scsi_execute(sdp, cmd, DMA_NONE, NULL, 0, NULL, &sshdr,
|
|
Lee Duncan |
89cf8b |
- SD_TIMEOUT, sdkp->max_retries, 0, RQF_PM, NULL);
|
|
Lee Duncan |
89cf8b |
- if (res) {
|
|
Lee Duncan |
89cf8b |
- sd_print_result(sdkp, "Start/Stop Unit failed", res);
|
|
Lee Duncan |
89cf8b |
- if (res > 0 && scsi_sense_valid(&sshdr)) {
|
|
Lee Duncan |
89cf8b |
- sd_print_sense_hdr(sdkp, &sshdr);
|
|
Lee Duncan |
89cf8b |
- /* 0x3a is medium not present */
|
|
Lee Duncan |
89cf8b |
- if (sshdr.asc == 0x3a)
|
|
Lee Duncan |
89cf8b |
- res = 0;
|
|
Lee Duncan |
89cf8b |
- }
|
|
Lee Duncan |
89cf8b |
- }
|
|
Lee Duncan |
89cf8b |
+ /* Wait until processing of sense data has finished. */
|
|
Lee Duncan |
89cf8b |
+ flush_work(&sdkp->start_done_work);
|
|
Lee Duncan |
89cf8b |
|
|
Lee Duncan |
89cf8b |
- /* SCSI error codes must not go to the generic layer */
|
|
Lee Duncan |
89cf8b |
- if (res)
|
|
Lee Duncan |
89cf8b |
- return -EIO;
|
|
Lee Duncan |
89cf8b |
-
|
|
Lee Duncan |
89cf8b |
- return 0;
|
|
Lee Duncan |
89cf8b |
+ return sd_submit_start(sdkp, cmd, sizeof(cmd));
|
|
Lee Duncan |
89cf8b |
}
|
|
Lee Duncan |
89cf8b |
|
|
Lee Duncan |
89cf8b |
/*
|
|
Lee Duncan |
89cf8b |
@@ -3644,6 +3690,8 @@ static void sd_shutdown(struct device *dev)
|
|
Lee Duncan |
89cf8b |
sd_printk(KERN_NOTICE, sdkp, "Stopping disk\n");
|
|
Lee Duncan |
89cf8b |
sd_start_stop_device(sdkp, 0);
|
|
Lee Duncan |
89cf8b |
}
|
|
Lee Duncan |
89cf8b |
+
|
|
Lee Duncan |
89cf8b |
+ flush_work(&sdkp->start_done_work);
|
|
Lee Duncan |
89cf8b |
}
|
|
Lee Duncan |
89cf8b |
|
|
Lee Duncan |
89cf8b |
static int sd_suspend_common(struct device *dev, bool ignore_stop_errors)
|
|
Lee Duncan |
89cf8b |
diff --git a/drivers/scsi/sd.h b/drivers/scsi/sd.h
|
|
Lee Duncan |
89cf8b |
index 5eea762f84d1..b89187761d61 100644
|
|
Lee Duncan |
89cf8b |
--- a/drivers/scsi/sd.h
|
|
Lee Duncan |
89cf8b |
+++ b/drivers/scsi/sd.h
|
|
Lee Duncan |
89cf8b |
@@ -150,6 +150,11 @@ struct scsi_disk {
|
|
Lee Duncan |
89cf8b |
unsigned urswrz : 1;
|
|
Lee Duncan |
89cf8b |
unsigned security : 1;
|
|
Lee Duncan |
89cf8b |
unsigned ignore_medium_access_errors : 1;
|
|
Lee Duncan |
89cf8b |
+
|
|
Lee Duncan |
89cf8b |
+ int start_result;
|
|
Lee Duncan |
89cf8b |
+ u32 start_sense_len;
|
|
Lee Duncan |
89cf8b |
+ u8 start_sense_buffer[SCSI_SENSE_BUFFERSIZE];
|
|
Lee Duncan |
89cf8b |
+ struct work_struct start_done_work;
|
|
Lee Duncan |
89cf8b |
};
|
|
Lee Duncan |
89cf8b |
#define to_scsi_disk(obj) container_of(obj, struct scsi_disk, disk_dev)
|
|
Lee Duncan |
89cf8b |
|
|
Lee Duncan |
89cf8b |
|