From patchwork Wed Feb 8 22:53:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 9563713 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 D3BAD60146 for ; Wed, 8 Feb 2017 22:54:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 90F762852D for ; Wed, 8 Feb 2017 22:54:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 81B6428532; Wed, 8 Feb 2017 22:54: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 5630F2852D for ; Wed, 8 Feb 2017 22:54:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751289AbdBHWyr (ORCPT ); Wed, 8 Feb 2017 17:54:47 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:57299 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751149AbdBHWyq (ORCPT ); Wed, 8 Feb 2017 17:54:46 -0500 Received: from pps.filterd (m0044010.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v18MoDok032430 for ; Wed, 8 Feb 2017 14:54:02 -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=SosEm1AKswkGVznQ2mmW5DSv22rcamO9xqHck3s0TTM=; b=bWLjNKNFCPdGn00Gzms+kwVaiCfbkAVUz5EthTAYZ5XMolcGueXYRQ2MOn4A+oZoUubU oqk/+IZzDDV+7IVGATdoVmtKjdtOF8M8/bXOjZhzC7+8ktaG9zoQH8YBe3bA0eC3QV/y 71NQo/TGGSR6P1iTRvLlonf5EX5+Km8njUs= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 28gatc8dtv-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Wed, 08 Feb 2017 14:54:02 -0800 Received: from mx-out.facebook.com (192.168.52.123) by PRN-CHUB13.TheFacebook.com (192.168.16.23) with Microsoft SMTP Server (TLS) id 14.3.294.0; Wed, 8 Feb 2017 14:54:01 -0800 Received: from facebook.com (2401:db00:11:d0be:face:0:17:0) by mx-out.facebook.com (10.212.236.89) with ESMTP id 7b6355b2ee5111e68f980002c95209d8-61f8a00 for ; Wed, 08 Feb 2017 14:54:01 -0800 Received: by devbig334.prn1.facebook.com (Postfix, from userid 4523) id 9B38742A2AFA; Wed, 8 Feb 2017 14:54:00 -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 v3] scsi/sd: release scan_mutex during sync_cache and start_stop Date: Wed, 8 Feb 2017 14:53:53 -0800 Message-ID: <20170208225353.82334-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 | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 9e0783b..14c5815 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; + int try_lock_scan_mutex; if (!sdkp) return; /* this can happen */ @@ -3311,15 +3314,26 @@ static void sd_shutdown(struct device *dev) if (pm_runtime_suspended(dev)) return; + sdev = sdkp->device; + shost = sdev->host; + try_lock_scan_mutex = mutex_trylock(&shost->scan_mutex); + if (sdkp->WCE && sdkp->media_present) { + mutex_unlock(&shost->scan_mutex); sd_printk(KERN_NOTICE, sdkp, "Synchronizing SCSI cache\n"); sd_sync_cache(sdkp); + mutex_lock(&shost->scan_mutex); } if (system_state != SYSTEM_RESTART && sdkp->device->manage_start_stop) { + mutex_unlock(&shost->scan_mutex); sd_printk(KERN_NOTICE, sdkp, "Stopping disk\n"); sd_start_stop_device(sdkp, 0); + mutex_lock(&shost->scan_mutex); } + + if (try_lock_scan_mutex) + mutex_unlock(&shost->scan_mutex); } static int sd_suspend_common(struct device *dev, bool ignore_stop_errors)