Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5932807ybv; Tue, 18 Feb 2020 06:43:54 -0800 (PST) X-Google-Smtp-Source: APXvYqy7ibKnEdtIQN64+YBB2hhWm0MGUi4us/ny2r6SiR7zJy/YtJcwX1y09O/z3L8KkH8Kzb1F X-Received: by 2002:a9d:7c99:: with SMTP id q25mr16335708otn.105.1582037034382; Tue, 18 Feb 2020 06:43:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582037034; cv=none; d=google.com; s=arc-20160816; b=xzjuZF0dkl6YcmOQ18F+Fj85bjYmIcfADm87tIBHaHbFxXu6LKLNK2pPNCyrub03J7 NGxqKEii5dW65e8rn5gXV+6+7Ui+xqCGA4J+d288QskSTX4ArBJf2F8p+NhoDAEmBjNz qlGqnKRHtukmLmE5c9PfSCop1DMhqX39UvXJzmEhZR6ao/mDLA8ZYNtNEJ8nrGxweoIF 8+xAK6w0gSCBQzkZoX2QZtofWN28Psl8SlDmcEAXIlQqB//84LAlgsXnhYRhp9YH5PSL CKUtKv6cs7o3Ow6LOMPXDf17D5eU3VCn/EEpzxSJ9eeVGLRSyVbuB5PNb7BZ4dMECI/Y VXgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=/5sIm0AXNYalpIKEnWd7zt8+P/1gDilkDC7cchW/41E=; b=yPmOENmcCmBTEt9dOtzQQRNgtzqZSn4l0KeuRaWtbTvVYpBVOlhx/q3Tc5LjBhW/bh bOFV6l8jIU/PuOiTcN57Ix362O+WcaJgDwXTKSveENJ2tKIn3g5lvBgVg1W1z+X0j1yq IbyPiFHaWhv8q+KlQRh9cZOgxraAlBxtNf2ZtXEHcAkJYYo5LUGsRVYBxOxyzt/bLRFx Enk4/HLWb8bqMkKAzyMD4vzX11wjdVrxdfVQpih3+t6Dw5Tj3M3B8XbWLHBuA9GYe03h rS095Mwc6p9vKKQgR10wqEjcrt3pvmglq0SjbCxnkm35+CX1fyfxYVQdV+uM4dMuRZg/ /68w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y19si1740242oto.102.2020.02.18.06.43.42; Tue, 18 Feb 2020 06:43:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726762AbgBROnX (ORCPT + 99 others); Tue, 18 Feb 2020 09:43:23 -0500 Received: from mail.archive.org ([207.241.224.6]:60886 "EHLO mail.archive.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726116AbgBROnW (ORCPT ); Tue, 18 Feb 2020 09:43:22 -0500 X-Greylist: delayed 372 seconds by postgrey-1.27 at vger.kernel.org; Tue, 18 Feb 2020 09:43:22 EST Received: from mail.archive.org (localhost [127.0.0.1]) by mail.archive.org (Postfix) with ESMTP id 64DB71FAF0; Tue, 18 Feb 2020 14:37:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mail.archive.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT autolearn=disabled version=3.4.2 Received: from kgpe-d16.fritz.box (a82-161-36-93.adsl.xs4all.nl [82.161.36.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: merlijn@archive.org) by mail.archive.org (Postfix) with ESMTPSA id DD9731FAEF; Tue, 18 Feb 2020 14:37:06 +0000 (UTC) From: Merlijn Wajer To: merlijn@wizzup.org, linux-scsi@vger.kernel.org Cc: Merlijn Wajer , Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" , Arnd Bergmann , linux-kernel@vger.kernel.org Subject: [PATCH v2] scsi: sr: get rid of sr global mutex Date: Tue, 18 Feb 2020 15:39:17 +0100 Message-Id: <20200218143918.30267-1-merlijn@archive.org> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Envelope-From: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When replacing the Big Kernel Lock in commit 2a48fc0ab24241755dc93bfd4f01d68efab47f5a ("block: autoconvert trivial BKL users to private mutex"), the lock was replaced with a sr-wide lock. This causes very poor performance when using multiple sr devices, as the sr driver was not able to execute more than one command to one drive at any given time, even when there were many CD drives available. Replace the global mutex with per-sr-device mutex. Someone tried this patch at the time, but it never made it upstream, due to possible concerns with race conditions, but it's not clear the patch actually caused those: https://www.spinics.net/lists/linux-scsi/msg63706.html https://www.spinics.net/lists/linux-scsi/msg63750.html Also see http://lists.xiph.org/pipermail/paranoia/2019-December/001647.html Signed-off-by: Merlijn Wajer Acked-by: Arnd Bergmann --- drivers/scsi/sr.c | 20 +++++++++++--------- drivers/scsi/sr.h | 2 ++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index 0fbb8fe6e521..fe0e1c721a99 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -79,7 +79,6 @@ MODULE_ALIAS_SCSI_DEVICE(TYPE_WORM); CDC_CD_R|CDC_CD_RW|CDC_DVD|CDC_DVD_R|CDC_DVD_RAM|CDC_GENERIC_PACKET| \ CDC_MRW|CDC_MRW_W|CDC_RAM) -static DEFINE_MUTEX(sr_mutex); static int sr_probe(struct device *); static int sr_remove(struct device *); static blk_status_t sr_init_command(struct scsi_cmnd *SCpnt); @@ -536,9 +535,9 @@ static int sr_block_open(struct block_device *bdev, fmode_t mode) scsi_autopm_get_device(sdev); check_disk_change(bdev); - mutex_lock(&sr_mutex); + mutex_lock(&cd->lock); ret = cdrom_open(&cd->cdi, bdev, mode); - mutex_unlock(&sr_mutex); + mutex_unlock(&cd->lock); scsi_autopm_put_device(sdev); if (ret) @@ -551,10 +550,10 @@ static int sr_block_open(struct block_device *bdev, fmode_t mode) static void sr_block_release(struct gendisk *disk, fmode_t mode) { struct scsi_cd *cd = scsi_cd(disk); - mutex_lock(&sr_mutex); + mutex_lock(&cd->lock); cdrom_release(&cd->cdi, mode); scsi_cd_put(cd); - mutex_unlock(&sr_mutex); + mutex_unlock(&cd->lock); } static int sr_block_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, @@ -565,7 +564,7 @@ static int sr_block_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, void __user *argp = (void __user *)arg; int ret; - mutex_lock(&sr_mutex); + mutex_lock(&cd->lock); ret = scsi_ioctl_block_when_processing_errors(sdev, cmd, (mode & FMODE_NDELAY) != 0); @@ -595,7 +594,7 @@ static int sr_block_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, scsi_autopm_put_device(sdev); out: - mutex_unlock(&sr_mutex); + mutex_unlock(&cd->lock); return ret; } @@ -608,7 +607,7 @@ static int sr_block_compat_ioctl(struct block_device *bdev, fmode_t mode, unsign void __user *argp = compat_ptr(arg); int ret; - mutex_lock(&sr_mutex); + mutex_lock(&cd->lock); ret = scsi_ioctl_block_when_processing_errors(sdev, cmd, (mode & FMODE_NDELAY) != 0); @@ -638,7 +637,7 @@ static int sr_block_compat_ioctl(struct block_device *bdev, fmode_t mode, unsign scsi_autopm_put_device(sdev); out: - mutex_unlock(&sr_mutex); + mutex_unlock(&cd->lock); return ret; } @@ -745,6 +744,7 @@ static int sr_probe(struct device *dev) disk = alloc_disk(1); if (!disk) goto fail_free; + mutex_init(&cd->lock); spin_lock(&sr_index_lock); minor = find_first_zero_bit(sr_index_bits, SR_DISKS); @@ -1055,6 +1055,8 @@ static void sr_kref_release(struct kref *kref) put_disk(disk); + mutex_destroy(&cd->lock); + kfree(cd); } diff --git a/drivers/scsi/sr.h b/drivers/scsi/sr.h index a2bb7b8bace5..339c624e04d8 100644 --- a/drivers/scsi/sr.h +++ b/drivers/scsi/sr.h @@ -20,6 +20,7 @@ #include #include +#include #define MAX_RETRIES 3 #define SR_TIMEOUT (30 * HZ) @@ -51,6 +52,7 @@ typedef struct scsi_cd { bool ignore_get_event:1; /* GET_EVENT is unreliable, use TUR */ struct cdrom_device_info cdi; + struct mutex lock; /* We hold gendisk and scsi_device references on probe and use * the refs on this kref to decide when to release them */ struct kref kref; -- 2.23.0