linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Joseph Qi <jiangqi903@gmail.com>
Cc: Jens Axboe <axboe@kernel.dk>,
	linux-block@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
	Bart Van Assche <bvanassche@acm.org>,
	John Garry <john.garry@huawei.com>,
	"Blank-Burian, Markus, Dr." <blankburian@uni-muenster.de>,
	Yufen Yu <yuyufen@huawei.com>
Subject: Re: [PATCH] blk-mq: fix is_flush_rq
Date: Mon, 23 Aug 2021 20:50:08 +0800	[thread overview]
Message-ID: <YSOZgPtd4xkeAzeI@T590> (raw)
In-Reply-To: <ae6c32cc-0bd1-601a-559e-8d6e2578f0ec@gmail.com>

On Mon, Aug 23, 2021 at 08:42:45PM +0800, Joseph Qi wrote:
> Hi Ming,
> 
> On 8/18/21 9:09 AM, Ming Lei wrote:
> > is_flush_rq() is called from bt_iter()/bt_tags_iter(), and runs the
> > following check:
> > 
> > 	hctx->fq->flush_rq == req
> > 
> > but the passed hctx from bt_iter()/bt_tags_iter() may be NULL because:
> > 
> > 1) memory re-order in blk_mq_rq_ctx_init():
> > 
> > 	rq->mq_hctx = data->hctx;
> > 	...
> > 	refcount_set(&rq->ref, 1);
> > 
> > OR
> > 
> > 2) tag re-use and ->rqs[] isn't updated with new request.
> > 
> > Fix the issue by re-writing is_flush_rq() as:
> > 
> > 	return rq->end_io == flush_end_io;
> > 
> > which turns out simpler to follow and immune to data race since we have
> > ordered WRITE rq->end_io and refcount_set(&rq->ref, 1).
> > 
> Recently we've run into a similar crash due to NULL rq->mq_hctx in
> blk_mq_put_rq_ref() on ARM, and it is a normal write request.
> Since memory reorder truly exists, we may also risk other uninitialized
> member accessing after this commit, at least we have to be more careful
> in busy_iter_fn...
> So here you don't use memory barrier before refcount_set() is for
> performance consideration?

Yes, also it is much simpler to check ->end_io in concept.


Thanks,
Ming


      reply	other threads:[~2021-08-23 12:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-18  1:09 [PATCH] blk-mq: fix is_flush_rq Ming Lei
2021-08-18  2:18 ` Jens Axboe
2021-08-18  3:02 ` Bart Van Assche
2021-08-18  3:31   ` Ming Lei
2021-08-23 12:42 ` Joseph Qi
2021-08-23 12:50   ` Ming Lei [this message]

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=YSOZgPtd4xkeAzeI@T590 \
    --to=ming.lei@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=blankburian@uni-muenster.de \
    --cc=bvanassche@acm.org \
    --cc=hch@lst.de \
    --cc=jiangqi903@gmail.com \
    --cc=john.garry@huawei.com \
    --cc=linux-block@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).