From patchwork Fri Apr 21 21:13:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 9693749 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 DEC126038D for ; Fri, 21 Apr 2017 21:13:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D03DD28484 for ; Fri, 21 Apr 2017 21:13:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C463028674; Fri, 21 Apr 2017 21:13:19 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI 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 4F0EA28484 for ; Fri, 21 Apr 2017 21:13:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1042341AbdDUVNS (ORCPT ); Fri, 21 Apr 2017 17:13:18 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:48941 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1042338AbdDUVNR (ORCPT ); Fri, 21 Apr 2017 17:13:17 -0400 Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v3LLDGiu011750 for ; Fri, 21 Apr 2017 14:13:16 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=facebook; bh=UVvCWi4Y9mWivC9hN2jofDzkVrM4TNqulwAc7DkU/6k=; b=EKWcSsyzUYZze6XgufyK7BytoU4EcPSqcMH0DRdneR98jgIzspuhgdWLobYZNDheu9iD pnbSvcqfi5R172alolRqd7pWV7U9n49cF8cBb2Jiha17asJE5y4xIrkxmRMikldGNXq2 C/zfZ5NG+VvLXO/9BCypTdtrOg+P5E8Dk4w= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 29ysarr3c1-5 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Fri, 21 Apr 2017 14:13:16 -0700 Received: from mx-out.facebook.com (192.168.52.123) by PRN-CHUB02.TheFacebook.com (192.168.16.12) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 21 Apr 2017 14:13:10 -0700 Received: from facebook.com (2401:db00:2120:20f2:face:0:9:0) by mx-out.facebook.com (10.102.107.97) with ESMTP id 527a777026d711e7bc070002c99331b0-295f99a0 for ; Fri, 21 Apr 2017 14:13:10 -0700 Received: by devbig102.frc2.facebook.com (Postfix, from userid 4523) id 91E694C01A5B; Fri, 21 Apr 2017 14:13:09 -0700 (PDT) Smtp-Origin-Hostprefix: devbig From: Song Liu Smtp-Origin-Hostname: devbig102.frc2.facebook.com To: CC: , , Song Liu Smtp-Origin-Cluster: frc2c02 Subject: [RFC] scsi: reduce protection of scan_mutex in scsi_remove_device Date: Fri, 21 Apr 2017 14:13:02 -0700 Message-ID: <20170421211302.2667649-1-songliubraving@fb.com> X-Mailer: git-send-email 2.9.3 X-FB-Internal: Safe MIME-Version: 1.0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-04-21_17:, , signatures=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 When a device is deleted through sysfs handle "delete", the code locks shost->scan_mutex. If multiple devices are deleted at the same time, these deletes will be handled in series. On the other hand, some devices do long latency IO during deletion, for example, sd_shutdown() may do sync cache and/or start_stop. It is not necessary for these commands to run in series. To reduce latency of parallel "delete" requests, this patch reduces the protection of scan_mutex. The only function with Scsi_Host called in __scsi_remove_device() is the optional slave_destroy(). Therefore, the protection of scan_mutex is only necessary for this function. Signed-off-by: Song Liu --- drivers/scsi/scsi_sysfs.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index 82dfe07..e7a9e28 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -610,7 +610,7 @@ static int scsi_sdev_check_buf_bit(const char *buf) return 1; else if (buf[0] == '0') return 0; - else + else return -EINVAL; } else return -EINVAL; @@ -774,7 +774,7 @@ store_queue_type_field(struct device *dev, struct device_attribute *attr, if (!sdev->tagged_supported) return -EINVAL; - + sdev_printk(KERN_INFO, sdev, "ignoring write to deprecated queue_type attribute"); return count; @@ -1302,8 +1302,11 @@ void __scsi_remove_device(struct scsi_device *sdev) blk_cleanup_queue(sdev->request_queue); cancel_work_sync(&sdev->requeue_work); - if (sdev->host->hostt->slave_destroy) + if (sdev->host->hostt->slave_destroy) { + mutex_lock(&sdev->host->scan_mutex); sdev->host->hostt->slave_destroy(sdev); + mutex_unlock(&sdev->host->scan_mutex); + } transport_destroy_device(dev); /* @@ -1322,11 +1325,7 @@ void __scsi_remove_device(struct scsi_device *sdev) **/ void scsi_remove_device(struct scsi_device *sdev) { - struct Scsi_Host *shost = sdev->host; - - mutex_lock(&shost->scan_mutex); __scsi_remove_device(sdev); - mutex_unlock(&shost->scan_mutex); } EXPORT_SYMBOL(scsi_remove_device);