All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Christie <michael.christie@oracle.com>
To: martin.petersen@oracle.com, linux-scsi@vger.kernel.org,
	target-devel@vger.kernel.org
Cc: Mike Christie <michael.christie@oracle.com>
Subject: [PATCH v2 4/8] target: Move buffer clearing hack
Date: Wed, 27 Sep 2023 21:09:03 -0500	[thread overview]
Message-ID: <20230928020907.5730-4-michael.christie@oracle.com> (raw)
In-Reply-To: <20230928020907.5730-1-michael.christie@oracle.com>

This moves the hack to clear some buffers to transport_handle_cdb_direct
so we can eventually merge transport_handle_cdb_direct and target_submit.

This also fixes up the comment so it's clear it was only for udev and
reflects that the referenced function does not exist and we now allow
more than 1 page for control CDBs.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
---
 drivers/target/target_core_transport.c | 49 +++++++++++---------------
 1 file changed, 21 insertions(+), 28 deletions(-)

diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index 709314415a01..c2ddd09051e8 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -1593,6 +1593,27 @@ int transport_handle_cdb_direct(
 	 */
 	core_alua_check_nonop_delay(cmd);
 
+	if (cmd->t_data_nents != 0) {
+		/*
+		 * This is primarily a hack for udev and tcm loop which sends
+		 * INQUIRYs with a single page and expects the data to be
+		 * cleared.
+		 */
+		if (!(cmd->se_cmd_flags & SCF_SCSI_DATA_CDB) &&
+		    cmd->data_direction == DMA_FROM_DEVICE) {
+			struct scatterlist *sgl = cmd->t_data_sg;
+			unsigned char *buf = NULL;
+
+			BUG_ON(!sgl);
+
+			buf = kmap_local_page(sg_page(sgl));
+			if (buf) {
+				memset(buf + sgl->offset, 0, sgl->length);
+				kunmap_local(buf);
+			}
+		}
+	}
+
 	if (!cmd->se_lun) {
 		dump_stack();
 		pr_err("cmd->se_lun is NULL\n");
@@ -1796,34 +1817,6 @@ EXPORT_SYMBOL_GPL(target_submit_prep);
  */
 void target_submit(struct se_cmd *se_cmd)
 {
-	struct scatterlist *sgl = se_cmd->t_data_sg;
-	unsigned char *buf = NULL;
-
-	might_sleep();
-
-	if (se_cmd->t_data_nents != 0) {
-		BUG_ON(!sgl);
-		/*
-		 * A work-around for tcm_loop as some userspace code via
-		 * scsi-generic do not memset their associated read buffers,
-		 * so go ahead and do that here for type non-data CDBs.  Also
-		 * note that this is currently guaranteed to be a single SGL
-		 * for this case by target core in target_setup_cmd_from_cdb()
-		 * -> transport_generic_cmd_sequencer().
-		 */
-		if (!(se_cmd->se_cmd_flags & SCF_SCSI_DATA_CDB) &&
-		     se_cmd->data_direction == DMA_FROM_DEVICE) {
-			if (sgl)
-				buf = kmap(sg_page(sgl)) + sgl->offset;
-
-			if (buf) {
-				memset(buf, 0, sgl->length);
-				kunmap(sg_page(sgl));
-			}
-		}
-
-	}
-
 	transport_handle_cdb_direct(se_cmd);
 }
 EXPORT_SYMBOL_GPL(target_submit);
-- 
2.34.1


  parent reply	other threads:[~2023-09-28  2:09 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-28  2:09 [PATCH v2 1/8] scsi: target: Make write_pending_must_be_called a bit field Mike Christie
2023-09-28  2:09 ` [PATCH v2 2/8] scsi: target: Have drivers report if they support direct submissions Mike Christie
2023-09-28  2:09 ` [PATCH v2 3/8] target: Move core_alua_check_nonop_delay call Mike Christie
2023-09-28  2:09 ` Mike Christie [this message]
2023-09-28  2:09 ` [PATCH v2 5/8] target: Kill transport_handle_cdb_direct Mike Christie
2023-09-28  2:09 ` [PATCH v2 6/8] scsi: target: Allow userspace to request direct submissions Mike Christie
2023-09-28  2:09 ` [PATCH v2 7/8] scsi: target: Unexport target_queue_submission Mike Christie
2023-09-28  2:09 ` [PATCH v2 8/8] scsi: target: Export fabric driver direct submit settings Mike Christie
2023-09-28  2:31 ` [PATCH v2 0/8] scsi: target: Allow userspace to config cmd submission Mike Christie
2023-10-13 19:57   ` Martin K. Petersen
2023-10-17  1:11   ` Martin K. Petersen

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=20230928020907.5730-4-michael.christie@oracle.com \
    --to=michael.christie@oracle.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=target-devel@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.