Message ID | 20230915081507.761711-10-dlemoal@kernel.org (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Fix libata suspend/resume handling and code cleanup | expand |
On 9/15/23 10:14, Damien Le Moal wrote: > 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 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 not calling sd_shutdown() in sd_remove() if the device > is not running. > > Cc: stable@vger.kernel.org > Signed-off-by: Damien Le Moal <dlemoal@kernel.org> > --- > drivers/scsi/sd.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c > index 1d106c8ad5af..d86306d42445 100644 > --- a/drivers/scsi/sd.c > +++ b/drivers/scsi/sd.c > @@ -3727,7 +3727,8 @@ static int sd_remove(struct device *dev) > > device_del(&sdkp->disk_dev); > del_gendisk(sdkp->disk); > - sd_shutdown(dev); > + if (sdkp->device->sdev_state == SDEV_RUNNING) > + sd_shutdown(dev); > > put_disk(sdkp->disk); > return 0; Reviewed-by: Hannes Reinecke <hare@suse.de> Cheers, Hannes
On 9/15/23 01:14, Damien Le Moal wrote: > 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 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 not calling sd_shutdown() in sd_remove() if the device > is not running. > > Cc: stable@vger.kernel.org > Signed-off-by: Damien Le Moal <dlemoal@kernel.org> > --- > drivers/scsi/sd.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c > index 1d106c8ad5af..d86306d42445 100644 > --- a/drivers/scsi/sd.c > +++ b/drivers/scsi/sd.c > @@ -3727,7 +3727,8 @@ static int sd_remove(struct device *dev) > > device_del(&sdkp->disk_dev); > del_gendisk(sdkp->disk); > - sd_shutdown(dev); > + if (sdkp->device->sdev_state == SDEV_RUNNING) > + sd_shutdown(dev); > > put_disk(sdkp->disk); > return 0; Reviewed-by: Bart Van Assche <bvanassche@acm.org>
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 1d106c8ad5af..d86306d42445 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -3727,7 +3727,8 @@ static int sd_remove(struct device *dev) device_del(&sdkp->disk_dev); del_gendisk(sdkp->disk); - sd_shutdown(dev); + if (sdkp->device->sdev_state == SDEV_RUNNING) + sd_shutdown(dev); put_disk(sdkp->disk); return 0;
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 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 not calling sd_shutdown() in sd_remove() if the device is not running. Cc: stable@vger.kernel.org Signed-off-by: Damien Le Moal <dlemoal@kernel.org> --- drivers/scsi/sd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)