From patchwork Wed Feb 8 20:42:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 9563355 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 00E71601E5 for ; Wed, 8 Feb 2017 20:42:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E54202845D for ; Wed, 8 Feb 2017 20:42:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D7A9E2845B; Wed, 8 Feb 2017 20:42:49 +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 5E67F2845B for ; Wed, 8 Feb 2017 20:42:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751355AbdBHUmo (ORCPT ); Wed, 8 Feb 2017 15:42:44 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:55331 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751143AbdBHUmn (ORCPT ); Wed, 8 Feb 2017 15:42:43 -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 v18KYZxV028052 for ; Wed, 8 Feb 2017 12:42:42 -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=Glhq7kMn8/ydbTgK7RXhmQOfU+9zZi+G1Sr3nRhS8CI=; b=mZJfOQbkA6pF4mKLe1ywcZnMgNTT+Vg22jmLHZvAS2NfQDEqaC1tf9/rENHcWgXr3oVr irCqSCw5o7TpgiuH3qBUDRn2s4pKWDwF36vEy9tniK8BzKBA3AnXST58qtOFSmSdWwQt 1u0MP1gsrhXwifJVkv1lNvWAUEfmWNdxryY= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 28g8avgk46-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Wed, 08 Feb 2017 12:42:42 -0800 Received: from mx-out.facebook.com (192.168.52.123) by PRN-CHUB09.TheFacebook.com (192.168.16.19) with Microsoft SMTP Server (TLS) id 14.3.294.0; Wed, 8 Feb 2017 12:42:41 -0800 Received: from facebook.com (2401:db00:11:d0be:face:0:17:0) by mx-out.facebook.com (10.102.107.97) with ESMTP id 22e9e6d8ee3f11e6b7030002c99331b0-291f5a50 for ; Wed, 08 Feb 2017 12:42:41 -0800 Received: by devbig334.prn1.facebook.com (Postfix, from userid 4523) id A41DE42A0905; Wed, 8 Feb 2017 12:42:41 -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 v2] scsi/sd: release scan_mutex during sync_cache and start_stop Date: Wed, 8 Feb 2017 12:42:40 -0800 Message-ID: <20170208204240.4002411-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_12:, , 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 long latency commands and relock the mutex after the command. Fixed bug from previous version. Reported-by: kernel test robot Signed-off-by: Song Liu --- drivers/scsi/sd.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 9e0783b..22add77 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -3304,6 +3304,9 @@ static int sd_start_stop_device(struct scsi_disk *sdkp, int start) static void sd_shutdown(struct device *dev) { struct scsi_disk *sdkp = dev_get_drvdata(dev); + struct scsi_device *sdev; + struct Scsi_Host *shost; + bool scan_mutex_locked; if (!sdkp) return; /* this can happen */ @@ -3311,14 +3314,26 @@ static void sd_shutdown(struct device *dev) if (pm_runtime_suspended(dev)) return; + sdev = sdkp->device; + shost = sdev->host; + scan_mutex_locked = mutex_is_locked(&shost->scan_mutex); + if (sdkp->WCE && sdkp->media_present) { + if (scan_mutex_locked) + mutex_unlock(&shost->scan_mutex); sd_printk(KERN_NOTICE, sdkp, "Synchronizing SCSI cache\n"); sd_sync_cache(sdkp); + if (scan_mutex_locked) + mutex_lock(&shost->scan_mutex); } if (system_state != SYSTEM_RESTART && sdkp->device->manage_start_stop) { + if (scan_mutex_locked) + mutex_unlock(&shost->scan_mutex); sd_printk(KERN_NOTICE, sdkp, "Stopping disk\n"); sd_start_stop_device(sdkp, 0); + if (scan_mutex_locked) + mutex_lock(&shost->scan_mutex); } }