From patchwork Tue Nov 7 17:38:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10047067 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DD7676032D for ; Tue, 7 Nov 2017 17:38:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C67AC288E4 for ; Tue, 7 Nov 2017 17:38:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BB1C52906C; Tue, 7 Nov 2017 17:38:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4FD1D288E4 for ; Tue, 7 Nov 2017 17:38:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751815AbdKGRiN (ORCPT ); Tue, 7 Nov 2017 12:38:13 -0500 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:60917 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751638AbdKGRiL (ORCPT ); Tue, 7 Nov 2017 12:38:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1510076291; x=1541612291; h=from:to:cc:subject:date:message-id:mime-version; bh=3EOuYFsuRG6shH4DCdt+32GodiqBtQq5tjheGmYBcgQ=; b=Anhd2GR9PsZaSa45rJS3VUnAtADeYoVfTkccUwNvIwjbL87/LRnZ1YHV iGy+f064L3heRaBlJQ0xnKRs3akm8yz3v3EgQOjaX0aRrung+rIsMKNs1 SFctR66W7IS8aSdMtQia89hAim4bCFQAm1PTVWUUerRtblAsFbW4uxTg4 Gt3kQxRmss6CiQ5kbfwitd+UzS97pfb3Qd8/1X/id+aUwSWRyZgO9C7uP bRYPmZSURnwJQI0+uWxsxbQyrc6RrJPpeRnBA3/lyaZeiVWHRdyqhoRtG MRsO22NisYKyxWv5sS1WzND0Kl8wDf4VXJF6VYKkEmZre/mqkcYuDQ9uv Q==; X-IronPort-AV: E=Sophos;i="5.43,434,1503331200"; d="scan'208";a="62118812" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 08 Nov 2017 01:38:11 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP; 07 Nov 2017 09:35:37 -0800 Received: from unknown (HELO MILHUBIP04.sdcorp.global.sandisk.com) ([10.177.9.97]) by uls-op-cesaip02.wdc.com with ESMTP; 07 Nov 2017 09:38:11 -0800 Received: from milsmgip12.sandisk.com (10.177.9.6) by MILHUBIP04.sdcorp.global.sandisk.com (10.177.9.97) with Microsoft SMTP Server id 14.3.319.2; Tue, 7 Nov 2017 09:38:10 -0800 X-AuditID: 0ab1095a-a27ff700000146e4-b5-5a01ef80dec7 Received: from thinkpad-bart.int.fusionio.com ( [10.177.9.6]) by (Symantec Messaging Gateway) with SMTP id 8F.1C.18148.08FE10A5; Tue, 7 Nov 2017 09:38:10 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" CC: , Bart Van Assche , Christoph Hellwig , Hannes Reinecke , "Johannes Thumshirn" Subject: [PATCH] sd: Fix a disk probing hang Date: Tue, 7 Nov 2017 09:38:07 -0800 Message-ID: <20171107173807.14396-1-bart.vanassche@wdc.com> X-Mailer: git-send-email 2.14.3 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprPJMWRmVeSWpSXmKPExsXCtZGTTbfpPWOUwZFr8haX/nxhtFjwZi+b xcrVR5ksVk3Ms3jcNYPVovv6DjaL5cf/MTmwezw4tJnFY/fNBjaPj09vsXis33KVxWPz6WqP z5vkPNoPdDMFsEdx2aSk5mSWpRbp2yVwZVy7/ou14KlIxbbXBQ2MSwS7GDk5JARMJF5c2cIO YgsJrGSUuNuvB2KzCehJnJq3jwnEFhHIlTj18AaQzcXBLLCLUeLbsdtsIAlhAR2J91s3gdks AqoSb/s+gg3iFbCWmLLpLCPEAnmJtW/vMU5g5FzAyLCKUSw3M6c4Nz2zwNBIrzgxLyWzOFsv OT93EyMkCKJ2MF6faH6IkYmDU6qBMUb0xv2wUKfNsy92tnlv0Nl336/78Jv4QM34ipXx3jem TfObdWZT0x+RX4bv43X5HbOLJ3PdetCzzDtULnfS+uLXu37aZnBe2H5F+oT2wRCWxxUT5xvZ iCbNYuxa82hHwUK1o7dnuF1b/MK+48sPPutmnpdTWuyirHQZw7X8t67731qoxX7rqxJLcUai oRZzUXEiAKF+TwKyAQAA MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Avoid that disk probing hangs as follows if a SCSI host is removed after disk scanning started and before it completed: Call Trace: __schedule+0x2fa/0xbb0 schedule+0x36/0x90 schedule_timeout+0x22c/0x570 io_schedule_timeout+0x1e/0x50 wait_for_completion_io_timeout+0x11f/0x180 blk_execute_rq+0x86/0xc0 scsi_execute+0xdb/0x1f0 sd_revalidate_disk+0xed/0x1c70 [sd_mod] sd_probe_async+0xc3/0x1d0 [sd_mod] async_run_entry_fn+0x38/0x160 process_one_work+0x20a/0x660 worker_thread+0x3d/0x3b0 kthread+0x13a/0x150 ret_from_fork+0x27/0x40 Signed-off-by: Bart Van Assche Cc: Christoph Hellwig Cc: Hannes Reinecke Cc: Johannes Thumshirn --- drivers/scsi/sd.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 0313486d85c8..d5e2b73c02ea 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -3225,11 +3225,13 @@ static void sd_probe_async(void *data, async_cookie_t cookie) { struct scsi_disk *sdkp = data; struct scsi_device *sdp; + struct Scsi_Host *host; struct gendisk *gd; u32 index; struct device *dev; sdp = sdkp->device; + host = sdp->host; gd = sdkp->disk; index = sdkp->index; dev = &sdp->sdev_gendev; @@ -3253,6 +3255,13 @@ static void sd_probe_async(void *data, async_cookie_t cookie) sdkp->first_scan = 1; sdkp->max_medium_access_timeouts = SD_MAX_MEDIUM_TIMEOUTS; + mutex_lock(&host->scan_mutex); + if (!scsi_host_scan_allowed(host)) { + sd_printk(KERN_NOTICE, sdkp, "%s: host being removed\n", + __func__); + goto unlock; + } + sd_revalidate_disk(gd); gd->flags = GENHD_FL_EXT_DEVT; @@ -3276,8 +3285,12 @@ static void sd_probe_async(void *data, async_cookie_t cookie) sd_printk(KERN_NOTICE, sdkp, "Attached SCSI %sdisk\n", sdp->removable ? "removable " : ""); +unlock: + mutex_unlock(&host->scan_mutex); + scsi_host_put(host); scsi_autopm_put_device(sdp); put_device(&sdkp->dev); + return; } /** @@ -3377,7 +3390,15 @@ static int sd_probe(struct device *dev) get_device(dev); dev_set_drvdata(dev, sdkp); - get_device(&sdkp->dev); /* prevent release before async_schedule */ + /* prevent release before async_schedule */ + error = -ENODEV; + if (scsi_host_get(sdp->host) == NULL) { + sd_printk(KERN_NOTICE, sdkp, "%s: host being removed\n", + __func__); + put_device(&sdkp->dev); + goto out; + } + get_device(&sdkp->dev); async_schedule_domain(sd_probe_async, sdkp, &scsi_sd_probe_domain); return 0;