From: Bart Van Assche <bvanassche@acm.org>
To: Jaesoo Lee <jalee@purestorage.com>
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
Jens Axboe <axboe@kernel.dk>,
Douglas Gilbert <dgilbert@interlog.com>,
linux-scsi@vger.kernel.org, linux-block@vger.kernel.org,
Roland Dreier <roland@purestorage.com>
Subject: Re: [PATCH] scsi: core: set result when the command cannot be dispatched
Date: Tue, 09 Apr 2019 16:44:59 -0700 [thread overview]
Message-ID: <1554853499.161891.22.camel@acm.org> (raw)
In-Reply-To: <CAJX3Cti2+3Wnn=pbkc9s-xgxCVw9q3EHPG04Yfasv50r=7ppQQ@mail.gmail.com>
On Tue, 2019-04-09 at 16:29 -0700, Jaesoo Lee wrote:
> Let me comment in line.
>
> On Tue, Apr 9, 2019 at 3:14 PM Bart Van Assche <bvanassche@acm.org> wrote:
> >
> > On Tue, 2019-04-09 at 14:53 -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. This commit also fixes another bug that the
> > > result field is not initialized when scsi_request is allocated.
> > >
> > > Signed-off-by: Jaesoo Lee <jalee@purestorage.com>
> > > ---
> > > block/scsi_ioctl.c | 1 +
> > > drivers/scsi/scsi_lib.c | 1 +
> > > 2 files changed, 2 insertions(+)
> > >
> > > diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
> > > index 533f4ae..f2d7979 100644
> > > --- a/block/scsi_ioctl.c
> > > +++ b/block/scsi_ioctl.c
> > > @@ -723,6 +723,7 @@ void scsi_req_init(struct scsi_request *req)
> > > req->cmd = req->__cmd;
> > > req->cmd_len = BLK_MAX_CDB;
> > > req->sense_len = 0;
> > > + req->result = 0;
> > > }
> > > EXPORT_SYMBOL(scsi_req_init);
> >
> > What makes you think that this assignment is necessary?
> >
>
> Actually, I discovered this before fixing this bug and we might not
> see this problem anymore once this bug is fixed.
>
> Previously, since we are not setting scsi_req(req)->result in
> scsi_queue_rq, I found that the application could receive another
> DID_TRANSPORT_DISRUPTED host_status again if the same 'struct request'
> is allocated for the IO.
>
> Please let me know if I need to remove this change.
Since SCSI LLDs have to set that result variable anyway if a request
completes successfully I'd prefer not to add that assignment.
> > > diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
> > > index 2018967..af1488d 100644
> > > --- a/drivers/scsi/scsi_lib.c
> > > +++ b/drivers/scsi/scsi_lib.c
> > > @@ -1699,6 +1699,7 @@ static blk_status_t scsi_queue_rq(struct
> > > blk_mq_hw_ctx *hctx,
> > > ret = BLK_STS_DEV_RESOURCE;
> > > break;
> > > default:
> > > + scsi_req(req)->result = DID_NO_CONNECT << 16;
> > > /*
> > > * Make sure to release all allocated ressources when
> > > * we hit an error, as we will never see this command
> >
> > What leads you to the conclusion that (ret != BLK_STS_OK &&
> > ret != BLK_STS_RESOUCE) means that there is a connectivity issue?
>
> I found this is what we are doing for legacy queue case; I referred to
> scsi_prep_return() and scsi_kill_request() code where we always
> returning DID_NO_CONNECT.
>
> However, I think proper return code handling should be something like:
>
> diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
> index 2018967..21e516e 100644
> --- a/drivers/scsi/scsi_lib.c
> +++ b/drivers/scsi/scsi_lib.c
> @@ -1699,6 +1699,10 @@ 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
> * we hit an error, as we will never see this command
The above looks better to me than the original patch.
Thanks,
Bart.
next prev parent reply other threads:[~2019-04-09 23:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1554846371-33660-1-git-send-email-jalee@purestorage.com>
2019-04-09 21:53 ` [PATCH] scsi: core: set result when the command cannot be dispatched Jaesoo Lee
2019-04-09 21:57 ` Jaesoo Lee
2019-04-09 22:14 ` Bart Van Assche
2019-04-09 23:29 ` Jaesoo Lee
2019-04-09 23:44 ` Bart Van Assche [this message]
2019-04-10 0:02 ` Jaesoo Lee
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=1554853499.161891.22.camel@acm.org \
--to=bvanassche@acm.org \
--cc=axboe@kernel.dk \
--cc=dgilbert@interlog.com \
--cc=jalee@purestorage.com \
--cc=jejb@linux.ibm.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=roland@purestorage.com \
/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