From: Ming Lei <ming.lei@redhat.com>
To: Yufen Yu <yuyufen@huawei.com>
Cc: josef@toxicpanda.com, axboe@kernel.dk,
linux-block@vger.kernel.org, nbd@other.debian.org,
Christoph Hellwig <hch@lst.de>
Subject: Re: [PATCH] nbd: make starting request more reasonable
Date: Mon, 16 Mar 2020 23:30:33 +0800 [thread overview]
Message-ID: <20200316153033.GA11016@ming.t460p> (raw)
In-Reply-To: <9cdba8b1-f0e5-a079-8d44-0078478dd4d8@huawei.com>
On Mon, Mar 16, 2020 at 08:26:35PM +0800, Yufen Yu wrote:
> Ping and Cc to more expert in blk-mq.
>
> On 2020/3/3 21:08, Yufen Yu wrote:
> > Our test robot reported a warning for refcount_dec trying to decrease
> > value '0'. The reason is that blk_mq_dispatch_rq_list() try to complete
> > the failed request from nbd driver, while the request have finished in
> > nbd timeout handle function. The race as following:
> >
> > CPU1 CPU2
> >
> > //req->ref = 1
> > blk_mq_dispatch_rq_list
> > nbd_queue_rq
> > nbd_handle_cmd
> > blk_mq_start_request
> > blk_mq_check_expired
> > //req->ref = 2
> > blk_mq_rq_timed_out
> > nbd_xmit_timeout
This shouldn't happen in reality, given rq->deadline is just updated
in blk_mq_start_request(), suppose you use the default 30 sec timeout.
How can the race be triggered in so short time?
Could you explain a bit your test case?
> > blk_mq_complete_request
> > //req->ref = 1
> > refcount_dec_and_test(&req->ref)
> >
> > refcount_dec_and_test(&req->ref)
> > //req->ref = 0
> > __blk_mq_free_request(req)
> > ret = BLK_STS_IOERR
> > blk_mq_end_request
> > // req->ref = 0, req have been free
> > refcount_dec_and_test(&rq->ref)
> >
> > In fact, the bug also have been reported by syzbot:
> > https://lkml.org/lkml/2018/12/5/1308
> >
> > Since the request have been freed by timeout handle, it can be reused
> > by others. Then, blk_mq_end_request() may get the re-initialized request
> > and free it, which is unexpected.
> >
> > To fix the problem, we move blk_mq_start_request() down until the driver
> > will handle the request actully. If .queue_rq return something error in
> > preparation phase, timeout handle may don't need. Thus, moving start
> > request down may be more reasonable. Then, nbd_queue_rq() will not return
> > BLK_STS_IOERR after starting request.
> >
> > Reported-by: Hulk Robot <hulkci@huawei.com>
> > Signed-off-by: Yufen Yu <yuyufen@huawei.com>
> > ---
> > drivers/block/nbd.c | 6 ++----
> > 1 file changed, 2 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
> > index 78181908f0df..5256e9d02a03 100644
> > --- a/drivers/block/nbd.c
> > +++ b/drivers/block/nbd.c
> > @@ -541,6 +541,8 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
> > return -EIO;
> > }
> > + blk_mq_start_request(req);
> > +
> > if (req->cmd_flags & REQ_FUA)
> > nbd_cmd_flags |= NBD_CMD_FLAG_FUA;
> > @@ -879,7 +881,6 @@ static int nbd_handle_cmd(struct nbd_cmd *cmd, int index)
> > if (!refcount_inc_not_zero(&nbd->config_refs)) {
> > dev_err_ratelimited(disk_to_dev(nbd->disk),
> > "Socks array is empty\n");
> > - blk_mq_start_request(req);
I think it is fine to not start request in case of failure, given
__blk_mq_end_request() doesn't check rq's state.
Thanks,
Ming
next prev parent reply other threads:[~2020-03-16 15:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-03 13:08 [PATCH] nbd: make starting request more reasonable Yufen Yu
2020-03-03 21:18 ` Josef Bacik
2020-03-04 2:10 ` Yufen Yu
2020-03-16 12:26 ` Yufen Yu
2020-03-16 15:30 ` Ming Lei [this message]
2020-03-16 16:02 ` Keith Busch
2020-03-17 2:41 ` Ming Lei
2020-03-23 14:08 ` Yufen Yu
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=20200316153033.GA11016@ming.t460p \
--to=ming.lei@redhat.com \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=josef@toxicpanda.com \
--cc=linux-block@vger.kernel.org \
--cc=nbd@other.debian.org \
--cc=yuyufen@huawei.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