Skip to content

Commit c196bf4

Browse files
Cong Zhangaxboe
authored andcommitted
blk-mq: Abort suspend when wakeup events are pending
During system suspend, wakeup capable IRQs for block device can be delayed, which can cause blk_mq_hctx_notify_offline() to hang indefinitely while waiting for pending request to complete. Skip the request waiting loop and abort suspend when wakeup events are pending to prevent the deadlock. Fixes: bf0beec ("blk-mq: drain I/O when all CPUs in a hctx are offline") Signed-off-by: Cong Zhang <cong.zhang@oss.qualcomm.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 71075d2 commit c196bf4

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

block/blk-mq.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/cache.h>
2424
#include <linux/sched/topology.h>
2525
#include <linux/sched/signal.h>
26+
#include <linux/suspend.h>
2627
#include <linux/delay.h>
2728
#include <linux/crash_dump.h>
2829
#include <linux/prefetch.h>
@@ -3718,6 +3719,7 @@ static int blk_mq_hctx_notify_offline(unsigned int cpu, struct hlist_node *node)
37183719
{
37193720
struct blk_mq_hw_ctx *hctx = hlist_entry_safe(node,
37203721
struct blk_mq_hw_ctx, cpuhp_online);
3722+
int ret = 0;
37213723

37223724
if (blk_mq_hctx_has_online_cpu(hctx, cpu))
37233725
return 0;
@@ -3738,12 +3740,24 @@ static int blk_mq_hctx_notify_offline(unsigned int cpu, struct hlist_node *node)
37383740
* frozen and there are no requests.
37393741
*/
37403742
if (percpu_ref_tryget(&hctx->queue->q_usage_counter)) {
3741-
while (blk_mq_hctx_has_requests(hctx))
3743+
while (blk_mq_hctx_has_requests(hctx)) {
3744+
/*
3745+
* The wakeup capable IRQ handler of block device is
3746+
* not called during suspend. Skip the loop by checking
3747+
* pm_wakeup_pending to prevent the deadlock and improve
3748+
* suspend latency.
3749+
*/
3750+
if (pm_wakeup_pending()) {
3751+
clear_bit(BLK_MQ_S_INACTIVE, &hctx->state);
3752+
ret = -EBUSY;
3753+
break;
3754+
}
37423755
msleep(5);
3756+
}
37433757
percpu_ref_put(&hctx->queue->q_usage_counter);
37443758
}
37453759

3746-
return 0;
3760+
return ret;
37473761
}
37483762

37493763
/*

0 commit comments

Comments
 (0)