public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Yang Yang <yang.yang@vivo.com>
To: Jens Axboe <axboe@kernel.dk>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Pavel Machek <pavel@kernel.org>, Len Brown <lenb@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Danilo Krummrich <dakr@kernel.org>,
	linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-pm@vger.kernel.org
Cc: Yang Yang <yang.yang@vivo.com>
Subject: [PATCH 1/2] PM: runtime: Fix I/O hang due to race between resume and runtime disable
Date: Wed, 26 Nov 2025 18:16:35 +0800	[thread overview]
Message-ID: <20251126101636.205505-2-yang.yang@vivo.com> (raw)
In-Reply-To: <20251126101636.205505-1-yang.yang@vivo.com>

We observed the following hung task during our test:

[ 3987.095999] INFO: task "kworker/u32:7":239 blocked for more than 188 seconds.
[ 3987.096017] task:kworker/u32:7   state:D stack:0     pid:239   tgid:239   ppid:2      flags:0x00000408
[ 3987.096042] Workqueue: writeback wb_workfn (flush-254:59)
[ 3987.096069] Call trace:
[ 3987.096073]  __switch_to+0x1a0/0x318
[ 3987.096089]  __schedule+0xa38/0xf9c
[ 3987.096104]  schedule+0x74/0x10c
[ 3987.096118]  __bio_queue_enter+0xb8/0x178
[ 3987.096132]  blk_mq_submit_bio+0x104/0x728
[ 3987.096145]  __submit_bio+0xa0/0x23c
[ 3987.096159]  submit_bio_noacct_nocheck+0x164/0x330
[ 3987.096173]  submit_bio_noacct+0x348/0x468
[ 3987.096186]  submit_bio+0x17c/0x198
[ 3987.096199]  f2fs_submit_write_bio+0x44/0xe8
[ 3987.096211]  __submit_merged_bio+0x40/0x11c
[ 3987.096222]  __submit_merged_write_cond+0xcc/0x1f8
[ 3987.096233]  f2fs_write_data_pages+0xbb8/0xd0c
[ 3987.096246]  do_writepages+0xe0/0x2f4
[ 3987.096255]  __writeback_single_inode+0x44/0x4ac
[ 3987.096272]  writeback_sb_inodes+0x30c/0x538
[ 3987.096289]  __writeback_inodes_wb+0x9c/0xec
[ 3987.096305]  wb_writeback+0x158/0x440
[ 3987.096321]  wb_workfn+0x388/0x5d4
[ 3987.096335]  process_scheduled_works+0x1c4/0x45c
[ 3987.096346]  worker_thread+0x32c/0x3e8
[ 3987.096356]  kthread+0x11c/0x1b0
[ 3987.096372]  ret_from_fork+0x10/0x20

 T1:                                   T2:
 blk_queue_enter
 blk_pm_resume_queue
 pm_request_resume
 __pm_runtime_resume(dev, RPM_ASYNC)
 rpm_resume                            __pm_runtime_disable
 dev->power.request_pending = true     dev->power.disable_depth++
 queue_work(pm_wq, &dev->power.work)   __pm_runtime_barrier
 wait_event                            cancel_work_sync(&dev->power.work)

T1 queues the work item, which is then cancelled by T2 before it starts
execution. As a result, q->dev cannot be resumed, and T1 waits here for
a long time.

Signed-off-by: Yang Yang <yang.yang@vivo.com>
---
 drivers/base/power/runtime.c | 3 ++-
 include/linux/pm.h           | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index 1b11a3cd4acc..fc9bf3fb3bb7 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -1533,7 +1533,8 @@ void __pm_runtime_disable(struct device *dev, bool check_resume)
 	 * means there probably is some I/O to process and disabling runtime PM
 	 * shouldn't prevent the device from processing the I/O.
 	 */
