FAILED: patch "[PATCH] scsi: Do not attempt to rescan suspended devices" failed to apply to 6.5-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.5-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.5.y
git checkout FETCH_HEAD
git cherry-pick -x ff48b37802e5c134e2dfc4d091f10b2eb5065a72
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2023100454-hamper-falsify-595d@gregkh' --subject-prefix 'PATCH 6.5.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From ff48b37802e5c134e2dfc4d091f10b2eb5065a72 Mon Sep 17 00:00:00 2001
From: Damien Le Moal <[email protected]>
Date: Fri, 15 Sep 2023 15:00:13 +0900
Subject: [PATCH] scsi: Do not attempt to rescan suspended devices
scsi_rescan_device() takes a scsi device lock before executing a device handler and device driver rescan methods. Waiting for the completion of any command issued to the device by these methods will thus be done with the device lock held. As a result, there is a risk of deadlocking within the power management code if scsi_rescan_device() is called to handle a device resume with the associated scsi device not yet resumed.
Avoid such situation by checking that the target scsi device is in the running state, that is, fully capable of executing commands, before proceeding with the rescan and bailout returning -EWOULDBLOCK otherwise. With this error return, the caller can retry rescaning the device after a delay.
The state check is done with the device lock held and is thus safe against incoming suspend power management operations.
drivers/scsi/scsi_scan.c +17 -1
@@ -1619,12 +1619,24 @@ int scsi_add_device(struct Scsi_Host *host, uint channel, }EXPORT_SYMBOL (scsi_add_device); -void scsi_rescan_device (struct scsi_device *sdev) +int scsi_rescan_device (struct scsi_device *sdev) {struct device *dev = &sdev->sdev_gendev; +int ret =0 ;device_lock (dev); +/* +* Bail out if the device is not running. Otherwise, the rescan may +* block waiting for commands to be executed, with us holding the +* device lock. This can result in a potential deadlock in the power +* management core code when system resume is on-going. +*/ +if (sdev->sdev_state !=SDEV_RUNNING ) { + ret = -EWOULDBLOCK ; + goto unlock; + } +scsi_attach_vpd (sdev);scsi_cdl_check (sdev);
@@ -1638,7 +1650,11 @@ void scsi_rescan_device(struct scsi_device *sdev) drv->rescan (dev);module_put (dev->driver->owner); } + +unlock:device_unlock (dev); + +return ret; }EXPORT_SYMBOL (scsi_rescan_device);
include/scsi/scsi_host.h +1 -1
@@ -764,7 +764,7 @@ scsi_template_proc_dir(const struct scsi_host_template *sht);#define scsi_template_proc_dir (sht) NULL#endif extern void scsi_scan_host (struct Scsi_Host *); -extern void scsi_rescan_device (struct scsi_device *); +extern int scsi_rescan_device (struct scsi_device *sdev);extern void scsi_remove_host (struct Scsi_Host *);extern struct Scsi_Host *scsi_host_get (struct Scsi_Host *);extern int scsi_host_busy (struct Scsi_Host *shost);
PATCH 1/1 scsi: Do not attempt to rescan suspended devices
Commit ff48b37802e5c134e2dfc4d091f10b2eb5065a72 upstream.
scsi_rescan_device() takes a scsi device lock before executing a device handler and device driver rescan methods. Waiting for the completion of any command issued to the device by these methods will thus be done with the device lock held. As a result, there is a risk of deadlocking within the power management code if scsi_rescan_device() is called to handle a device resume with the associated scsi device not yet resumed.
Avoid such situation by checking that the target scsi device is in the running state, that is, fully capable of executing commands, before proceeding with the rescan and bailout returning -EWOULDBLOCK otherwise. With this error return, the caller can retry rescaning the device after a delay.
The state check is done with the device lock held and is thus safe against incoming suspend power management operations.
--- drivers/scsi/scsi_priv.h | 2 +- drivers/scsi/scsi_scan.c | 18 +++++++++++++++++- include/scsi/scsi_host.h | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-)
drivers/scsi/scsi_priv.h +1 -1
@@ -138,7 +138,7 @@ extern int scsi_complete_async_scans(void);extern int scsi_scan_host_selected (struct Scsi_Host *,unsigned int ,unsigned int ,u64 ,enum scsi_scan_mode );extern void scsi_forget_host (struct Scsi_Host *); -extern void scsi_rescan_device (struct device *); +extern int scsi_rescan_device (struct device *dev);/* scsi_sysctl.c */ #ifdef CONFIG_SYSCTL
drivers/scsi/scsi_scan.c +17 -1
@@ -1619,12 +1619,24 @@ int scsi_add_device(struct Scsi_Host *host, uint channel, }EXPORT_SYMBOL (scsi_add_device); -void scsi_rescan_device (struct device *dev) +int scsi_rescan_device (struct device *dev) {struct scsi_device *sdev =to_scsi_device (dev); +int ret =0 ;device_lock (dev); +/* +* Bail out if the device is not running. Otherwise, the rescan may +* block waiting for commands to be executed, with us holding the +* device lock. This can result in a potential deadlock in the power +* management core code when system resume is on-going. +*/ +if (sdev->sdev_state !=SDEV_RUNNING ) { + ret = -EWOULDBLOCK ; + goto unlock; + } +scsi_attach_vpd (sdev);scsi_cdl_check (sdev);
@@ -1638,7 +1650,11 @@ void scsi_rescan_device(struct device *dev) drv->rescan (dev);module_put (dev->driver->owner); } + +unlock:device_unlock (dev); + +return ret; }EXPORT_SYMBOL (scsi_rescan_device);
include/scsi/scsi_host.h +1 -1
@@ -764,7 +764,7 @@ scsi_template_proc_dir(const struct scsi_host_template *sht);#define scsi_template_proc_dir (sht) NULL#endif extern void scsi_scan_host (struct Scsi_Host *); -extern void scsi_rescan_device (struct device *); +extern int scsi_rescan_device (struct device *dev);extern void scsi_remove_host (struct Scsi_Host *);extern struct Scsi_Host *scsi_host_get (struct Scsi_Host *);extern int scsi_host_busy (struct Scsi_Host *shost);
Signature · 1 line
2.41.0