Skip to content

Commit 17c2c52

Browse files
Aleksandr Miloserdovgregkh
authored andcommitted
scsi: target: core: Add cmd length set before cmd complete
[ Upstream commit 1c73e0c ] TCM doesn't properly handle underflow case for service actions. One way to prevent it is to always complete command with target_complete_cmd_with_length(), however it requires access to data_sg, which is not always available. This change introduces target_set_cmd_data_length() function which allows to set command data length before completing it. Link: https://lore.kernel.org/r/20210209072202.41154-2-a.miloserdov@yadro.com Reviewed-by: Roman Bolshakov <r.bolshakov@yadro.com> Reviewed-by: Bodo Stroesser <bostroesser@gmail.com> Signed-off-by: Aleksandr Miloserdov <a.miloserdov@yadro.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 79b4fdd commit 17c2c52

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

‎drivers/target/target_core_transport.c‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -873,11 +873,9 @@ void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status)
873873
}
874874
EXPORT_SYMBOL(target_complete_cmd);
875875

876-
void target_complete_cmd_with_length(struct se_cmd *cmd, u8 scsi_status, int length)
876+
void target_set_cmd_data_length(struct se_cmd *cmd, int length)
877877
{
878-
if ((scsi_status == SAM_STAT_GOOD ||
879-
cmd->se_cmd_flags & SCF_TREAT_READ_AS_NORMAL) &&
880-
length < cmd->data_length) {
878+
if (length < cmd->data_length) {
881879
if (cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) {
882880
cmd->residual_count += cmd->data_length - length;
883881
} else {
@@ -887,6 +885,15 @@ void target_complete_cmd_with_length(struct se_cmd *cmd, u8 scsi_status, int len
887885

888886
cmd->data_length = length;
889887
}
888+
}
889+
EXPORT_SYMBOL(target_set_cmd_data_length);
890+
891+
void target_complete_cmd_with_length(struct se_cmd *cmd, u8 scsi_status, int length)
892+
{
893+
if (scsi_status == SAM_STAT_GOOD ||
894+
cmd->se_cmd_flags & SCF_TREAT_READ_AS_NORMAL) {
895+
target_set_cmd_data_length(cmd, length);
896+
}
890897

891898
target_complete_cmd(cmd, scsi_status);
892899
}

‎include/target/target_core_backend.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ int transport_backend_register(const struct target_backend_ops *);
7272
void target_backend_unregister(const struct target_backend_ops *);
7373

7474
void target_complete_cmd(struct se_cmd *, u8);
75+
void target_set_cmd_data_length(struct se_cmd *, int);
7576
void target_complete_cmd_with_length(struct se_cmd *, u8, int);
7677

7778
void transport_copy_sense_to_cmd(struct se_cmd *, unsigned char *);

0 commit comments

Comments
 (0)