lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240620175703.605111-37-yury.norov@gmail.com>
Date: Thu, 20 Jun 2024 10:56:59 -0700
From: Yury Norov <yury.norov@...il.com>
To: linux-kernel@...r.kernel.org,
	"James E.J. Bottomley" <James.Bottomley@...senPartnership.com>,
	"Martin K. Petersen" <martin.petersen@...cle.com>,
	linux-scsi@...r.kernel.org
Cc: Yury Norov <yury.norov@...il.com>,
	Alexey Klimov <alexey.klimov@...aro.org>,
	Bart Van Assche <bvanassche@....org>,
	Jan Kara <jack@...e.cz>,
	Linus Torvalds <torvalds@...ux-foundation.org>,
	Matthew Wilcox <willy@...radead.org>,
	Mirsad Todorovac <mirsad.todorovac@....unizg.hr>,
	Rasmus Villemoes <linux@...musvillemoes.dk>,
	Sergey Shtylyov <s.shtylyov@....ru>
Subject: [PATCH v4 36/40] scsi: sr: drop locking around SR index bitmap

The driver accesses the sr_index_bits bitmaps to set/clear individual
bits only. Now that we have an atomic bit search helper, we can drop
the sr_index_lock that protects the sr_index_bits, and make all this
routine lockless.

While there, use DECLARE_BITMAP() to declare sr_index_bits.

Signed-off-by: Yury Norov <yury.norov@...il.com>
---
 drivers/scsi/sr.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index 7ab000942b97..3b4e04ed8b4a 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -33,6 +33,7 @@
  *	check resource allocation in sr_init and some cleanups
  */
 
+#include <linux/find_atomic.h>
 #include <linux/module.h>
 #include <linux/fs.h>
 #include <linux/kernel.h>
@@ -103,8 +104,7 @@ static struct scsi_driver sr_template = {
 	.done			= sr_done,
 };
 
-static unsigned long sr_index_bits[SR_DISKS / BITS_PER_LONG];
-static DEFINE_SPINLOCK(sr_index_lock);
+static DECLARE_BITMAP(sr_index_bits, SR_DISKS);
 
 static struct lock_class_key sr_bio_compl_lkclass;
 
@@ -566,10 +566,7 @@ static void sr_free_disk(struct gendisk *disk)
 {
 	struct scsi_cd *cd = disk->private_data;
 
-	spin_lock(&sr_index_lock);
 	clear_bit(MINOR(disk_devt(disk)), sr_index_bits);
-	spin_unlock(&sr_index_lock);
-
 	unregister_cdrom(&cd->cdi);
 	mutex_destroy(&cd->lock);
 	kfree(cd);
@@ -628,15 +625,11 @@ static int sr_probe(struct device *dev)
 		goto fail_free;
 	mutex_init(&cd->lock);
 
-	spin_lock(&sr_index_lock);
-	minor = find_first_zero_bit(sr_index_bits, SR_DISKS);
+	minor = find_and_set_bit(sr_index_bits, SR_DISKS);
 	if (minor == SR_DISKS) {
-		spin_unlock(&sr_index_lock);
 		error = -EBUSY;
 		goto fail_put;
 	}
-	__set_bit(minor, sr_index_bits);
-	spin_unlock(&sr_index_lock);
 
 	disk->major = SCSI_CDROM_MAJOR;
 	disk->first_minor = minor;
@@ -700,9 +693,7 @@ static int sr_probe(struct device *dev)
 unregister_cdrom:
 	unregister_cdrom(&cd->cdi);
 fail_minor:
-	spin_lock(&sr_index_lock);
 	clear_bit(minor, sr_index_bits);
-	spin_unlock(&sr_index_lock);
 fail_put:
 	put_disk(disk);
 	mutex_destroy(&cd->lock);
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