Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2576217rdb; Fri, 22 Sep 2023 02:45:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGTtsGQD5twDc3G6jaElYwTzWEn8l0xLq5B02UuaFv00PIHHpDvSgLysiCOJuoNAtRCJQat X-Received: by 2002:a05:6a21:778d:b0:14d:792:aafb with SMTP id bd13-20020a056a21778d00b0014d0792aafbmr7091761pzc.54.1695375920884; Fri, 22 Sep 2023 02:45:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695375920; cv=none; d=google.com; s=arc-20160816; b=SZJviyhYvXJwCwgjeaaXnAcO4Wo2JugdrAPs4GuuXQodoPihlRzlFJLHlCvYor0SR0 jBKDGeeSJC25HPOjmz+VMT1E2eWaMO1+STrdJTFAqYfWMT5Pg8ChCOjBOW4W9oBSZ6Gz Ngq9W1Nd4veoXQW1LpxRQeV+oDW/QhFb3sj/+S3oO1M8DJ4vTJJx7XRrS79JGZaEj1nR 4QmSuw6BYQCcaIsimzmS0R7zHb/EkDOY4GfeVMzsIVo3s+A/XWdEKSD7/n5oHwizvwQg CLctfFD8E8ojnFFloHTdJnUqj0KaOB4GCXJeGOWFckmwyZ7e+QAd58P2ZVtXl9TY9ckk GlQg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=+ENTlMtxnBTgd1Hz7eOykHNjcnwFfUipQpPFphAQRfQ=; fh=czI/RuS43lIcejQG7heSpqlilKbUywFjC/3GVjzlias=; b=OHULgDuNQ+jP4AsjnFYSpg0g0iRy/MzQ9ZditOXBptQhWwTejA9yK8O4DauHg2wyyO zmBVYHJtSFqtHwp86nSMc+/wIC73dUNnqOfIQ2GBjDwO0jM6UTGQ7Il+dGKyOB6DuJ89 rk6RKqrubYRlcGITUMzjSQEkZ0WWlIDXlJlHQvttdZx/Gi1FQA94JOgdU12HETesxwNi Je+UMmL4gGQ49T6nMEhC8n7SfP+6mvpsbvzFx0dVzT2Apq0t0vRMNcq1vVeo9Kax5+s8 4Oo1G56Ew9w3tAfvwZtPGCK737QUYc9aioeX93FBYe7rySS16DbZpQTGVpA8Qid8E9FU iMVA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id ga17-20020a17090b039100b00267ba1c43adsi3446964pjb.101.2023.09.22.02.45.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 02:45:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 912C6837CF3E; Fri, 22 Sep 2023 02:37:11 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233120AbjIVJhJ (ORCPT + 99 others); Fri, 22 Sep 2023 05:37:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233017AbjIVJhG (ORCPT ); Fri, 22 Sep 2023 05:37:06 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8533F192; Fri, 22 Sep 2023 02:37:00 -0700 (PDT) Received: from kwepemm000012.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4RsRty3PB1z15NP6; Fri, 22 Sep 2023 17:34:50 +0800 (CST) Received: from build.huawei.com (10.175.101.6) by kwepemm000012.china.huawei.com (7.193.23.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Fri, 22 Sep 2023 17:36:58 +0800 From: Wenchao Hao To: "James E . J . Bottomley" , "Martin K . Petersen" , , CC: , , Wenchao Hao Subject: [PATCH 1/2] scsi: core: scsi_device_online() return false if state is SDEV_CANCEL Date: Fri, 22 Sep 2023 17:36:35 +0800 Message-ID: <20230922093636.2645961-2-haowenchao2@huawei.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20230922093636.2645961-1-haowenchao2@huawei.com> References: <20230922093636.2645961-1-haowenchao2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm000012.china.huawei.com (7.193.23.142) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 22 Sep 2023 02:37:11 -0700 (PDT) SDEV_CANCEL is set when removing device and scsi_device_online() should return false if sdev_state is SDEV_CANCEL. IO hang would be caused if return true when state is SDEV_CANCEL with following order: T1: T2:scsi_error_handler __scsi_remove_device() scsi_device_set_state(sdev, SDEV_CANCEL) scsi_eh_flush_done_q() if (scsi_device_online(sdev)) scsi_queue_insert(scmd,...) The command added by scsi_queue_insert() would never be handled any more. Signed-off-by: Wenchao Hao --- include/scsi/scsi_device.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h index 75b2235b99e2..c498a12f7715 100644 --- a/include/scsi/scsi_device.h +++ b/include/scsi/scsi_device.h @@ -517,7 +517,8 @@ static inline int scsi_device_online(struct scsi_device *sdev) { return (sdev->sdev_state != SDEV_OFFLINE && sdev->sdev_state != SDEV_TRANSPORT_OFFLINE && - sdev->sdev_state != SDEV_DEL); + sdev->sdev_state != SDEV_DEL && + sdev->sdev_state != SDEV_CANCEL); } static inline int scsi_device_blocked(struct scsi_device *sdev) { -- 2.32.0