From c4733c7166b7e696ba5c6f4b78e10d40936aec04 Mon Sep 17 00:00:00 2001 From: Zhao Wuyun Date: Fri, 10 Jun 2022 16:01:43 +0800 Subject: [PATCH] block: peek PM requests during runtime PM queue blocked during runtime PM when at the following situation: process A: runtime suspend run and set the PM status to RPM_SUSPENDING then run req with RQF_PM with blk_execute_rq(req->q, NULL, req, 1) then the req queued to head it is not executed when the driver is busy process B: normal device management operation run req with no RQF_PM with blk_execute_rq(req->q, NULL, req, 1) the the req is queued in front of the RQF_PM req of process A __blk_run_queue still not run because the first req is non RQF_PM req and with RQF_SOFTBARRIER, so the queue is totally blocked when at RPM_SUSPENDING status. see the following task calltrace: process A: [] __switch_to+0x10c [] __schedule+0x670 [] schedule+0x74 [] schedule_timeout+0x328 [] io_schedule_timeout+0x24 [] wait_for_common_io+0x90 [] wait_for_completion_io_timeout+0x24 [] blk_execute_rq+0x88 [] scsi_execute+0x114 [] sd_sync_cache+0xfc [] sd_suspend_common+0x58 [] sd_suspend_runtime+0x20 [] scsi_runtime_suspend+0x70 [] __rpm_callback+0xcc [] rpm_callback+0x5c [] rpm_suspend+0x1e8 [] pm_runtime_work+0x7c [] process_one_work+0x1bc [] worker_thread+0x214 [] kthread+0x11c [] ret_from_fork+0x10 process B: [] __switch_to+0x10c [] __schedule+0x670 [] schedule+0x74 [] schedule_timeout+0x328 [] io_schedule_timeout+0x24 [] wait_for_common_io+0x90 [] wait_for_completion_io_timeout+0x24 [] blk_execute_rq+0x88 [] scsi_execute+0x114 [] scsi_test_unit_ready+0x70 [] sd_check_events+0xd4 [] disk_check_events+0x58 [] disk_events_workfn+0x20 [] process_one_work+0x1bc [] worker_thread+0x214 [] kthread+0x11c [] ret_from_fork+0x10 Signed-off-by: Zhao Wuyun --- block/blk-core.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/block/blk-core.c b/block/blk-core.c index a33775cd97be..8b9272bfdc09 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -2856,6 +2856,15 @@ static struct request *elv_next_request(struct request_queue *q) if (blk_pm_allow_request(rq)) return rq; + /* + * let the PM request run, + * or the queue may be blocked by the non-PM request + * with RQF_SOFTBARRIER forever while doing runtime PM. + */ + if (q->rpm_status == RPM_SUSPENDING + || q->rpm_status == RPM_RESUMING) + continue; + if (rq->rq_flags & RQF_SOFTBARRIER) break; } -- 2.32.1 (Apple Git-133)