From patchwork Tue Oct 27 20:14:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 7501711 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 080EEBEEA4 for ; Tue, 27 Oct 2015 20:14:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E5BF820997 for ; Tue, 27 Oct 2015 20:14:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BB3CE20993 for ; Tue, 27 Oct 2015 20:14:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965243AbbJ0UOr (ORCPT ); Tue, 27 Oct 2015 16:14:47 -0400 Received: from mail-by2on0077.outbound.protection.outlook.com ([207.46.100.77]:31621 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S965031AbbJ0UOp (ORCPT ); Tue, 27 Oct 2015 16:14:45 -0400 Received: from BLUPR0201CA0033.namprd02.prod.outlook.com (10.163.116.43) by CY1PR02MB1262.namprd02.prod.outlook.com (10.163.16.155) with Microsoft SMTP Server (TLS) id 15.1.306.13; Tue, 27 Oct 2015 20:14:41 +0000 Received: from BY2FFO11OLC010.protection.gbl (2a01:111:f400:7c0c::185) by BLUPR0201CA0033.outlook.office365.com (2a01:111:e400:52e7::43) with Microsoft SMTP Server (TLS) id 15.1.306.13 via Frontend Transport; Tue, 27 Oct 2015 20:14:41 +0000 Authentication-Results: spf=pass (sender IP is 63.163.107.173) smtp.mailfrom=sandisk.com; HansenPartnership.com; dkim=none (message not signed) header.d=none; HansenPartnership.com; dmarc=bestguesspass action=none header.from=sandisk.com; Received-SPF: Pass (protection.outlook.com: domain of sandisk.com designates 63.163.107.173 as permitted sender) receiver=protection.outlook.com; client-ip=63.163.107.173; helo=milsmgep12.sandisk.com; Received: from milsmgep12.sandisk.com (63.163.107.173) by BY2FFO11OLC010.mail.protection.outlook.com (10.1.15.21) with Microsoft SMTP Server id 15.1.306.13 via Frontend Transport; Tue, 27 Oct 2015 20:14:40 +0000 Received: from MILHUBIP04.sdcorp.global.sandisk.com ( [172.22.12.162]) by milsmgep12.sandisk.com (Symantec Messaging Gateway) with SMTP id EA.C4.32178.03BDF265; Tue, 27 Oct 2015 13:14:40 -0700 (PDT) Received: from milsmgip11.sandisk.com (10.177.8.100) by MILHUBIP04.sdcorp.global.sandisk.com (10.177.9.97) with Microsoft SMTP Server id 14.3.248.2; Tue, 27 Oct 2015 13:14:40 -0700 X-AuditID: ac160a69-f79f76d000007db2-a2-562fdb3081ba Received: from [10.60.52.33] ( [10.177.8.100]) by milsmgip11.sandisk.com (Symantec Messaging Gateway) with SMTP id 3C.76.03643.03BDF265; Tue, 27 Oct 2015 13:14:40 -0700 (PDT) Subject: Re: [PATCH] scsi: restart list search after unlock in scsi_remove_target To: Johannes Thumshirn , Christoph Hellwig , , References: <20151019143546.GA7486@lst.de> <1445848537.16404.26.camel@suse.de> From: Bart Van Assche Message-ID: <562FDB30.1060304@sandisk.com> Date: Tue, 27 Oct 2015 13:14:40 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <1445848537.16404.26.camel@suse.de> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrBLMWRmVeSWpSXmKPExsWyRoxnka7Bbf0wgw13FS1Wrj7KZLGxn8Pi cdcMVovu6zvYHFg8pk06xeax+2YDm8fm09UenzfJBbBEcdmkpOZklqUW6dslcGX8OT+BuWCz asXTxZ1MDYzH5boYOTgkBEwkvkw272LkBDLFJC7cW8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UwdVgRmvlrEpfvj78WzLl6opFW5ybFX3rNzPrfG+v4Hv8pWgoFnH dXfFyZ5W+NrbqpDnO3OxIc/er5JbWPbb2h971L732iun72Xx0p3fsq9teuHacybo3Oz+A8kP tnv6OzivmrVxvqxgmWPktAlCs6/vsKxWYinOSDTUYi4qTgQApQO93fMBAAA= X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11OLC010; 1:SQdYCBLvWAQvMCG3GtuO+toqP6oSjJ1NgLAPe7w4e4xBa8iM6cQ0IkFbIJv1OKtrUdKkCADhQQp9D5g/NeB1M1M7VTXYXTOHqJNzz+2k6sbmrg3WfDs328W3XMe7l4sf8wWtcQp9zoYFt2rXuOaDDbPam/47iNLV1+kVRdJWFR0DT8gK7vilNrJyS1O6S0psIth7v6tAaGS+zU5Ane5YDshxGRcEsuYki0DlWX+aimUaicKUfX/eKM6PndKyVjggX5UPlD/AvtI8ov/3nqN3Hah3FP+L+noCH5Ofgebx0oObbcd/BrvV7UOjGsvZica2Kq2yCXkgqc5xoC85wcy2fi0KKi48P4UCUAS9Eda1qz/g+BeWcJQioMeiS72AzAic X-Forefront-Antispam-Report: CIP:63.163.107.173; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(438002)(377454003)(199003)(24454002)(164054003)(479174004)(189002)(106466001)(69596002)(83506001)(4001350100001)(97736004)(19580395003)(64126003)(92566002)(189998001)(2950100001)(2201001)(5001960100002)(86362001)(5001770100001)(81156007)(19580405001)(107886002)(77096005)(5008740100001)(65806001)(47776003)(5007970100001)(36756003)(65816999)(33656002)(23676002)(11100500001)(87266999)(54356999)(87936001)(80316001)(50986999)(59896002)(50466002)(76176999)(65956001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR02MB1262; H:milsmgep12.sandisk.com; FPR:; SPF:Pass; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; CY1PR02MB1262; 2:JGqX88pBsNIw1lq272E150km4aITptH0R92Spr2Zu8jpbEHR6L20oHAgVCk+yw4xrpaEHGEVm40Kw4i1J7OMlk69Jv3mDwQ0QRwVv7BgNdqJze4VgYtsbVqH5tUWKW523k/OjerATjpu+SwnGF/ZLTmgJIkRZgrrkBQItVKMAr0=; 3:FmcseIWVbCWuJ3c4VUICt8CdRyJolyhG+E5c9A+WOqY69nxZCwuTPgkRLOsv9P8qnSMFx8aM7TvTTm1Ugg2ll2NdMYmIFjmx28lUK+J1gMbMAAvPOapQMQt/mwGK4lJOxPJKwhpR236w+1dmqKKdSMqDleTPAH7liRmjN6UMVPdGBftNt9nQb2Fq7C+JuukinqL/F4u0Cec6z8zDFK9c0e7SM21tKi+LWGypemJMk1F8HNAwi+88QAIF1BoP2JIEuCS2gNzqIjt8Su2g0sw+0Q==; 25:95IwpjMs0UStWvUwC/KL5FGB9tFU063HgZHio51tstOzWWvybEnB6oVv9IYyKyEL9UhYRPKuRj9RgXEi4zA5LmxrZy5570MLg/47OQHJ5NDXrN8R5yrDT3roRH+RKhcyqJ/iM3xfl3PQOoGuERHJcedAZtvjOMjHaW2JDqoNPKY4bGJELohrdjoBjTBEcL2wwtsm3fEGshnKv7JXX3v8wXecsBpV6ZkXjaFJnmpDWyYIXyvTen9bks5sMeZ/wF9Jj9xFcQdrhsyn9KWzKWfWww== X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(8251501001); SRVR:CY1PR02MB1262; X-Microsoft-Exchange-Diagnostics: 1; CY1PR02MB1262; 20:nULwbx3KG8LRrUsb4h3Uid2kH/TfC2hqrT7Dgvh3L3ALQVSbw+vg8kj8D6MMilKAxwZs1jxVPffoyxLCh3bgjFCdI4XZz9NS3+uA/miZEVfcZXYomqcJxZ1VqNOWLqaNQOE2qGiin0PiM7kBCUSl/vdVjVCmSOjmshdvqWXoVnSHGU6PYWAA42igczaTx/uZ0/YHcSdovU9T/cCwOPTYGOt/3/MITsymbz2pZypnkpqBt39G/R18IICBn0fJJG7YIYFLKbxTemipuC0Ny/oJ+p4GxxlA7BjV2n1/c5ozCL3WOOXu4+7HXxbviSDN+U+AHTa302R3qth8wjFzBp2nbDvPUyog/gyQCQRutHoKXCqGvaI+r9GGvFnTuYCZ0chwJAeMzvhfsAB+A968vCSktWBLWspK+dj5XCn07dk0X3+8O+j3FoI4DS1iKL+6xbUysrp4QtXKEFbZhhOTmyTDAy+NQOwcgGaEmSwHxTnwX/pw3T5EiTkzK6E8SnkLSDj0; 4:l5+Qdh66Op5thM/hjifIOGeFu0MW22EiQ4QnWkHrmivRiForCifpIPNwO3FVlqns16ti/7S3ynZxjZw22SM7wdKCfx8In3SAr6ol7JfvT69qvUZ38N6bfxJhYyDWj9rT07c35k4/2a0eUO1uOvvK3BARmHYR5IFHLSnrMMVjQKE7HoFneJ7XBnf6RW34aKucmi58I15suvNS8REdxwa5Z1twKlslC7YXQ2uciDAW5bG5SUZVEswL8zDthORuRpjT9NRE/el29PttfPQ/ma0+LUFOjA5Ehg9x/BHh4wRBkgEjYgHLqEdc/Ib0yyhLo+M7kosZaRldx5hxUd9xg20OyBuKyAOvT7GYHjFCFttIUIpCT5SPnZlDPBZqRhvp3UFz X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(5005006)(520078)(3002001)(102215026); SRVR:CY1PR02MB1262; BCL:0; PCL:0; RULEID:; SRVR:CY1PR02MB1262; X-Forefront-PRVS: 0742443479 X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtDWTFQUjAyTUIxMjYyOzIzOi81b0t4UFcxbVJNRDNtSVJnYkVEckxXeWIw?= =?utf-8?B?b3pCVzNGZERVYXY4cFgwM2kxSUlxOUUraUJHdThySjdkYm9nYUM5UTRBaVhh?= =?utf-8?B?VjVES2J5eFlrSjNPcnQwcWplM2tPT1B3cGpWQndGWGNPRzVVbURxbU1VU2lY?= =?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hrPWfcczHoPWWT2oScdkZ8KkeQRw3QBL+97guuDE8AsPthDqBvq5xuaaizYYNZfdCfbuj/QJAmbQ6U9XsFHDQGSW1XL52adpFcpOV3yiyHdqhU11+fGFXQvYI0JWEvSUfyRZiWMAZIhiVaYYQyU5QtLN9lM3LYltqnLngPD3ol+97Ba7B439swFNvYJP/f0UQ7 SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: sandisk.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Oct 2015 20:14:40.8632 (UTC) X-MS-Exchange-CrossTenant-Id: fcd9ea9c-ae8c-460c-ab3c-3db42d7ac64d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=fcd9ea9c-ae8c-460c-ab3c-3db42d7ac64d; Ip=[63.163.107.173]; Helo=[milsmgep12.sandisk.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR02MB1262 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On 10/26/2015 01:35 AM, Johannes Thumshirn wrote: > I haven't heard anything from the original reporter of the lockup but > my test's went all O.K., so > > Tested-by: Johannes Thumshirn > Reviewed-by: Johannes Thumshirn Hello Christoph and Johannes, How about the patch below, which is a variant of Christoph's patch ? Thanks, Bart. [PATCH] scsi: Restart list search after unlock in scsi_remove_target When dropping a lock while iterating a list we must restart the search as other threads could have manipulated the list under us. Without this we can get stuck in an endless loop. Introduce a new member variable "visible" in struct scsi_target to track presence in sysfs. Reported-by: Johannes Thumshirn Tested-by: Johannes Thumshirn Reviewed-by: Johannes Thumshirn --- drivers/scsi/scsi_scan.c | 16 +++------------- drivers/scsi/scsi_sysfs.c | 19 ++++++------------- include/scsi/scsi_device.h | 1 + 3 files changed, 10 insertions(+), 26 deletions(-) diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c index f9f3f82..7b74470 100644 --- a/drivers/scsi/scsi_scan.c +++ b/drivers/scsi/scsi_scan.c @@ -314,7 +314,6 @@ static void scsi_target_destroy(struct scsi_target *starget) struct Scsi_Host *shost = dev_to_shost(dev->parent); unsigned long flags; - starget->state = STARGET_DEL; transport_destroy_device(dev); spin_lock_irqsave(shost->host_lock, flags); if (shost->hostt->target_destroy) @@ -379,12 +378,8 @@ static void scsi_target_reap_ref_release(struct kref *kref) struct scsi_target *starget = container_of(kref, struct scsi_target, reap_ref); - /* - * if we get here and the target is still in the CREATED state that - * means it was allocated but never made visible (because a scan - * turned up no LUNs), so don't call device_del() on it. - */ - if (starget->state != STARGET_CREATED) { + if (starget->visible) { + starget->visible = false; transport_remove_device(&starget->dev); device_del(&starget->dev); } @@ -507,12 +502,7 @@ static struct scsi_target *scsi_alloc_target(struct device *parent, */ void scsi_target_reap(struct scsi_target *starget) { - /* - * serious problem if this triggers: STARGET_DEL is only set in the if - * the reap_ref drops to zero, so we're trying to do another final put - * on an already released kref - */ - BUG_ON(starget->state == STARGET_DEL); + starget->state = STARGET_DEL; scsi_target_reap_ref_put(starget); } diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index 5e085d4..de8e202 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -974,7 +974,7 @@ static int scsi_target_add(struct scsi_target *starget) { int error; - if (starget->state != STARGET_CREATED) + if (starget->visible) return 0; error = device_add(&starget->dev); @@ -983,6 +983,7 @@ static int scsi_target_add(struct scsi_target *starget) return error; } transport_add_device(&starget->dev); + starget->visible = true; starget->state = STARGET_RUNNING; pm_runtime_set_active(&starget->dev); @@ -1166,31 +1167,23 @@ static void __scsi_remove_target(struct scsi_target *starget) void scsi_remove_target(struct device *dev) { struct Scsi_Host *shost = dev_to_shost(dev->parent); - struct scsi_target *starget, *last = NULL; + struct scsi_target *starget; unsigned long flags; - /* remove targets being careful to lookup next entry before - * deleting the last - */ +restart: spin_lock_irqsave(shost->host_lock, flags); list_for_each_entry(starget, &shost->__targets, siblings) { if (starget->state == STARGET_DEL) continue; if (starget->dev.parent == dev || &starget->dev == dev) { - /* assuming new targets arrive at the end */ kref_get(&starget->reap_ref); spin_unlock_irqrestore(shost->host_lock, flags); - if (last) - scsi_target_reap(last); - last = starget; __scsi_remove_target(starget); - spin_lock_irqsave(shost->host_lock, flags); + scsi_target_reap(starget); + goto restart; } } spin_unlock_irqrestore(shost->host_lock, flags); - - if (last) - scsi_target_reap(last); } EXPORT_SYMBOL(scsi_remove_target); diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h index fe89d7c..d5a5f21 100644 --- a/include/scsi/scsi_device.h +++ b/include/scsi/scsi_device.h @@ -267,6 +267,7 @@ struct scsi_target { unsigned int expecting_lun_change:1; /* A device has reported * a 3F/0E UA, other devices on * the same target will also. */ + unsigned int visible:1; /* visible in sysfs */ /* commands actually active on LLD. */ atomic_t target_busy; atomic_t target_blocked;