All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] target: Fix zero-length regressions in v3.8-rc1 code
@ 2013-01-29 22:26 Nicholas A. Bellinger
  2013-01-29 22:26 ` [PATCH 1/3] target: Fix zero-length INQUIRY additional sense code regression Nicholas A. Bellinger
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Nicholas A. Bellinger @ 2013-01-29 22:26 UTC (permalink / raw)
  To: target-devel
  Cc: linux-scsi, Christoph Hellwig, Paolo Bonzini, Roland Dreier,
	Nicholas Bellinger

From: Nicholas Bellinger <nab@linux-iscsi.org>

Hi folks,

The following are a handful of zero-length CDB regression bugfixes to address
breakage introduced by the recent sense_reason_t conversion in v3.8-rc1 code,
which incorrectly assumed CHECK_CONDITION status (in all CDB emulation cases)
when NULL was returned by transport_kmap_data_sg().

Please review, as I'd like to get these into v3.8-rc6.

Thank you,

--nab

Nicholas Bellinger (3):
  target: Fix zero-length INQUIRY additional sense code regression
  target: Fix zero-length MODE_SENSE regression
  target: Fix zero-length READ_CAPACITY_16 regression

 drivers/target/target_core_sbc.c |   18 +++++++--------
 drivers/target/target_core_spc.c |   44 +++++++++----------------------------
 2 files changed, 19 insertions(+), 43 deletions(-)

-- 
1.7.2.5

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

* [PATCH 1/3] target: Fix zero-length INQUIRY additional sense code regression
  2013-01-29 22:26 [PATCH 0/3] target: Fix zero-length regressions in v3.8-rc1 code Nicholas A. Bellinger
@ 2013-01-29 22:26 ` Nicholas A. Bellinger
  2013-01-29 22:26 ` [PATCH 2/3] target: Fix zero-length MODE_SENSE regression Nicholas A. Bellinger
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Nicholas A. Bellinger @ 2013-01-29 22:26 UTC (permalink / raw)
  To: target-devel
  Cc: linux-scsi, Christoph Hellwig, Paolo Bonzini, Roland Dreier,
	Nicholas Bellinger

From: Nicholas Bellinger <nab@linux-iscsi.org>

This patch fixes a minor regression introduced in v3.8-rc1 code
where a zero-length INQUIRY was no longer returning the correct
INVALID FIELD IN CDB additional sense code.

This regression was introduced with the following commit:

  commit de103c93aff0bed0ae984274e5dc8b95899badab
  Author: Christoph Hellwig <hch@lst.de>
  Date:   Tue Nov 6 12:24:09 2012 -0800

      target: pass sense_reason as a return value

and this patch has been tested with the following zero-length CDB:

  sg_raw /dev/sdd 12 00 83 00 00 00
  SCSI Status: Check Condition

  Sense Information:
   Fixed format, current;  Sense key: Illegal Request
   Additional sense: Invalid field in cdb

Cc: Christoph Hellwig <hch@lst.de>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Roland Dreier <roland@purestorage.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
---
 drivers/target/target_core_spc.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c
index 84f9e96..f8857d4 100644
--- a/drivers/target/target_core_spc.c
+++ b/drivers/target/target_core_spc.c
@@ -641,11 +641,10 @@ spc_emulate_inquiry(struct se_cmd *cmd)
 
 out:
 	rbuf = transport_kmap_data_sg(cmd);
-	if (!rbuf)
-		return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
-
-	memcpy(rbuf, buf, min_t(u32, sizeof(buf), cmd->data_length));
-	transport_kunmap_data_sg(cmd);
+	if (rbuf) {
+		memcpy(rbuf, buf, min_t(u32, sizeof(buf), cmd->data_length));
+		transport_kunmap_data_sg(cmd);
+	}
 
 	if (!ret)
 		target_complete_cmd(cmd, GOOD);
-- 
1.7.2.5

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

* [PATCH 2/3] target: Fix zero-length MODE_SENSE regression
  2013-01-29 22:26 [PATCH 0/3] target: Fix zero-length regressions in v3.8-rc1 code Nicholas A. Bellinger
  2013-01-29 22:26 ` [PATCH 1/3] target: Fix zero-length INQUIRY additional sense code regression Nicholas A. Bellinger
