Blob Blame History Raw
From: Jeff Mahoney <jeffm@suse.com>
Subject: scsi: libsas: allocate sense buffer for bsg queue
Patch-mainline: Never, SAS was converted to bsg-lib in 4.14
References: bsc#1131467

Upstream commit 82ed4db499b (block: split scsi_request out of struct request)
pulled the SCSI-specific components of struct request into a separate
struct scsi_request.  Prior to this commit, blk_execute_rq, bsg, sg_io,
sg_scsi_ioctl, etc all allocated a static buffer on the stack and assigned
it to request->sense.  After this commit, queue owners became responsible
for ensuring scsi_request->sense was initialized.  The SAS BSG implementation
was overlooked and scsi_request->sense was never cleared, causing trouble
later when LLDDs assumed that it was a valid pointer and used it.

This patch follows the convention found in the above commit and adds
sense buffer allocation to the bsg queue for SAS devices.  In 4.14,
SAS was converted to use the bsg-lib API which does something similar.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 drivers/scsi/scsi_transport_sas.c |   21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

--- a/drivers/scsi/scsi_transport_sas.c
+++ b/drivers/scsi/scsi_transport_sas.c
@@ -214,6 +214,23 @@ static void sas_host_release(struct devi
 		blk_cleanup_queue(q);
 }
 
+/*
+ * struct scsi_request must be first so that scsi_req works properly.
+ * See commit 82ed4db499b (block: split scsi_request out of struct request).
+ */
+struct sas_scsi_request {
+	struct scsi_request sreq;
+	char sense[SCSI_SENSE_BUFFERSIZE];
+};
+
+static void sas_initialize_rq(struct request *rq)
+{
+	struct sas_scsi_request *req = blk_mq_rq_to_pdu(rq);
+
+	scsi_req_init(&req->sreq);
+	req->sreq.sense = req->sense;
+}
+
 static int sas_bsg_initialize(struct Scsi_Host *shost, struct sas_rphy *rphy)
 {
 	struct request_queue *q;
@@ -231,8 +248,8 @@ static int sas_bsg_initialize(struct Scs
 	q = blk_alloc_queue(GFP_KERNEL);
 	if (!q)
 		return -ENOMEM;
-	q->initialize_rq_fn = scsi_initialize_rq;
-	q->cmd_size = sizeof(struct scsi_request);
+	q->initialize_rq_fn = sas_initialize_rq;
+	q->cmd_size = sizeof(struct sas_scsi_request);
 
 	if (rphy) {
 		q->request_fn = sas_non_host_smp_request;