From: Wondertan via B4 Relay <devnull+hlibwondertan.gmail.com@kernel.org>
To: "Rafael J. Wysocki" <rafael@kernel.org>, linux-pm@vger.kernel.org
Cc: Daniel Lezcano <daniel.lezcano@kernel.org>,
Christian Loehle <christian.loehle@arm.com>,
linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org,
Thorsten Leemhuis <linux@leemhuis.info>
Subject: [PATCH] cpuidle: Do not reinstall the idle handler while paused
Date: Tue, 17 Nov 2026 23:00:03 +0400 [thread overview]
Message-ID: <20261117-cpuidle-pause-fix-v1-1-b2789fce4c16@gmail.com> (raw)
From: Wondertan <hlibwondertan@gmail.com>
The PM core pauses cpuidle before taking secondary CPUs offline during
system-wide transitions and resumes it after bringing them back online
(pm_sleep_disable_secondary_cpus()/pm_sleep_enable_secondary_cpus()), so
that CPUs do not enter cpuidle-managed idle states in that window.
However, with acpi_idle, acpi_soft_cpu_online() calls
acpi_processor_hotplug() for every CPU brought back online, and that
function brackets its update with cpuidle_pause_and_lock() and
cpuidle_resume_and_unlock(). The latter reinstalls the idle handler
unconditionally, so cpuidle is effectively resumed as soon as the first
secondary CPU is back online. The remaining CPUs are then brought up,
and cache_aps_init() runs stop_machine(), with idle CPUs entering deep
ACPI C-states. cpuidle_register_device() and cpuidle_switch_governor()
can undo the pause in the same way.
On a Framework Laptop 16 (AMD Ryzen AI 9 HX 370, BIOS 04.01), whose
_CST exposes C2/C3 with the SystemIO entry method, this intermittently
hangs hibernation after the image has been created: a CPU idling in
io_idle() does not respond to an IPI and another CPU soft-locks waiting
for it, either in smp_call_function_many_cond() (text poking from
sched_cpu_activate() while an SMT sibling is onlined) or in
multi_cpu_stop() (the MTRR rendezvous in cache_aps_init()). The image is
never written and the next boot reports "PM: Image not found (code -22)":
watchdog: BUG: soft lockup - CPU#12 stuck for 22s! [cpuhp/12:89]
RIP: 0010:smp_call_function_many_cond+0x147/0x520
on_each_cpu_cond_mask+0x24/0x40
smp_text_poke_batch_finish+0xe2/0x380
arch_jump_label_transform_apply+0x1a/0x30
static_key_slow_inc_cpuslocked+0x4f/0xa0
sched_cpu_activate+0x13c/0x150
...
thaw_secondary_cpus.cold+0x5e/0xd2
hibernation_snapshot+0x231/0x530
NMI backtrace for cpu 0 skipped: idling at io_idle+0x3/0x30
watchdog: BUG: soft lockup - CPU#3 stuck for 22s! [migration/3:37]
Stopper: multi_cpu_stop+0x0/0x140 <- __stop_cpus.constprop.0+0x6d/0xb0
(23 CPUs in multi_cpu_stop)
NMI backtrace for cpu 2 skipped: idling at io_idle+0x3/0x30
Online CPUs can only be in io_idle() via cpuidle, so cpuidle was not
paused at that point. Tracing power:cpu_idle across the transition on
6.18.59 confirms it: while CPUs 1-23 were being brought online (between
the first and the last CPU_ON "end" events, about 35 ms), idle CPUs
entered C2 263 times and C3 305 times on all 24 CPUs, the first C3 entry
coming 0.6 ms after CPU1 was onlined. The failure rate was about one in
four hibernations, higher on battery; disabling C2/C3 via sysfs around
hibernation made it go away.
Fix this by recording that cpuidle has been paused by cpuidle_pause()
and not reinstalling the idle handler until cpuidle_resume() is called.
All callers of cpuidle_install_idle_handler() hold cpuidle_lock, which
also protects the new flag.
With this change on top of 6.18.62 and 7.3.4, the same trace across a
real hibernation and resume with C2/C3 enabled shows no C2/C3 entries
in that window (only C1), hibernation completes, and C2/C3 are used
again once the transition is over.
The root cause analysis, the fix, the tracing used to verify it and
this changelog were produced with an AI coding assistant (Claude Code,
model claude-opus-5-5), working from pstore dumps, ftrace captures and
the kernel sources. All builds and tests were run on the affected
machine as described above.
Fixes: 8651f97bd951 ("PM / cpuidle: System resume hang fix with cpuidle")
Cc: stable@vger.kernel.org
Signed-off-by: Wondertan <hlibwondertan@gmail.com>
---
Tested only on the one affected machine (AMD, acpi_idle, BIOS 04.01
and 04.02): built and run-tested on 6.18.62 and 7.3.4 (Arch linux-lts
and linux configs, x86_64). drivers/cpuidle/cpuidle.c in 7.3.4 is
identical to mainline apart from this change. On mainline
(141b164bbe18) drivers/cpuidle/ was only built (W=1, no warnings), not
booted. Not tested with intel_idle or other cpuidle drivers.
Earlier report of the hangs, before the root cause was known:
"[REGRESSION?] hibernation soft lockup in migration/0 after image
creation", linux-pm, 2026-07-09.
---
drivers/cpuidle/cpuidle.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
index 2d2f40a2c..3e26b1760 100644
--- a/drivers/cpuidle/cpuidle.c
+++ b/drivers/cpuidle/cpuidle.c
@@ -39,6 +39,7 @@ LIST_HEAD(cpuidle_detected_devices);
static int enabled_devices;
static int off __read_mostly;
static int initialized __read_mostly;
+static bool paused; /* Protected by cpuidle_lock */
int cpuidle_disabled(void)
{
@@ -465,7 +466,12 @@ __cpuidle u64 cpuidle_poll_time(struct cpuidle_driver *drv,
*/
void cpuidle_install_idle_handler(void)
{
- if (enabled_devices) {
+ /*
+ * Do not reinstall the idle handler while cpuidle is paused for a
+ * system transition, even if a nested cpuidle_resume_and_unlock()
+ * (e.g. from the ACPI processor CPU online callback) asks for it.
+ */
+ if (enabled_devices && !paused) {
/* Make sure all changes finished before we switch to new idle */
smp_wmb();
initialized = 1;
@@ -515,6 +521,7 @@ EXPORT_SYMBOL_GPL(cpuidle_resume_and_unlock);
void cpuidle_pause(void)
{
mutex_lock(&cpuidle_lock);
+ paused = true;
cpuidle_uninstall_idle_handler();
mutex_unlock(&cpuidle_lock);
}
@@ -523,6 +530,7 @@ void cpuidle_pause(void)
void cpuidle_resume(void)
{
mutex_lock(&cpuidle_lock);
+ paused = false;
cpuidle_install_idle_handler();
mutex_unlock(&cpuidle_lock);
}
---
base-commit: 141b164bbe186423e295b139e40e8e2d11cf1341
change-id: 20261117-cpuidle-pause-fix-854cd6110d77
Best regards,
--
Wondertan <hlibwondertan@gmail.com>
reply other threads:[~2026-11-17 19:01 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261117-cpuidle-pause-fix-v1-1-b2789fce4c16@gmail.com \
--to=devnull+hlibwondertan.gmail.com@kernel.org \
--cc=christian.loehle@arm.com \
--cc=daniel.lezcano@kernel.org \
--cc=hlibwondertan@gmail.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux@leemhuis.info \
--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
all inboxes | Powered by JetHome®