@ 2013-01-29 22:26 ` Nicholas A. Bellinger
  2013-01-29 22:26 ` [PATCH 3/3] target: Fix zero-length READ_CAPACITY_16 regression Nicholas A. Bellinger
  2013-01-30  9:24 ` [PATCH 0/3] target: Fix zero-length regressions in v3.8-rc1 code Paolo Bonzini
  3 siblings, 0 replies; 5+ messages in thread
From: Nicholas A. Bellinger @ 2013-01-29 22:26 UTC (permalink / raw)
  To: target-devel
  Cc: linux-scsi, Christoph Hellwig, Paolo Bonzini, Roland Dreier,
	Nicholas Bellinger

From: Nicholas Bellinger <nab@linux-iscsi.org>

This patch fixes a regression introduced in v3.8-rc1 code where
a zero-length MODE_SENSE was no longer returning GOOD status, but
instead returning TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE to generate
a CHECK_CONDITION status.

This regression was introduced with the following commit:

  commit de103c93aff0bed0ae984274e5dc8b95899badab
  Author: Christoph Hellwig <hch@lst.de>
  Date:   Tue Nov 6 12:24:09 2012 -0800

      target: pass sense_reason as a return value

and this patch has been tested with the following zero-length CDB:

  sg_raw /dev/sdd 5a 00 0a 00 00 00 00 00 00 00
  SCSI Status: Good

  Sense Information:
  sense buffer empty

Cc: Christoph Hellwig <hch@lst.de>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Roland Dreier <roland@purestorage.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
---
 drivers/target/target_core_spc.c |   35 +++++++----------------------------
 1 files changed, 7 insertions(+), 28 deletions(-)

diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c
index f8857d4..2d88f08 100644
--- a/drivers/target/target_core_spc.c
+++ b/drivers/target/target_core_spc.c
@@ -850,7 +850,7 @@ static sense_reason_t spc_emulate_modesense(struct se_cmd *cmd)
 {
 	struct se_device *dev = cmd->se_dev;
 	char *cdb = cmd->t_task_cdb;
-	unsigned char *buf, *map_buf;
+	unsigned char buf[SE_MODE_PAGE_BUF], *rbuf;
 	int type = dev->transport->get_device_type(dev);
 	int ten = (cmd->t_task_cdb[0] == MODE_SENSE_10);
 	bool dbd = !!(cdb[1] & 0x08);
@@ -862,26 +862,8 @@ static sense_reason_t spc_emulate_modesense(struct se_cmd *cmd)
 	int ret;
 	int i;
 
-	map_buf = transport_kmap_data_sg(cmd);
-	if (!map_buf)
-		return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
-	/*
-	 * If SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC is not set, then we
-	 * know we actually allocated a full page.  Otherwise, if the
-	 * data buffer is too small, allocate a temporary buffer so we
-	 * don't have to worry about overruns in all our INQUIRY
-	 * emulation handling.
-	 */
-	if (cmd->data_length < SE_MODE_PAGE_BUF &&
-	    (cmd->se_cmd_flags & SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC)) {
-		buf = kzalloc(SE_MODE_PAGE_BUF, GFP_KERNEL);
-		if (!buf) {
-			transport_kunmap_data_sg(cmd);
-			return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
-		}
-	} else {
-		buf = map_buf;
-	}
+	memset(buf, 0, SE_MODE_PAGE_BUF);
+
 	/*
 	 * Skip over MODE DATA LENGTH + MEDIUM TYPE fields to byte 3 for
 	 * MODE_SENSE_10 and byte 2 for MODE_SENSE (6).
@@ -933,8 +915,6 @@ static sense_reason_t spc_emulate_modesense(struct se_cmd *cmd)
 	if (page == 0x3f) {
 		if (subpage != 0x00 && subpage != 0xff) {
 			pr_warn("MODE_SENSE: Invalid subpage code: 0x%02x\n", subpage);
-			kfree(buf);
-			transport_kunmap_data_sg(cmd);
 			return TCM_INVALID_CDB_FIELD;
 		}
 
@@ -971,7 +951,6 @@ static sense_reason_t spc_emulate_modesense(struct se_cmd *cmd)
 		pr_err("MODE SENSE: unimplemented page/subpage: 0x%02x/0x%02x\n",
 		       page, subpage);
 
-	transport_kunmap_data_sg(cmd);
 	return TCM_UNKNOWN_MODE_PAGE;
 
 set_length:
@@ -980,12 +959,12 @@ set_length:
 	else
 		buf[0] = length - 1;
 
-	if (buf != map_buf) {
-		memcpy(map_buf, buf, cmd->data_length);
-		kfree(buf);
+	rbuf = transport_kmap_data_sg(cmd);
+	if (rbuf) {
+		memcpy(rbuf, buf, min_t(u32, SE_MODE_PAGE_BUF, cmd->data_length));
+		transport_kunmap_data_sg(cmd);
 	}
 
-	transport_kunmap_data_sg(cmd);
 	target_complete_cmd(cmd, GOOD);
 	return 0;
 }
-- 
1.7.2.5

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

* [PATCH 3/3] target: Fix zero-length READ_CAPACITY_16 regression
  2013-01-29 22:26 [PATCH 0/3] target: Fix zero-length regressions in v3.8-rc1 code Nicholas A. Bellinger
  2013-01-29 22:26 ` [PATCH 1/3] target: Fix zero-length INQUIRY additional sense code regression Nicholas A. Bellinger
  2013-01-29 22:26 ` [PATCH 2/3] target: Fix zero-length MODE_SENSE regression Nicholas A. Bellinger
@ 2013-01-29 22:26 ` Nicholas A. Bellinger
  2013-01-30  9:24 ` [PATCH 0/3] target: Fix zero-length regressions in v3.8-rc1 code Paolo Bonzini
  3 siblings, 0 replies; 5+ messages in thread
From: Nicholas A. Bellinger @ 2013-01-29 22:26 UTC (permalink / raw)
  To: target-devel
  Cc: linux-scsi, Christoph Hellwig, Paolo Bonzini, Roland Dreier,
	Nicholas Bellinger

From: Nicholas Bellinger <nab@linux-iscsi.org>

This patch fixes a regression introduced in v3.8-rc1 code where a
zero-length READ_CAPACITY_16 was no longer returning GOOD status, but
instead returning TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE to generate
a CHECK_CONDITION status.

This regression was introduced with the following commit:

  commit de103c93aff0bed0ae984274e5dc8b95899badab
  Author: Christoph Hellwig <hch@lst.de>
  Date:   Tue Nov 6 12:24:09 2012 -0800

      target: pass sense_reason as a return value

and this patch has been tested with the following zero-length CDB:

  sg_raw /dev/sdd 9e 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  SCSI Status: Good

  Sense Information:
  sense buffer empty

Also, convert sbc_emulate_readcapacity() to follow the same method
of handling transport_kmap_data_sg() return values, but we never
expect a zero-length request here.

Cc: Christoph Hellwig <hch@lst.de>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Roland Dreier <roland@purestorage.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
---
 drivers/target/target_core_sbc.c |   18 ++++++++----------
 1 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/target/target_core_sbc.c b/drivers/target/target_core_sbc.c
index 26a6d18..a664c66 100644
--- a/drivers/target/target_core_sbc.c
+++ b/drivers/target/target_core_sbc.c
@@ -58,11 +58,10 @@ sbc_emulate_readcapacity(struct se_cmd *cmd)
 	buf[7] = dev->dev_attrib.block_size & 0xff;
 
 	rbuf = transport_kmap_data_sg(cmd);
-	if (!rbuf)
-		return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
-
-	memcpy(rbuf, buf, min_t(u32, sizeof(buf), cmd->data_length));
-	transport_kunmap_data_sg(cmd);
+	if (rbuf) {
+		memcpy(rbuf, buf, min_t(u32, sizeof(buf), cmd->data_length));
+		transport_kunmap_data_sg(cmd);
+	}
 
 	target_complete_cmd(cmd, GOOD);
 	return 0;
@@ -97,11 +96,10 @@ sbc_emulate_readcapacity_16(struct se_cmd *cmd)
 		buf[14] = 0x80;
 
 	rbuf = transport_kmap_data_sg(cmd);
-	if (!rbuf)
-		return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
-
-	memcpy(rbuf, buf, min_t(u32, sizeof(buf), cmd->data_length));
-	transport_kunmap_data_sg(cmd);
+	if (rbuf) {
+		memcpy(rbuf, buf, min_t(u32, sizeof(buf), cmd->data_length));
+		transport_kunmap_data_sg(cmd);
+	}
 
 	target_complete_cmd(cmd, GOOD);
 	return 0;
-- 
1.7.2.5

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

* Re: [PATCH 0/3] target: Fix zero-length regressions in v3.8-rc1 code
  2013-01-29 22:26 [PATCH 0/3] target: Fix zero-length regressions in v3.8-rc1 code Nicholas A. Bellinger
                   ` (2 preceding siblings ...)
  2013-01-29 22:26 ` [PATCH 3/3] target: Fix zero-length READ_CAPACITY_16 regression Nicholas A. Bellinger
@ 2013-01-30  9:24 ` Paolo Bonzini
  3 siblings, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2013-01-30  9:24 UTC (permalink / raw)
  To: Nicholas A. Bellinger
  Cc: target-devel, linux-scsi, Christoph Hellwig, Roland Dreier

