Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp2726378pxt; Mon, 9 Aug 2021 07:32:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwe03oXi4+13DJfk+9tbihNkkWtWHJhK45Kwpt7SpIwIPKO5FKvJHBkB1crKSNegQ8hmGF3 X-Received: by 2002:a02:5bca:: with SMTP id g193mr22569334jab.129.1628519534969; Mon, 09 Aug 2021 07:32:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628519534; cv=none; d=google.com; s=arc-20160816; b=TXjqPZEPXPypCaHoHODmEq+UZR4mHEMLTTeK57c1pZ06jR5PKIz6UwLq50Zt3Ch6VI 5htt/65hVqGMCIhWfzgM0wKSJHm3Wq8suQug/gWMLgjDlFrYZhtKzXQMTF1FKsDaDy2r 4QGXqtGX4TPKe4o9MDkd8a+s2ku2JsyYTtCO0BKL6x0xtb/OaBkdOVFcTxLOCRD0TC0I CkqDkicefs3d8r225OGduKo+Fx/BlLUBUxRCKzzs56hsY2e7ZkLZhXPEMuiwnAJM2tco x5mKH98dVw1DgEKDVd+bxQgWAmulKA1GgmSxTaiCF4s2w8/tsJX3ov4vpAjY2C/DjbA8 LATQ== 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=+C0F53FdM7JYKrZHDVcv9Uc6mfCbplRqZkYI87bUJRw=; b=O7QuLWZxyev81ZCx4fg63DDf17/XakH6nJRzJo6+GD7glBtwD4jGhTjl056Lvyduby 2QIw6wkPBTT4S40P0TQfC13/mYiNmanBJvDYYOUbmLcWeYH8E5ZTbv6yV5Yw2fXV5Tzn VCjvNv7QGYaXYnLzfxamRVYUa7u3kuPSGeIZPQ82nnTpkxa+AIY+BnGxDVXUKcoXJrd/ 91fVM/Dk5yn5wav439SXlFznNcwfsnmq4J5clEwlCA+y44+2WQkn/QCLfoo/jBy+b01o bNNRSWcF+xDfOuElgdz01EO1F2RgWjxPvxwitDGcETh9jNkNGADtHntNI3dqbTTOqkvv 5yow== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m16si7800051jat.17.2021.08.09.07.32.03; Mon, 09 Aug 2021 07:32:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234171AbhHINnj (ORCPT + 99 others); Mon, 9 Aug 2021 09:43:39 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:7811 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233102AbhHINni (ORCPT ); Mon, 9 Aug 2021 09:43:38 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Gjy2Z39jgzYmhN; Mon, 9 Aug 2021 21:43:02 +0800 (CST) Received: from dggema773-chm.china.huawei.com (10.1.198.217) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Mon, 9 Aug 2021 21:43:15 +0800 Received: from localhost.huawei.com (10.175.124.27) by dggema773-chm.china.huawei.com (10.1.198.217) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Mon, 9 Aug 2021 21:43:14 +0800 From: To: , , , CC: , , , , , Subject: [PATCH v2] scsi: core: Fix hang of freezing queue between blocking and running device Date: Mon, 9 Aug 2021 22:13:08 +0800 Message-ID: <20210809141308.3700854-1-lijinlin3@huawei.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggema773-chm.china.huawei.com (10.1.198.217) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Li Jinlin We found a hang issue, the test steps are as follows: 1. blocking device via scsi_device_set_state() 2. dd if=/dev/sda of=/mnt/t.log bs=1M count=10 3. echo none > /sys/block/sda/queue/scheduler 4. echo "running" >/sys/block/sda/device/state Step 3 and 4 should finish this work after step 4, but they hangs. CPU#0 CPU#1 CPU#2 --------------- ---------------- ---------------- Step 1: blocking device Step 2: dd xxxx ^^^^^^ get request q_usage_counter++ Step 3: switching scheculer elv_iosched_store elevator_switch blk_mq_freeze_queue blk_freeze_queue > blk_freeze_queue_start ^^^^^^ mq_freeze_depth++ > blk_mq_run_hw_queues ^^^^^^ can't run queue when dev blocked > blk_mq_freeze_queue_wait ^^^^^^ Hang here!!! wait q_usage_counter==0 Step 4: running device store_state_field scsi_rescan_device scsi_attach_vpd scsi_vpd_inquiry __scsi_execute blk_get_request blk_mq_alloc_request blk_queue_enter ^^^^^^ Hang here!!! wait mq_freeze_depth==0 blk_mq_run_hw_queues ^^^^^^ dispatch IO, q_usage_counter will reduce to zero blk_mq_unfreeze_queue ^^^^^ mq_freeze_depth-- Step 3 and 4 wait for each other. To fix this, we need to run queue before rescanning device when the device state changes to SDEV_RUNNING. Fixes: f0f82e2476f6 ("scsi: core: Fix capacity set to zero after offlinining device") Signed-off-by: Li Jinlin Signed-off-by: Qiu Laibin --- changes since v1 send with Message-ID: 20210805143231.1713299-1-lijinlin3@huawei.com - Modify the subject to make it distinct - Modify the message to fix typo and make it distinct - Reduce the number of SOB drivers/scsi/scsi_sysfs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index c3a710bceba0..aa701582c950 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -809,12 +809,12 @@ store_state_field(struct device *dev, struct device_attribute *attr, ret = scsi_device_set_state(sdev, state); /* * If the device state changes to SDEV_RUNNING, we need to - * rescan the device to revalidate it, and run the queue to - * avoid I/O hang. + * run the queue to avoid I/O hang, and rescan the device + * to revalidate it. */ if (ret == 0 && state == SDEV_RUNNING) { - scsi_rescan_device(dev); blk_mq_run_hw_queues(sdev->request_queue, true); + scsi_rescan_device(dev); } mutex_unlock(&sdev->state_mutex); -- 2.27.0