Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3056702rdh; Thu, 28 Sep 2023 00:49:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEvxEj7VMH+jjTmmXrUvqyPlRN7t3RQ3+bXQTD0rQfDnJkZFevnPciRX3NknlxObQoDO6xb X-Received: by 2002:a05:6358:724f:b0:143:5d3f:f397 with SMTP id i15-20020a056358724f00b001435d3ff397mr760435rwa.16.1695887347575; Thu, 28 Sep 2023 00:49:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695887347; cv=none; d=google.com; s=arc-20160816; b=McrzpwDIXVSZvIdINISzR9vc7QH6+5y0ei7LDslZ2hUSSvKN0MKC7GPgalAomDQFjq YMmvSRIajmy6vYwggl8Gi7lPaYPMmg1K0y+H4JOergcCwjEwj+IJRrpc87JGx2KQzllj 2TFC3LFqmmvanoBBMNnalytZFWK6bApN2dUQVlfDBtdkxQZ9DChScTvVAw2uHWOS8nrq MMRmezbzA6pubVuRDQbVR6U/Ts/IPSSY5q7FsnbeOYcBWCNkhuC1PUV+qV6CWOylkZ4V NjDT1Mb4Q3Mw7/3FTnT96d54/8RNHJOwX7tCAfDz6SPYpqGOmRVouoIAcwaJcI/DidMd zHAA== 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=JZEtTRGz9l8sqkUsayO2rCWyJugfqPMPVp+Qs8+o5iJSKyoGu2Qb8zN7DRDJ4eZAu7 vqDY2DYeEw+lzFQ87EA4JY2J8edjl2H8KVSgIZg40EsT6ltVRal5rZFsgfv3wlRUnEFR WOhS7TOFBuKhHXXpc6od4zxv2vZNO2dAfV3kFc0fKB+ze/Mt4gNKSO+B3LC5W+jDu46E l589wyoB9ScS5/9t9wgdGtHXkw0sT9o+BisowLti+bWWkX3NaJD6MbiiuQ/DTapjGusy wTJVCnakBlhezld+K07KuknY3Y8B6rKd4x8vPTaLc+H55UikFEsT4ERtGJUes7M5tGAO +Tyg== 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 j9-20020a056a00234900b00690fe3ec830si19253120pfj.55.2023.09.28.00.49.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 00:49:07 -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 BFE638022445; Thu, 28 Sep 2023 00:36:51 -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 S230294AbjI1Hge (ORCPT + 99 others); Thu, 28 Sep 2023 03:36:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229894AbjI1HgW (ORCPT ); Thu, 28 Sep 2023 03:36:22 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 134CA97; Thu, 28 Sep 2023 00:36:18 -0700 (PDT) Received: from kwepemm000012.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Rx4tx5qBgzNntS; Thu, 28 Sep 2023 15:32:25 +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; Thu, 28 Sep 2023 15:36:15 +0800 From: Wenchao Hao To: "James E . J . Bottomley" , "Martin K . Petersen" , CC: , , Wenchao Hao Subject: [PATCH v2 3/4] scsi: scsi_error: Fix device reset is not triggered Date: Thu, 28 Sep 2023 15:35:42 +0800 Message-ID: <20230928073543.3496394-4-haowenchao2@huawei.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20230928073543.3496394-1-haowenchao2@huawei.com> References: <20230928073543.3496394-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: dggems704-chm.china.huawei.com (10.3.19.181) 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]); Thu, 28 Sep 2023 00:36:52 -0700 (PDT) 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, -- 2.32.0