Skip to content

Commit 99398d2

Browse files
committed
scsi: sd: Do not issue commands to suspended disks on shutdown
If an error occurs when resuming a host adapter before the devices attached to the adapter are resumed, the adapter low level driver may remove the scsi host, resulting in a call to sd_remove() for the disks of the host. This in turn results in a call to sd_shutdown() which will issue a synchronize cache command and a start stop unit command to spindown the disk. sd_shutdown() issues the commands only if the device is not already runtime suspended but does not check the power state for system-wide suspend/resume. That is, the commands may be issued with the device in a suspended state, which causes PM resume to hang, forcing a reset of the machine to recover. Fix this by tracking the suspended state of a disk by introducing the suspended boolean field in the scsi_disk structure. This flag is set to true when the disk is suspended is sd_suspend_common() and resumed with sd_resume(). When suspended is true, sd_shutdown() is not executed from sd_remove(). Cc: stable@vger.kernel.org Signed-off-by: Damien Le Moal <dlemoal@kernel.org> Reviewed-by: Hannes Reinecke <hare@suse.de> Reviewed-by: Bart Van Assche <bvanassche@acm.org> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 75e2bd5 commit 99398d2

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

drivers/scsi/sd.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3741,7 +3741,8 @@ static int sd_remove(struct device *dev)
37413741

37423742
device_del(&sdkp->disk_dev);
37433743
del_gendisk(sdkp->disk);
3744-
sd_shutdown(dev);
3744+
if (!sdkp->suspended)
3745+
sd_shutdown(dev);
37453746

37463747
put_disk(sdkp->disk);
37473748
return 0;
@@ -3872,6 +3873,9 @@ static int sd_suspend_common(struct device *dev, bool runtime)
38723873
ret = 0;
38733874
}
38743875

3876+
if (!ret)
3877+
sdkp->suspended = true;
3878+
38753879
return ret;
38763880
}
38773881

@@ -3891,21 +3895,26 @@ static int sd_suspend_runtime(struct device *dev)
38913895
static int sd_resume(struct device *dev, bool runtime)
38923896
{
38933897
struct scsi_disk *sdkp = dev_get_drvdata(dev);
3894-
int ret;
3898+
int ret = 0;
38953899

38963900
if (!sdkp) /* E.g.: runtime resume at the start of sd_probe() */
38973901
return 0;
38983902

3899-
if (!sd_do_start_stop(sdkp->device, runtime))
3903+
if (!sd_do_start_stop(sdkp->device, runtime)) {
3904+
sdkp->suspended = false;
39003905
return 0;
3906+
}
39013907

39023908
if (!sdkp->device->no_start_on_resume) {
39033909
sd_printk(KERN_NOTICE, sdkp, "Starting disk\n");
39043910
ret = sd_start_stop_device(sdkp, 1);
39053911
}
39063912

3907-
if (!ret)
3913+
if (!ret) {
39083914
opal_unlock_from_suspend(sdkp->opal_dev);
3915+
sdkp->suspended = false;
3916+
}
3917+
39093918
return ret;
39103919
}
39113920

drivers/scsi/sd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ struct scsi_disk {
131131
u8 provisioning_mode;
132132
u8 zeroing_mode;
133133
u8 nr_actuators; /* Number of actuators */
134+
bool suspended; /* Disk is suspended (stopped) */
134135
unsigned ATO : 1; /* state of disk ATO bit */
135136
unsigned cache_override : 1; /* temp override of WCE,RCD */
136137
unsigned WCE : 1; /* state of disk WCE bit */

0 commit comments

Comments
 (0)