mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yang Yang <yang.yang@vivo.com>
To: Jens Axboe <axboe@kernel.dk>,
	linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: onlyfever@icloud.com, yang.yang@vivo.com
Subject: [PATCH] blk-mq: fix hang issue in blk_queue_enter()
Date: Mon, 14 Sep 2020 00:19:03 -0700	[thread overview]
Message-ID: <20200914071903.65704-1-yang.yang@vivo.com> (raw)

There is a race between blk_queue_enter() and block layer's runtime
suspend.

 CPU0                                CPU1
 ---------------------------------   -------------------------------
 blk_pre_runtime_suspend(q) {        blk_queue_enter() {
   /* q->rpm_status=RPM_ACTIVE */
   blk_set_pm_only(q)
   /* q->pm_only=1 */
   blk_freeze_queue_start(q)
   blk_mq_unfreeze_queue(q)
                                       if (percpu_ref_tryget_live()) {
                                         /* pm=0 && q->pm_only=1 */
                                         if (pm || !blk_queue_pm_only(q)) {
                                         } else {
                                           percpu_ref_put()
                                         }
                                       }
                                       wait_event(q->mq_freeze_wq,
                                         (!q->mq_freeze_depth &&
                                         /* q->rpm_status=RPM_ACTIVE
                                            q->pm_only=1 */
                                         (pm || (blk_pm_request_resume(q),
                                          !blk_queue_pm_only(q)))) ||
                                          blk_queue_dying(q))
                                     }
   spin_lock_irq(&q->queue_lock)
   q->rpm_status = RPM_SUSPENDING
   spin_unlock_irq(&q->queue_lock)
 }

At this point blk_pm_request_resume() missed the chance to resume the
queue, so blk_queue_enter() may wait here forever.
The solution is to wake up the mq_freeze_wq after runtime suspend
completed, make blk_pm_request_resume() reexamine the q->rpm_status flag.

Signed-off-by: Yang Yang <yang.yang@vivo.com>
---
 block/blk-pm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/block/blk-pm.c b/block/blk-pm.c
index b85234d758f7..dec7d0aef606 100644
--- a/block/blk-pm.c
+++ b/block/blk-pm.c
@@ -132,6 +132,8 @@ void blk_post_runtime_suspend(struct request_queue *q, int err)
 
 	if (err)
 		blk_clear_pm_only(q);
+	else
+		wake_up_all(&q->mq_freeze_wq);
 }
 EXPORT_SYMBOL(blk_post_runtime_suspend);
 
-- 
2.17.1


             reply	other threads:[~2020-09-14  7:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-14  7:19 Yang Yang [this message]
2020-09-14 16:48 ` Bart Van Assche
     [not found] <11a3283f-7857-0448-7424-8840fb5f2ea7@web.de>
2020-09-15  8:34 ` Yang Yang

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=20200914071903.65704-1-yang.yang@vivo.com \
    --to=yang.yang@vivo.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=onlyfever@icloud.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

all inboxes | Powered by JetHome®