From: Ming Lei <ming.lei@redhat.com>
To: Keith Busch <kbusch@kernel.org>
Cc: Jens Axboe <axboe@kernel.dk>,
Bart Van Assche <bvanassche@acm.org>,
Johannes Thumshirn <Johannes.Thumshirn@wdc.com>,
linux-nvme@lists.infradead.org, linux-block@vger.kernel.org,
Hannes Reinecke <hare@suse.de>, Chao Leng <lengchao@huawei.com>,
Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>
Subject: Re: [PATCH V4 2/4] blk-mq: implement queue quiesce via percpu_ref for BLK_MQ_F_BLOCKING
Date: Thu, 10 Sep 2020 09:53:21 +0800 [thread overview]
Message-ID: <20200910015321.GA7420@T590> (raw)
In-Reply-To: <20200909160409.GA3356175@dhcp-10-100-145-180.wdl.wdc.com>
On Wed, Sep 09, 2020 at 09:04:09AM -0700, Keith Busch wrote:
> On Wed, Sep 09, 2020 at 06:41:14PM +0800, Ming Lei wrote:
> > void blk_mq_quiesce_queue(struct request_queue *q)
> > {
> > - struct blk_mq_hw_ctx *hctx;
> > - unsigned int i;
> > - bool rcu = false;
> > + bool blocking = !!(q->tag_set->flags & BLK_MQ_F_BLOCKING);
> > + bool was_quiesced =__blk_mq_quiesce_queue_nowait(q);
> >
> > - __blk_mq_quiesce_queue_nowait(q);
> > + if (!was_quiesced && blocking)
> > + percpu_ref_kill(&q->dispatch_counter);
> >
> > - queue_for_each_hw_ctx(q, hctx, i) {
> > - if (hctx->flags & BLK_MQ_F_BLOCKING)
> > - synchronize_srcu(hctx->srcu);
> > - else
> > - rcu = true;
> > - }
> > - if (rcu)
> > + if (blocking)
> > + wait_event(q->mq_quiesce_wq,
> > + percpu_ref_is_zero(&q->dispatch_counter));
> > + else
> > synchronize_rcu();
> > }
>
> In the previous version, you had ensured no thread can unquiesce a queue
> while another is waiting for quiescence. Now that the locking is gone,
> a thread could unquiesce the queue before percpu_ref reaches zero, so
> the wait_event() may never complete on the resurrected percpu_ref.
>
> I don't think any drivers do such a thing today, but it just looks like
> the implementation leaves open the possibility.
This driver can cause bigger trouble if it unquiesces its queue which is
being quiesced and still not done.
However, we can avoid that by the following delta change:
diff --git a/block/blk-mq.c b/block/blk-mq.c
index 7669fe815cf9..5632727d71fa 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -225,9 +225,16 @@ static void __blk_mq_quiesce_queue(struct request_queue *q, bool wait)
if (!wait)
return;
+ /*
+ * In case of F_BLOCKING, if driver unquiesces its queue which is being
+ * quiesced and still not done, it can cause bigger trouble, and we simply
+ * return & warn once for avoiding hang here.
+ */
if (blocking)
wait_event(q->mq_quiesce_wq,
- percpu_ref_is_zero(&q->dispatch_counter));
+ percpu_ref_is_zero(&q->dispatch_counter) ||
+ WARN_ON_ONCE(!percpu_ref_is_dying(
+ &q->dispatch_counter)));
else
synchronize_rcu();
}
Thanks,
Ming
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
next prev parent reply other threads:[~2020-09-10 1:53 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-09 10:41 [PATCH V4 0/4] blk-mq: implement queue quiesce via percpu_ref for BLK_MQ_F_BLOCKING Ming Lei
2020-09-09 10:41 ` [PATCH V4 1/4] block: use test_and_{clear|test}_bit to set/clear QUEUE_FLAG_QUIESCED Ming Lei
2020-09-09 10:41 ` [PATCH V4 2/4] blk-mq: implement queue quiesce via percpu_ref for BLK_MQ_F_BLOCKING Ming Lei
2020-09-09 16:04 ` Keith Busch
2020-09-09 20:53 ` Sagi Grimberg
2020-09-10 8:03 ` Ming Lei
2020-09-10 1:53 ` Ming Lei [this message]
2020-09-10 14:55 ` Keith Busch
2020-09-09 10:41 ` [PATCH V4 3/4] blk-mq: add tagset quiesce interface Ming Lei
2020-09-09 10:41 ` [PATCH V4 4/4] nvme: use blk_mq_[un]quiesce_tagset Ming Lei
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=20200910015321.GA7420@T590 \
--to=ming.lei@redhat.com \
--cc=Johannes.Thumshirn@wdc.com \
--cc=axboe@kernel.dk \
--cc=bvanassche@acm.org \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=lengchao@huawei.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
/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).