All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHv2] scsi: core: set result when the command cannot be dispatched
       [not found] <1554854375-7708-1-git-send-email-jalee@purestorage.com>
@ 2019-04-10  0:02 ` Jaesoo Lee
  2019-04-10  5:58   ` Hannes Reinecke
                     ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jaesoo Lee @ 2019-04-10  0:02 UTC (permalink / raw)
  To: Bart Van Assche, James E.J. Bottomley, Martin K. Petersen,
	Jens Axboe, Douglas Gilbert
  Cc: linux-block, linux-scsi, Roland Dreier

When SCSI blk-mq is enabled, there is a bug in handling errors in scsi_queue_rq.
Specifically, the bug is not setting result field of scsi_request correctly when
the dispatch of the command has been failed. Since the upper layer code
including the sg_io ioctl expects to receive any error status from result field
of scsi_request, the error is silently ignored and this could cause data
corruptions for some applications.

Signed-off-by: Jaesoo Lee <jalee@purestorage.com>
---
 drivers/scsi/scsi_lib.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 2018967..dc2550c 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -1699,8 +1699,12 @@ static blk_status_t scsi_queue_rq(struct
blk_mq_hw_ctx *hctx,
                        ret = BLK_STS_DEV_RESOURCE;
                break;
        default:
+               if (unlikely(!scsi_device_online(sdev)))
+                       scsi_req(req)->result = DID_NO_CONNECT << 16;
+               else
+                       scsi_req(req)->result = DID_ERROR << 16;
                /*
-                * Make sure to release all allocated ressources when
+                * Make sure to release all allocated resources when
                 * we hit an error, as we will never see this command
                 * again.
                 */
--
2.7.4

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

* Re: [PATCHv2] scsi: core: set result when the command cannot be dispatched
  2019-04-10  0:02 ` [PATCHv2] scsi: core: set result when the command cannot be dispatched Jaesoo Lee
@ 2019-04-10  5:58   ` Hannes Reinecke
  2019-04-10 16:26   ` Bart Van Assche
  2019-04-16  2:36   ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Hannes Reinecke @ 2019-04-10  5:58 UTC (permalink / raw)
  To: Jaesoo Lee, Bart Van Assche, James E.J. Bottomley,
	Martin K. Petersen, Jens Axboe, Douglas Gilbert
  Cc: linux-block, linux-scsi, Roland Dreier

On 4/10/19 2:02 AM, Jaesoo Lee wrote:
> When SCSI blk-mq is enabled, there is a bug in handling errors in scsi_queue_rq.
> Specifically, the bug is not setting result field of scsi_request correctly when
> the dispatch of the command has been failed. Since the upper layer code
> including the sg_io ioctl expects to receive any error status from result field
> of scsi_request, the error is silently ignored and this could cause data
> corruptions for some applications.
> 
> Signed-off-by: Jaesoo Lee <jalee@purestorage.com>
> ---
>   drivers/scsi/scsi_lib.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
> index 2018967..dc2550c 100644
> --- a/drivers/scsi/scsi_lib.c
> +++ b/drivers/scsi/scsi_lib.c
> @@ -1699,8 +1699,12 @@ static blk_status_t scsi_queue_rq(struct
> blk_mq_hw_ctx *hctx,
>                          ret = BLK_STS_DEV_RESOURCE;
>                  break;
>          default:
> +               if (unlikely(!scsi_device_online(sdev)))
> +                       scsi_req(req)->result = DID_NO_CONNECT << 16;
> +               else
> +                       scsi_req(req)->result = DID_ERROR << 16;
>                  /*
> -                * Make sure to release all allocated ressources when
> +                * Make sure to release all allocated resources when
>                   * we hit an error, as we will never see this command
>                   * again.
>                   */
> --
> 2.7.4
> 
Reviewed-by: Hannes Reinecke <hare@suse.com>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		   Teamlead Storage & Networking
hare@suse.de			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Mary Higgins, Sri Rasiah
HRB 21284 (AG Nürnberg)

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

* Re: [PATCHv2] scsi: core: set result when the command cannot be dispatched
  2019-04-10  0:02 ` [PATCHv2] scsi: core: set result when the command cannot be dispatched Jaesoo Lee
  2019-04-10  5:58   ` Hannes Reinecke
@ 2019-04-10 16:26   ` Bart Van Assche
  2019-04-16  2:36   ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Bart Van Assche @ 2019-04-10 16:26 UTC (permalink / raw)
  To: Jaesoo Lee, James E.J. Bottomley, Martin K. Petersen, Jens Axboe,
	Douglas Gilbert
  Cc: linux-block, linux-scsi, Roland Dreier

On Tue, 2019-04-09 at 17:02 -0700, Jaesoo Lee wrote:
> When SCSI blk-mq is enabled, there is a bug in handling errors in scsi_queue_rq.
> Specifically, the bug is not setting result field of scsi_request correctly when
> the dispatch of the command has been failed. Since the upper layer code
> including the sg_io ioctl expects to receive any error status from result field
> of scsi_request, the error is silently ignored and this could cause data
> corruptions for some applications.
> 
> Signed-off-by: Jaesoo Lee <jalee@purestorage.com>
> ---
>  drivers/scsi/scsi_lib.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
> index 2018967..dc2550c 100644
> --- a/drivers/scsi/scsi_lib.c
> +++ b/drivers/scsi/scsi_lib.c
> @@ -1699,8 +1699,12 @@ static blk_status_t scsi_queue_rq(struct
> blk_mq_hw_ctx *hctx,
>                         ret = BLK_STS_DEV_RESOURCE;
>                 break;
>         default:
> +               if (unlikely(!scsi_device_online(sdev)))
> +                       scsi_req(req)->result = DID_NO_CONNECT << 16;
> +               else
> +                       scsi_req(req)->result = DID_ERROR << 16;
>                 /*
> -                * Make sure to release all allocated ressources when
> +                * Make sure to release all allocated resources when
>                  * we hit an error, as we will never see this command
>                  * again.
>                  */

Should "Fixes:" and "Cc: stable" tags be added to this patch?

Anyway:

Reviewed-by: Bart Van Assche <bvanassche@acm.org>



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

* Re: [PATCHv2] scsi: core: set result when the command cannot be dispatched
  2019-04-10  0:02 ` [PATCHv2] scsi: core: set result when the command cannot be dispatched Jaesoo Lee
  2019-04-10  5:58   ` Hannes Reinecke
  2019-04-10 16:26   ` Bart Van Assche
@ 2019-04-16  2:36   ` Martin K. Petersen
  2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2019-04-16  2:36 UTC (permalink / raw)
  To: Jaesoo Lee
  Cc: Bart Van Assche, James E.J. Bottomley, Martin K. Petersen,
	Jens Axboe, Douglas Gilbert, linux-block, linux-scsi,
	Roland Dreier


Jaesoo,

> When SCSI blk-mq is enabled, there is a bug in handling errors in
> scsi_queue_rq.  Specifically, the bug is not setting result field of
> scsi_request correctly when the dispatch of the command has been
> failed. Since the upper layer code including the sg_io ioctl expects
> to receive any error status from result field of scsi_request, the
> error is silently ignored and this could cause data corruptions for
> some applications.

Applied to 5.1/scsi-fixes, thank you!

-- 
Martin K. Petersen	Oracle Linux Engineering

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

end of thread, other threads:[~2019-04-16  2:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1554854375-7708-1-git-send-email-jalee@purestorage.com>
2019-04-10  0:02 ` [PATCHv2] scsi: core: set result when the command cannot be dispatched Jaesoo Lee
2019-04-10  5:58   ` Hannes Reinecke
2019-04-10 16:26   ` Bart Van Assche
2019-04-16  2:36   ` Martin K. Petersen

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.