Il 29/01/2013 23:26, Nicholas A. Bellinger ha scritto:
> From: Nicholas Bellinger <nab@linux-iscsi.org>
> 
> Hi folks,
> 
> The following are a handful of zero-length CDB regression bugfixes to address
> breakage introduced by the recent sense_reason_t conversion in v3.8-rc1 code,
> which incorrectly assumed CHECK_CONDITION status (in all CDB emulation cases)
> when NULL was returned by transport_kmap_data_sg().
> 
> Please review, as I'd like to get these into v3.8-rc6.
> 
> Thank you,
> 
> --nab
> 
> Nicholas Bellinger (3):
>   target: Fix zero-length INQUIRY additional sense code regression
>   target: Fix zero-length MODE_SENSE regression
>   target: Fix zero-length READ_CAPACITY_16 regression
> 
>  drivers/target/target_core_sbc.c |   18 +++++++--------
>  drivers/target/target_core_spc.c |   44 +++++++++----------------------------
>  2 files changed, 19 insertions(+), 43 deletions(-)
> 

Looks good, but given the mess I made in my own zero-length patches,
don't really count it as a Reviewed-by.

Paolo

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

end of thread, other threads:[~2013-01-30  9:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-29 22:26 [PATCH 0/3] target: Fix zero-length regressions in v3.8-rc1 code Nicholas A. Bellinger
2013-01-29 22:26 ` [PATCH 1/3] target: Fix zero-length INQUIRY additional sense code regression Nicholas A. Bellinger
2013-01-29 22:26 ` [PATCH 2/3] target: Fix zero-length MODE_SENSE regression Nicholas A. Bellinger
2013-01-29 22:26 ` [PATCH 3/3] target: Fix zero-length READ_CAPACITY_16 regression Nicholas A. Bellinger
2013-01-30  9:24 ` [PATCH 0/3] target: Fix zero-length regressions in v3.8-rc1 code Paolo Bonzini

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.