From patchwork Wed Jun 5 09:17:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenchao Hao X-Patchwork-Id: 13686448 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 32EE318FC8B; Wed, 5 Jun 2024 09:17:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717579069; cv=none; b=Wcdi2bjf8Ppi2OzbYsddV5Nl3yMB+c9xwdDtw0EV6NBxiyHX6JE65oV/UUUvUkgp5ZFg6eBZr6D24ttLdOQ7wXIPitaF+keFfzB94GSAUsNFb8w7eUEkdFKrFkZSFEX8tcnMz4bDIoHEq8ruhSukInR7Wx3v4JyQn1IF8bliWAI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717579069; c=relaxed/simple; bh=FHjszgusd45PxdBvhkAiO3DDpb6AUvLCakPupDn86fg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nTnb9VphaY9RYEt5ctRdLTLjGCUW4dFlJvb4g8zLv5VRAEx2kQ86dw+q/1Qjn/5+PFYAx21rYHuQDoG4t6JQ9ghoUSqvNepJcMdVA2YEwBTczdcW9lsh0tNZ4WdlVohz3/H5TQv46tZc5ArhXy4Vxp1M65pe+hLKhpYKwO0F5t0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VGJ71kK6; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VGJ71kK6" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1f63642ab8aso41116285ad.3; Wed, 05 Jun 2024 02:17:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717579067; x=1718183867; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/F5j1VsPlycd0S6aZpefRlptM4yjlekAf0hSgA6m9EA=; b=VGJ71kK6aDZrbtmnz76EcE+BE+Fp8DjvnyGJT98r2wccEj02jP4AtCcP6R9vbFU1F2 ugAcAxEaNAb+kvd1LJVhmj9um6IsFIF6RH1xRPCFi52ynJUlucgis/9MGbczgMyGV2/D aA3v2FyqAebXNBI8juTqGDVRA89lFJ7aFYRCIfuX+9Wb4ojGXTRfUm36HR7bxyqmFPGr 7k4xgW8zNAqFWhjUxJ20v0HDZ0C2LCPy8EPvPOS7hwGZpmij5BnKXLtgZLwB5E76edS6 UAR/pbEU5mGg6iHmAdnqix0U387EqwlP6LG1F6utXaZXRMGdW5IQq4v+/829GtygMkwX hyCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717579067; x=1718183867; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/F5j1VsPlycd0S6aZpefRlptM4yjlekAf0hSgA6m9EA=; b=djnRncAwizW/tSJBlcvSIKf35xjy8Rkegs/1F/zdmfOPQ/Nb8qW9BIPS3FJMrzyKgZ IAHvYreqWzkFyHQRsI6CMJtD4TnZ+XcZ4IuUzeJ2NxcmmOxlTRgsixIYiwRaHF+YdEVi WHIL5DDi8q6PH5czn3TchezV4hkdnHGC4K33v0UkRHN3R1tLRqWu0vGkPfTCVmtsZxJ5 f25jUwPoVLeOHaKR0vEuQT4dBlit1F8td4+KDmCYip7QFhMxifph3UUGHLfNktuepGv2 577t9BnGV3ALb+0vLLMAbHDdC11aVhr4L2fZsqTs8sn9sNDrTDMBwuP8e91DEQP827Dh rtkA== X-Forwarded-Encrypted: i=1; AJvYcCWrYUGJmI4dn8ap1dxtnPxhkwxF0v6X+Akxc49XkFjd+08V36N+95QLf3Ogz21Kfu/NZBI6mpQqcsZDI1rnYNj0/JXJVCHCfQNjanFm3l6aK/zrTVhZJPld96uI6s8okTnGLlf9baumUw== X-Gm-Message-State: AOJu0YxE0nBv0vk02071ikUYwOs9bzoHuddSl3DhTaASUTwbricxsRXX ziIbZMse1HkkX0XuXmLu7XdZC2HcRhZP7uvj03mK01AAefzLCQJ/ X-Google-Smtp-Source: AGHT+IGkGWWqtkgd9ErKwUWCKt04PhbIzbOF+JXhmpepSdkGfgMGWkZaPy+md/106vx2JrvsOMuCjg== X-Received: by 2002:a17:903:41d1:b0:1f4:7d8b:cd87 with SMTP id d9443c01a7336-1f6a5a7bb03mr24517345ad.67.1717579067378; Wed, 05 Jun 2024 02:17:47 -0700 (PDT) Received: from localhost (97.64.23.41.16clouds.com. [97.64.23.41]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f676917bb2sm55621545ad.230.2024.06.05.02.17.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 02:17:47 -0700 (PDT) From: Wenchao Hao To: "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Wenchao Hao Subject: [PATCH v5 1/3] scsi: core: Add new helper to iterate all devices of host Date: Wed, 5 Jun 2024 17:17:29 +0800 Message-Id: <20240605091731.3111195-2-haowenchao22@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20240605091731.3111195-1-haowenchao22@gmail.com> References: <20240605091731.3111195-1-haowenchao22@gmail.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 3e0c0381277a..5913de543d93 100644 --- a/drivers/scsi/scsi.c +++ b/drivers/scsi/scsi.c @@ -735,20 +735,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; @@ -761,6 +759,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); /** @@ -780,9 +794,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; @@ -792,7 +810,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 9c540f5468eb..5cb294ff0a41 100644 --- a/include/scsi/scsi_device.h +++ b/include/scsi/scsi_device.h @@ -412,7 +412,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 @@ -422,11 +423,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 Wed Jun 5 09:17:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenchao Hao X-Patchwork-Id: 13686449 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E709718FDC4; Wed, 5 Jun 2024 09:17:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717579072; cv=none; b=YDbqudRmBbqClc5MpEOuJO05Hb1KkaK0n4D5+rWIExUj3Z2bNGqpZSRev6Yu4wZqPamOXZKspeQ/9/9L5PpOp5KGjPrbObx9xwhz9/yv+P44+F/mXf+pjkpuV+XgnzHWw6zfoysdzocxyLmLrC9Dv1YYWWRYXUUp4vT3fXwzpMg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717579072; c=relaxed/simple; bh=pMxUMl191c0/PG/P+rLKeQn8EAI2483T2RHmYGHHcKg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MMNKRe5N5TUS5x87VBTd6Nemqh2uKOL9RTylmM1w3wWBq9frwMTE5M0gCfBUNaXIvVCvboWi6CaHOojyNF6FOkiqifT0PAOqgeJ/cXPqsfl9eAx3Oc6cZO0kVrmwRPPuFCBpt+USU+r/MN46oJlDLAFZ3DPMbCijDbj4gpOy29k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FnmuLER2; arc=none smtp.client-ip=209.85.215.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FnmuLER2" Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-6c5bcb8e8edso4066535a12.2; Wed, 05 Jun 2024 02:17:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717579070; x=1718183870; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aqcyHeP6+d7Q5rGdMikjLoTNpmMTGK5vgU8vu0L1700=; b=FnmuLER2DrFRbkFXGjikW4vKUASwC1mg3oqgzPWVdVbi4mAU1tdc73P/Ps+NiQFTAO 5K0K6T4i/ycJS9KsCmhLH5V4lcw4QcoZN/p5IG5Y6uF/DCITfW+r0x88zXGtbqGoI9Zg T8Rx/oDXc8TxRnxKjH/Aq6OXTwlGggAm9Jn2JhZ6vlPvMA64dkzJgdDWPsZu7pIgFGxd zo/lY7iYFFzI9pWKau+cryvz9KLRUNThlD0Ls60yfV87hgzaJVG1JrpV+ulZ8vVdGkVx QEaNOFA9JFgMuBG2o8csfWOTNJ3jKOntUjgVgfh72M2l2mX4cj32TgcXDuZGcIO8ec0f P/aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717579070; x=1718183870; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aqcyHeP6+d7Q5rGdMikjLoTNpmMTGK5vgU8vu0L1700=; b=b2u1O3tmUHibgKm3BJm0+4ATVRYYMNCLMQJK/koWi/szdDueU2ZKw2zT0AZ7RxMMNO htSd+tvx56aYGA3kTEn3Ch1M36Rot3DqeB6dSMtyCneK49kXSRycNedFf02KG/ZOp0Np slNAm6lbV0xlKvpTP+Cjy86We7kNABSu9mHkDInKKFj5ia2hBlvmqKwGYJvCTaaHmO4S W+qmUfnBIypy/9Z01K07XYg6Sw/JISkN37VpdCyxIEhWT3bGJlcXSwdFUlDsFwhatICo aciadMFF3MvLgfkT2sovKkUUUXZnzJUj7zpKpVwD+CSbqY40M0kxgb/Ozus3uSI6zDIL 0a2A== X-Forwarded-Encrypted: i=1; AJvYcCVJNHjvl7w049rlsKLwl84XXRO/n5FPvtA0IIiG9/E0nOtgPB/u6o8q5YuFdDjPbXI/+EgwRVPSBxKAXLMXOHH0EUkbu6r6JU/TqVoeQsO99Ul9PXvZ5xdlz5wxL1QSvEwSrV3z+zXw7g== X-Gm-Message-State: AOJu0YwP6XdvZ5OgU0+7YDJmaE9e3fW48lk1aRrV9ml+q8ryihddVN7B ZC8m1L6ydypks5xBiGTR1xf65V0HMMO9WY8MUr++dnXbMXHjYfbu X-Google-Smtp-Source: AGHT+IFwBnpigS8zdTpmmJXpHWyi1qsZY2sMMHV6dmnZiD38Zapxw5OiDYqkRkPD8FKDfgamoiA26w== X-Received: by 2002:a05:6a20:3d87:b0:1af:6fe9:5039 with SMTP id adf61e73a8af0-1b2b73ade2fmr2408720637.1.1717579070168; Wed, 05 Jun 2024 02:17:50 -0700 (PDT) Received: from localhost (97.64.23.41.16clouds.com. [97.64.23.41]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c2806cfa62sm964831a91.48.2024.06.05.02.17.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 02:17:49 -0700 (PDT) From: Wenchao Hao To: "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Wenchao Hao Subject: [PATCH v5 2/3] scsi: scsi_error: Fix wrong statistic when print error info Date: Wed, 5 Jun 2024 17:17:30 +0800 Message-Id: <20240605091731.3111195-3-haowenchao22@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20240605091731.3111195-1-haowenchao22@gmail.com> References: <20240605091731.3111195-1-haowenchao22@gmail.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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(). Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") 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 612489afe8d2..a61fd8af3b1f 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -409,7 +409,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 Wed Jun 5 09:17:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenchao Hao X-Patchwork-Id: 13686450 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0A01190051; Wed, 5 Jun 2024 09:17:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717579075; cv=none; b=YfdOqzD594/nVRFkHC123QvNRIH1lqTAt37z8bhkfGVgWes+gism5ZGK1kEVe1l46mvUxd7xGazo3eNhdJmBqyUKDBwSNmGLv8iYVnJYo8W+2YpdhrDXMZCudlvLIYehjhUHVGGRT2p42LjmWzrA9b1V2b6A+HTfwf5H3tu4SsI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717579075; c=relaxed/simple; bh=QU/idcVM4otdxk+iVm4L+rSCGwk9/9AmyQ9pVxLqVA0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UANh9IfGa6KYUHQGToucSY+5bjbYVxD4uvD2nHwXYeNPw3iIt9QuU+/oK8nP/mSZ+iQTJokWLxxMGgTTeP4IFc0m/2vhi74F2h9LMa6JopRiOVwevQCfvVfe0XAoGNabVm3to4c7yTZ4MD0Czwiq66hMVU5wrllPnkshvJ+yPQI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=PxFlksZA; arc=none smtp.client-ip=209.85.210.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PxFlksZA" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-70260814b2dso617886b3a.1; Wed, 05 Jun 2024 02:17:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717579073; x=1718183873; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rb8TvlwBPqPDumdC3j6Umh6H2xQnXI3Qx2U5XQXVFps=; b=PxFlksZAOAHwhmd/a9xBq/n1VJ8pJErcMpBABopOKk/iXCmPCgUYjOAjV1lFNGHRlL KUe9PoCi9WNTAhf7Gn0uhnuId3HAKSbZ4P3O4L6Jt4u2PjDr0sPvugzFgpo/Ch/dXzLg B+sx5rgebWR/djdfs3lDTswUmQqMVdtM6JUxMmba9UnFckhY7WhGTEt/IIyRh4Ku+uQn 8curO5h3gXTWq1B1y0Abz1HdMQa4OXRBkvRKEdq9pnB1AMuCKZIrOqdK2XcCvgj31Qog 6r3Q2KXKF0YBbYUsbJeaGhHwHNiiuBH+tPeiOACRWL/C4uw/IbaX7axMoNX/tNB2K3mT Teug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717579073; x=1718183873; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rb8TvlwBPqPDumdC3j6Umh6H2xQnXI3Qx2U5XQXVFps=; b=vDBgFt6e1bzv27lILafHibE5UV7jtKJDb+tqX6OVBAMfpWG6SJRMYfkQUh/3GkFVbo 92nCmUgqWYk6ocK3TprEIIAhTYk2a+ImpIcCLdzLpAJdkD1Ij9EcaGY3oN6P/3hya6Dj y+VQOQZme5IpPlwURrM/EUOnqsNLTCQrqmv2l+M0XPchYP7tUj6MAoGg2ahpu0hLfFLC B2zYVPJkhvgR/e8Sk6IbzKVaOUDTuSvycZZoxKQjkm2m0b6oi8aCg/+4/hwKByK3N/ro o6cdi5Oj0xg6jzQN22QcDW6qJIJ3rF7dk1/dK7JSeX9yF5pPlfdjTV8GauSjqplIyeMl jzaQ== X-Forwarded-Encrypted: i=1; AJvYcCWOpHR+V7s36I+Pk1PRbRm2dFbb88xpQlvBWjYt0CwzmbMRStEnwj8JMVDW30BAph2exwHvaz/DrClTAAjY0rBuPAU7XTuyqbSXC6lcKr58QCXecMNZoCq9/jc4KokgtxLPKOVIhNaomw== X-Gm-Message-State: AOJu0Yxu0+4BIzDo5LNwSKK942EAI7VNGIpLBTNne+smRmX0FQ0cBl6J jbju3jNfiq7P2qNdIwlNekTtaG5Dl8bHfGeV2XSzdG6iBe0PImcM X-Google-Smtp-Source: AGHT+IEKs17Yc7zGzcdRhEdzekurmlGaDm9rgSC3O14gNe1ncYRplcpMtwzg/MR2bP+6nRJ8W1Hqpw== X-Received: by 2002:a05:6a21:18e:b0:1b2:b183:69f6 with SMTP id adf61e73a8af0-1b2b6fd4d89mr3503703637.16.1717579073106; Wed, 05 Jun 2024 02:17:53 -0700 (PDT) Received: from localhost (97.64.23.41.16clouds.com. [97.64.23.41]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-702423da888sm8265740b3a.60.2024.06.05.02.17.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 02:17:52 -0700 (PDT) From: Wenchao Hao To: "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Wenchao Hao Subject: [PATCH v5 3/3] scsi: scsi_error: Fix device reset is not triggered Date: Wed, 5 Jun 2024 17:17:31 +0800 Message-Id: <20240605091731.3111195-4-haowenchao22@gmail.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20240605091731.3111195-1-haowenchao22@gmail.com> References: <20240605091731.3111195-1-haowenchao22@gmail.com> Precedence: bulk X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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(). Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") 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 a61fd8af3b1f..ab4a58f92838 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -1571,7 +1571,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,