target-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [v3 0/2] scsi: target: fix sense key for invalid XCOPY request
@ 2021-08-03 14:54 Sergey Samoylenko
  2021-08-03 14:54 ` [v3 1/2] scsi: target: allows backend drivers to fail with specific sense codes Sergey Samoylenko
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Sergey Samoylenko @ 2021-08-03 14:54 UTC (permalink / raw)
  To: martin.petersen, michael.christie, ddiss, bvanassche, target-devel
  Cc: linux-scsi, linux, Sergey Samoylenko

EXTENDED COPY tests in libiscsi [1] show that TCM doesn't
follow SPC4 when detects invalid parameters in a XCOPY
command or IO errors. The replies from TCM contain wrong sense
key or ASCQ for incorrect request.

The series fixes the following tests from libiscsi:

  SCSI.ExtendedCopy.DescrType
  SCSI.ExtendedCopy.DescrLimits
  SCSI.ExtendedCopy.ParamHdr
  SCSI.ExtendedCopy.ValidSegDescr
  SCSI.ExtendedCopy.ValidTgtDescr

1. https://github.com/sahlberg/libiscsi

Sergey Samoylenko (2):
  scsi: target: allows backend drivers to fail with specific sense codes
  scsi: target: fix sense key for invalid XCOPY request

 drivers/target/target_core_transport.c | 15 ++++++++++++---
 drivers/target/target_core_xcopy.c     | 26 +++++++++++++++-----------
 include/target/target_core_backend.h   |  1 +
 include/target/target_core_base.h      |  2 ++
 4 files changed, 30 insertions(+), 14 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [v3 1/2] scsi: target: allows backend drivers to fail with specific sense codes
  2021-08-03 14:54 [v3 0/2] scsi: target: fix sense key for invalid XCOPY request Sergey Samoylenko
@ 2021-08-03 14:54 ` Sergey Samoylenko
  2021-08-03 14:54 ` [v3 2/2] scsi: target: fix sense key for invalid XCOPY request Sergey Samoylenko
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Sergey Samoylenko @ 2021-08-03 14:54 UTC (permalink / raw)
  To: martin.petersen, michael.christie, ddiss, bvanassche, target-devel
  Cc: linux-scsi, linux, Sergey Samoylenko

Currently, backend drivers can fail IO with
SAM_STAT_CHECK_CONDITION which gets us
TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE. The patch adds
a new helper that allows backend drivers to fail with
specific sense codes.

This is based on a patch from Mike Christie <michael.christie@oracle.com>.

Cc: Mike Christie <michael.christie@oracle.com>

Reviewed-by: David Disseldorp <ddiss@suse.de>
[ Moved target_complete_cmd_with_sense() helper to mainline ]
Signed-off-by: Sergey Samoylenko <s.samoylenko@yadro.com>
---
 drivers/target/target_core_transport.c | 15 ++++++++++++---
 include/target/target_core_backend.h   |  1 +
 include/target/target_core_base.h      |  2 ++
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index 065834480179..72cbf006d9d1 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -736,8 +736,7 @@ static void target_complete_failure_work(struct work_struct *work)
 {
 	struct se_cmd *cmd = container_of(work, struct se_cmd, work);
 
-	transport_generic_request_failure(cmd,
-			TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE);
+	transport_generic_request_failure(cmd, cmd->sense_reason);
 }
 
 /*
@@ -855,7 +854,8 @@ static bool target_cmd_interrupted(struct se_cmd *cmd)
 }
 
 /* May be called from interrupt context so must not sleep. */
-void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status)
+void target_complete_cmd_with_sense(struct se_cmd *cmd, u8 scsi_status,
+				    sense_reason_t sense_reason)
 {
 	struct se_wwn *wwn = cmd->se_sess->se_tpg->se_tpg_wwn;
 	int success, cpu;
@@ -865,6 +865,7 @@ void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status)
 		return;
 
 	cmd->scsi_status = scsi_status;
+	cmd->sense_reason = sense_reason;
 
 	spin_lock_irqsave(&cmd->t_state_lock, flags);
 	switch (cmd->scsi_status) {
@@ -893,6 +894,14 @@ void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status)
 
 	queue_work_on(cpu, target_completion_wq, &cmd->work);
 }
+EXPORT_SYMBOL(target_complete_cmd_with_sense);
+
+void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status)
+{
+	target_complete_cmd_with_sense(cmd, scsi_status, scsi_status ?
+			      TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE :
+			      TCM_NO_SENSE);
+}
 EXPORT_SYMBOL(target_complete_cmd);
 
 void target_set_cmd_data_length(struct se_cmd *cmd, int length)
diff --git a/include/target/target_core_backend.h b/include/target/target_core_backend.h
index 1f78b09bba55..675f3a1fe613 100644
--- a/include/target/target_core_backend.h
+++ b/include/target/target_core_backend.h
@@ -75,6 +75,7 @@ void	target_backend_unregister(const struct target_backend_ops *);
 
 void	target_complete_cmd(struct se_cmd *, u8);
 void	target_set_cmd_data_length(struct se_cmd *, int);
+void	target_complete_cmd_with_sense(struct se_cmd *, u8, sense_reason_t);
 void	target_complete_cmd_with_length(struct se_cmd *, u8, int);
 
 void	transport_copy_sense_to_cmd(struct se_cmd *, unsigned char *);
diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
index f53e0f160695..fb11c7693b25 100644
--- a/include/target/target_core_base.h
+++ b/include/target/target_core_base.h
@@ -457,6 +457,8 @@ enum target_core_dif_check {
 #define TCM_ACA_TAG	0x24
 
 struct se_cmd {
+	/* Used for fail with specific sense codes */
+	sense_reason_t		sense_reason;
 	/* SAM response code being sent to initiator */
 	u8			scsi_status;
 	u16			scsi_sense_length;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [v3 2/2] scsi: target: fix sense key for invalid XCOPY request
  2021-08-03 14:54 [v3 0/2] scsi: target: fix sense key for invalid XCOPY request Sergey Samoylenko
  2021-08-03 14:54 ` [v3 1/2] scsi: target: allows backend drivers to fail with specific sense codes Sergey Samoylenko
