* [RESEND PATCH 0/3] scsi: target: Set correct residual data
@ 2020-12-03 8:20 Anastasia Kovaleva
2020-12-03 8:20 ` [RESEND PATCH 1/3] scsi: target: core: Set residuals for 4Kn devices Anastasia Kovaleva
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Anastasia Kovaleva @ 2020-12-03 8:20 UTC (permalink / raw)
To: martin.petersen; +Cc: target-devel, linux-scsi, linux, Anastasia Kovaleva
Hi Martin,
Please apply the changes to 5.11/scsi-queue at your earliest
convenience.
The series changes the behavior of the target in regard to processing
commands with overflow/underflow in accordance with the standarts.
The target driver used to process the DMA_TO_DEVICE commands with
residuals (in particular, WRITE command) incorrectly. The target
response contained neither a residual count, nor an OVERFLOW/UNDERFLOW
bit. Such behavior did not comply with the RFC 7143. Also the
returned ASC and ASCQ were incorrect according to FCP-4,
and residuals were not set for the 4Kn devices.
This patches fix the major inconsistances in processing these kind of
commands.
This patch series has been tested with a modified libiscsi testing
library.
The link to the pull request:
https://github.com/sahlberg/libiscsi/pull/345
Write10Residuals, Write12Residuals, Write16Residuals tests have passed.
Thanks,
Anastasia
Anastasia Kovaleva (2):
scsi: target: core: Signal WRITE residuals
scsi: target: core: Change ASCQ for residual write
Roman Bolshakov (1):
scsi: target: core: Set residuals for 4Kn devices
drivers/target/target_core_transport.c | 53 +++++++++++++-------------
include/target/target_core_base.h | 1 +
2 files changed, 28 insertions(+), 26 deletions(-)
--
2.24.3 (Apple Git-128)
^ permalink raw reply [flat|nested] 7+ messages in thread
* [RESEND PATCH 1/3] scsi: target: core: Set residuals for 4Kn devices
2020-12-03 8:20 [RESEND PATCH 0/3] scsi: target: Set correct residual data Anastasia Kovaleva
@ 2020-12-03 8:20 ` Anastasia Kovaleva
2020-12-03 8:20 ` [RESEND PATCH 2/3] scsi: target: core: Signal WRITE residuals Anastasia Kovaleva
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Anastasia Kovaleva @ 2020-12-03 8:20 UTC (permalink / raw)
To: martin.petersen
Cc: target-devel, linux-scsi, linux, Roman Bolshakov,
Bart Van Assche, Konstantin Vinogradov
From: Roman Bolshakov <r.bolshakov@yadro.com>
TCM always fails SBC commands with residuals for 4Kn devices when the
command is processed by sbc_parse_cdb(). That prevents residual
signalling to the transport driver because residual kind and residual
amount aren't set. It also makes residual handling different from
512-byte formatted devices - if there are residuals 512-byte LUN would
proceed with command execution while 4K-byte LUN would fail.
Based-on: https://patchwork.kernel.org/project/target-devel/patch/20170523234854.21452-31-bart.vanassche@sandisk.com/
Based-on-patch-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
Signed-off-by: Konstantin Vinogradov <k.vinogradov@yadro.com>
---
drivers/target/target_core_transport.c | 11 -----------
1 file changed, 11 deletions(-)
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index fca4bd079d02..f27a7d6cc1e0 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -1332,17 +1332,6 @@ target_cmd_size_check(struct se_cmd *cmd, unsigned int size)
return TCM_INVALID_CDB_FIELD;
}
}
- /*
- * Reject READ_* or WRITE_* with overflow/underflow for
- * type SCF_SCSI_DATA_CDB.
- */
- if (dev->dev_attrib.block_size != 512) {
- pr_err("Failing OVERFLOW/UNDERFLOW for LBA op"
- " CDB on non 512-byte sector setup subsystem"
- " plugin: %s\n", dev->transport->name);
- /* Returns CHECK_CONDITION + INVALID_CDB_FIELD */
- return TCM_INVALID_CDB_FIELD;
- }
/*
* For the overflow case keep the existing fabric provided
* ->data_length. Otherwise for the underflow case, reset
--
2.24.3 (Apple Git-128)
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [RESEND PATCH 2/3] scsi: target: core: Signal WRITE residuals
2020-12-03 8:20 [RESEND PATCH 0/3] scsi: target: Set correct residual data Anastasia Kovaleva
2020-12-03 8:20 ` [RESEND PATCH 1/3] scsi: target: core: Set residuals for 4Kn devices Anastasia Kovaleva
@ 2020-12-03 8:20 ` Anastasia Kovaleva
2020-12-03 8:20 ` [RESEND PATCH 3/3] scsi: target: core: Change ASCQ for residual write Anastasia Kovaleva
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Anastasia Kovaleva @ 2020-12-03 8:20 UTC (permalink / raw)
To: martin.petersen
Cc: target-devel, linux-scsi, linux, Anastasia Kovaleva, Roman Bolshakov
According to RFC 7143 11.4.5.2.:
If SPDTL > EDTL for a task, iSCSI Overflow MUST be signaled in the
SCSI Response PDU as specified in Section 11.4.5.1. The Residual
Count MUST be set to the numerical value of (SPDTL - EDTL).
If SPDTL < EDTL for a task, iSCSI Underflow MUST be signaled in the
SCSI Response PDU as specified in Section 11.4.5.1. The Residual
Count MUST be set to the numerical value of (EDTL - SPDTL).
libiscsi has residual write tests that check residual kind and residual
amount and all of them (Write10Residuals, Write12Residuals,
Write16Residuals) currently fail.
One of the reasons why they fail is because target completes write
commands with INVALID FIELD IN CDB before setting the Overflow/Underflow
bit and residual amount.
Set the Overflow/Underflow bit and the residual amount before failing a
write to comply with RFC 7143.
Signed-off-by: Anastasia Kovaleva <a.kovaleva@yadro.com>
Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
---
drivers/target/target_core_transport.c | 34 +++++++++++++++-----------
1 file changed, 20 insertions(+), 14 deletions(-)
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index f27a7d6cc1e0..eb51298cab4f 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -1313,6 +1313,26 @@ target_cmd_size_check(struct se_cmd *cmd, unsigned int size)
" %u does not match SCSI CDB Length: %u for SAM Opcode:"
" 0x%02x\n", cmd->se_tfo->fabric_name,
cmd->data_length, size, cmd->t_task_cdb[0]);
+ /*
+ * For READ command for the overflow case keep the existing
+ * fabric provided ->data_length. Otherwise for the underflow
+ * case, reset ->data_length to the smaller SCSI expected data
+ * transfer length.
+ */
+ if (size > cmd->data_length) {
+ cmd->se_cmd_flags |= SCF_OVERFLOW_BIT;
+ cmd->residual_count = (size - cmd->data_length);
+ } else {
+ cmd->se_cmd_flags |= SCF_UNDERFLOW_BIT;
+ cmd->residual_count = (cmd->data_length - size);
+ /*
+ * Do not truncate ->data_length for WRITE command to
+ * dump all payload
+ */
+ if (cmd->data_direction == DMA_FROM_DEVICE) {
+ cmd->data_length = size;
+ }
+ }
if (cmd->data_direction == DMA_TO_DEVICE) {
if (cmd->se_cmd_flags & SCF_SCSI_DATA_CDB) {
@@ -1332,20 +1352,6 @@ target_cmd_size_check(struct se_cmd *cmd, unsigned int size)
return TCM_INVALID_CDB_FIELD;
}
}
- /*
- * For the overflow case keep the existing fabric provided
- * ->data_length. Otherwise for the underflow case, reset
- * ->data_length to the smaller SCSI expected data transfer
- * length.
- */
- if (size > cmd->data_length) {
- cmd->se_cmd_flags |= SCF_OVERFLOW_BIT;
- cmd->residual_count = (size - cmd->data_length);
- } else {
- cmd->se_cmd_flags |= SCF_UNDERFLOW_BIT;
- cmd->residual_count = (cmd->data_length - size);
- cmd->data_length = size;
- }
}
return target_check_max_data_sg_nents(cmd, dev, size);
--
2.24.3 (Apple Git-128)
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [RESEND PATCH 3/3] scsi: target: core: Change ASCQ for residual write
2020-12-03 8:20 [RESEND PATCH 0/3] scsi: target: Set correct residual data Anastasia Kovaleva
2020-12-03 8:20 ` [RESEND PATCH 1/3] scsi: target: core: Set residuals for 4Kn devices Anastasia Kovaleva
2020-12-03 8:20 ` [RESEND PATCH 2/3] scsi: target: core: Signal WRITE residuals Anastasia Kovaleva
@ 2020-12-03 8:20 ` Anastasia Kovaleva
2021-01-21 15:24 ` [RESEND PATCH 0/3] scsi: target: Set correct residual data Anastasia Kovaleva
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Anastasia Kovaleva @ 2020-12-03 8:20 UTC (permalink / raw)
To: martin.petersen
Cc: target-devel, linux-scsi, linux, Anastasia Kovaleva, Roman Bolshakov
According to FCP-4 (9.4.2):
If the command requested that data beyond the length specified by the
FCP_DL field be transferred, then the device server shall set the
FCP_RESID_OVER bit (see 9.5.8) to one in the FCP_RSP IU and:
a) process the command normally except that data beyond the FCP_DL
count shall not be requested or transferred;
b) transfer no data and return CHECK CONDITION status with the sense
key set to ILLEGAL REQUEST and the additional sense code set to INVALID
FIELD IN COMMAND INFORMATION UNIT; or
c) may transfer data and return CHECK CONDITION status with the sense
key set to ABORTED COMMAND and the additional sense code set to
INVALID FIELD IN COMMAND INFORMATION UNIT.
TCM follows b) and transfers no data for residual writes but returns
INVALID FIELD IN CDB instead of INVALID FIELD IN COMMAND INFORMATION
UNIT.
Change the ASCQ to INVALID FIELD IN COMMAND INFORMATION UNIT to meet the
standart.
Signed-off-by: Anastasia Kovaleva <a.kovaleva@yadro.com>
Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
---
drivers/target/target_core_transport.c | 8 +++++++-
include/target/target_core_base.h | 1 +
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index eb51298cab4f..94cee131f5b7 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -1338,7 +1338,7 @@ target_cmd_size_check(struct se_cmd *cmd, unsigned int size)
if (cmd->se_cmd_flags & SCF_SCSI_DATA_CDB) {
pr_err_ratelimited("Rejecting underflow/overflow"
" for WRITE data CDB\n");
- return TCM_INVALID_CDB_FIELD;
+ return TCM_INVALID_FIELD_IN_COMMAND_IU;
}
/*
* Some fabric drivers like iscsi-target still expect to
@@ -1879,6 +1879,7 @@ void transport_generic_request_failure(struct se_cmd *cmd,
case TCM_UNSUPPORTED_TARGET_DESC_TYPE_CODE:
case TCM_TOO_MANY_SEGMENT_DESCS:
case TCM_UNSUPPORTED_SEGMENT_DESC_TYPE_CODE:
+ case TCM_INVALID_FIELD_IN_COMMAND_IU:
break;
case TCM_OUT_OF_RESOURCES:
cmd->scsi_status = SAM_STAT_TASK_SET_FULL;
@@ -3205,6 +3206,11 @@ static const struct sense_detail sense_detail_table[] = {
.asc = 0x55,
.ascq = 0x04, /* INSUFFICIENT REGISTRATION RESOURCES */
},
+ [TCM_INVALID_FIELD_IN_COMMAND_IU] = {
+ .key = ILLEGAL_REQUEST,
+ .asc = 0x0e,
+ .ascq = 0x03, /* INVALID FIELD IN COMMAND INFORMATION UNIT */
+ },
};
/**
diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
index 63dd12124139..54dcc0eb25fa 100644
--- a/include/target/target_core_base.h
+++ b/include/target/target_core_base.h
@@ -187,6 +187,7 @@ enum tcm_sense_reason_table {
TCM_UNSUPPORTED_SEGMENT_DESC_TYPE_CODE = R(0x1c),
TCM_INSUFFICIENT_REGISTRATION_RESOURCES = R(0x1d),
TCM_LUN_BUSY = R(0x1e),
+ TCM_INVALID_FIELD_IN_COMMAND_IU = R(0x1f),
#undef R
};
--
2.24.3 (Apple Git-128)
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [RESEND PATCH 0/3] scsi: target: Set correct residual data
2020-12-03 8:20 [RESEND PATCH 0/3] scsi: target: Set correct residual data Anastasia Kovaleva
` (2 preceding siblings ...)
2020-12-03 8:20 ` [RESEND PATCH 3/3] scsi: target: core: Change ASCQ for residual write Anastasia Kovaleva
@ 2021-01-21 15:24 ` Anastasia Kovaleva
2021-01-27 4:12 ` Martin K. Petersen
2021-01-29 19:01 ` Martin K. Petersen
5 siblings, 0 replies; 7+ messages in thread
From: Anastasia Kovaleva @ 2021-01-21 15:24 UTC (permalink / raw)
To: martin.petersen; +Cc: target-devel, linux-scsi, linux
Hi,
Could you please tell me if there are any objections to these changes?
These patches are applicable to 5.12/scsi-queue.
Thanks,
Anastasia
On 03.12.2020, 11:21, "Anastasia Kovaleva" <a.kovaleva@yadro.com> wrote:
Hi Martin,
Please apply the changes to 5.11/scsi-queue at your earliest
convenience.
The series changes the behavior of the target in regard to processing
commands with overflow/underflow in accordance with the standarts.
The target driver used to process the DMA_TO_DEVICE commands with
residuals (in particular, WRITE command) incorrectly. The target
response contained neither a residual count, nor an OVERFLOW/UNDERFLOW
bit. Such behavior did not comply with the RFC 7143. Also the
returned ASC and ASCQ were incorrect according to FCP-4,
and residuals were not set for the 4Kn devices.
This patches fix the major inconsistances in processing these kind of
commands.
This patch series has been tested with a modified libiscsi testing
library.
The link to the pull request:
https://github.com/sahlberg/libiscsi/pull/345
Write10Residuals, Write12Residuals, Write16Residuals tests have passed.
Thanks,
Anastasia
Anastasia Kovaleva (2):
scsi: target: core: Signal WRITE residuals
scsi: target: core: Change ASCQ for residual write
Roman Bolshakov (1):
scsi: target: core: Set residuals for 4Kn devices
drivers/target/target_core_transport.c | 53 +++++++++++++-------------
include/target/target_core_base.h | 1 +
2 files changed, 28 insertions(+), 26 deletions(-)
--
2.24.3 (Apple Git-128)
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RESEND PATCH 0/3] scsi: target: Set correct residual data
2020-12-03 8:20 [RESEND PATCH 0/3] scsi: target: Set correct residual data Anastasia Kovaleva
` (3 preceding siblings ...)
2021-01-21 15:24 ` [RESEND PATCH 0/3] scsi: target: Set correct residual data Anastasia Kovaleva
@ 2021-01-27 4:12 ` Martin K. Petersen
2021-01-29 19:01 ` Martin K. Petersen
5 siblings, 0 replies; 7+ messages in thread
From: Martin K. Petersen @ 2021-01-27 4:12 UTC (permalink / raw)
To: Anastasia Kovaleva; +Cc: martin.petersen, target-devel, linux-scsi, linux
Anastasia,
> The series changes the behavior of the target in regard to processing
> commands with overflow/underflow in accordance with the standarts.
Applied to 5.12/scsi-staging, thanks!
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RESEND PATCH 0/3] scsi: target: Set correct residual data
2020-12-03 8:20 [RESEND PATCH 0/3] scsi: target: Set correct residual data Anastasia Kovaleva
` (4 preceding siblings ...)
2021-01-27 4:12 ` Martin K. Petersen
@ 2021-01-29 19:01 ` Martin K. Petersen
5 siblings, 0 replies; 7+ messages in thread
From: Martin K. Petersen @ 2021-01-29 19:01 UTC (permalink / raw)
To: Anastasia Kovaleva; +Cc: Martin K . Petersen, target-devel, linux, linux-scsi
On Thu, 3 Dec 2020 11:20:32 +0300, Anastasia Kovaleva wrote:
> Please apply the changes to 5.11/scsi-queue at your earliest
> convenience.
>
> The series changes the behavior of the target in regard to processing
> commands with overflow/underflow in accordance with the standarts.
>
> The target driver used to process the DMA_TO_DEVICE commands with
> residuals (in particular, WRITE command) incorrectly. The target
> response contained neither a residual count, nor an OVERFLOW/UNDERFLOW
> bit. Such behavior did not comply with the RFC 7143. Also the
> returned ASC and ASCQ were incorrect according to FCP-4,
> and residuals were not set for the 4Kn devices.
>
> [...]
Applied to 5.12/scsi-queue, thanks!
[1/3] scsi: target: core: Set residuals for 4Kn devices
https://git.kernel.org/mkp/scsi/c/eb90e45542b5
[2/3] scsi: target: core: Signal WRITE residuals
https://git.kernel.org/mkp/scsi/c/cc0b6ad72e18
[3/3] scsi: target: core: Change ASCQ for residual write
https://git.kernel.org/mkp/scsi/c/ead0ffc95a89
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-01-29 19:04 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-03 8:20 [RESEND PATCH 0/3] scsi: target: Set correct residual data Anastasia Kovaleva
2020-12-03 8:20 ` [RESEND PATCH 1/3] scsi: target: core: Set residuals for 4Kn devices Anastasia Kovaleva
2020-12-03 8:20 ` [RESEND PATCH 2/3] scsi: target: core: Signal WRITE residuals Anastasia Kovaleva
2020-12-03 8:20 ` [RESEND PATCH 3/3] scsi: target: core: Change ASCQ for residual write Anastasia Kovaleva
2021-01-21 15:24 ` [RESEND PATCH 0/3] scsi: target: Set correct residual data Anastasia Kovaleva
2021-01-27 4:12 ` Martin K. Petersen
2021-01-29 19:01 ` 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).