-	if (check_resume && dev->power.request_pending &&
+	if ((check_resume || dev->power.force_check_resume) &&
+	    dev->power.request_pending &&
 	    dev->power.request == RPM_REQ_RESUME) {
 		/*
 		 * Prevent suspends and idle notifications from being carried
diff --git a/include/linux/pm.h b/include/linux/pm.h
index cc7b2dc28574..4eb20569cdbc 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -708,6 +708,7 @@ struct dev_pm_info {
 	bool			use_autosuspend:1;
 	bool			timer_autosuspends:1;
 	bool			memalloc_noio:1;
+	bool			force_check_resume:1;
 	unsigned int		links_count;
 	enum rpm_request	request;
 	enum rpm_status		runtime_status;
-- 
2.34.1


  reply	other threads:[~2025-11-26 10:17 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-26 10:16 [PATCH 0/2] PM: runtime: Fix potential I/O hang Yang Yang
2025-11-26 10:16 ` Yang Yang [this message]
2025-11-26 11:30   ` [PATCH 1/2] PM: runtime: Fix I/O hang due to race between resume and runtime disable Rafael J. Wysocki
2025-11-26 11:59     ` YangYang
2025-11-26 12:36       ` Rafael J. Wysocki
2025-11-26 15:33         ` Bart Van Assche
2025-11-26 15:41           ` Rafael J. Wysocki
2025-11-26 18:40             ` Bart Van Assche
2025-11-27 11:29               ` YangYang
2025-11-27 12:44                 ` Rafael J. Wysocki
2025-11-28  7:20                   ` YangYang
2025-12-01 16:40                 ` Bart Van Assche
2025-11-26 18:06     ` Bart Van Assche
2025-11-26 19:16       ` Rafael J. Wysocki
2025-11-26 19:34         ` Rafael J. Wysocki
2025-11-26 20:17           ` Rafael J. Wysocki
2025-11-26 21:10             ` Bart Van Assche
2025-11-26 21:30               ` Rafael J. Wysocki
2025-11-26 22:47                 ` Bart Van Assche
2025-11-27 12:34                   ` Rafael J. Wysocki
2025-12-01  9:46                     ` YangYang
2025-12-01 12:56                       ` YangYang
2025-12-01 18:55                         ` Rafael J. Wysocki
2025-12-02 10:33                           ` YangYang
2025-12-02 12:18                             ` Rafael J. Wysocki
2025-12-01 18:47                       ` Rafael J. Wysocki
2025-12-01 19:58                         ` [PATCH v1] PM: sleep: Do not flag runtime PM workqueue as freezable Rafael J. Wysocki
2025-12-02  1:06                           ` Bart Van Assche
2025-12-02 11:53                             ` Rafael J. Wysocki
2025-12-02 13:29                               ` Rafael J. Wysocki
2025-12-02 10:36                           ` YangYang
2025-12-02 14:58                           ` Ulf Hansson
2025-12-02  0:40                         ` [PATCH 1/2] PM: runtime: Fix I/O hang due to race between resume and runtime disable Bart Van Assche
2025-12-02 12:14                           ` Rafael J. Wysocki
2025-12-02 13:37                             ` Rafael J. Wysocki
2025-12-05 15:24                         ` [PATCH v2] PM: sleep: Do not flag runtime PM workqueue as freezable Rafael J. Wysocki
2025-12-05 19:10                           ` Bart Van Assche
2025-12-07 11:23                             ` Rafael J. Wysocki
2025-11-26 10:16 ` [PATCH 2/2] blk-mq: Fix I/O hang caused by incomplete device resume Yang Yang
2025-11-26 11:31 ` [PATCH 0/2] PM: runtime: Fix potential I/O hang Rafael J. Wysocki
2025-11-26 15:48   ` Bart Van Assche
2025-11-26 16:59     ` Rafael J. Wysocki
2025-11-26 17:21       ` Rafael J. Wysocki
2025-11-26 17:34         ` Rafael J. Wysocki

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=20251126101636.205505-2-yang.yang@vivo.com \
    --to=yang.yang@vivo.com \
    --cc=axboe@kernel.dk \
    --cc=dakr@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=lenb@kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=pavel@kernel.org \
    --cc=rafael@kernel.org \
    /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