From patchwork Thu Feb 9 01:01:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 9563853 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 22A5C60216 for ; Thu, 9 Feb 2017 01:01:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 955A0284C9 for ; Thu, 9 Feb 2017 01:01:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 89A8E284D0; Thu, 9 Feb 2017 01:01:23 +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 E496D284D8 for ; Thu, 9 Feb 2017 01:01:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751639AbdBIBBW (ORCPT ); Wed, 8 Feb 2017 20:01:22 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:60066 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751317AbdBIBBV (ORCPT ); Wed, 8 Feb 2017 20:01:21 -0500 Received: from pps.filterd (m0109333.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v190xljp009657 for ; Wed, 8 Feb 2017 17:01:20 -0800 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=kj2hDWPedpDwMn0z0erezMeOadulTUQOX1FvPatsqME=; b=d7wbCi1eRfRENVNv6HppQurnLLszVloTdDl6EwQb6RUyc4aiOBdQd8q91xw5V1pkttlJ SJK3lu8JDWQxteKGkNZS8UtzUm57oUNVASXf9fhAKOqw6xmFxgzuFzcO8KYv1s/KJvty F1+PED2zI+1PY911E3joEcnd67323MthRj8= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 28g8avhdrj-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Wed, 08 Feb 2017 17:01:20 -0800 Received: from mx-out.facebook.com (192.168.52.123) by PRN-CHUB11.TheFacebook.com (192.168.16.21) with Microsoft SMTP Server (TLS) id 14.3.294.0; Wed, 8 Feb 2017 17:01:19 -0800 Received: from facebook.com (2401:db00:11:d0be:face:0:17:0) by mx-out.facebook.com (10.212.232.63) with ESMTP id 43f026f2ee6311e6adea0002c992ebde-295eaa00 for ; Wed, 08 Feb 2017 17:01:19 -0800 Received: by devbig334.prn1.facebook.com (Postfix, from userid 4523) id 67E1D42A09CE; Wed, 8 Feb 2017 17:01:18 -0800 (PST) Smtp-Origin-Hostprefix: devbig From: Song Liu Smtp-Origin-Hostname: devbig334.prn1.facebook.com To: CC: , , , Song Liu Smtp-Origin-Cluster: prn1c29 Subject: [PATCH v4] scsi/sd: release scan_mutex during sync_cache and start_stop Date: Wed, 8 Feb 2017 17:01:16 -0800 Message-ID: <20170209010116.362206-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-02-08_14:, , 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, sd_shutdown() sometimes issues long latency commands: sync cache and start_stop. It is not necessary for these commands to run in series. To reduce latency of parallel "delete" requests, this patch unlock shost->scan_mutex before calling sd_shutdown(), relock the mutex afterwards. Fixed bug from previous version. Reported-by: kernel test robot Signed-off-by: Song Liu Cc: Christoph Hellwig Cc: Bart Van Assche --- drivers/scsi/sd.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 9e0783b..61ea308 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -3211,9 +3211,13 @@ static int sd_probe(struct device *dev) static int sd_remove(struct device *dev) { struct scsi_disk *sdkp; + struct scsi_device *sdev; + struct Scsi_Host *shost; dev_t devt; sdkp = dev_get_drvdata(dev); + sdev = sdkp->device; + shost = sdev->host; devt = disk_devt(sdkp->disk); scsi_autopm_get_device(sdkp->device); @@ -3221,7 +3225,9 @@ static int sd_remove(struct device *dev) async_synchronize_full_domain(&scsi_sd_probe_domain); device_del(&sdkp->dev); del_gendisk(sdkp->disk); + mutex_unlock(&shost->scan_mutex); sd_shutdown(dev); + mutex_lock(&shost->scan_mutex); sd_zbc_remove(sdkp);