@ 2021-08-03 14:54 ` Sergey Samoylenko
  2021-08-17  3:09 ` [v3 0/2] " Martin K. Petersen
  2021-08-24  4:03 ` Martin K. Petersen
  3 siblings, 0 replies; 5+ messages in thread
From: Sergey Samoylenko @ 2021-08-03 14:54 UTC (permalink / raw)
  To: martin.petersen, michael.christie, ddiss, bvanassche, target-devel
  Cc: linux-scsi, linux, Sergey Samoylenko, Roman Bolshakov,
	Konstantin Shelekhin

TCM fails to pass the following tests in libiscsi:

  SCSI.ExtendedCopy.DescrType
  SCSI.ExtendedCopy.DescrLimits
  SCSI.ExtendedCopy.ParamHdr
  SCSI.ExtendedCopy.ValidSegDescr
  SCSI.ExtendedCopy.ValidTgtDescr

XCOPY always returns the same NOT READY sense key for all
detected errors. It changes a sense key for invalid requests
to ILLEGAL REQUEST sense key, for aborted transferring data
(IO error and etc.) to COPY ABORTED.

Fixes: d877d7275be34ad ("target: Fix a deadlock between the XCOPY code and iSCSI session shutdown")
Reviewed-by: David Disseldorp <ddiss@suse.de>
Reviewed-by: Roman Bolshakov <r.bolshakov@yadro.com>
Reviewed-by: Konstantin Shelekhin <k.shelekhin@yadro.com>
Signed-off-by: Sergey Samoylenko <s.samoylenko@yadro.com>
---
 drivers/target/target_core_xcopy.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/drivers/target/target_core_xcopy.c b/drivers/target/target_core_xcopy.c
index 0f1319336f3e..d4fe7cb2bd00 100644
--- a/drivers/target/target_core_xcopy.c
+++ b/drivers/target/target_core_xcopy.c
@@ -674,12 +674,16 @@ static void target_xcopy_do_work(struct work_struct *work)
 	unsigned int max_sectors;
 	int rc = 0;
 	unsigned short nolb, max_nolb, copied_nolb = 0;
+	sense_reason_t sense_rc;
 
-	if (target_parse_xcopy_cmd(xop) != TCM_NO_SENSE)
+	sense_rc = target_parse_xcopy_cmd(xop);
+	if (sense_rc != TCM_NO_SENSE)
 		goto err_free;
 
-	if (WARN_ON_ONCE(!xop->src_dev) || WARN_ON_ONCE(!xop->dst_dev))
+	if (WARN_ON_ONCE(!xop->src_dev) || WARN_ON_ONCE(!xop->dst_dev)) {
+		sense_rc = TCM_INVALID_PARAMETER_LIST;
 		goto err_free;
+	}
 
 	src_dev = xop->src_dev;
 	dst_dev = xop->dst_dev;
@@ -762,20 +766,20 @@ static void target_xcopy_do_work(struct work_struct *work)
 	return;
 
 out:
+	/*
+	 * The XCOPY command was aborted after some data was transferred.
+	 * Terminate command with CHECK CONDITION status, with the sense key
+	 * set to COPY ABORTED.
+	 */
+	sense_rc = TCM_COPY_TARGET_DEVICE_NOT_REACHABLE;
 	xcopy_pt_undepend_remotedev(xop);
 	target_free_sgl(xop->xop_data_sg, xop->xop_data_nents);
 
 err_free:
 	kfree(xop);
-	/*
-	 * Don't override an error scsi status if it has already been set
-	 */
-	if (ec_cmd->scsi_status == SAM_STAT_GOOD) {
-		pr_warn_ratelimited("target_xcopy_do_work: rc: %d, Setting X-COPY"
-			" CHECK_CONDITION -> sending response\n", rc);
-		ec_cmd->scsi_status = SAM_STAT_CHECK_CONDITION;
-	}
-	target_complete_cmd(ec_cmd, ec_cmd->scsi_status);
+	pr_warn_ratelimited("target_xcopy_do_work: rc: %d, sense: %u, XCOPY operation failed\n",
+			   rc, sense_rc);
+	target_complete_cmd_with_sense(ec_cmd, SAM_STAT_CHECK_CONDITION, sense_rc);
 }
 
 /*
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [v3 0/2] scsi: target: fix sense key for invalid XCOPY request
  2021-08-03 14:54 [v3 0/2] scsi: target: fix sense key for invalid XCOPY request Sergey Samoylenko
  2021-08-03 14:54 ` [v3 1/2] scsi: target: allows backend drivers to fail with specific sense codes Sergey Samoylenko
  2021-08-03 14:54 ` [v3 2/2] scsi: target: fix sense key for invalid XCOPY request Sergey Samoylenko
@ 2021-08-17  3:09 ` Martin K. Petersen
  2021-08-24  4:03 ` Martin K. Petersen
  3 siblings, 0 replies; 5+ messages in thread
From: Martin K. Petersen @ 2021-08-17  3:09 UTC (permalink / raw)
  To: Sergey Samoylenko
  Cc: martin.petersen, michael.christie, ddiss, bvanassche,
	target-devel, linux-scsi, linux


Sergey,

> EXTENDED COPY tests in libiscsi [1] show that TCM doesn't follow SPC4
> when detects invalid parameters in a XCOPY command or IO errors. The
> replies from TCM contain wrong sense key or ASCQ for incorrect
> request.

Applied to 5.15/scsi-staging, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [v3 0/2] scsi: target: fix sense key for invalid XCOPY request
  2021-08-03 14:54 [v3 0/2] scsi: target: fix sense key for invalid XCOPY request Sergey Samoylenko
                   ` (2 preceding siblings ...)
  2021-08-17  3:09 ` [v3 0/2] " Martin K. Petersen
@ 2021-08-24  4:03 ` Martin K. Petersen
  3 siblings, 0 replies; 5+ messages in thread
