From patchwork Mon Oct 16 02:03:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenchao Hao X-Patchwork-Id: 153138 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3190067vqb; Sun, 15 Oct 2023 19:04:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH8ACvE9dIAzhqgxp8PYo1wd4o7bJEZCJ7awps3DDjDsXZssOiqxDpHjmACApaZdXWEXb9y X-Received: by 2002:a05:6808:15a8:b0:3ad:f3c0:5da3 with SMTP id t40-20020a05680815a800b003adf3c05da3mr40270235oiw.3.1697421874971; Sun, 15 Oct 2023 19:04:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697421874; cv=none; d=google.com; s=arc-20160816; b=S+XG6eDb9gYKg2uCNM2I9K31CDH26YfhjfZSId9lQ4+WWHHy2sHcSuFN5TZnGUTxUD 5TCACxt0mLN4UywTgPLhIiHZSJgCTvFPySFh7wM3jKyAq5PbRXCdadlybpNhqVf3xTVw ecU9YZ7ElL7gINkPLTXL3mIvytJsnBzLqnKbFKNTF9JBvyUvweLJcSLW4Qcn8bpfKxU1 /maH4YorNK6lGdlPSK3t4UYyyEW42DxFe/JzTwJyYNknNUrZQRgtSkAI+Wje/k23HqgT 4JpmEaX+Ad/TXUhxdf5KxmNaVEe2FZssT/Vod8XSwcjgTbBD6HmMZ/9L1pd6z2iHvbdT Cdog== 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=H9FM+jxlu2sopr+ewGbc/FXFm1IlY0h5uuDiF18ha+Y=; fh=ZDcIlyYggP5K3GvQBQF3K/GzUnCJV+bQb/1GDPxM7E4=; b=gceKSVZFcnadAHVhB+feZV8vLXh/Tso5IC/hK/LvuMfrBvFve+G8tMWjQ+50YF1cMc PdXOJUjRflXZW+mcIHUkY1A4GhIn18DhHfgqCWN/whmTWYMJ7kNI+CRpxYXfeQKk4tbw XIXWvNMjVBRxIle+SSg3+I+7OZ19LkulZpi+kI20JnSH+cS4Evqoy6CfxPDpF77MCmLg 27AfqY0+cNeUNGcmj2pft8HfTJt5WvGaj0iP3NlkVG58GjGRCj2WPOp+2bhTp015WXw2 OJo49sOUY8xekB/sPavXWoWc2gvphHYuVCxlAeHU8ph1AYIwE37/1+yfx3wZmjgCElYM dyzg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id 28-20020a630c5c000000b005855f67e490si10024385pgm.690.2023.10.15.19.04.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 19:04:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 30F90805DEDC; Sun, 15 Oct 2023 19:04:31 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231331AbjJPCDv (ORCPT + 19 others); Sun, 15 Oct 2023 22:03:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231314AbjJPCDn (ORCPT ); Sun, 15 Oct 2023 22:03:43 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 665CE95; Sun, 15 Oct 2023 19:03:40 -0700 (PDT) Received: from kwepemm000012.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4S80dl2C9HzvPyk; Mon, 16 Oct 2023 09:58:51 +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; Mon, 16 Oct 2023 10:03:32 +0800 From: Wenchao Hao To: "James E . J . Bottomley" , "Martin K . Petersen" , CC: , , Wenchao Hao Subject: [PATCH v3 1/4] scsi: core: Add new helper to iterate all devices of host Date: Mon, 16 Oct 2023 10:03:11 +0800 Message-ID: <20231016020314.1269636-2-haowenchao2@huawei.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20231016020314.1269636-1-haowenchao2@huawei.com> References: <20231016020314.1269636-1-haowenchao2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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 pete.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 (pete.vger.email [0.0.0.0]); Sun, 15 Oct 2023 19:04:31 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779875839946852836 X-GMAIL-MSGID: 1779875839946852836 shost_for_each_device() would skip devices which is in SDEV_CANCEL or SDEV_DEL state, for some scenarios, we donot want to skip these devices, so add a new macro shost_for_each_device_include_deleted() to handle it. Following changes are introduced: 1. Rework scsi_device_get(), add new helper __scsi_device_get() which determine if skip deleted scsi_device by parameter "skip_deleted". 2. Add new parameter "skip_deleted" to __scsi_iterate_devices() which is used when calling __scsi_device_get() 3. Update shost_for_each_device() to call __scsi_iterate_devices() with "skip_deleted" true 4. Add new macro shost_for_each_device_include_deleted() which call __scsi_iterate_devices() with "skip_deleted" false Signed-off-by: Wenchao Hao --- drivers/scsi/scsi.c | 46 ++++++++++++++++++++++++++------------ include/scsi/scsi_device.h | 25 ++++++++++++++++++--- 2 files changed, 54 insertions(+), 17 deletions(-) diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c index d1c0ba3ef1f5..a9d695841250 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c @@ -704,20 +704,18 @@ int scsi_cdl_enable(struct scsi_device *sdev, bool enable) return 0; } -/** - * scsi_device_get - get an additional reference to a scsi_device +/* + * __scsi_device_get - get an additional reference to a scsi_device * @sdev: device to get a reference to - * - * Description: Gets a reference to the scsi_device and increments the use count - * of the underlying LLDD module. You must hold host_lock of the - * parent Scsi_Host or already have a reference when calling this. - * - * This will fail if a device is deleted or cancelled, or when the LLD module - * is in the process of being unloaded. + * @skip_deleted: when true, would return failed if device is deleted */ -int scsi_device_get(struct scsi_device *sdev) +static int __scsi_device_get(struct scsi_device *sdev, bool skip_deleted) { - if (sdev->sdev_state == SDEV_DEL || sdev->sdev_state == SDEV_CANCEL) + /* + * if skip_deleted is true and device is in removing, return failed + */ + if (skip_deleted && + (sdev->sdev_state == SDEV_DEL || sdev->sdev_state == SDEV_CANCEL)) goto fail; if (!try_module_get(sdev->host->hostt->module)) goto fail; @@ -730,6 +728,22 @@ int scsi_device_get(struct scsi_device *sdev) fail: return -ENXIO; } + +/** + * scsi_device_get - get an additional reference to a scsi_device + * @sdev: device to get a reference to + * + * Description: Gets a reference to the scsi_device and increments the use count + * of the underlying LLDD module. You must hold host_lock of the + * parent Scsi_Host or already have a reference when calling this. + * + * This will fail if a device is deleted or cancelled, or when the LLD module + * is in the process of being unloaded. + */ +int scsi_device_get(struct scsi_device *sdev) +{ + return __scsi_device_get(sdev, 0); +} EXPORT_SYMBOL(scsi_device_get); /** @@ -749,9 +763,13 @@ void scsi_device_put(struct scsi_device *sdev) } EXPORT_SYMBOL(scsi_device_put); -/* helper for shost_for_each_device, see that for documentation */ +/** + * helper for shost_for_each_device, see that for documentation + * @skip_deleted: if true, sdev in progress of removing would be skipped + */ struct scsi_device *__scsi_iterate_devices(struct Scsi_Host *shost, - struct scsi_device *prev) + struct scsi_device *prev, + bool skip_deleted) { struct list_head *list = (prev ? &prev->siblings : &shost->__devices); struct scsi_device *next = NULL; @@ -761,7 +779,7 @@ struct scsi_device *__scsi_iterate_devices(struct Scsi_Host *shost, while (list->next != &shost->__devices) { next = list_entry(list->next, struct scsi_device, siblings); /* skip devices that we can't get a reference to */ - if (!scsi_device_get(next)) + if (!__scsi_device_get(next, skip_deleted)) break; next = NULL; list = list->next; diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h index b9230b6add04..ed02755bbc42 100644 --- a/include/scsi/scsi_device.h +++ b/include/scsi/scsi_device.h @@ -390,7 +390,8 @@ extern void __starget_for_each_device(struct scsi_target *, void *, /* only exposed to implement shost_for_each_device */ extern struct scsi_device *__scsi_iterate_devices(struct Scsi_Host *, - struct scsi_device *); + struct scsi_device *, + bool); /** * shost_for_each_device - iterate over all devices of a host @@ -400,11 +401,29 @@ extern struct scsi_device *__scsi_iterate_devices(struct Scsi_Host *, * Iterator that returns each device attached to @shost. This loop * takes a reference on each device and releases it at the end. If * you break out of the loop, you must call scsi_device_put(sdev). + * + * Note: this macro would skip sdev which is in progress of removing */ #define shost_for_each_device(sdev, shost) \ - for ((sdev) = __scsi_iterate_devices((shost), NULL); \ + for ((sdev) = __scsi_iterate_devices((shost), NULL, 1); \ + (sdev); \ + (sdev) = __scsi_iterate_devices((shost), (sdev), 1)) + +/* + * shost_for_each_device_include_deleted- iterate over all devices of a host + * @sdev: the &struct scsi_device to use as a cursor + * @shost: the &struct scsi_host to iterate over + * + * Iterator that returns each device attached to @shost. This loop + * takes a reference on each device and releases it at the end. If + * you break out of the loop, you must call scsi_device_put(sdev). + * + * Note: this macro would include sdev which is in progress of removing + */ +#define shost_for_each_device_include_deleted(sdev, shost) \ + for ((sdev) = __scsi_iterate_devices((shost), NULL, 0); \ (sdev); \ - (sdev) = __scsi_iterate_devices((shost), (sdev))) + (sdev) = __scsi_iterate_devices((shost), (sdev), 0)) /** * __shost_for_each_device - iterate over all devices of a host (UNLOCKED) From patchwork Mon Oct 16 02:03:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenchao Hao X-Patchwork-Id: 153137 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3189936vqb; Sun, 15 Oct 2023 19:04:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH7fkL0NM1P7jVqyVE6OwAZ9rybe7WnV2yB+op3clWH+rzIHNfDn1OA8PoeUrPeAU1Zib9I X-Received: by 2002:a05:6358:2927:b0:166:bed7:b4d0 with SMTP id y39-20020a056358292700b00166bed7b4d0mr1301263rwb.1.1697421850587; Sun, 15 Oct 2023 19:04:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697421850; cv=none; d=google.com; s=arc-20160816; b=S2HHhE5u2dWwJ9SlZ5AfbhgHiAqNM2q5L2vrIlQ3p79vNTHtnI9JVlJg/A4NDgXv0y rpGEVLJszlCCtoUFBWVCmH4aH6rO/gpDyhK7JBF0nT/pLBRsv2II4g2lB9t3s6AHxxhM BifatM8NX6kW93qtmlB5yLZOjVtVI7I7tp0LoV808EO++subvKbUqVvie56yEvzGF9rE lBIZup2s6s5P5t/M/0VfUYv3Vf3RwpkRS7r2M5QPsHiqMMEo40ekyqO8jQXhH9SAU539 itLTUWpCp4cT61+XDOPTZg9ch+mZ3eU4UeB/c6915Kqok4j8rb7V+L1vQ537huv+nefj lBFQ== 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=5HXWY/1eKTi2AaycFfWdMtNMxCXH8NCt5M62vjx8klI=; fh=ZDcIlyYggP5K3GvQBQF3K/GzUnCJV+bQb/1GDPxM7E4=; b=ILPriOuXcgnkGdleCjoBQ5gkwMX+zeIIkZgrp4OGXPIXrtYSnXN4lQ4lx0bb/TAmmL 2zMY5PQRoHCpQuyiKvXzHPIcgpQMBlKKOlqZiXwA1ambzBtxmcB5AUywBg34QyDSsC6n rv8MBYnhovfHyYQjptmY8ZXiQ/ugdS78YNQck7mY9O1HWiwONlAUHajHEt1lK+sq1zgy 8nIiyn8yMkMHoTdcL0j4zBCnK0AML2EhTQI3lc05XZ8mjCHYzw+Ur0VQXGOea8cqNqH4 LIiADuif4+xTwZ5N1YUmrwYWov0187TUoaa8Tu8IJdr1yrY/oq+xlFn8Irxhb17/JJV9 gBmg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id bx38-20020a056a02052600b005af15600342si5686043pgb.268.2023.10.15.19.04.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 19:04:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 6672F806155E; Sun, 15 Oct 2023 19:04:06 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230527AbjJPCDk (ORCPT + 19 others); Sun, 15 Oct 2023 22:03:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229639AbjJPCDj (ORCPT ); Sun, 15 Oct 2023 22:03:39 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 374C8C1; Sun, 15 Oct 2023 19:03:37 -0700 (PDT) Received: from kwepemm000012.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4S80g125lDzVlcD; Mon, 16 Oct 2023 09:59:57 +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; Mon, 16 Oct 2023 10:03:33 +0800 From: Wenchao Hao To: "James E . J . Bottomley" , "Martin K . Petersen" , CC: , , Wenchao Hao Subject: [PATCH v3 2/4] scsi: scsi_error: Fix wrong statistic when print error info Date: Mon, 16 Oct 2023 10:03:12 +0800 Message-ID: <20231016020314.1269636-3-haowenchao2@huawei.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20231016020314.1269636-1-haowenchao2@huawei.com> References: <20231016020314.1269636-1-haowenchao2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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 pete.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 (pete.vger.email [0.0.0.0]); Sun, 15 Oct 2023 19:04:06 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779875814371698033 X-GMAIL-MSGID: 1779875814371698033 shost_for_each_device() would skip devices which is in progress of removing, so commands of these devices would be ignored in scsi_eh_prt_fail_stats(). Fix this issue by using shost_for_each_device_include_deleted() to iterate devices in scsi_eh_prt_fail_stats(). Signed-off-by: Wenchao Hao --- drivers/scsi/scsi_error.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index c67cdcdc3ba8..2550f8cd182a 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -407,7 +407,7 @@ static inline void scsi_eh_prt_fail_stats(struct Scsi_Host *shost, int cmd_cancel = 0; int devices_failed = 0; - shost_for_each_device(sdev, shost) { + shost_for_each_device_include_deleted(sdev, shost) { list_for_each_entry(scmd, work_q, eh_entry) { if (scmd->device == sdev) { ++total_failures; From patchwork Mon Oct 16 02:03:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenchao Hao X-Patchwork-Id: 153140 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3190189vqb; Sun, 15 Oct 2023 19:04:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEXpk1WsOLoiucRSgGh6dAfi5pzcevI6Buy0VicDi+eppXiYpgyClafT2NDCWSPhrhJt6lR X-Received: by 2002:a05:6a20:9417:b0:16c:4959:c372 with SMTP id hl23-20020a056a20941700b0016c4959c372mr18770669pzb.6.1697421894089; Sun, 15 Oct 2023 19:04:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697421894; cv=none; d=google.com; s=arc-20160816; b=vpvQOMeSrewiI7tWaIKjXccctKgV9jCwyTgKXHMH8nUJAZOd8GFM9K2MGD0uGURJCS +4yip1BQMno9v3xdeO8g9qs1Utxp3/JvtxcANihjQALxO/n0qWJu39DPKHglktR/eroT bcmjZFM461ILtWpts2uFQl8XBEXdkhF/rbaAwNJ8dXG78ZQeQ+yNjhtH5/2+iaihE1uS Zq1PtbiwXvXKYJDStTxdaIDxiQVlYqXFKK787LINFJGL2czI/Iqkn8F3jvXVQwUfjboa tar6WuvCfn4PdtDONO7iuvCAK2+y4zcyKMEUxRb0ZUpqIsYbmmzu9dm6+TaqC8XOYFoZ dFfQ== 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=G8udQ0pF8FR5Qf8H1klqpSe+/RrH35jrGc6Tl54PFmM=; fh=ZDcIlyYggP5K3GvQBQF3K/GzUnCJV+bQb/1GDPxM7E4=; b=TEBgsBa8rJEwf7ZwKAzbNv5tYfyW0STgSzP2blUjCsYeRJedHno6y3lKhub1csSOap v6Emrq2VkT0BRwp+lIGbVbrcC+BPQJYoIrZDjybAuA/oK9zwRKGTp6FHOkp+G7Yr0TFI cyWldqQ3DSf4s6hu7ptPi3KGX0nPIcf8YTYzL7o3Jiu5MItxcISUh+qn4rGkrPm42Lyc dvkhZYbivCeaXeWghrEz/4Mlb7oE2Xqt7Gcp3O9Kxhv+iZVsDagZsS3tUMiS5dLjsIPm EoQaFHW2Pd2tB0LwBk/V9NzLUQUXAC96548O+batZ5l07Exy2PAe9lfvMBmbC0KPK5xl tAXw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id t2-20020a17090abc4200b0027b15e572c2si5063266pjv.21.2023.10.15.19.04.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 19:04:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 733E880608C1; Sun, 15 Oct 2023 19:04:51 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231423AbjJPCDy (ORCPT + 19 others); Sun, 15 Oct 2023 22:03:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231325AbjJPCDn (ORCPT ); Sun, 15 Oct 2023 22:03:43 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64770C1; Sun, 15 Oct 2023 19:03:42 -0700 (PDT) Received: from kwepemm000012.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4S80fc1qVPzNnxT; Mon, 16 Oct 2023 09:59:36 +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; Mon, 16 Oct 2023 10:03:34 +0800 From: Wenchao Hao To: "James E . J . Bottomley" , "Martin K . Petersen" , CC: , , Wenchao Hao Subject: [PATCH v3 3/4] scsi: scsi_error: Fix device reset is not triggered Date: Mon, 16 Oct 2023 10:03:13 +0800 Message-ID: <20231016020314.1269636-4-haowenchao2@huawei.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20231016020314.1269636-1-haowenchao2@huawei.com> References: <20231016020314.1269636-1-haowenchao2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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 howler.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 (howler.vger.email [0.0.0.0]); Sun, 15 Oct 2023 19:04:51 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779875859672950653 X-GMAIL-MSGID: 1779875859672950653 shost_for_each_device() would skip devices which is in progress of removing, so scsi_try_bus_device_reset() for these devices would be skipped in scsi_eh_bus_device_reset() with following order: T1: T2:scsi_error_handle __scsi_remove_device scsi_device_set_state(sdev, SDEV_DEL) // would skip device with SDEV_DEL state shost_for_each_device() scsi_try_bus_device_reset flush all commands ... releasing and free scsi_device Some drivers like smartpqi only implement eh_device_reset_handler, if device reset is skipped, the commands which had been sent to firmware or devices hardware are not cleared. The error handle would flush all these commands in scsi_unjam_host(). When the commands are finished by hardware, use after free issue is triggered. Fix this issue by using shost_for_each_device_include_deleted() to iterate devices in scsi_eh_bus_device_reset(). Signed-off-by: Wenchao Hao --- drivers/scsi/scsi_error.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index 2550f8cd182a..57e3cc556549 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -1568,7 +1568,7 @@ static int scsi_eh_bus_device_reset(struct Scsi_Host *shost, struct scsi_device *sdev; enum scsi_disposition rtn; - shost_for_each_device(sdev, shost) { + shost_for_each_device_include_deleted(sdev, shost) { if (scsi_host_eh_past_deadline(shost)) { SCSI_LOG_ERROR_RECOVERY(3, sdev_printk(KERN_INFO, sdev, From patchwork Mon Oct 16 02:03:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenchao Hao X-Patchwork-Id: 153139 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp3190081vqb; Sun, 15 Oct 2023 19:04:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHsh/wnYihCIUq13n+yLkW0eFfTgANjWNDrxrj2euRAX/jY6MxT/1eM1Ayo7CY64Sschv/r X-Received: by 2002:a05:6a00:4ac1:b0:6b9:7d5c:bb58 with SMTP id ds1-20020a056a004ac100b006b97d5cbb58mr5616465pfb.0.1697421876407; Sun, 15 Oct 2023 19:04:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697421876; cv=none; d=google.com; s=arc-20160816; b=iJn6FKDw0Mhsx7ezkDaXb45KBoMAhWtCSHPc/4r5tM5Z+UVL7I14Nze0NcqB10ZEbY RwthWHq4n21yK5YK2lFL6rXxJX6Ju5IH7KnzYilWld3U8WnkqS5QIiwJJVh3ZzukMfeS xb1uBIIVo9hfZK9Brv/CJ7MFIOp9IS2bORe2gkViOXNLwqtx5mUmjsR8y8GQ/B4DcVx/ wuYFwHKAm9Nd/ApQK7MuWbEDTlgVfu7KnZbIMnccn6ySyNrFa32AkvY6LxCo0+vOHCM1 6GIWhYCwsgi52VZ0KuvhQJLa3mD5lC7rHwb6KEmJr+t4yUpPSK880GKk9pAu8q0SbPFk jPzw== 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=SCdjDueQHmYAC0v4B3pVqWz7wNyspaHOvR0H9+rRfPE=; fh=ZDcIlyYggP5K3GvQBQF3K/GzUnCJV+bQb/1GDPxM7E4=; b=FV2xWnaofnl9ZBSFauHKAtkm6g8+6Hp6SzKaAY2/zKpKCYuA5jFTyMrjJAnmMOpmdy lGPWQpfiwaKM7o1/zcSsALXp3zkX3vXZ0jaX7miEUgd2mdu6pMnS7oefDNLWkMAmx9UQ 6/ApE3IN4WXa5iiR98NDv1wPpVoUrjDyzqhrBPxnMlxF0PfZd8HHdTHfReBnBpOuLp24 UXk/orlNjWFMdoztmenYlBc/K/bzijT3pfnbMmoCPof/fwbjP6SdpH4hSBtC1b78BGIV pras3iYQz44e/Q49QwupZG6wjr9okkyRhIMVYuBlWJwyP81hv6fP9WGlibiK/7FCjnIV hDlg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id g4-20020aa796a4000000b006be2b79b254si785150pfk.368.2023.10.15.19.04.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 19:04:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 631F4806A974; Sun, 15 Oct 2023 19:04:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231332AbjJPCDo (ORCPT + 19 others); Sun, 15 Oct 2023 22:03:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230283AbjJPCDj (ORCPT ); Sun, 15 Oct 2023 22:03:39 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C2ADC5; Sun, 15 Oct 2023 19:03:37 -0700 (PDT) Received: from kwepemm000012.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4S80g231KSzVlcN; Mon, 16 Oct 2023 09:59:58 +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; Mon, 16 Oct 2023 10:03:34 +0800 From: Wenchao Hao To: "James E . J . Bottomley" , "Martin K . Petersen" , CC: , , Wenchao Hao Subject: [PATCH v3 4/4] scsi: scsi_core: Fix IO hang when device removing Date: Mon, 16 Oct 2023 10:03:14 +0800 Message-ID: <20231016020314.1269636-5-haowenchao2@huawei.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20231016020314.1269636-1-haowenchao2@huawei.com> References: <20231016020314.1269636-1-haowenchao2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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 howler.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 (howler.vger.email [0.0.0.0]); Sun, 15 Oct 2023 19:04:34 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779875841428392778 X-GMAIL-MSGID: 1779875841428392778 shost_for_each_device() would skip devices which is in progress of removing, so scsi_run_queue() for these devices would be skipped in scsi_run_host_queues() after blocking hosts' IO. 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) ... sd_remove() del_gendisk() blk_mq_freeze_queue_wait() scsi_eh_flush_done_q() scsi_queue_insert(scmd,...) scsi_queue_insert() would not kick device's queue since commit 8b566edbdbfb ("scsi: core: Only kick the requeue list if necessary") After scsi_unjam_host(), the scsi error handler would call scsi_run_host_queues() to trigger run queue for devices, while it would not run queue for devices which is in progress of removing because shost_for_each_device() would skip them. So the requests added to these queues would not be handled any more, and the removing device process would hang too. Fix this issue by using shost_for_each_device_include_deleted() in scsi_run_host_queues() to trigger a run queue for devices in removing. Signed-off-by: Wenchao Hao --- drivers/scsi/scsi_lib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 195ca80667d0..40f407ffd26f 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -466,7 +466,7 @@ void scsi_run_host_queues(struct Scsi_Host *shost) { struct scsi_device *sdev; - shost_for_each_device(sdev, shost) + shost_for_each_device_include_deleted(sdev, shost) scsi_run_queue(sdev->request_queue); }