scsi: use spinlock instead of mutex for RCU-protected VPD inquiry data
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
@@ -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
@@ -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
@@ -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
----- 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 dataFrom: "Ewan D. Milne" <[email protected]>
A spinlock is sufficient for this purpose, and much smaller.
Signed-off-by Ewan D. Milne <[email protected]>--- 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@@ -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@@ -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@@ -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]>
Quoted 5 lines · Ewan D. Milne
From: "Ewan D. Milne" <[email protected]>
A spinlock is sufficient for this purpose, and much smaller.
Signed-off-by Ewan D. Milne <[email protected]>
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