From: Bodo Stroesser <bostroesser@gmail.com>
To: a.miloserdov@yadro.com, target-devel@vger.kernel.org
Cc: linux-scsi@vger.kernel.org, martin.petersen@oracle.com,
r.bolshakov@yadro.com
Subject: Re: [PATCH 1/2] scsi: target: core: Add cmd length set before cmd complete
Date: Tue, 9 Feb 2021 18:30:59 +0100 [thread overview]
Message-ID: <e1cc56b8-bdbb-b2fd-91ef-a7bd24fbb465@gmail.com> (raw)
In-Reply-To: <20210209072202.41154-2-a.miloserdov@yadro.com>
On 09.02.21 08:22, Aleksandr Miloserdov wrote:
> 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.
>
> Signed-off-by: Aleksandr Miloserdov <a.miloserdov@yadro.com>
> Reviewed-by: Roman Bolshakov <r.bolshakov@yadro.com>
> ---
> drivers/target/target_core_transport.c | 15 +++++++++++----
> include/target/target_core_backend.h | 1 +
> 2 files changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
> index fca4bd079d02..c98540355512 100644
> --- a/drivers/target/target_core_transport.c
> +++ b/drivers/target/target_core_transport.c
> @@ -879,11 +879,9 @@ void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status)
> }
> EXPORT_SYMBOL(target_complete_cmd);
>
> -void target_complete_cmd_with_length(struct se_cmd *cmd, u8 scsi_status, int length)
> +void target_set_cmd_data_length(struct se_cmd *cmd, int length)
> {
> - if ((scsi_status == SAM_STAT_GOOD ||
> - cmd->se_cmd_flags & SCF_TREAT_READ_AS_NORMAL) &&
> - length < cmd->data_length) {
> + if (length < cmd->data_length) {
> if (cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) {
> cmd->residual_count += cmd->data_length - length;
> } else {
> @@ -893,6 +891,15 @@ void target_complete_cmd_with_length(struct se_cmd *cmd, u8 scsi_status, int len
>
> cmd->data_length = length;
> }
> +}
> +EXPORT_SYMBOL(target_set_cmd_data_length);
> +
> +void target_complete_cmd_with_length(struct se_cmd *cmd, u8 scsi_status, int length)
> +{
> + if (scsi_status == SAM_STAT_GOOD ||
> + cmd->se_cmd_flags & SCF_TREAT_READ_AS_NORMAL) {
> + target_set_cmd_data_length(cmd, length);
> + }
>
> target_complete_cmd(cmd, scsi_status);
> }
> diff --git a/include/target/target_core_backend.h b/include/target/target_core_backend.h
> index 6336780d83a7..ce2fba49c95d 100644
> --- a/include/target/target_core_backend.h
> +++ b/include/target/target_core_backend.h
> @@ -72,6 +72,7 @@ int transport_backend_register(const struct target_backend_ops *);
> 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_length(struct se_cmd *, u8, int);
>
> void transport_copy_sense_to_cmd(struct se_cmd *, unsigned char *);
>
Looks ok to me.
Reviewed-by: Bodo Stroesser <bostroesser@gmail.com>
next prev parent reply other threads:[~2021-02-09 17:32 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-09 7:22 [PATCH 0/2] Fix target not properly truncating command data length Aleksandr Miloserdov
2021-02-09 7:22 ` [PATCH 1/2] scsi: target: core: Add cmd length set before cmd complete Aleksandr Miloserdov
2021-02-09 17:30 ` Bodo Stroesser [this message]
2021-02-09 7:22 ` [PATCH 2/2] scsi: target: core: Prevent underflow for service actions Aleksandr Miloserdov
2021-02-09 17:31 ` Bodo Stroesser
2021-02-23 3:22 ` [PATCH 0/2] Fix target not properly truncating command data length Martin K. Petersen
2021-02-26 2:22 ` 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=e1cc56b8-bdbb-b2fd-91ef-a7bd24fbb465@gmail.com \
--to=bostroesser@gmail.com \
--cc=a.miloserdov@yadro.com \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=r.bolshakov@yadro.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox