public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Bart Van Assche <bart.vanassche@wdc.com>
To: "Martin K . Petersen" <martin.petersen@oracle.com>,
	"James E . J . Bottomley" <jejb@linux.vnet.ibm.com>
Cc: linux-scsi@vger.kernel.org,
	Bart Van Assche <bart.vanassche@wdc.com>,
	Christoph Hellwig <hch@lst.de>, Hannes Reinecke <hare@suse.de>,
	Johannes Thumshirn <jthumshirn@suse.de>,
	Shane Seymour <shane.seymour@hpe.com>
Subject: [PATCH 07/19] Fix RCU handling of scsi_device.vpd_pg8[03]
Date: Wed, 23 Aug 2017 14:39:57 -0700	[thread overview]
Message-ID: <20170823214009.15015-8-bart.vanassche@wdc.com> (raw)
In-Reply-To: <20170823214009.15015-1-bart.vanassche@wdc.com>

Only annotate pointers that are shared across threads with __rcu.
Use rcu_dereference() when dereferencing an RCU pointer. Protect
also the RCU pointer dereferences when freeing RCU pointers. This
patch suppresses about twenty sparse complaints about the vpd_pg8[03]
pointers.

Fixes: commit 09e2b0b14690 ("scsi: rescan VPD attributes")
Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Johannes Thumshirn <jthumshirn@suse.de>
Cc: Shane Seymour <shane.seymour@hpe.com>
---
 drivers/scsi/scsi.c       | 6 +++---
 drivers/scsi/scsi_lib.c   | 8 ++++----
 drivers/scsi/scsi_sysfs.c | 7 +++++--
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 3d38c6d463b8..5bb15e698969 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -426,7 +426,7 @@ void scsi_attach_vpd(struct scsi_device *sdev)
 	int vpd_len = SCSI_VPD_PG_LEN;
 	int pg80_supported = 0;
 	int pg83_supported = 0;
-	unsigned char __rcu *vpd_buf, *orig_vpd_buf = NULL;
+	unsigned char *vpd_buf, *orig_vpd_buf = NULL;
 
 	if (!scsi_device_supports_vpd(sdev))
 		return;
@@ -474,7 +474,7 @@ void scsi_attach_vpd(struct scsi_device *sdev)
 			goto retry_pg80;
 		}
 		mutex_lock(&sdev->inquiry_mutex);
-		orig_vpd_buf = sdev->vpd_pg80;
+		orig_vpd_buf = rcu_dereference(sdev->vpd_pg80);
 		sdev->vpd_pg80_len = result;
 		rcu_assign_pointer(sdev->vpd_pg80, vpd_buf);
 		mutex_unlock(&sdev->inquiry_mutex);
@@ -503,7 +503,7 @@ void scsi_attach_vpd(struct scsi_device *sdev)
 			goto retry_pg83;
 		}
 		mutex_lock(&sdev->inquiry_mutex);
-		orig_vpd_buf = sdev->vpd_pg83;
+		orig_vpd_buf = rcu_dereference(sdev->vpd_pg83);
 		sdev->vpd_pg83_len = result;
 		rcu_assign_pointer(sdev->vpd_pg83, vpd_buf);
 		mutex_unlock(&sdev->inquiry_mutex);
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 1905962fb992..2ca91d251c5f 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -3282,7 +3282,7 @@ int scsi_vpd_lun_id(struct scsi_device *sdev, char *id, size_t id_len)
 	u8 cur_id_type = 0xff;
 	u8 cur_id_size = 0;
 	unsigned char *d, *cur_id_str;
-	unsigned char __rcu *vpd_pg83;
+	unsigned char *vpd_pg83;
 	int id_size = -EINVAL;
 
 	rcu_read_lock();
@@ -3431,7 +3431,7 @@ EXPORT_SYMBOL(scsi_vpd_lun_id);
 int scsi_vpd_tpg_id(struct scsi_device *sdev, int *rel_id)
 {
 	unsigned char *d;
-	unsigned char __rcu *vpd_pg83;
+	unsigned char *vpd_pg83;
 	int group_id = -EAGAIN, rel_port = -1;
 
 	rcu_read_lock();
@@ -3441,8 +3441,8 @@ int scsi_vpd_tpg_id(struct scsi_device *sdev, int *rel_id)
 		return -ENXIO;
 	}
 