From: Martin K. Petersen @ 2021-08-24  4:03 UTC (permalink / raw)
  To: target-devel, bvanassche, ddiss, michael.christie, Sergey Samoylenko
  Cc: Martin K . Petersen, linux, linux-scsi

On Tue, 3 Aug 2021 17:54:08 +0300, Sergey Samoylenko wrote:

> EXTENDED COPY tests in libiscsi [1] show that TCM doesn't
> follow SPC4 when detects invalid parameters in a XCOPY
> command or IO errors. The replies from TCM contain wrong sense
> key or ASCQ for incorrect request.
> 
> The series fixes the following tests from libiscsi:
> 
> [...]

Applied to 5.15/scsi-queue, thanks!

[1/2] scsi: target: allows backend drivers to fail with specific sense codes
      https://git.kernel.org/mkp/scsi/c/44678553ad7e
[2/2] scsi: target: fix sense key for invalid XCOPY request
      https://git.kernel.org/mkp/scsi/c/0394b5048efd

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-08-24  4:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-03 14:54 [v3 0/2] scsi: target: fix sense key for invalid XCOPY request Sergey Samoylenko
2021-08-03 14:54 ` [v3 1/2] scsi: target: allows backend drivers to fail with specific sense codes Sergey Samoylenko
2021-08-03 14:54 ` [v3 2/2] scsi: target: fix sense key for invalid XCOPY request Sergey Samoylenko
2021-08-17  3:09 ` [v3 0/2] " Martin K. Petersen
2021-08-24  4:03 ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).