* Regression caused by f5bbbbe4d635 @ 2018-09-24 18:44 Jens Axboe 2018-09-24 19:13 ` Keith Busch 0 siblings, 1 reply; 4+ messages in thread From: Jens Axboe @ 2018-09-24 18:44 UTC (permalink / raw) To: jianchao.wang; +Cc: linux-block@vger.kernel.org, Ming Lei, Keith Busch Hi, This commit introduced a rcu_read_lock() inside blk_mq_queue_tag_busy_iter() - this is problematic for the timout code, since we now end up holding the RCU read lock over the timeout code. As just one example, nvme ends up doing: nvme_timeout() nvme_dev_disable() mutex_lock(&dev->shutdown_lock); and things are then obviously unhappy... -- Jens Axboe ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Regression caused by f5bbbbe4d635 2018-09-24 18:44 Regression caused by f5bbbbe4d635 Jens Axboe @ 2018-09-24 19:13 ` Keith Busch 2018-09-24 19:51 ` Bart Van Assche 0 siblings, 1 reply; 4+ messages in thread From: Keith Busch @ 2018-09-24 19:13 UTC (permalink / raw) To: Jens Axboe; +Cc: jianchao.wang, linux-block@vger.kernel.org, Ming Lei On Mon, Sep 24, 2018 at 12:44:13PM -0600, Jens Axboe wrote: > Hi, > > This commit introduced a rcu_read_lock() inside > blk_mq_queue_tag_busy_iter() - this is problematic for the timout code, > since we now end up holding the RCU read lock over the timeout code. As > just one example, nvme ends up doing: > > nvme_timeout() > nvme_dev_disable() > mutex_lock(&dev->shutdown_lock); > > and things are then obviously unhappy... Yah, there's never been a requirement that tag iterator callbacks be non-blocking as far as I remember. The queue's reference in blk_mq_timeout_work looks applicable to any blk_mq_queue_tag_busy_iter user, so just moving it there looks like it should do what f5bbbbe4d635 was trying to fix. --- diff --git a/block/blk-mq-tag.c b/block/blk-mq-tag.c index 94e1ed667b6e..850577a3de6d 100644 --- a/block/blk-mq-tag.c +++ b/block/blk-mq-tag.c @@ -320,18 +320,21 @@ void blk_mq_queue_tag_busy_iter(struct request_queue *q, busy_iter_fn *fn, struct blk_mq_hw_ctx *hctx; int i; - /* - * __blk_mq_update_nr_hw_queues will update the nr_hw_queues and - * queue_hw_ctx after freeze the queue. So we could use q_usage_counter - * to avoid race with it. __blk_mq_update_nr_hw_queues will users - * synchronize_rcu to ensure all of the users go out of the critical - * section below and see zeroed q_usage_counter. + /* A deadlock might occur if a request is stuck requiring a + * timeout at the same time a queue freeze is waiting + * completion, since the timeout code would not be able to + * acquire the queue reference here. + * + * That's why we don't use blk_queue_enter here; instead, we use + * percpu_ref_tryget directly, because we need to be able to + * obtain a reference even in the short window between the queue + * starting to freeze, by dropping the first reference in + * blk_freeze_queue_start, and the moment the last request is + * consumed, marked by the instant q_usage_counter reaches + * zero. */ - rcu_read_lock(); - if (percpu_ref_is_zero(&q->q_usage_counter)) { - rcu_read_unlock(); + if (!percpu_ref_tryget(&q->q_usage_counter)) return; - } queue_for_each_hw_ctx(q, hctx, i) { struct blk_mq_tags *tags = hctx->tags; @@ -347,7 +350,7 @@ void blk_mq_queue_tag_busy_iter(struct request_queue *q, busy_iter_fn *fn, bt_for_each(hctx, &tags->breserved_tags, fn, priv, true); bt_for_each(hctx, &tags->bitmap_tags, fn, priv, false); } - rcu_read_unlock(); + blk_queue_exit(q); } static int bt_alloc(struct sbitmap_queue *bt, unsigned int depth, diff --git a/block/blk-mq.c b/block/blk-mq.c index 85a1c1a59c72..28d128450621 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -848,22 +848,6 @@ static void blk_mq_timeout_work(struct work_struct *work) struct blk_mq_hw_ctx *hctx; int i; - /* A deadlock might occur if a request is stuck requiring a - * timeout at the same time a queue freeze is waiting - * completion, since the timeout code would not be able to - * acquire the queue reference here. - * - * That's why we don't use blk_queue_enter here; instead, we use - * percpu_ref_tryget directly, because we need to be able to - * obtain a reference even in the short window between the queue - * starting to freeze, by dropping the first reference in - * blk_freeze_queue_start, and the moment the last request is - * consumed, marked by the instant q_usage_counter reaches - * zero. - */ - if (!percpu_ref_tryget(&q->q_usage_counter)) - return; - blk_mq_queue_tag_busy_iter(q, blk_mq_check_expired, &next); if (next != 0) { @@ -881,7 +865,6 @@ static void blk_mq_timeout_work(struct work_struct *work) blk_mq_tag_idle(hctx); } } - blk_queue_exit(q); } struct flush_busy_ctx_data { @@ -2974,10 +2957,7 @@ static void __blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set, list_for_each_entry(q, &set->tag_list, tag_set_list) blk_mq_freeze_queue(q); - /* - * Sync with blk_mq_queue_tag_busy_iter. - */ - synchronize_rcu(); + /* * Switch IO scheduler to 'none', cleaning up the data associated * with the previous scheduler. We will switch back once we are done -- ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: Regression caused by f5bbbbe4d635 2018-09-24 19:13 ` Keith Busch @ 2018-09-24 19:51 ` Bart Van Assche 2018-09-24 20:00 ` Keith Busch 0 siblings, 1 reply; 4+ messages in thread From: Bart Van Assche @ 2018-09-24 19:51 UTC (permalink / raw) To: Keith Busch, Jens Axboe Cc: jianchao.wang, linux-block@vger.kernel.org, Ming Lei On Mon, 2018-09-24 at 13:13 -0600, Keith Busch wrote: > diff --git a/block/blk-mq.c b/block/blk-mq.c > index 85a1c1a59c72..28d128450621 100644 > --- a/block/blk-mq.c > +++ b/block/blk-mq.c > @@ -848,22 +848,6 @@ static void blk_mq_timeout_work(struct work_struct *work) > struct blk_mq_hw_ctx *hctx; > int i; > > - /* A deadlock might occur if a request is stuck requiring a > - * timeout at the same time a queue freeze is waiting > - * completion, since the timeout code would not be able to > - * acquire the queue reference here. > - * > - * That's why we don't use blk_queue_enter here; instead, we use > - * percpu_ref_tryget directly, because we need to be able to > - * obtain a reference even in the short window between the queue > - * starting to freeze, by dropping the first reference in > - * blk_freeze_queue_start, and the moment the last request is > - * consumed, marked by the instant q_usage_counter reaches > - * zero. > - */ > - if (!percpu_ref_tryget(&q->q_usage_counter)) > - return; > - > blk_mq_queue_tag_busy_iter(q, blk_mq_check_expired, &next); > > if (next != 0) { > @@ -881,7 +865,6 @@ static void blk_mq_timeout_work(struct work_struct *work) > blk_mq_tag_idle(hctx); > } > } > - blk_queue_exit(q); > } Hi Keith, The above introduces a behavior change: if the percpu_ref_tryget() call inside blk_mq_queue_tag_busy_iter() fails then blk_mq_timeout_work() will now call blk_mq_tag_idle(). I think that's wrong if the percpu_ref_tryget() call fails due to the queue having been frozen. Please make blk_mq_queue_tag_busy_iter() return a bool that indicates whether or not it has iterated over the request queue. Thanks, Bart. ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Regression caused by f5bbbbe4d635 2018-09-24 19:51 ` Bart Van Assche @ 2018-09-24 20:00 ` Keith Busch 0 siblings, 0 replies; 4+ messages in thread From: Keith Busch @ 2018-09-24 20:00 UTC (permalink / raw) To: Bart Van Assche Cc: Jens Axboe, jianchao.wang, linux-block@vger.kernel.org, Ming Lei On Mon, Sep 24, 2018 at 12:51:07PM -0700, Bart Van Assche wrote: > On Mon, 2018-09-24 at 13:13 -0600, Keith Busch wrote: > > diff --git a/block/blk-mq.c b/block/blk-mq.c > > index 85a1c1a59c72..28d128450621 100644 > > --- a/block/blk-mq.c > > +++ b/block/blk-mq.c > > @@ -848,22 +848,6 @@ static void blk_mq_timeout_work(struct work_struct *work) > > struct blk_mq_hw_ctx *hctx; > > int i; > > > > - /* A deadlock might occur if a request is stuck requiring a > > - * timeout at the same time a queue freeze is waiting > > - * completion, since the timeout code would not be able to > > - * acquire the queue reference here. > > - * > > - * That's why we don't use blk_queue_enter here; instead, we use > > - * percpu_ref_tryget directly, because we need to be able to > > - * obtain a reference even in the short window between the queue > > - * starting to freeze, by dropping the first reference in > > - * blk_freeze_queue_start, and the moment the last request is > > - * consumed, marked by the instant q_usage_counter reaches > > - * zero. > > - */ > > - if (!percpu_ref_tryget(&q->q_usage_counter)) > > - return; > > - > > blk_mq_queue_tag_busy_iter(q, blk_mq_check_expired, &next); > > > > if (next != 0) { > > @@ -881,7 +865,6 @@ static void blk_mq_timeout_work(struct work_struct *work) > > blk_mq_tag_idle(hctx); > > } > > } > > - blk_queue_exit(q); > > } > > Hi Keith, > > The above introduces a behavior change: if the percpu_ref_tryget() call inside > blk_mq_queue_tag_busy_iter() fails then blk_mq_timeout_work() will now call > blk_mq_tag_idle(). I think that's wrong if the percpu_ref_tryget() call fails > due to the queue having been frozen. Please make blk_mq_queue_tag_busy_iter() > return a bool that indicates whether or not it has iterated over the request > queue. Good point, thanks for the feedback. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-09-24 20:00 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2018-09-24 18:44 Regression caused by f5bbbbe4d635 Jens Axboe 2018-09-24 19:13 ` Keith Busch 2018-09-24 19:51 ` Bart Van Assche 2018-09-24 20:00 ` Keith Busch
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).