-	d = sdev->vpd_pg83 + 4;
-	while (d < sdev->vpd_pg83 + sdev->vpd_pg83_len) {
+	d = vpd_pg83 + 4;
+	while (d < vpd_pg83 + sdev->vpd_pg83_len) {
 		switch (d[1] & 0xf) {
 		case 0x4:
 			/* Relative target port */
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index 5ed473a87589..cf8a2088a9ba 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -456,8 +456,11 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work)
 	/* NULL queue means the device can't be used */
 	sdev->request_queue = NULL;
 
-	kfree(sdev->vpd_pg83);
-	kfree(sdev->vpd_pg80);
+	mutex_lock(&sdev->inquiry_mutex);
+	kfree(rcu_dereference(sdev->vpd_pg83));
+	kfree(rcu_dereference(sdev->vpd_pg80));
+	mutex_unlock(&sdev->inquiry_mutex);
+
 	kfree(sdev->inquiry);
 	kfree(sdev);
 
-- 
2.14.0

  parent reply	other threads:[~2017-08-23 21:41 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-23 21:39 [PATCH 00/19] SCSI patches for kernel v4.14 Bart Van Assche
2017-08-23 21:39 ` [PATCH 01/19] Remove an obsolete function declaration Bart Van Assche
2017-08-24  9:02   ` Christoph Hellwig
2017-08-23 21:39 ` [PATCH 02/19] Avoid sign extension of scsi_device.type Bart Van Assche
2017-08-24  6:10   ` Hannes Reinecke
2017-08-24  9:02   ` Christoph Hellwig
2017-08-23 21:39 ` [PATCH 03/19] Suppress gcc 7 fall-through warnings reported with W=1 Bart Van Assche
2017-08-24  9:03   ` Christoph Hellwig
2017-08-23 21:39 ` [PATCH 04/19] Convert a strncmp() call into a strcmp() call Bart Van Assche
2017-08-24  9:03   ` Christoph Hellwig
2017-08-25 15:43   ` Hannes Reinecke
2017-08-23 21:39 ` [PATCH 05/19] scsi_setup_fs_cmnd(): Call scsi_req_init() instead of open-coding it Bart Van Assche
2017-08-24  9:05   ` Christoph Hellwig
2017-08-24 16:17     ` Bart Van Assche
2017-08-23 21:39 ` [PATCH 06/19] Document which queue type a function is intended for Bart Van Assche
2017-08-24  9:05   ` Christoph Hellwig
2017-08-24 16:57     ` Bart Van Assche
2017-08-24 16:58       ` hch
2017-08-24 17:22         ` Bart Van Assche
2017-08-25 15:44   ` Hannes Reinecke
2017-08-23 21:39 ` Bart Van Assche [this message]
2017-08-24  9:07   ` [PATCH 07/19] Fix RCU handling of scsi_device.vpd_pg8[03] Christoph Hellwig
2017-08-24 16:54     ` Bart Van Assche
2017-08-25  5:58       ` Seymour, Shane M
2017-08-25  6:59         ` hch
2017-08-25 20:04         ` Bart Van Assche
2017-08-28  2:02           ` Seymour, Shane M
2017-08-25 15:49   ` Hannes Reinecke
2017-08-25 16:26     ` Bart Van Assche
2017-08-23 21:39 ` [PATCH 08/19] Use blk_mq_rq_to_pdu() to convert a request to a SCSI command pointer Bart Van Assche
2017-08-24  9:07   ` Christoph Hellwig
2017-08-23 21:39 ` [PATCH 09/19] sd, sr: Convert two assignments into warning statements Bart Van Assche
2017-08-24  9:08   ` Christoph Hellwig
2017-08-23 21:40 ` [PATCH 10/19] sd: Fix indentation Bart Van Assche
2017-08-24  9:08   ` Christoph Hellwig
2017-08-25 15:50   ` Hannes Reinecke
2017-08-23 21:40 ` [PATCH 11/19] sd: Remove a useless comparison Bart Van Assche
2017-08-25 15:50   ` Hannes Reinecke
2017-08-23 21:40 ` [PATCH 12/19] sg: Fix type of last blk_trace_setup() argument Bart Van Assche
2017-08-24  9:08   ` Christoph Hellwig
2017-08-25 15:51   ` Hannes Reinecke
2017-08-23 21:40 ` [PATCH 13/19] libiscsi: Fix indentation Bart Van Assche
2017-08-24  9:08   ` Christoph Hellwig
2017-08-25 15:51   ` Hannes Reinecke
2017-08-23 21:40 ` [PATCH 14/19] libsas: Remove a set-but-not-used variable Bart Van Assche
2017-08-24  9:09   ` Christoph Hellwig
2017-08-25 15:51   ` Hannes Reinecke
2017-08-23 21:40 ` [PATCH 15/19] libsas: Annotate fall-through in a switch statement Bart Van Assche
2017-08-24  9:09   ` Christoph Hellwig
2017-08-25 15:52   ` Hannes Reinecke
2017-08-23 21:40 ` [PATCH 16/19] scsi_transport_sas, sas_tlr_supported(): Check kzalloc() return value Bart Van Assche
2017-08-24  9:09   ` Christoph Hellwig
2017-08-25 15:52   ` Hannes Reinecke
2017-08-23 21:40 ` [PATCH 17/19] scsi_transport_srp: Suppress a W=1 compiler warning Bart Van Assche
2017-08-24  9:11   ` Christoph Hellwig
2017-08-24 16:27     ` Bart Van Assche
2017-08-25 15:29       ` hch
2017-08-25 15:40         ` Bart Van Assche
2017-08-25 15:56           ` hch
2017-08-23 21:40 ` [PATCH 18/19] scsi_debug: Remove a set-but-not-used variable Bart Van Assche
2017-08-24  9:12   ` Christoph Hellwig
2017-08-25 15:53   ` Hannes Reinecke
2017-08-23 21:40 ` [PATCH 19/19] iscsi_tcp: " Bart Van Assche
2017-08-24  9:12   ` Christoph Hellwig
2017-08-25 15:53   ` Hannes Reinecke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170823214009.15015-8-bart.vanassche@wdc.com \
    --to=bart.vanassche@wdc.com \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=jejb@linux.vnet.ibm.com \
    --cc=jthumshirn@suse.de \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=shane.seymour@hpe.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox