SCSI core and UFS patches for kernel v6.4
Subsystems (2)
Bart Van Assche
reviewercover SCSI core and UFS patches for kernel v6.4
Hi Martin,
This patch series includes a patch for making sd_shutdown() fail future I/O and also two UFS patches.
Patch 3/3 of this series has been posted earlier. Compared to the previous version of that patch, a Fixes: tag has been added.
Please consider this patch series for the next merge window.
Thanks,
Bart.
Bart Van Assche (3):
scsi: sd: Let sd_shutdown() fail future I/O
scsi: ufs: Simplify ufshcd_wl_shutdown()
scsi: ufs: Increase the START STOP UNIT timeout from one to ten
seconds
drivers/scsi/sd.c | 9 ++++++++- drivers/ufs/core/ufshcd.c | 15 +++------------ 2 files changed, 11 insertions(+), 13 deletions(-)
Bart Van Assche
reviewerPATCH 1/3 scsi: sd: Let sd_shutdown() fail future I/O
System shutdown happens as follows (see e.g. the systemd source file src/shutdown/shutdown.c):
* sync() is called.
* reboot(RB_AUTOBOOT/RB_HALT_SYSTEM/RB_POWER_OFF) is called.
* If the reboot() system call returns, log an error message.
The reboot() system call causes the kernel to call kernel_restart(), kernel_halt() or kernel_power_off(). Each of these functions calls device_shutdown(). device_shutdown() calls sd_shutdown().
After sd_shutdown() has been called the .shutdown() callback of the LLD will be called. This makes it unsafe to submit I/O after sd_shutdown() has finished. Let sd_shutdown() fail future I/O such that LLD .shutdown() callbacks can be simplified.
--- drivers/scsi/sd.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/scsi/sd.c +8 -1
@@ -3699,12 +3699,13 @@ static int sd_start_stop_device(struct scsi_disk *sdkp, int start)static void sd_shutdown (struct device *dev) {struct scsi_disk *sdkp =dev_get_drvdata (dev); +struct request_queue *q;if (!sdkp)return ;/* this can happen */ if (pm_runtime_suspended (dev)) -return ; + goto fail_future_io;if (sdkp->WCE && sdkp->media_present) {sd_printk (KERN_NOTICE , sdkp,"Synchronizing SCSI cache\n" );
@@ -3715,6 +3716,12 @@ static void sd_shutdown(struct device *dev)sd_printk (KERN_NOTICE , sdkp,"Stopping disk\n" );sd_start_stop_device (sdkp,0 ); } + +fail_future_io: + q = sdkp->disk->queue; +blk_queue_flag_set (QUEUE_FLAG_DYING , q); +blk_mq_freeze_queue (q); +blk_mq_unfreeze_queue (q); }static int sd_suspend_common (struct device *dev,bool ignore_stop_errors)
Re: [PATCH 1/3] scsi: sd: Let sd_shutdown() fail future I/O
Quoted 6 lines · Bart Van Assche
System shutdown happens as follows (see e.g. the systemd source file
src/shutdown/shutdown.c):
*sync()is called.
*reboot(RB_AUTOBOOT/RB_HALT_SYSTEM/RB_POWER_OFF)is called.
* If thereboot()system call returns, log an error message.
Quoted 7 lines
The
reboot()system call causes the kernel to callkernel_restart(),kernel_halt()orkernel_power_off(). Each of these functions callsdevice_shutdown().device_shutdown()callssd_shutdown().After
sd_shutdown()has been called the .shutdown() callback of the LLD will be called. This makes it unsafe to submit I/O aftersd_shutdown()has finished.
unsafe often means a bug, can you explain it in details about the 'unsafe'?
Quoted 33 lines
Let
sd_shutdown()fail future I/O such that LLD .shutdown() callbacks can be simplified.Cc Christoph Hellwig <[email protected]>Cc Ming Lei <[email protected]>Cc Hannes Reinecke <[email protected]>Cc Mike Christie <[email protected]>Cc Tomas Henzl <[email protected]>Signed-off-by Bart Van Assche <[email protected]>--- drivers/scsi/sd.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)drivers/scsi/sd.c +2
-1@@ -3699,12 +3699,13 @@ static int sd_start_stop_device(struct scsi_disk *sdkp, int start)static void sd_shutdown (struct device *dev) {struct scsi_disk *sdkp =dev_get_drvdata (dev); +struct request_queue *q;if (!sdkp)return ;/* this can happen */ if (pm_runtime_suspended (dev)) -return ; + goto fail_future_io;if (sdkp->WCE && sdkp->media_present) {sd_printk (KERN_NOTICE , sdkp,"Synchronizing SCSI cache\n" );
drivers/scsi/sd.c static void sd_shutdown(struct device *dev) · line 3724
Quoted 9 lines
drivers/scsi/sd.c +6
-0@@ -3715,6 +3716,12 @@ static void sd_shutdown(struct device *dev)sd_printk (KERN_NOTICE , sdkp,"Stopping disk\n" );sd_start_stop_device (sdkp,0 ); } + +fail_future_io: + q = sdkp->disk->queue; +blk_queue_flag_set (QUEUE_FLAG_DYING , q); +blk_mq_freeze_queue (q); +blk_mq_unfreeze_queue (q);
freeze queue can slow down reboot a lot especially when there are lots of LUNs/Hosts because each device ->shutdown() is serialized.
I think it can be done by changing sdev state to SDEV_OFFLINE here.
Thanks,
Ming
Bart Van Assche
reviewerRe: [PATCH 1/3] scsi: sd: Let sd_shutdown() fail future I/O
Quoted 11 lines · Ming Lei
Quoted 10 lines · Bart Van Assche
System shutdown happens as follows (see e.g. the systemd source file
src/shutdown/shutdown.c):
*sync()is called.
*reboot(RB_AUTOBOOT/RB_HALT_SYSTEM/RB_POWER_OFF)is called.
* If thereboot()system call returns, log an error message.The
reboot()system call causes the kernel to callkernel_restart(),kernel_halt()orkernel_power_off(). Each of these functions callsdevice_shutdown().device_shutdown()callssd_shutdown().
Quoted 5 lines
Quoted 3 lines
After
sd_shutdown()has been called the .shutdown() callback of the LLD will be called. This makes it unsafe to submit I/O aftersd_shutdown()has finished.unsafe often means a bug, can you explain it in details about the 'unsafe'?
In this case that means that a kernel crash could be triggered.
Quoted 10 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+fail_future_io: + q = sdkp->disk->queue; + blk_queue_flag_set(QUEUE_FLAG_DYING, q); + blk_mq_freeze_queue(q); + blk_mq_unfreeze_queue(q);freeze queue can slow down reboot a lot especially when there are lots of LUNs/Hosts because each device ->shutdown() is serialized.
I think it can be done by changing sdev state to
SDEV_OFFLINEhere.
Hi Ming,
Changing the SCSI device state is not sufficient to wait for pending commands to finish. How about replacing this patch with the patch below?
drivers/scsi/sd.c +10 -1
@@ -3699,12 +3699,13 @@ static int sd_start_stop_device(struct scsi_disk *sdkp, int start)static void sd_shutdown (struct device *dev) {struct scsi_disk *sdkp =dev_get_drvdata (dev); +struct request_queue *q;if (!sdkp)return ;/* this can happen */ if (pm_runtime_suspended (dev)) -return ; + goto fail_future_io;if (sdkp->WCE && sdkp->media_present) {sd_printk (KERN_NOTICE , sdkp,"Synchronizing SCSI cache\n" );
@@ -3715,6 +3716,14 @@ static void sd_shutdown(struct device *dev)sd_printk (KERN_NOTICE , sdkp,"Stopping disk\n" );sd_start_stop_device (sdkp,0 ); } + +fail_future_io: + q = sdkp->disk->queue; +blk_queue_flag_set (QUEUE_FLAG_DYING , q); +if (!scsi_host_busy (sdkp->device->host)) +return ; +blk_mq_freeze_queue (q); +blk_mq_unfreeze_queue (q); } static int sd_suspend_common(struct device *dev, bool
Bart Van Assche
reviewerPATCH 2/3 scsi: ufs: Simplify ufshcd_wl_shutdown()
In reply to Bart Van AsscheNow that sd_shutdown() fails future I/O the code for quiescing LUNs in ufshcd_wl_shutdown() is superfluous. Remove the code for quiescing LUNs. Also remove the ufshcd_rpm_get_sync() call because it is not necessary to resume a UFS device before submitting a START STOP UNIT command.
--- drivers/ufs/core/ufshcd.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-)
drivers/ufs/core/ufshcd.c +1 -11
@@ -9768,22 +9768,12 @@ static int ufshcd_wl_resume(struct device *dev)static void ufshcd_wl_shutdown (struct device *dev) {struct scsi_device *sdev =to_scsi_device (dev); -struct ufs_hba *hba; - - hba =shost_priv (sdev->host); +struct ufs_hba *hba =shost_priv (sdev->host);down (&hba->host_sem); hba->shutting_down = true;up (&hba->host_sem); -/* Turn on everything while shutting down */ -ufshcd_rpm_get_sync (hba); -scsi_device_quiesce (sdev); -shost_for_each_device (sdev, hba->host) { -if (sdev == hba->ufs_device_wlun) -continue ; -scsi_device_quiesce (sdev); - }__ufshcd_wl_suspend (hba,UFS_SHUTDOWN_PM ); }
Bart Van Assche
reviewerPATCH 3/3 scsi: ufs: Increase the START STOP UNIT timeout from one to ten seconds
In reply to Bart Van AsscheOne UFS vendor asked to increase the UFS timeout from 1 s to 3 s. Another UFS vendor asked to increase the UFS timeout from 1 s to 10 s. Hence this patch that increases the UFS timeout to 10 s. This patch can cause the total timeout to exceed 20 s, the Android shutdown timeout. This is fine since the loop around ufshcd_execute_start_stop() exists to deal with unit attentions and because unit attentions are reported quickly.
--- drivers/ufs/core/ufshcd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/ufs/core/ufshcd.c +2 -1
@@ -9182,7 +9182,8 @@ static int ufshcd_execute_start_stop(struct scsi_device *sdev, };return scsi_execute_cmd (sdev, cdb,REQ_OP_DRV_IN ,/*buffer=*/ NULL , -/*bufflen=*/ 0 ,/*timeout=*/ HZ ,/*retries=*/ 0 , &args); +/*bufflen=*/ 0 ,/*timeout=*/ 10 *HZ ,/*retries=*/ 0 , + &args); }/**