From: "Rafael J. Wysocki" <rafael@kernel.org>
To: Bart Van Assche <bvanassche@acm.org>
Cc: Yang Yang <yang.yang@vivo.com>, Jens Axboe <axboe@kernel.dk>,
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
Subject: Re: [PATCH 1/2] PM: runtime: Fix I/O hang due to race between resume and runtime disable
Date: Wed, 26 Nov 2025 21:17:51 +0100 [thread overview]
Message-ID: <4697314.LvFx2qVVIh@rafael.j.wysocki> (raw)
In-Reply-To: <CAJZ5v0hKpGbwFmxcH8qe=DPf_5GX=LD=Fqj3dgOApUoE1RmJAQ@mail.gmail.com>
On Wednesday, November 26, 2025 8:34:54 PM CET Rafael J. Wysocki wrote:
> On Wed, Nov 26, 2025 at 8:16 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
> >
> > On Wed, Nov 26, 2025 at 7:06 PM Bart Van Assche <bvanassche@acm.org> wrote:
> > >
> > > On 11/26/25 3:30 AM, Rafael J. Wysocki wrote:
> > > > On Wed, Nov 26, 2025 at 11:17 AM Yang Yang <yang.yang@vivo.com> wrote:
> > > >> T1: T2:
> > > >> blk_queue_enter
> > > >> blk_pm_resume_queue
> > > >> pm_request_resume
> > > >
> > > > Shouldn't this be pm_runtime_resume() rather?
> > >
> > > I tried to make that change on an Android device. As a result, the
> > > kernel complaint shown below appeared. My understanding is that sleeping
> > > in atomic context can trigger a deadlock and hence is not allowed.
> > >
> > > [ 13.728890][ T1] WARNING: CPU: 6 PID: 1 at
> > > kernel/sched/core.c:9714 __might_sleep+0x78/0x84
> > > [ 13.758800][ T1] Call trace:
> > > [ 13.759027][ T1] __might_sleep+0x78/0x84
> > > [ 13.759340][ T1] __pm_runtime_resume+0x40/0xb8
> > > [ 13.759781][ T1] __bio_queue_enter+0xc0/0x1cc
> > > [ 13.760153][ T1] blk_mq_submit_bio+0x884/0xadc
> > > [ 13.760548][ T1] __submit_bio+0x2c8/0x49c
> > > [ 13.760879][ T1] __submit_bio_noacct_mq+0x38/0x88
> > > [ 13.761242][ T1] submit_bio_noacct_nocheck+0x4fc/0x7b8
> > > [ 13.761631][ T1] submit_bio+0x214/0x4c0
> > > [ 13.761941][ T1] mpage_readahead+0x1b8/0x1fc
> > > [ 13.762284][ T1] blkdev_readahead+0x18/0x28
> > > [ 13.762660][ T1] page_cache_ra_unbounded+0x310/0x4d8
> > > [ 13.763072][ T1] page_cache_ra_order+0xc0/0x5b0
> > > [ 13.763434][ T1] page_cache_sync_ra+0x17c/0x268
> > > [ 13.763782][ T1] filemap_read+0x4c4/0x12f4
> > > [ 13.764125][ T1] blkdev_read_iter+0x100/0x164
> > > [ 13.764475][ T1] vfs_read+0x188/0x348
> > > [ 13.764789][ T1] __se_sys_pread64+0x84/0xc8
> > > [ 13.765180][ T1] __arm64_sys_pread64+0x1c/0x2c
> > > [ 13.765556][ T1] invoke_syscall+0x58/0xf0
> > > [ 13.765876][ T1] do_el0_svc+0x8c/0xe0
> > > [ 13.766172][ T1] el0_svc+0x50/0xd4
> > > [ 13.766583][ T1] el0t_64_sync_handler+0x20/0xf4
> > > [ 13.766932][ T1] el0t_64_sync+0x1bc/0x1c0
> > > [ 13.767294][ T1] irq event stamp: 2589614
> > > [ 13.767592][ T1] hardirqs last enabled at (2589613):
> > > [<ffffffc0800eaf24>] finish_lock_switch+0x70/0x108
> > > [ 13.768283][ T1] hardirqs last disabled at (2589614):
> > > [<ffffffc0814b66f4>] el1_dbg+0x24/0x80
> > > [ 13.768875][ T1] softirqs last enabled at (2589370):
> > > [<ffffffc080082a7c>] ____do_softirq+0x10/0x20
> > > [ 13.769529][ T1] softirqs last disabled at (2589349):
> > > [<ffffffc080082a7c>] ____do_softirq+0x10/0x20
> > >
> > > I think that the filemap_invalidate_lock_shared() call in
> > > page_cache_ra_unbounded() forbids sleeping in submit_bio().
> >
> > The wait_event() macro in __bio_queue_enter() calls might_sleep() at
> > the very beginning, so why would it not complain?
> >
> > IIUC, this is the WARN_ONCE() in __might_sleep() about the task state
> > being different from TASK_RUNNING, which triggers because
> > prepare_to_wait_event() changes the task state to
> > TASK_UNINTERRUPTIBLE.
> >
> > This means that calling pm_runtime_resume() cannot be part of the
> > wait_event() condition, so blk_pm_resume_queue() and the wait_event()
> > macros involving it would need some rewriting.
>
> Interestingly enough, the pm_request_resume() call in
> blk_pm_resume_queue() is not even necessary in the __bio_queue_enter()
> case because pm is false there and it doesn't even check
> q->rpm_status.
>
> So in fact the resume is only necessary in blk_queue_enter() if pm is nonzero.
If I'm not completely in the weeds, something like the patch below should be
doable.
Also, I'd consider using pm_runtime_get_noresume() and pm_runtime_put_noidle()
in blk_queue_enter() and blk_queue_exit(), respectively, in the "pm != 0" case
to prevent the device from suspending while the .q_usage_counter ref is held.
---
block/blk-core.c | 6 +++---
block/blk-pm.h | 7 ++++---
2 files changed, 7 insertions(+), 6 deletions(-)
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -309,6 +309,8 @@ int blk_queue_enter(struct request_queue
if (flags & BLK_MQ_REQ_NOWAIT)
return -EAGAIN;
+ /* if necessary, resume .dev (assume success). */
+ blk_pm_resume_queue(pm, q);
/*
* read pair of barrier in blk_freeze_queue_start(), we need to
* order reading __PERCPU_REF_DEAD flag of .q_usage_counter and
@@ -318,9 +320,7 @@ int blk_queue_enter(struct request_queue
*/
smp_rmb();
wait_event(q->mq_freeze_wq,
- (!q->mq_freeze_depth &&
- blk_pm_resume_queue(pm, q)) ||
- blk_queue_dying(q));
+ !q->mq_freeze_depth || blk_queue_dying(q));
if (blk_queue_dying(q))
return -ENODEV;
}
--- a/block/blk-pm.h
+++ b/block/blk-pm.h
@@ -10,9 +10,10 @@ static inline int blk_pm_resume_queue(co
{
if (!q->dev || !blk_queue_pm_only(q))
return 1; /* Nothing to do */
- if (pm && q->rpm_status != RPM_SUSPENDED)
- return 1; /* Request allowed */
- pm_request_resume(q->dev);
+
+ if (pm)
+ pm_runtime_resume(q->dev);
+
return 0;
}
next prev parent reply other threads:[~2025-11-26 20: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 ` [PATCH 1/2] PM: runtime: Fix I/O hang due to race between resume and runtime disable Yang Yang
2025-11-26 11:30 ` 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 [this message]
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=4697314.LvFx2qVVIh@rafael.j.wysocki \
--to=rafael@kernel.org \
--cc=axboe@kernel.dk \
--cc=bvanassche@acm.org \
--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=yang.yang@vivo.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