[PATCH] scsi: fix hung_task when change host from recovery to running via sysfs

From: Ye Bin
Date: Tue Mar 21 2023 - 04:44:10 EST


From: Ye Bin <yebin10@xxxxxxxxxx>

When do follow test:
Step1: echo "recovery" > /sys/class/scsi_host/host0/state
Step2: dd if=/dev/sda of=/dev/null count=1 &
Step3: echo "running" > /sys/class/scsi_host/host0/state
Got issue as follows:
INFO: task dd:14545 blocked for more than 143 seconds.
Not tainted 6.3.0-rc2-next-20230315-dirty #406
"echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
task:dd state:D stack:23376 pid:14545 ppid:14439 flags:0x00000000
Call Trace:
<TASK>
__schedule+0x232e/0x55a0
schedule+0xde/0x1a0
scsi_block_when_processing_errors+0x2e9/0x350
sd_open+0x10c/0x6d0
blkdev_get_whole+0x99/0x260
blkdev_get_by_dev+0x556/0xbe0
blkdev_open+0x140/0x2c0
do_dentry_open+0x6cc/0x13f0
path_openat+0x1b3b/0x26b0
do_filp_open+0x1ce/0x2a0
do_sys_openat2+0x61b/0x990
do_sys_open+0xc7/0x150
do_syscall_64+0x39/0xb0
entry_SYSCALL_64_after_hwframe+0x63/0xcd

Above issue happens as when change host state by sysfs, there isn't wakeup
waiter.
To solve above issue, just wakeup waiter when change state success. There is
no additional judgment here because modifying the host state is more used in
testing.

Signed-off-by: Ye Bin <yebin10@xxxxxxxxxx>
---
drivers/scsi/scsi_sysfs.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index ee28f73af4d4..ae6b1476b869 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -216,6 +216,9 @@ store_shost_state(struct device *dev, struct device_attribute *attr,

if (scsi_host_set_state(shost, state))
return -EINVAL;
+ else
+ wake_up(&shost->host_wait);
+
return count;
}

--
2.31.1