Skip to contentSkip to conversation

scsi: use spinlock instead of mutex for RCU-protected VPD inquiry data

PATCH In review Ewan D. Milne 3 participants 3 messages May 20, 2016 – May 23, 2016 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: use spinlock instead of mutex for RCU-protected VPD inquiry data

From: "Ewan D. Milne" <[email protected]>

A spinlock is sufficient for this purpose, and much smaller.

---
 drivers/scsi/scsi.c        | 8 ++++----
 drivers/scsi/scsi_scan.c   | 2 +-
 include/scsi/scsi_device.h | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)
drivers/scsi/scsi.c +4 -4
index 1deb6ad..330d807 100644
@@ -829,11 +829,11 @@ retry_pg80:
 			kfree(vpd_buf);
 			goto retry_pg80;
 		}
-		mutex_lock(&sdev->inquiry_mutex);
+		spin_lock(&sdev->inquiry_lock);
 		orig_vpd_buf = sdev->vpd_pg80;
 		sdev->vpd_pg80_len = result;
 		rcu_assign_pointer(sdev->vpd_pg80, vpd_buf);
-		mutex_unlock(&sdev->inquiry_mutex);
+		spin_unlock(&sdev->inquiry_lock);
 		synchronize_rcu();
 		if (orig_vpd_buf) {
 			kfree(orig_vpd_buf);
@@ -858,11 +858,11 @@ retry_pg83:
 			kfree(vpd_buf);
 			goto retry_pg83;
 		}
-		mutex_lock(&sdev->inquiry_mutex);
+		spin_lock(&sdev->inquiry_lock);
 		orig_vpd_buf = sdev->vpd_pg83;
 		sdev->vpd_pg83_len = result;
 		rcu_assign_pointer(sdev->vpd_pg83, vpd_buf);
-		mutex_unlock(&sdev->inquiry_mutex);
+		spin_unlock(&sdev->inquiry_lock);
 		synchronize_rcu();
 		if (orig_vpd_buf)
 			kfree(orig_vpd_buf);
drivers/scsi/scsi_scan.c +1 -1
index e0a78f5..f445615 100644
@@ -240,7 +240,7 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget,
 	INIT_LIST_HEAD(&sdev->starved_entry);
 	INIT_LIST_HEAD(&sdev->event_list);
 	spin_lock_init(&sdev->list_lock);
-	mutex_init(&sdev->inquiry_mutex);
+	spin_lock_init(&sdev->inquiry_lock);
 	INIT_WORK(&sdev->event_work, scsi_evt_thread);
 	INIT_WORK(&sdev->requeue_work, scsi_requeue_run_queue);
 
include/scsi/scsi_device.h +1 -1
index a6c346d..0410ed8 100644
@@ -115,7 +115,7 @@ struct scsi_device {
 	char type;
 	char scsi_level;
 	char inq_periph_qual;	/* PQ from INQUIRY data */	
-	struct mutex inquiry_mutex;
+	spinlock_t inquiry_lock;
 	unsigned char inquiry_len;	/* valid bytes in 'inquiry' */
 	unsigned char * inquiry;	/* INQUIRY response data */
 	const char * vendor;		/* [back_compat] point into 'inquiry' ... */
Signature · 1 line
2.1.0
#1 lore raw

----- Original Message -----

Quoted 78 lines

From: "Ewan D. Milne" <[email protected]>
To: [email protected]
Sent: Friday, May 20, 2016 8:56:14 AM
Subject: [PATCH] scsi: use spinlock instead of mutex for RCU-protected VPD inquiry data

From: "Ewan D. Milne" <[email protected]>

A spinlock is sufficient for this purpose, and much smaller.

---
 drivers/scsi/scsi.c        | 8 ++++----
 drivers/scsi/scsi_scan.c   | 2 +-
 include/scsi/scsi_device.h | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)
drivers/scsi/scsi.c +4 -4
index 1deb6ad..330d807 100644
@@ -829,11 +829,11 @@ retry_pg80:
 			kfree(vpd_buf);
 			goto retry_pg80;
 		}
-		mutex_lock(&sdev->inquiry_mutex);
+		spin_lock(&sdev->inquiry_lock);
 		orig_vpd_buf = sdev->vpd_pg80;
 		sdev->vpd_pg80_len = result;
 		rcu_assign_pointer(sdev->vpd_pg80, vpd_buf);
-		mutex_unlock(&sdev->inquiry_mutex);
+		spin_unlock(&sdev->inquiry_lock);
 		synchronize_rcu();
 		if (orig_vpd_buf) {
 			kfree(orig_vpd_buf);
@@ -858,11 +858,11 @@ retry_pg83:
 			kfree(vpd_buf);
 			goto retry_pg83;
 		}
-		mutex_lock(&sdev->inquiry_mutex);
+		spin_lock(&sdev->inquiry_lock);
 		orig_vpd_buf = sdev->vpd_pg83;
 		sdev->vpd_pg83_len = result;
 		rcu_assign_pointer(sdev->vpd_pg83, vpd_buf);
-		mutex_unlock(&sdev->inquiry_mutex);
+		spin_unlock(&sdev->inquiry_lock);
 		synchronize_rcu();
 		if (orig_vpd_buf)
 			kfree(orig_vpd_buf);
drivers/scsi/scsi_scan.c +1 -1
index e0a78f5..f445615 100644
@@ -240,7 +240,7 @@ static struct scsi_device *scsi_alloc_sdev(struct
 scsi_target *starget,
 	INIT_LIST_HEAD(&sdev->starved_entry);
 	INIT_LIST_HEAD(&sdev->event_list);
 	spin_lock_init(&sdev->list_lock);
-	mutex_init(&sdev->inquiry_mutex);
+	spin_lock_init(&sdev->inquiry_lock);
 	INIT_WORK(&sdev->event_work, scsi_evt_thread);
 	INIT_WORK(&sdev->requeue_work, scsi_requeue_run_queue);
include/scsi/scsi_device.h +1 -2
index a6c346d..0410ed8 100644
@@ -115,7 +115,7 @@ struct scsi_device {
 	char type;
 	char scsi_level;
 	char inq_periph_qual;	/* PQ from INQUIRY data */
-	struct mutex inquiry_mutex;
+	spinlock_t inquiry_lock;
 	unsigned char inquiry_len;	/* valid bytes in 'inquiry' */
 	unsigned char * inquiry;	/* INQUIRY response data */
 	const char * vendor;		/* [back_compat] point into 'inquiry' ... */
--

2.1.0

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Look fine to me:
Reviewed by: Laurence Oberman <[email protected]>

Reviewed-by on v1 1/1
#2 lore raw
In reply to Ewan D. Milne
Quoted 5 lines · Ewan D. Milne

From: "Ewan D. Milne" <[email protected]>

A spinlock is sufficient for this purpose, and much smaller.

Signature · 10 lines
Johannes Thumshirn                                          Storage
[email protected]                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html