Message ID | 20230321084204.1860900-1-yebin@huaweicloud.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1662644wrt; Tue, 21 Mar 2023 01:51:53 -0700 (PDT) X-Google-Smtp-Source: AK7set+AKg95UNtriMQ8cxp5VITmDKn28f38C5LScD6Q7eh+xBqW7nsyQ6B3Rv6G7NJLLwGtgkcQ X-Received: by 2002:a17:902:f68c:b0:1a1:7b8d:6719 with SMTP id l12-20020a170902f68c00b001a17b8d6719mr2925482plg.27.1679388712874; Tue, 21 Mar 2023 01:51:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679388712; cv=none; d=google.com; s=arc-20160816; b=VbLDd+iwIFoQUJik1x13gy2KzQE9b2r4k4FpzEIILbus5MtTraWSzsTtgxApLpiM0F 03embIhlq6OpHjZ7x3lXFdtOJP+0mLTlxfhWT/sF1xdewf7kc/p3ne5gAeEGIEeKFYov n4TqEka1eIdCC/l38xvi5yhlC1ix++tl4i7HiyrhlZW/ssHyr1MT6Q1TrGBLNXM2TN6n S2151oiuFJZ0f4ZOAzgP9SB3H46qkAq2QCDJIuJa5Jeu+x3YbZcum5r1Y2Kzn0Ei1BwY InKGYjCgOQG7ccRrayqXT5mk8ZA6DvsH8YgrTJ7MusMJIUiXwvXcqGWZIByCEfWs057H EnWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=qTOxoB2DwIaBHjQ7bSWbAxXUfMOkJucyawYSPjmMNwQ=; b=rvW7fON3WvJZYU23ZhNbblN3E5eS6wKhqvmQNItIjhHcSKHB4xcCskp112lZcxYMg2 32ib9oFeXadSOljaWvPEqZoJV/M1JS77RJne1KsQPQbRdodkVhfvRegk9gRGub+pAJ/+ j4Idd0pYrXsajdknBAsivxoJVmwZzp6d6f6HQMY4K39zNnoX+G1IwpYL3DTIvWy8P9gF PY40b4woChMiwWCl4zXbMLKBnqCC8+3jmD+t10kxinvAiLF4JZXQg0K4CikPtT0evGvf 4ZC3mzEAHSBtAaViA90fkglgXidgYBRgxV/vrUvS0wq0saVgG0sBFKS8wRlk//axDzvK alBg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l9-20020a17090270c900b001a1ba07911bsi8268401plt.530.2023.03.21.01.51.37; Tue, 21 Mar 2023 01:51:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229771AbjCUIoG (ORCPT <rfc822;pusanteemu@gmail.com> + 99 others); Tue, 21 Mar 2023 04:44:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229792AbjCUIoD (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 21 Mar 2023 04:44:03 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B49CE15C94; Tue, 21 Mar 2023 01:43:09 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.169]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4PglVT5r6wz4f3nTB; Tue, 21 Mar 2023 16:42:57 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP3 (Coremail) with SMTP id _Ch0CgBnFCIRbhlkMJs0FQ--.59469S4; Tue, 21 Mar 2023 16:42:59 +0800 (CST) From: Ye Bin <yebin@huaweicloud.com> To: jejb@linux.ibm.com, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ye Bin <yebin10@huawei.com> Subject: [PATCH] scsi: fix hung_task when change host from recovery to running via sysfs Date: Tue, 21 Mar 2023 16:42:04 +0800 Message-Id: <20230321084204.1860900-1-yebin@huaweicloud.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: _Ch0CgBnFCIRbhlkMJs0FQ--.59469S4 X-Coremail-Antispam: 1UD129KBjvJXoW7AF4fAry3ZFy3AFW5Gr4UJwb_yoW8AFy5pr WrJ34UGr48uw1Ika1q9F1UKFy5G3yvyFykKFZ7u348ZFy8JFy2q3Z5JFWjqFyUGrW8urn5 WF1DWFs8Ka1jqaUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUgEb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x 0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG 6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFV Cjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCj c4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4 CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1x MIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJVW8JwCI42IY6xAIw20EY4v20xvaj40_WFyUJV Cq3wCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIY CTnIWIevJa73UjIFyTuYvjxUrR6zUUUUU X-CM-SenderInfo: p1hex046kxt4xhlfz01xgou0bp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760966699046167642?= X-GMAIL-MSGID: =?utf-8?q?1760966699046167642?= |
Series |
scsi: fix hung_task when change host from recovery to running via sysfs
|
|
Commit Message
Ye Bin
March 21, 2023, 8:42 a.m. UTC
From: Ye Bin <yebin10@huawei.com> 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@huawei.com> --- drivers/scsi/scsi_sysfs.c | 3 +++ 1 file changed, 3 insertions(+)
Comments
On Tue, Mar 21, 2023 at 04:42:04PM +0800, Ye Bin wrote: > From: Ye Bin <yebin10@huawei.com> > > When do follow test: > Step1: echo "recovery" > /sys/class/scsi_host/host0/state Hmm, that make me wonder, what potential use-case this is for? Just testing? For SDEVs we explicitly filter what states can be set from user-space. Only `SDEV_RUNNING` and `SDEV_OFFLINE` can be set in `store_state_field()`. There is probably quite a few other bad things you can do with this interface by using any of the other states used for device destruction or EH, and then trigger I/O or said destruction/EH otherwise. Not sure handling this one special case of `SHOST_RECOVERY` is quite enough. > 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 >
On 2023/3/21 22:22, Benjamin Block wrote: > On Tue, Mar 21, 2023 at 04:42:04PM +0800, Ye Bin wrote: >> From: Ye Bin <yebin10@huawei.com> >> >> When do follow test: >> Step1: echo "recovery" > /sys/class/scsi_host/host0/state > Hmm, that make me wonder, what potential use-case this is for? Just > testing? Thank you for your reply. Actually, I'm looking for a way to temporarily stop sending IO to the driver. Setting the state of the host to recovery can do this, but I changed the state to running and found that the process could not be woken up. I don't know what the purpose of designing this sysfs interface was. But this modification can solve the effect I want to achieve. > For SDEVs we explicitly filter what states can be set from user-space. > Only `SDEV_RUNNING` and `SDEV_OFFLINE` can be set in > `store_state_field()`. > There is probably quite a few other bad things you can do with this > interface by using any of the other states used for device destruction > or EH, and then trigger I/O or said destruction/EH otherwise. > Not sure handling this one special case of `SHOST_RECOVERY` is quite > enough. > > >> 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 >>
On Wed, Mar 22, 2023 at 09:24:32AM +0800, yebin (H) wrote: > On 2023/3/21 22:22, Benjamin Block wrote: > > On Tue, Mar 21, 2023 at 04:42:04PM +0800, Ye Bin wrote: > >> From: Ye Bin <yebin10@huawei.com> > >> > >> When do follow test: > >> Step1: echo "recovery" > /sys/class/scsi_host/host0/state > > > > Hmm, that make me wonder, what potential use-case this is for? Just > > testing? > > Thank you for your reply. > Actually, I'm looking for a way to temporarily stop sending IO to the > driver. > Setting the state of the host to recovery can do this, but I changed > the state to running and found that the process could not be woken up. > I don't know what the purpose of designing this sysfs interface was. > But this modification can solve the effect I want to achieve. My first thought when seeing this was that maybe we should also limit this interface to say `SHOST_RUNNING` and `SHOST_RECOVERY` (similar to what is done in `store_state_field()`). That would limit the amount of corner cases drastically. And in case of setting `SHOST_RUNNING` after the scsi host was set to `SHOST_RECOVERY`, we could also make use of the already existing function `scsi_restart_operations()` to handle the restart in the same way as EH does. But it's not up to me, to make that call. > > For SDEVs we explicitly filter what states can be set from user-space. > > Only `SDEV_RUNNING` and `SDEV_OFFLINE` can be set in > > `store_state_field()`. > > There is probably quite a few other bad things you can do with this > > interface by using any of the other states used for device destruction > > or EH, and then trigger I/O or said destruction/EH otherwise. > > Not sure handling this one special case of `SHOST_RECOVERY` is quite > > enough. > > > >> 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); In the very least, this should first check whether we really just made the transition from `SHOST_RECOVERY` to `SHOST_RUNNING` before calling this `wake_up()`. And for that - first get old state, then set the new state - we probably would also need to grab the `host_lock` to make that race free. Just calling `wake_up()` without knowing what state transition we just made doesn't sound right to me. > >> + > >> return count; > >> } > >> > >> -- > >> 2.31.1 > >> >
On 3/23/23 5:21 AM, Benjamin Block wrote: > On Wed, Mar 22, 2023 at 09:24:32AM +0800, yebin (H) wrote: >> On 2023/3/21 22:22, Benjamin Block wrote: >>> On Tue, Mar 21, 2023 at 04:42:04PM +0800, Ye Bin wrote: >>>> From: Ye Bin <yebin10@huawei.com> >>>> >>>> When do follow test: >>>> Step1: echo "recovery" > /sys/class/scsi_host/host0/state >>> >>> Hmm, that make me wonder, what potential use-case this is for? Just >>> testing? >> >> Thank you for your reply. >> Actually, I'm looking for a way to temporarily stop sending IO to the >> driver. >> Setting the state of the host to recovery can do this, but I changed >> the state to running and found that the process could not be woken up. >> I don't know what the purpose of designing this sysfs interface was. >> But this modification can solve the effect I want to achieve. > > My first thought when seeing this was that maybe we should also limit > this interface to say `SHOST_RUNNING` and `SHOST_RECOVERY` (similar to > what is done in `store_state_field()`). > That would limit the amount of corner cases drastically. > > And in case of setting `SHOST_RUNNING` after the scsi host was set to > `SHOST_RECOVERY`, we could also make use of the already existing > function `scsi_restart_operations()` to handle the restart in the same > way as EH does. > I agree we should limit the states we can set. It doesn't make sense for userspace to be able to set states like SHOST_CANCEL and I think it would later break functions like scsi_remove_host. Maybe instead of allowing SHOST_RECOVERY to be used by userspace we want a new state SHOST_BLOCKED which just does the specific operation we want. If we re-use SHOST_RECOVERY for userspace blocking IO there could be issues later on because that state also means we are going to be performing the eh callouts and not just stopping IO. Or maybe instead of a different state we just add another shost field similar to tmf_in_progress which forces scsi_queue_rq to not queue IO to the drivers.
On 3/21/23 8:24 PM, yebin (H) wrote: > > > On 2023/3/21 22:22, Benjamin Block wrote: >> On Tue, Mar 21, 2023 at 04:42:04PM +0800, Ye Bin wrote: >>> From: Ye Bin <yebin10@huawei.com> >>> >>> When do follow test: >>> Step1: echo "recovery" > /sys/class/scsi_host/host0/state >> Hmm, that make me wonder, what potential use-case this is for? Just >> testing? > Thank you for your reply. > Actually, I'm looking for a way to temporarily stop sending IO to the driver. Is this just for testing something or does a user/app need this functionality for something? We used to be able to block specific devices but we removed that. It was useful for people like us where we need to do some low kernel testing like testing for how upper layers handle IO hangs, but I think it was not useful for other users so it was removed.
On 2023/3/24 0:12, Mike Christie wrote: > On 3/21/23 8:24 PM, yebin (H) wrote: >> >> On 2023/3/21 22:22, Benjamin Block wrote: >>> On Tue, Mar 21, 2023 at 04:42:04PM +0800, Ye Bin wrote: >>>> From: Ye Bin <yebin10@huawei.com> >>>> >>>> When do follow test: >>>> Step1: echo "recovery" > /sys/class/scsi_host/host0/state >>> Hmm, that make me wonder, what potential use-case this is for? Just >>> testing? >> Thank you for your reply. >> Actually, I'm looking for a way to temporarily stop sending IO to the driver. > Is this just for testing something or does a user/app need this > functionality for something? This can be used to store IO in the block layer, enabling some fault recovery that is insensitive to the upper layer.Also want to use this state to test the block layer. > We used to be able to block specific devices but we removed that. > It was useful for people like us where we need to do some low kernel > testing like testing for how upper layers handle IO hangs, but I > think it was not useful for other users so it was removed. > > . >
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; }