* [PATCH v2 1/3] cpufreq: Improve suspend-resume synchronization
2026-11-03 19:42 [PATCH v2 0/3] cpufreq: Fix synchronization with system suspend/resume Rafael J. Wysocki
@ 2026-11-03 19:45 ` Rafael J. Wysocki
2026-11-18 13:03 ` [REGRESSION: " Borah, Chaitanya Kumar
2026-11-03 19:47 ` [PATCH v2 2/3] cpufreq: Force passing target frequency to driver during resume Rafael J. Wysocki
` (7 subsequent siblings)
8 siblings, 1 reply; 15+ messages in thread
From: Rafael J. Wysocki @ 2026-11-03 19:45 UTC (permalink / raw)
To: Linux PM
Cc: Viresh Kumar, Christian Loehle, Doug Smythies, Zak,
Srinivas Pandruvada, Mario Limonciello
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
The suspend-resume synchronization in the cpufreq core is not perfect
because the global cpufreq_suspended variable is set at the end of
cpufreq_suspend() after stopping governors for all of the active
policies, so the governor .limits() callback may run via
cpufreq_governor_limits() after stopping the governor and before
setting cpufreq_suspended which is questionable. Likewise, the
governor .limits() callback may run between clearing cpufreq_suspended
in cpufreq_resume() and starting the governor.
Address this by adding a per-policy "suspended" flag that is always
read under the policy rwsem and is updated under it when the governor
is stopped in cpufreq_suspend() and when the governor is restarted in
cpufreq_resume().
Also make cpufreq_resume() use the cpus_read_lock guard to reflect
what is done in cpufreq_suspend() and call cpufreq_exit_governor() for
policies that were suspended during a system suspend transition and
are inactive during the subsequent system resume (to avoid leaking an
inactive policy with a stopped governor that has not exited yet).
Fixes: 8e30444e1530 ("cpufreq: fix cpufreq suspend/resume for intel_pstate")
Fixes: b1b12babe3b7 ("cpufreq: update 'cpufreq_suspended' after stopping governors")
Cc: All applicable <stable@vger.kernel.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
v1 -> v2:
* Retain all of the cpufreq_suspended checks to avoid carrying out
governor operations after suspending cpufreq during system
shutdown and during hibernation resume on systems with SMT (Sashiko)
* Rearrange cpufreq_resume() to walk all cpufreq policies and call
cpufreq_resume_policy() for all of them
* Call cpufreq_exit_governor() in cpufreq_resume_policy() for
policies that were suspended during a system suspend transition and
are inactive during the subsequent system resume (Sashiko)
* Update cpufreq_suspended under cpus_read_lock in cpufreq_resume()
for more symmetry with cpufreq_suspend()
* Update changelog
---
drivers/cpufreq/cpufreq.c | 86 +++++++++++++++++++++++++++++++++-------------
include/linux/cpufreq.h | 3 +
2 files changed, 66 insertions(+), 23 deletions(-)
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -35,6 +35,9 @@
static LIST_HEAD(cpufreq_policy_list);
/* Macros to iterate over CPU policies */
+#define for_each_policy(__policy) \
+ list_for_each_entry(__policy, &cpufreq_policy_list, policy_list)
+
#define for_each_suitable_policy(__policy, __active) \
list_for_each_entry(__policy, &cpufreq_policy_list, policy_list) \
if ((__active) == !policy_is_inactive(__policy))
@@ -1956,6 +1959,14 @@ int cpufreq_generic_suspend(struct cpufr
}
EXPORT_SYMBOL(cpufreq_generic_suspend);
+static void cpufreq_suspend_policy(struct cpufreq_policy *policy)
+{
+ guard(cpufreq_policy_write)(policy);
+
+ cpufreq_stop_governor(policy);
+ policy->suspended = true;
+}
+
/**
* cpufreq_suspend() - Suspend CPUFreq governors.
*
@@ -1978,11 +1989,8 @@ void cpufreq_suspend(void)
pr_debug("%s: Suspending Governors\n", __func__);
for_each_active_policy(policy) {
- if (has_target()) {
- scoped_guard(cpufreq_policy_write, policy) {
- cpufreq_stop_governor(policy);
- }
- }
+ if (has_target())
+ cpufreq_suspend_policy(policy);
if (cpufreq_driver->suspend && cpufreq_driver->suspend(policy))
pr_err("%s: Failed to suspend driver: %s\n", __func__,
@@ -1994,6 +2002,32 @@ suspend:
cpus_read_unlock();
}
+static void cpufreq_resume_policy(struct cpufreq_policy *policy, bool start)
+{
+ guard(cpufreq_policy_write)(policy);
+
+ if (!policy->suspended)
+ return;
+
+ policy->suspended = false;
+
+ if (policy_is_inactive(policy)) {
+ /*
+ * The policy was active when it was suspended, so its governor
+ * is still there. Let the governor go.
+ */
+ cpufreq_exit_governor(policy);
+ return;
+ }
+
+ if (!start)
+ return;
+
+ if (cpufreq_start_governor(policy))
+ pr_err("%s: Failed to start governor for CPU%u's policy\n",
+ __func__, policy->cpu);
+}
+
/**
* cpufreq_resume() - Resume CPUFreq governors.
*
@@ -2003,11 +2037,12 @@ suspend:
void cpufreq_resume(void)
{
struct cpufreq_policy *policy;
- int ret;
if (!cpufreq_driver)
return;
+ guard(cpus_read_lock)();
+
if (unlikely(!cpufreq_suspended))
return;
@@ -2018,19 +2053,18 @@ void cpufreq_resume(void)
pr_debug("%s: Resuming Governors\n", __func__);
- for_each_active_policy(policy) {
- if (cpufreq_driver->resume && cpufreq_driver->resume(policy)) {
- pr_err("%s: Failed to resume driver: %s\n", __func__,
- cpufreq_driver->name);
- } else if (has_target()) {
- scoped_guard(cpufreq_policy_write, policy) {
- ret = cpufreq_start_governor(policy);
- }
+ for_each_policy(policy) {
+ int ret = 0;
+ if (cpufreq_driver->resume && !policy_is_inactive(policy)) {
+ ret = cpufreq_driver->resume(policy);
if (ret)
- pr_err("%s: Failed to start governor for CPU%u's policy\n",
- __func__, policy->cpu);
+ pr_err("%s: Failed to resume driver: %s\n", __func__,
+ cpufreq_driver->name);
}
+
+ if (has_target())
+ cpufreq_resume_policy(policy, ret == 0);
}
}
@@ -2412,12 +2446,17 @@ __weak struct cpufreq_governor *cpufreq_
return NULL;
}
+static bool cpufreq_is_suspended(struct cpufreq_policy *policy)
+{
+ return cpufreq_suspended || policy->suspended;
+}
+
static int cpufreq_init_governor(struct cpufreq_policy *policy)
{
int ret;
- /* Don't start any governor operations if we are entering suspend */
- if (cpufreq_suspended)
+ /* Don't start any governor operations for suspended policies. */
+ if (cpufreq_is_suspended(policy))
return 0;
/*
* Governor might not be initiated here if ACPI _PPC changed
@@ -2460,7 +2499,7 @@ static int cpufreq_init_governor(struct
static void cpufreq_exit_governor(struct cpufreq_policy *policy)
{
- if (cpufreq_suspended || !policy->governor)
+ if (cpufreq_is_suspended(policy) || !policy->governor)
return;
pr_debug("%s: for CPU %u\n", __func__, policy->cpu);
@@ -2475,7 +2514,7 @@ int cpufreq_start_governor(struct cpufre
{
int ret;
- if (cpufreq_suspended)
+ if (cpufreq_is_suspended(policy))
return 0;
if (!policy->governor)
@@ -2499,7 +2538,7 @@ int cpufreq_start_governor(struct cpufre
void cpufreq_stop_governor(struct cpufreq_policy *policy)
{
- if (cpufreq_suspended || !policy->governor)
+ if (cpufreq_is_suspended(policy) || !policy->governor)
return;
pr_debug("%s: for CPU %u\n", __func__, policy->cpu);
@@ -2510,7 +2549,7 @@ void cpufreq_stop_governor(struct cpufre
static void cpufreq_governor_limits(struct cpufreq_policy *policy)
{
- if (cpufreq_suspended || !policy->governor)
+ if (cpufreq_is_suspended(policy) || !policy->governor)
return;
pr_debug("%s: for CPU %u\n", __func__, policy->cpu);
@@ -2747,7 +2786,8 @@ static void cpufreq_policy_refresh(struc
* -> ask driver for current freq and notify governors about a change
*/
if (cpufreq_driver->get && has_target() &&
- (cpufreq_suspended || WARN_ON(!cpufreq_verify_current_freq(policy, false))))
+ (cpufreq_is_suspended(policy) ||
+ WARN_ON(!cpufreq_verify_current_freq(policy, false))))
return;
refresh_frequency_limits(policy);
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -149,6 +149,9 @@ struct cpufreq_policy {
/* Pending policy->min/max update for the driver */
bool update_limits;
+ /* The policy has been suspended. */
+ bool suspended;
+
/* Cached frequency lookup from cpufreq_driver_resolve_freq. */
unsigned int cached_target_freq;
unsigned int cached_resolved_idx;
^ permalink raw reply [flat|nested] 15+ messages in thread* [REGRESSION: [PATCH v2 1/3] cpufreq: Improve suspend-resume synchronization
2026-11-03 19:45 ` [PATCH v2 1/3] cpufreq: Improve suspend-resume synchronization Rafael J. Wysocki
@ 2026-11-18 13:03 ` Borah, Chaitanya Kumar
0 siblings, 0 replies; 15+ messages in thread
From: Borah, Chaitanya Kumar @ 2026-11-18 13:03 UTC (permalink / raw)
To: Rafael J. Wysocki, Linux PM
Cc: Viresh Kumar, Christian Loehle, Doug Smythies, Zak,
Srinivas Pandruvada, Mario Limonciello,
intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
ravitejax.veesam
Hello Rafael,
On 11/4/2026 1:15 AM, Rafael J. Wysocki wrote:
> From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
>
> The suspend-resume synchronization in the cpufreq core is not perfect
> because the global cpufreq_suspended variable is set at the end of
> cpufreq_suspend() after stopping governors for all of the active
> policies, so the governor .limits() callback may run via
> cpufreq_governor_limits() after stopping the governor and before
> setting cpufreq_suspended which is questionable. Likewise, the
> governor .limits() callback may run between clearing cpufreq_suspended
> in cpufreq_resume() and starting the governor.
>
> Address this by adding a per-policy "suspended" flag that is always
> read under the policy rwsem and is updated under it when the governor
> is stopped in cpufreq_suspend() and when the governor is restarted in
> cpufreq_resume().
>
> Also make cpufreq_resume() use the cpus_read_lock guard to reflect
> what is done in cpufreq_suspend() and call cpufreq_exit_governor() for
> policies that were suspended during a system suspend transition and
> are inactive during the subsequent system resume (to avoid leaking an
> inactive policy with a stopped governor that has not exited yet).
>
This seems to be causing regression in our CI [1] (affecting dg1 and
dg2). We could not revert the patch cleanly but resetting to its parent
heals the issue.
<4> [510.751891] ======================================================
<4> [510.751907] WARNING: possible circular locking dependency detected
<4> [510.751925] 7.4.0-rc3-CI_DRM_19546-gfb078d17b966+ #1 Tainted: G S
U L
<4> [510.751946] ------------------------------------------------------
<4> [510.751962] rtcwake/4256 is trying to acquire lock:
<4> [510.751977] ffffffff83ce0f40
(intel_pstate_driver_lock){+.+.}-{3:3}, at: set_power_ctl_ee_state+0x1a/0x90
<4> [510.752022]
but task is already holding lock:
<4> [510.752038] ffffffff83886890 (cpu_hotplug_lock){++++}-{0:0}, at:
cpufreq_resume+0x23/0x250
<4> [510.752074]
which lock already depends on the new lock.
<4> [510.752094]
the existing dependency chain (in reverse order) is:
<4> [510.752112]
-> #1 (cpu_hotplug_lock){++++}-{0:0}:
<4> [510.752137] cpus_read_lock+0x3c/0x100
<4> [510.752157] cpufreq_register_driver+0xca/0x380
<4> [510.752175] intel_pstate_register_driver+0x9e/0x1d0
<4> [510.752192] intel_pstate_init+0x3e3/0xb30
<4> [510.752211] do_one_initcall+0x59/0x3d0
<4> [510.752229] kernel_init_freeable+0x3dc/0x6b0
<4> [510.752249] kernel_init+0x20/0x210
<4> [510.752264] ret_from_fork+0x3bf/0x470
<4> [510.752282] ret_from_fork_asm+0x1a/0x30
<4> [510.752299]
-> #0 (intel_pstate_driver_lock){+.+.}-{3:3}:
<4> [510.752325] __lock_acquire+0x1700/0x29c0
<4> [510.752341] lock_acquire+0xd9/0x2f0
<4> [510.752355] __mutex_lock+0xae/0x1030
<4> [510.752372] mutex_lock_nested+0x1b/0x30
<4> [510.752390] set_power_ctl_ee_state+0x1a/0x90
<4> [510.752409] intel_pstate_resume+0x109/0x110
<4> [510.752428] cpufreq_resume+0x153/0x250
<4> [510.752445] dpm_resume+0x1f1/0x390
<4> [510.752459] dpm_resume_end+0x11/0x30
<4> [510.752474] suspend_devices_and_enter+0x372/0xcb0
<4> [510.752491] pm_suspend+0x372/0x840
<4> [510.752506] state_store+0x6e/0xe0
<4> [510.752523] kobj_attr_store+0x12/0x40
<4> [510.752541] sysfs_kf_write+0x4d/0x80
<4> [510.752559] kernfs_fop_write_iter+0x193/0x240
<4> [510.752576] vfs_write+0x285/0x530
<4> [510.752591] ksys_write+0x6f/0xf0
<4> [510.752606] __x64_sys_write+0x19/0x30
<4> [510.752622] x64_sys_call+0x1285/0x27e0
<4> [510.752637] do_syscall_64+0xec/0x680
<4> [510.752654] entry_SYSCALL_64_after_hwframe+0x76/0x7e
Could you please check why the patch causes this regression and provide
a fix if necessary?
Regards
Chaitanya
[1]
https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_19546/shard-dg1-14/igt@i915_suspend@basic-s2idle-without-i915.html
--Bisect Logs--
git bisect start
# status: waiting for both good and bad commits
# bad: [cfe67bbcfc37474cbb4482d750d4fba34bbc5a24] drm-tip:
2026y-11m-17d-05h-12m-00s UTC integration manifest
git bisect bad cfe67bbcfc37474cbb4482d750d4fba34bbc5a24
# status: waiting for good commit(s), bad commit known
# good: [39e407b553ec15d4a233b651531ad431ed7542be] drm/sun4i: dw-hdmi:
Deinit PHY in bind error path
git bisect good 39e407b553ec15d4a233b651531ad431ed7542be
# bad: [715f145f6204363a50853eb15719dc860db0bc01] drm/i915/dsb: Realign
GOSUB only for QW slots 6 and 7
git bisect bad 715f145f6204363a50853eb15719dc860db0bc01
# bad: [7e1392a42ea288d70a266f6553fe06f57f8647ea] Merge tag
'net-7.4-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net
git bisect bad 7e1392a42ea288d70a266f6553fe06f57f8647ea
# good: [0359338fd8cf1a2dc001d0cd69c331c17decee88] af_unix: Inherit
SO_INQ in unix_stream_connect()
git bisect good 0359338fd8cf1a2dc001d0cd69c331c17decee88
# good: [79eb6679ef6a0d5ea68da53a8321fb1dc72299b9] Merge tag
'loongarch-fixes-7.4-1' of
git://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson
git bisect good 79eb6679ef6a0d5ea68da53a8321fb1dc72299b9
# bad: [baa6744dc939a927e2c94e5f20aff01ac538aef1] Merge tag
'acpi-7.4-rc3' of
git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
git bisect bad baa6744dc939a927e2c94e5f20aff01ac538aef1
# good: [2cca8a6f6ae690755862f5b633125119dcf6bd0c] Merge patch series
"ns: fixes identifier fixes"
git bisect good 2cca8a6f6ae690755862f5b633125119dcf6bd0c
# bad: [df42809bd599109660bd3f95e2e22330c80993df] Merge branches
'pm-cpufreq' and 'pm-runtime'
git bisect bad df42809bd599109660bd3f95e2e22330c80993df
# bad: [6bc092a0fc4d331a4adbbb664078af149c580834] cpufreq: acpi-cpufreq:
fix P-state index mismatch in extract_io()
git bisect bad 6bc092a0fc4d331a4adbbb664078af149c580834
# bad: [02e77af824d5be3a94fdd885835a352f90d24c5c] cpufreq: intel_pstate:
Clear last written P-state value on suspend
git bisect bad 02e77af824d5be3a94fdd885835a352f90d24c5c
# bad: [eee2a44e4e2b41c0699919a550d41cc38daa4f42] cpufreq: Improve
suspend-resume synchronization
git bisect bad eee2a44e4e2b41c0699919a550d41cc38daa4f42
# good: [e6f50e602e373583423654ec000cad8b8d08f7bc] cpufreq: Hold the
policy write lock when changing boost state
git bisect good e6f50e602e373583423654ec000cad8b8d08f7bc
# first bad commit: [eee2a44e4e2b41c0699919a550d41cc38daa4f42] cpufreq:
Improve suspend-resume synchronization
> Fixes: 8e30444e1530 ("cpufreq: fix cpufreq suspend/resume for intel_pstate")
> Fixes: b1b12babe3b7 ("cpufreq: update 'cpufreq_suspended' after stopping governors")
> Cc: All applicable <stable@vger.kernel.org>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
>
> v1 -> v2:
> * Retain all of the cpufreq_suspended checks to avoid carrying out
> governor operations after suspending cpufreq during system
> shutdown and during hibernation resume on systems with SMT (Sashiko)
>
> * Rearrange cpufreq_resume() to walk all cpufreq policies and call
> cpufreq_resume_policy() for all of them
>
> * Call cpufreq_exit_governor() in cpufreq_resume_policy() for
> policies that were suspended during a system suspend transition and
> are inactive during the subsequent system resume (Sashiko)
>
> * Update cpufreq_suspended under cpus_read_lock in cpufreq_resume()
> for more symmetry with cpufreq_suspend()
>
> * Update changelog
>
> ---
> drivers/cpufreq/cpufreq.c | 86 +++++++++++++++++++++++++++++++++-------------
> include/linux/cpufreq.h | 3 +
> 2 files changed, 66 insertions(+), 23 deletions(-)
>
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -35,6 +35,9 @@
> static LIST_HEAD(cpufreq_policy_list);
>
> /* Macros to iterate over CPU policies */
> +#define for_each_policy(__policy) \
> + list_for_each_entry(__policy, &cpufreq_policy_list, policy_list)
> +
> #define for_each_suitable_policy(__policy, __active) \
> list_for_each_entry(__policy, &cpufreq_policy_list, policy_list) \
> if ((__active) == !policy_is_inactive(__policy))
> @@ -1956,6 +1959,14 @@ int cpufreq_generic_suspend(struct cpufr
> }
> EXPORT_SYMBOL(cpufreq_generic_suspend);
>
> +static void cpufreq_suspend_policy(struct cpufreq_policy *policy)
> +{
> + guard(cpufreq_policy_write)(policy);
> +
> + cpufreq_stop_governor(policy);
> + policy->suspended = true;
> +}
> +
> /**
> * cpufreq_suspend() - Suspend CPUFreq governors.
> *
> @@ -1978,11 +1989,8 @@ void cpufreq_suspend(void)
> pr_debug("%s: Suspending Governors\n", __func__);
>
> for_each_active_policy(policy) {
> - if (has_target()) {
> - scoped_guard(cpufreq_policy_write, policy) {
> - cpufreq_stop_governor(policy);
> - }
> - }
> + if (has_target())
> + cpufreq_suspend_policy(policy);
>
> if (cpufreq_driver->suspend && cpufreq_driver->suspend(policy))
> pr_err("%s: Failed to suspend driver: %s\n", __func__,
> @@ -1994,6 +2002,32 @@ suspend:
> cpus_read_unlock();
> }
>
> +static void cpufreq_resume_policy(struct cpufreq_policy *policy, bool start)
> +{
> + guard(cpufreq_policy_write)(policy);
> +
> + if (!policy->suspended)
> + return;
> +
> + policy->suspended = false;
> +
> + if (policy_is_inactive(policy)) {
> + /*
> + * The policy was active when it was suspended, so its governor
> + * is still there. Let the governor go.
> + */
> + cpufreq_exit_governor(policy);
> + return;
> + }
> +
> + if (!start)
> + return;
> +
> + if (cpufreq_start_governor(policy))
> + pr_err("%s: Failed to start governor for CPU%u's policy\n",
> + __func__, policy->cpu);
> +}
> +
> /**
> * cpufreq_resume() - Resume CPUFreq governors.
> *
> @@ -2003,11 +2037,12 @@ suspend:
> void cpufreq_resume(void)
> {
> struct cpufreq_policy *policy;
> - int ret;
>
> if (!cpufreq_driver)
> return;
>
> + guard(cpus_read_lock)();
> +
> if (unlikely(!cpufreq_suspended))
> return;
>
> @@ -2018,19 +2053,18 @@ void cpufreq_resume(void)
>
> pr_debug("%s: Resuming Governors\n", __func__);
>
> - for_each_active_policy(policy) {
> - if (cpufreq_driver->resume && cpufreq_driver->resume(policy)) {
> - pr_err("%s: Failed to resume driver: %s\n", __func__,
> - cpufreq_driver->name);
> - } else if (has_target()) {
> - scoped_guard(cpufreq_policy_write, policy) {
> - ret = cpufreq_start_governor(policy);
> - }
> + for_each_policy(policy) {
> + int ret = 0;
>
> + if (cpufreq_driver->resume && !policy_is_inactive(policy)) {
> + ret = cpufreq_driver->resume(policy);
> if (ret)
> - pr_err("%s: Failed to start governor for CPU%u's policy\n",
> - __func__, policy->cpu);
> + pr_err("%s: Failed to resume driver: %s\n", __func__,
> + cpufreq_driver->name);
> }
> +
> + if (has_target())
> + cpufreq_resume_policy(policy, ret == 0);
> }
> }
>
> @@ -2412,12 +2446,17 @@ __weak struct cpufreq_governor *cpufreq_
> return NULL;
> }
>
> +static bool cpufreq_is_suspended(struct cpufreq_policy *policy)
> +{
> + return cpufreq_suspended || policy->suspended;
> +}
> +
> static int cpufreq_init_governor(struct cpufreq_policy *policy)
> {
> int ret;
>
> - /* Don't start any governor operations if we are entering suspend */
> - if (cpufreq_suspended)
> + /* Don't start any governor operations for suspended policies. */
> + if (cpufreq_is_suspended(policy))
> return 0;
> /*
> * Governor might not be initiated here if ACPI _PPC changed
> @@ -2460,7 +2499,7 @@ static int cpufreq_init_governor(struct
>
> static void cpufreq_exit_governor(struct cpufreq_policy *policy)
> {
> - if (cpufreq_suspended || !policy->governor)
> + if (cpufreq_is_suspended(policy) || !policy->governor)
> return;
>
> pr_debug("%s: for CPU %u\n", __func__, policy->cpu);
> @@ -2475,7 +2514,7 @@ int cpufreq_start_governor(struct cpufre
> {
> int ret;
>
> - if (cpufreq_suspended)
> + if (cpufreq_is_suspended(policy))
> return 0;
>
> if (!policy->governor)
> @@ -2499,7 +2538,7 @@ int cpufreq_start_governor(struct cpufre
>
> void cpufreq_stop_governor(struct cpufreq_policy *policy)
> {
> - if (cpufreq_suspended || !policy->governor)
> + if (cpufreq_is_suspended(policy) || !policy->governor)
> return;
>
> pr_debug("%s: for CPU %u\n", __func__, policy->cpu);
> @@ -2510,7 +2549,7 @@ void cpufreq_stop_governor(struct cpufre
>
> static void cpufreq_governor_limits(struct cpufreq_policy *policy)
> {
> - if (cpufreq_suspended || !policy->governor)
> + if (cpufreq_is_suspended(policy) || !policy->governor)
> return;
>
> pr_debug("%s: for CPU %u\n", __func__, policy->cpu);
> @@ -2747,7 +2786,8 @@ static void cpufreq_policy_refresh(struc
> * -> ask driver for current freq and notify governors about a change
> */
> if (cpufreq_driver->get && has_target() &&
> - (cpufreq_suspended || WARN_ON(!cpufreq_verify_current_freq(policy, false))))
> + (cpufreq_is_suspended(policy) ||
> + WARN_ON(!cpufreq_verify_current_freq(policy, false))))
> return;
>
> refresh_frequency_limits(policy);
> --- a/include/linux/cpufreq.h
> +++ b/include/linux/cpufreq.h
> @@ -149,6 +149,9 @@ struct cpufreq_policy {
> /* Pending policy->min/max update for the driver */
> bool update_limits;
>
> + /* The policy has been suspended. */
> + bool suspended;
> +
> /* Cached frequency lookup from cpufreq_driver_resolve_freq. */
> unsigned int cached_target_freq;
> unsigned int cached_resolved_idx;
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2 2/3] cpufreq: Force passing target frequency to driver during resume
2026-11-03 19:42 [PATCH v2 0/3] cpufreq: Fix synchronization with system suspend/resume Rafael J. Wysocki
2026-11-03 19:45 ` [PATCH v2 1/3] cpufreq: Improve suspend-resume synchronization Rafael J. Wysocki
@ 2026-11-03 19:47 ` Rafael J. Wysocki
2026-11-04 11:56 ` Christian Loehle
2026-11-03 19:49 ` [PATCH v2 3/3] cpufreq: intel_pstate: Clear last written P-state value on suspend Rafael J. Wysocki
` (6 subsequent siblings)
8 siblings, 1 reply; 15+ messages in thread
From: Rafael J. Wysocki @ 2026-11-03 19:47 UTC (permalink / raw)
To: Linux PM
Cc: Viresh Kumar, Christian Loehle, Doug Smythies, Zak,
Srinivas Pandruvada, Mario Limonciello
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
The policy->cur value preserved across a system suspend-resume cycle
may become stale in some cases and it may prevent the CPU performance
scaling logic from being updated due to the target_freq == policy->cur
check in __cpufreq_driver_target() [1].
To address this, adjust the existing mechanism to force the invocation
of the driver .target() callback in __cpufreq_driver_target() and make
cpufreq_resume_policy() use it.
This involves renaming update_limits in struct cpufreq_policy to
force_target and moving the driver CPUFREQ_NEED_UPDATE_LIMITS flag check
from __cpufreq_driver_target() to cpufreq_set_policy(), where it is used
as a condition for setting policy->force_target.
In cpufreq_resume_policy(), policy->force_target is set for drivers that
implement the .target() callback, but don't implement the .get() one,
which is the case when the driver callback needs to run if policy->cur
becomes stale while suspended.
Fixes: 2f0aea936360 ("cpufreq: suspend governors on system suspend/hibernate")
Link: https://lore.kernel.org/linux-pm/20261027143725.3763827-1-zakbrightonknight@gmail.com/ [1]
Reported-by: Zak Brighton Knight <zakbrightonknight@gmail.com>
Reported-by: Doug Smythies <dsmythies@telus.net>
Cc: All applicable <stable@vger.kernel.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
v1 -> v2:
* Always clear policy->force_target if set in __cpufreq_driver_target()
to avoid forcing the driver callback next time unnecessarily (Sashiko)
* Replace an outdated comment in __cpufreq_driver_target()
* Set policy->force_target only if .target() is present and .get() is not
present because that is the only case in which it may matter
* Update changelog
---
drivers/cpufreq/cpufreq.c | 33 +++++++++++++++++++++------------
include/linux/cpufreq.h | 4 ++--
2 files changed, 23 insertions(+), 14 deletions(-)
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -2023,6 +2023,15 @@ static void cpufreq_resume_policy(struct
if (!start)
return;
+ /*
+ * Force executing the driver .target() callback, if present, in the
+ * next invocation of __cpufreq_driver_target() in case policy->cur has
+ * become stale while suspended, but do it only for drivers without a
+ * .get() callback for which cpufreq_verify_current_freq() is a NOP.
+ */
+ if (cpufreq_driver->target && !cpufreq_driver->get)
+ policy->force_target = true;
+
if (cpufreq_start_governor(policy))
pr_err("%s: Failed to start governor for CPU%u's policy\n",
__func__, policy->cpu);
@@ -2400,17 +2409,14 @@ int __cpufreq_driver_target(struct cpufr
policy->cpu, policy->cur, target_freq, old_target_freq, relation);
/*
- * This might look like a redundant call as we are checking it again
- * after finding index. But it is left intentionally for cases where
- * exactly same freq is called again and so we can save on few function
- * calls.
+ * Unless invoking the target callback is forced, skip the update if the
+ * frequency is not really changing.
*/
- if (target_freq == policy->cur) {
- if (!(cpufreq_driver->flags & CPUFREQ_NEED_UPDATE_LIMITS) ||
- !policy->update_limits)
- return 0;
-
- policy->update_limits = false;
+ if (policy->force_target) {
+ /* Avoid forcing the driver callback unnecessarily next time. */
+ policy->force_target = false;
+ } else if (target_freq == policy->cur) {
+ return 0;
}
if (cpufreq_driver->target) {
@@ -2669,6 +2675,7 @@ static int cpufreq_set_policy(struct cpu
struct cpufreq_governor *new_gov,
unsigned int new_pol)
{
+ bool need_update_limits = cpufreq_driver->flags & CPUFREQ_NEED_UPDATE_LIMITS;
struct cpufreq_policy_data new_data;
struct cpufreq_governor *old_gov;
unsigned int freq;
@@ -2708,7 +2715,8 @@ static int cpufreq_set_policy(struct cpu
CPUFREQ_RELATION_H);
if (freq != policy->max) {
WRITE_ONCE(policy->max, freq);
- policy->update_limits = true;
+ if (need_update_limits)
+ policy->force_target = true;
}
freq = __resolve_freq(policy, new_data.min, new_data.min, new_data.max,
@@ -2716,7 +2724,8 @@ static int cpufreq_set_policy(struct cpu
freq = min(freq, policy->max);
if (freq != policy->min) {
WRITE_ONCE(policy->min, freq);
- policy->update_limits = true;
+ if (need_update_limits)
+ policy->force_target = true;
}
trace_cpu_frequency_limits(policy);
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -146,8 +146,8 @@ struct cpufreq_policy {
/* Per policy boost supported flag. */
bool boost_supported;
- /* Pending policy->min/max update for the driver */
- bool update_limits;
+ /* Force passing target frequency to the driver. */
+ bool force_target;
/* The policy has been suspended. */
bool suspended;
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH v2 2/3] cpufreq: Force passing target frequency to driver during resume
2026-11-03 19:47 ` [PATCH v2 2/3] cpufreq: Force passing target frequency to driver during resume Rafael J. Wysocki
@ 2026-11-04 11:56 ` Christian Loehle
2026-11-04 13:44 ` Rafael J. Wysocki (Intel)
0 siblings, 1 reply; 15+ messages in thread
From: Christian Loehle @ 2026-11-04 11:56 UTC (permalink / raw)
To: Rafael J. Wysocki, Linux PM
Cc: Viresh Kumar, Doug Smythies, Zak, Srinivas Pandruvada,
Mario Limonciello
On 11/3/26 19:47, Rafael J. Wysocki wrote:
> From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
>
> The policy->cur value preserved across a system suspend-resume cycle
> may become stale in some cases and it may prevent the CPU performance
> scaling logic from being updated due to the target_freq == policy->cur
> check in __cpufreq_driver_target() [1].
>
> To address this, adjust the existing mechanism to force the invocation
> of the driver .target() callback in __cpufreq_driver_target() and make
> cpufreq_resume_policy() use it.
>
> This involves renaming update_limits in struct cpufreq_policy to
> force_target and moving the driver CPUFREQ_NEED_UPDATE_LIMITS flag check
> from __cpufreq_driver_target() to cpufreq_set_policy(), where it is used
> as a condition for setting policy->force_target.
>
> In cpufreq_resume_policy(), policy->force_target is set for drivers that
> implement the .target() callback, but don't implement the .get() one,
> which is the case when the driver callback needs to run if policy->cur
> becomes stale while suspended.
>
> Fixes: 2f0aea936360 ("cpufreq: suspend governors on system suspend/hibernate")
> Link: https://lore.kernel.org/linux-pm/20261027143725.3763827-1-zakbrightonknight@gmail.com/ [1]
> Reported-by: Zak Brighton Knight <zakbrightonknight@gmail.com>
> Reported-by: Doug Smythies <dsmythies@telus.net>
> Cc: All applicable <stable@vger.kernel.org>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
>
> v1 -> v2:
> * Always clear policy->force_target if set in __cpufreq_driver_target()
> to avoid forcing the driver callback next time unnecessarily (Sashiko)
>
> * Replace an outdated comment in __cpufreq_driver_target()
>
> * Set policy->force_target only if .target() is present and .get() is not
> present because that is the only case in which it may matter
>
> * Update changelog
>
> ---
> drivers/cpufreq/cpufreq.c | 33 +++++++++++++++++++++------------
> include/linux/cpufreq.h | 4 ++--
> 2 files changed, 23 insertions(+), 14 deletions(-)
>
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -2023,6 +2023,15 @@ static void cpufreq_resume_policy(struct
> if (!start)
> return;
>
> + /*
> + * Force executing the driver .target() callback, if present, in the
> + * next invocation of __cpufreq_driver_target() in case policy->cur has
> + * become stale while suspended, but do it only for drivers without a
> + * .get() callback for which cpufreq_verify_current_freq() is a NOP.
> + */
> + if (cpufreq_driver->target && !cpufreq_driver->get)
> + policy->force_target = true;
> +
> if (cpufreq_start_governor(policy))
> pr_err("%s: Failed to start governor for CPU%u's policy\n",
> __func__, policy->cpu);
> @@ -2400,17 +2409,14 @@ int __cpufreq_driver_target(struct cpufr
> policy->cpu, policy->cur, target_freq, old_target_freq, relation);
>
> /*
> - * This might look like a redundant call as we are checking it again
> - * after finding index. But it is left intentionally for cases where
> - * exactly same freq is called again and so we can save on few function
> - * calls.
> + * Unless invoking the target callback is forced, skip the update if the
> + * frequency is not really changing.
> */
> - if (target_freq == policy->cur) {
> - if (!(cpufreq_driver->flags & CPUFREQ_NEED_UPDATE_LIMITS) ||
> - !policy->update_limits)
> - return 0;
> -
> - policy->update_limits = false;
> + if (policy->force_target) {
> + /* Avoid forcing the driver callback unnecessarily next time. */
> + policy->force_target = false;
> + } else if (target_freq == policy->cur) {
> + return 0;
> [snip]
This is too early though? Should be something like:
---->8-----
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 5f0ddb8823cb..66bc53f13eef 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -2398,6 +2398,7 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
unsigned int relation)
{
unsigned int old_target_freq = target_freq;
+ int ret;
if (cpufreq_disabled())
return -ENODEV;
@@ -2412,12 +2413,8 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
* Unless invoking the target callback is forced, skip the update if the
* frequency is not really changing.
*/
- if (policy->force_target) {
- /* Avoid forcing the driver callback unnecessarily next time. */
- policy->force_target = false;
- } else if (target_freq == policy->cur) {
+ if (!policy->force_target && target_freq == policy->cur)
return 0;
- }
if (cpufreq_driver->target) {
/*
@@ -2427,13 +2424,18 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
if (!policy->efficiencies_available)
relation &= ~CPUFREQ_RELATION_E;
- return cpufreq_driver->target(policy, target_freq, relation);
+ ret = cpufreq_driver->target(policy, target_freq, relation);
+ } else if (cpufreq_driver->target_index) {
+ ret = __target_index(policy, policy->cached_resolved_idx);
+ } else {
+ return -EINVAL;
}
- if (!cpufreq_driver->target_index)
- return -EINVAL;
+ /* Failed updates still need to be passed to the driver next time. */
+ if (!ret)
+ policy->force_target = false;
- return __target_index(policy, policy->cached_resolved_idx);
+ return ret;
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH v2 2/3] cpufreq: Force passing target frequency to driver during resume
2026-11-04 11:56 ` Christian Loehle
@ 2026-11-04 13:44 ` Rafael J. Wysocki (Intel)
2026-11-04 15:09 ` Christian Loehle
0 siblings, 1 reply; 15+ messages in thread
From: Rafael J. Wysocki (Intel) @ 2026-11-04 13:44 UTC (permalink / raw)
To: Christian Loehle
Cc: Rafael J. Wysocki, Linux PM, Viresh Kumar, Doug Smythies, Zak,
Srinivas Pandruvada, Mario Limonciello
On Wed, Nov 4, 2026 at 12:56 PM Christian Loehle
<christian.loehle@arm.com> wrote:
>
> On 11/3/26 19:47, Rafael J. Wysocki wrote:
> > From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
> >
> > The policy->cur value preserved across a system suspend-resume cycle
> > may become stale in some cases and it may prevent the CPU performance
> > scaling logic from being updated due to the target_freq == policy->cur
> > check in __cpufreq_driver_target() [1].
> >
> > To address this, adjust the existing mechanism to force the invocation
> > of the driver .target() callback in __cpufreq_driver_target() and make
> > cpufreq_resume_policy() use it.
> >
> > This involves renaming update_limits in struct cpufreq_policy to
> > force_target and moving the driver CPUFREQ_NEED_UPDATE_LIMITS flag check
> > from __cpufreq_driver_target() to cpufreq_set_policy(), where it is used
> > as a condition for setting policy->force_target.
> >
> > In cpufreq_resume_policy(), policy->force_target is set for drivers that
> > implement the .target() callback, but don't implement the .get() one,
> > which is the case when the driver callback needs to run if policy->cur
> > becomes stale while suspended.
> >
> > Fixes: 2f0aea936360 ("cpufreq: suspend governors on system suspend/hibernate")
> > Link: https://lore.kernel.org/linux-pm/20261027143725.3763827-1-zakbrightonknight@gmail.com/ [1]
> > Reported-by: Zak Brighton Knight <zakbrightonknight@gmail.com>
> > Reported-by: Doug Smythies <dsmythies@telus.net>
> > Cc: All applicable <stable@vger.kernel.org>
> > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> > ---
> >
> > v1 -> v2:
> > * Always clear policy->force_target if set in __cpufreq_driver_target()
> > to avoid forcing the driver callback next time unnecessarily (Sashiko)
> >
> > * Replace an outdated comment in __cpufreq_driver_target()
> >
> > * Set policy->force_target only if .target() is present and .get() is not
> > present because that is the only case in which it may matter
> >
> > * Update changelog
> >
> > ---
> > drivers/cpufreq/cpufreq.c | 33 +++++++++++++++++++++------------
> > include/linux/cpufreq.h | 4 ++--
> > 2 files changed, 23 insertions(+), 14 deletions(-)
> >
> > --- a/drivers/cpufreq/cpufreq.c
> > +++ b/drivers/cpufreq/cpufreq.c
> > @@ -2023,6 +2023,15 @@ static void cpufreq_resume_policy(struct
> > if (!start)
> > return;
> >
> > + /*
> > + * Force executing the driver .target() callback, if present, in the
> > + * next invocation of __cpufreq_driver_target() in case policy->cur has
> > + * become stale while suspended, but do it only for drivers without a
> > + * .get() callback for which cpufreq_verify_current_freq() is a NOP.
> > + */
> > + if (cpufreq_driver->target && !cpufreq_driver->get)
> > + policy->force_target = true;
> > +
> > if (cpufreq_start_governor(policy))
> > pr_err("%s: Failed to start governor for CPU%u's policy\n",
> > __func__, policy->cpu);
> > @@ -2400,17 +2409,14 @@ int __cpufreq_driver_target(struct cpufr
> > policy->cpu, policy->cur, target_freq, old_target_freq, relation);
> >
> > /*
> > - * This might look like a redundant call as we are checking it again
> > - * after finding index. But it is left intentionally for cases where
> > - * exactly same freq is called again and so we can save on few function
> > - * calls.
> > + * Unless invoking the target callback is forced, skip the update if the
> > + * frequency is not really changing.
> > */
> > - if (target_freq == policy->cur) {
> > - if (!(cpufreq_driver->flags & CPUFREQ_NEED_UPDATE_LIMITS) ||
> > - !policy->update_limits)
> > - return 0;
> > -
> > - policy->update_limits = false;
> > + if (policy->force_target) {
> > + /* Avoid forcing the driver callback unnecessarily next time. */
> > + policy->force_target = false;
> > + } else if (target_freq == policy->cur) {
> > + return 0;
> > [snip]
>
> This is too early though? Should be something like:
I don't think so.
If the driver has a problem, there is not much the core can do about it.
Do you have any specific drivers in mind here?
> ---->8-----
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index 5f0ddb8823cb..66bc53f13eef 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -2398,6 +2398,7 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
> unsigned int relation)
> {
> unsigned int old_target_freq = target_freq;
> + int ret;
>
> if (cpufreq_disabled())
> return -ENODEV;
> @@ -2412,12 +2413,8 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
> * Unless invoking the target callback is forced, skip the update if the
> * frequency is not really changing.
> */
> - if (policy->force_target) {
> - /* Avoid forcing the driver callback unnecessarily next time. */
> - policy->force_target = false;
> - } else if (target_freq == policy->cur) {
> + if (!policy->force_target && target_freq == policy->cur)
> return 0;
> - }
>
> if (cpufreq_driver->target) {
> /*
> @@ -2427,13 +2424,18 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
> if (!policy->efficiencies_available)
> relation &= ~CPUFREQ_RELATION_E;
>
> - return cpufreq_driver->target(policy, target_freq, relation);
> + ret = cpufreq_driver->target(policy, target_freq, relation);
> + } else if (cpufreq_driver->target_index) {
> + ret = __target_index(policy, policy->cached_resolved_idx);
> + } else {
> + return -EINVAL;
> }
>
> - if (!cpufreq_driver->target_index)
> - return -EINVAL;
> + /* Failed updates still need to be passed to the driver next time. */
> + if (!ret)
> + policy->force_target = false;
>
> - return __target_index(policy, policy->cached_resolved_idx);
> + return ret;
>
>
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH v2 2/3] cpufreq: Force passing target frequency to driver during resume
2026-11-04 13:44 ` Rafael J. Wysocki (Intel)
@ 2026-11-04 15:09 ` Christian Loehle
2026-11-04 15:46 ` Rafael J. Wysocki (Intel)
0 siblings, 1 reply; 15+ messages in thread
From: Christian Loehle @ 2026-11-04 15:09 UTC (permalink / raw)
To: Rafael J. Wysocki (Intel)
Cc: Linux PM, Viresh Kumar, Doug Smythies, Zak, Srinivas Pandruvada,
Mario Limonciello
On 11/4/26 13:44, Rafael J. Wysocki (Intel) wrote:
> On Wed, Nov 4, 2026 at 12:56 PM Christian Loehle
> <christian.loehle@arm.com> wrote:
>>
>> On 11/3/26 19:47, Rafael J. Wysocki wrote:
>>> From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
>>>
>>> The policy->cur value preserved across a system suspend-resume cycle
>>> may become stale in some cases and it may prevent the CPU performance
>>> scaling logic from being updated due to the target_freq == policy->cur
>>> check in __cpufreq_driver_target() [1].
>>>
>>> To address this, adjust the existing mechanism to force the invocation
>>> of the driver .target() callback in __cpufreq_driver_target() and make
>>> cpufreq_resume_policy() use it.
>>>
>>> This involves renaming update_limits in struct cpufreq_policy to
>>> force_target and moving the driver CPUFREQ_NEED_UPDATE_LIMITS flag check
>>> from __cpufreq_driver_target() to cpufreq_set_policy(), where it is used
>>> as a condition for setting policy->force_target.
>>>
>>> In cpufreq_resume_policy(), policy->force_target is set for drivers that
>>> implement the .target() callback, but don't implement the .get() one,
>>> which is the case when the driver callback needs to run if policy->cur
>>> becomes stale while suspended.
>>>
>>> Fixes: 2f0aea936360 ("cpufreq: suspend governors on system suspend/hibernate")
>>> Link: https://lore.kernel.org/linux-pm/20261027143725.3763827-1-zakbrightonknight@gmail.com/ [1]
>>> Reported-by: Zak Brighton Knight <zakbrightonknight@gmail.com>
>>> Reported-by: Doug Smythies <dsmythies@telus.net>
>>> Cc: All applicable <stable@vger.kernel.org>
>>> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>>> ---
>>>
>>> v1 -> v2:
>>> * Always clear policy->force_target if set in __cpufreq_driver_target()
>>> to avoid forcing the driver callback next time unnecessarily (Sashiko)
>>>
>>> * Replace an outdated comment in __cpufreq_driver_target()
>>>
>>> * Set policy->force_target only if .target() is present and .get() is not
>>> present because that is the only case in which it may matter
>>>
>>> * Update changelog
>>>
>>> ---
>>> drivers/cpufreq/cpufreq.c | 33 +++++++++++++++++++++------------
>>> include/linux/cpufreq.h | 4 ++--
>>> 2 files changed, 23 insertions(+), 14 deletions(-)
>>>
>>> --- a/drivers/cpufreq/cpufreq.c
>>> +++ b/drivers/cpufreq/cpufreq.c
>>> @@ -2023,6 +2023,15 @@ static void cpufreq_resume_policy(struct
>>> if (!start)
>>> return;
>>>
>>> + /*
>>> + * Force executing the driver .target() callback, if present, in the
>>> + * next invocation of __cpufreq_driver_target() in case policy->cur has
>>> + * become stale while suspended, but do it only for drivers without a
>>> + * .get() callback for which cpufreq_verify_current_freq() is a NOP.
>>> + */
>>> + if (cpufreq_driver->target && !cpufreq_driver->get)
>>> + policy->force_target = true;
>>> +
>>> if (cpufreq_start_governor(policy))
>>> pr_err("%s: Failed to start governor for CPU%u's policy\n",
>>> __func__, policy->cpu);
>>> @@ -2400,17 +2409,14 @@ int __cpufreq_driver_target(struct cpufr
>>> policy->cpu, policy->cur, target_freq, old_target_freq, relation);
>>>
>>> /*
>>> - * This might look like a redundant call as we are checking it again
>>> - * after finding index. But it is left intentionally for cases where
>>> - * exactly same freq is called again and so we can save on few function
>>> - * calls.
>>> + * Unless invoking the target callback is forced, skip the update if the
>>> + * frequency is not really changing.
>>> */
>>> - if (target_freq == policy->cur) {
>>> - if (!(cpufreq_driver->flags & CPUFREQ_NEED_UPDATE_LIMITS) ||
>>> - !policy->update_limits)
>>> - return 0;
>>> -
>>> - policy->update_limits = false;
>>> + if (policy->force_target) {
>>> + /* Avoid forcing the driver callback unnecessarily next time. */
>>> + policy->force_target = false;
>>> + } else if (target_freq == policy->cur) {
>>> + return 0;
>>> [snip]
>>
>> This is too early though? Should be something like:
>
> I don't think so.
>
> If the driver has a problem, there is not much the core can do about it.
>
> Do you have any specific drivers in mind here?
Well drivers cppc_cpufreq is certainly possible with PCC.
I don't have a platform where this would likely be an issue, but MPAR limits
is an obvious one. For resume specifically, interestingly enough, MPAR limits
uses ktime_get() instead of _boottime, so it might not be entirely unreasonable
that we would hit this.
That being said cppc_cpufreq implements .get() making the above moot for resume.
Nonetheless the old update_limits path retained the update_limits flag on the write
failure and now we drop force_target?
> [snip]
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH v2 2/3] cpufreq: Force passing target frequency to driver during resume
2026-11-04 15:09 ` Christian Loehle
@ 2026-11-04 15:46 ` Rafael J. Wysocki (Intel)
0 siblings, 0 replies; 15+ messages in thread
From: Rafael J. Wysocki (Intel) @ 2026-11-04 15:46 UTC (permalink / raw)
To: Christian Loehle
Cc: Rafael J. Wysocki (Intel), Linux PM, Viresh Kumar, Doug Smythies,
Zak, Srinivas Pandruvada, Mario Limonciello
On Wed, Nov 4, 2026 at 4:09 PM Christian Loehle
<christian.loehle@arm.com> wrote:
>
> On 11/4/26 13:44, Rafael J. Wysocki (Intel) wrote:
> > On Wed, Nov 4, 2026 at 12:56 PM Christian Loehle
> > <christian.loehle@arm.com> wrote:
> >>
> >> On 11/3/26 19:47, Rafael J. Wysocki wrote:
> >>> From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
> >>>
> >>> The policy->cur value preserved across a system suspend-resume cycle
> >>> may become stale in some cases and it may prevent the CPU performance
> >>> scaling logic from being updated due to the target_freq == policy->cur
> >>> check in __cpufreq_driver_target() [1].
> >>>
> >>> To address this, adjust the existing mechanism to force the invocation
> >>> of the driver .target() callback in __cpufreq_driver_target() and make
> >>> cpufreq_resume_policy() use it.
> >>>
> >>> This involves renaming update_limits in struct cpufreq_policy to
> >>> force_target and moving the driver CPUFREQ_NEED_UPDATE_LIMITS flag check
> >>> from __cpufreq_driver_target() to cpufreq_set_policy(), where it is used
> >>> as a condition for setting policy->force_target.
> >>>
> >>> In cpufreq_resume_policy(), policy->force_target is set for drivers that
> >>> implement the .target() callback, but don't implement the .get() one,
> >>> which is the case when the driver callback needs to run if policy->cur
> >>> becomes stale while suspended.
> >>>
> >>> Fixes: 2f0aea936360 ("cpufreq: suspend governors on system suspend/hibernate")
> >>> Link: https://lore.kernel.org/linux-pm/20261027143725.3763827-1-zakbrightonknight@gmail.com/ [1]
> >>> Reported-by: Zak Brighton Knight <zakbrightonknight@gmail.com>
> >>> Reported-by: Doug Smythies <dsmythies@telus.net>
> >>> Cc: All applicable <stable@vger.kernel.org>
> >>> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> >>> ---
> >>>
> >>> v1 -> v2:
> >>> * Always clear policy->force_target if set in __cpufreq_driver_target()
> >>> to avoid forcing the driver callback next time unnecessarily (Sashiko)
> >>>
> >>> * Replace an outdated comment in __cpufreq_driver_target()
> >>>
> >>> * Set policy->force_target only if .target() is present and .get() is not
> >>> present because that is the only case in which it may matter
> >>>
> >>> * Update changelog
> >>>
> >>> ---
> >>> drivers/cpufreq/cpufreq.c | 33 +++++++++++++++++++++------------
> >>> include/linux/cpufreq.h | 4 ++--
> >>> 2 files changed, 23 insertions(+), 14 deletions(-)
> >>>
> >>> --- a/drivers/cpufreq/cpufreq.c
> >>> +++ b/drivers/cpufreq/cpufreq.c
> >>> @@ -2023,6 +2023,15 @@ static void cpufreq_resume_policy(struct
> >>> if (!start)
> >>> return;
> >>>
> >>> + /*
> >>> + * Force executing the driver .target() callback, if present, in the
> >>> + * next invocation of __cpufreq_driver_target() in case policy->cur has
> >>> + * become stale while suspended, but do it only for drivers without a
> >>> + * .get() callback for which cpufreq_verify_current_freq() is a NOP.
> >>> + */
> >>> + if (cpufreq_driver->target && !cpufreq_driver->get)
> >>> + policy->force_target = true;
> >>> +
> >>> if (cpufreq_start_governor(policy))
> >>> pr_err("%s: Failed to start governor for CPU%u's policy\n",
> >>> __func__, policy->cpu);
> >>> @@ -2400,17 +2409,14 @@ int __cpufreq_driver_target(struct cpufr
> >>> policy->cpu, policy->cur, target_freq, old_target_freq, relation);
> >>>
> >>> /*
> >>> - * This might look like a redundant call as we are checking it again
> >>> - * after finding index. But it is left intentionally for cases where
> >>> - * exactly same freq is called again and so we can save on few function
> >>> - * calls.
> >>> + * Unless invoking the target callback is forced, skip the update if the
> >>> + * frequency is not really changing.
> >>> */
> >>> - if (target_freq == policy->cur) {
> >>> - if (!(cpufreq_driver->flags & CPUFREQ_NEED_UPDATE_LIMITS) ||
> >>> - !policy->update_limits)
> >>> - return 0;
> >>> -
> >>> - policy->update_limits = false;
> >>> + if (policy->force_target) {
> >>> + /* Avoid forcing the driver callback unnecessarily next time. */
> >>> + policy->force_target = false;
> >>> + } else if (target_freq == policy->cur) {
> >>> + return 0;
> >>> [snip]
> >>
> >> This is too early though? Should be something like:
> >
> > I don't think so.
> >
> > If the driver has a problem, there is not much the core can do about it.
> >
> > Do you have any specific drivers in mind here?
>
> Well drivers cppc_cpufreq is certainly possible with PCC.
> I don't have a platform where this would likely be an issue, but MPAR limits
> is an obvious one. For resume specifically, interestingly enough, MPAR limits
> uses ktime_get() instead of _boottime, so it might not be entirely unreasonable
> that we would hit this.
> That being said cppc_cpufreq implements .get() making the above moot for resume.
>
> Nonetheless the old update_limits path retained the update_limits flag on the write
> failure and now we drop force_target?
The relevant code before the change is this:
if (target_freq == policy->cur) {
if (!(cpufreq_driver->flags & CPUFREQ_NEED_UPDATE_LIMITS) ||
!policy->update_limits)
return 0;
policy->update_limits = false;
}
so strictly speaking it only cleared policy->update_limits when
target_freq == policy->cur (which was arguably kind of a mistake), but
when that happened, the flag was cleared regardless of driver errors.
So yes, the behavior is different, but it makes more logical sense to me now.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2 3/3] cpufreq: intel_pstate: Clear last written P-state value on suspend
2026-11-03 19:42 [PATCH v2 0/3] cpufreq: Fix synchronization with system suspend/resume Rafael J. Wysocki
2026-11-03 19:45 ` [PATCH v2 1/3] cpufreq: Improve suspend-resume synchronization Rafael J. Wysocki
2026-11-03 19:47 ` [PATCH v2 2/3] cpufreq: Force passing target frequency to driver during resume Rafael J. Wysocki
@ 2026-11-03 19:49 ` Rafael J. Wysocki
2026-11-03 20:06 ` [PATCH v2 0/3] cpufreq: Fix synchronization with system suspend/resume Mario Limonciello
` (5 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Rafael J. Wysocki @ 2026-11-03 19:49 UTC (permalink / raw)
To: Linux PM
Cc: Viresh Kumar, Christian Loehle, Doug Smythies, Zak,
Srinivas Pandruvada, Mario Limonciello
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Preserving cpu->pstate.current_pstate across system suspend-resume
cycles, when running in the passive mode with HWP disabled, is a mistake
because its value from before system suspend may become stale after the
subsequent system resume and in some cases it prevents MSR_IA32_PERF_CTL
from being updated properly after system resume [1].
Address this by clearing cpu->pstate.current_pstate after the governor
has been stopped during system suspend.
Fixes: 001c76f05b01 ("cpufreq: intel_pstate: Generic governors support")
Fixes: 4adcf2e5829f ("cpufreq: intel_pstate: Add ->offline and ->online callbacks")
Link: https://lore.kernel.org/linux-pm/20261027143725.3763827-1-zakbrightonknight@gmail.com/ [1]
Reported-by: Zak Brighton Knight <zakbrightonknight@gmail.com>
Reported-by: Doug Smythies <dsmythies@telus.net>
Cc: All applicable <stable@vger.kernel.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
v1 -> v2: No changes
---
drivers/cpufreq/intel_pstate.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -3389,10 +3389,11 @@ static void intel_cpufreq_cpu_exit(struc
static int intel_cpufreq_suspend(struct cpufreq_policy *policy)
{
+ struct cpudata *cpu = all_cpu_data[policy->cpu];
+
intel_pstate_suspend(policy);
if (hwp_active) {
- struct cpudata *cpu = all_cpu_data[policy->cpu];
u64 value = READ_ONCE(cpu->hwp_req_cached);
/*
@@ -3403,6 +3404,17 @@ static int intel_cpufreq_suspend(struct
value &= ~HWP_DESIRED_PERF(~0L);
wrmsrq_on_cpu(cpu->cpu, MSR_HWP_REQUEST, value);
WRITE_ONCE(cpu->hwp_req_cached, value);
+ } else {
+ /*
+ * Invalidate the cached P-state value that may be stale when
+ * the governor is started again during resume and may prevent
+ * MSR_IA32_PERF_CTL from being updated.
+ *
+ * This does not require synchronization because the core
+ * prevents frequency updates for suspended policies from
+ * occurring.
+ */
+ cpu->pstate.current_pstate = 0;
}
return 0;
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH v2 0/3] cpufreq: Fix synchronization with system suspend/resume
2026-11-03 19:42 [PATCH v2 0/3] cpufreq: Fix synchronization with system suspend/resume Rafael J. Wysocki
` (2 preceding siblings ...)
2026-11-03 19:49 ` [PATCH v2 3/3] cpufreq: intel_pstate: Clear last written P-state value on suspend Rafael J. Wysocki
@ 2026-11-03 20:06 ` Mario Limonciello
2026-11-03 23:26 ` Zak Brighton Knight
` (4 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Mario Limonciello @ 2026-11-03 20:06 UTC (permalink / raw)
To: Rafael J. Wysocki, Linux PM
Cc: Viresh Kumar, Christian Loehle, Doug Smythies, Zak,
Srinivas Pandruvada
On 11/3/26 13:42, Rafael J. Wysocki wrote:
> Hi,
>
> This is an update of
>
> https://lore.kernel.org/linux-pm/5162355.31r3eYUQgx@rafael.j.wysocki/
>
> that modifies the first two patches in the series (to address Sashiko
> findings) and drops the last one.
>
> This series fixes issues related to the synchronization between cpufreq
> and the intel_pstate driver with system suspend/resume mentioned here:
>
> https://lore.kernel.org/linux-pm/CAJZ5v0hT6aoX4tuJM+rO_5iequFc_7rEXCoaFnHoJBaH3JP4KA@mail.gmail.com/
>
> The first patch actually prevents governor operations from being
> carried out on suspended cpufreq policies.
>
> The second one forces the driver .target() callback to be invoked on
> the first frequency update after cpufreq policy resume.
>
> The third one causes intel_pstate to invalidate the cached last
> P-state value during suspend.
>
> Thanks!
Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH v2 0/3] cpufreq: Fix synchronization with system suspend/resume
2026-11-03 19:42 [PATCH v2 0/3] cpufreq: Fix synchronization with system suspend/resume Rafael J. Wysocki
` (3 preceding siblings ...)
2026-11-03 20:06 ` [PATCH v2 0/3] cpufreq: Fix synchronization with system suspend/resume Mario Limonciello
@ 2026-11-03 23:26 ` Zak Brighton Knight
2026-11-04 2:44 ` Zhongqiu Han
` (3 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Zak Brighton Knight @ 2026-11-03 23:26 UTC (permalink / raw)
To: Rafael J. Wysocki
Cc: Linux PM, Viresh Kumar, Christian Loehle, Doug Smythies,
Srinivas Pandruvada, Mario Limonciello
On Tue, 3 Nov 2026 at 19:49, Rafael J. Wysocki <rafael@kernel.org> wrote:
>
> This is an update of
>
> https://lore.kernel.org/linux-pm/5162355.31r3eYUQgx@rafael.j.wysocki/
>
> that modifies the first two patches in the series (to address Sashiko
> findings) and drops the last one.
Same tests as for v1 on the T520 (7.4-rc1 + v2, lockdep), same results:
the P-state is right after resume in every passive mode case, active
mode is unchanged, and there are no lockdep reports.
I also made CPU3 fail to come back during resume (hotplug/fail set to
irq/affinity:online, passive + schedutil), then onlined it by hand. On
7.2.15, CPU3 comes back without a cpufreq policy ("Failed to initialize
policy for cpu: 3 (-16)"); with v2 it's fine. That test also gives a
WARNING in rebuild_sched_domains_locked() (cpuset.c:1059): the rebuild
sugov_exit() asks for runs while the cpusets still include CPU3, since
cpuset_cpu_active() only updates them once num_cpus_frozen is back to
0. On 7.2.15, switching CPU0's governor in that state gives the same
warning, so it doesn't come from the series. Onlining CPU3 then also
gives intel_epb's "duplicate filename ... energy_perf_bias" sysfs
warning, on both kernels.
I used Claude Code to script and run the tests.
Tested-by: Zak Brighton Knight <zakbrightonknight@gmail.com>
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH v2 0/3] cpufreq: Fix synchronization with system suspend/resume
2026-11-03 19:42 [PATCH v2 0/3] cpufreq: Fix synchronization with system suspend/resume Rafael J. Wysocki
` (4 preceding siblings ...)
2026-11-03 23:26 ` Zak Brighton Knight
@ 2026-11-04 2:44 ` Zhongqiu Han
2026-11-04 4:19 ` Viresh Kumar
` (2 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Zhongqiu Han @ 2026-11-04 2:44 UTC (permalink / raw)
To: Rafael J. Wysocki, Linux PM
Cc: Viresh Kumar, Christian Loehle, Doug Smythies, Zak,
Srinivas Pandruvada, Mario Limonciello, zhongqiu.han
On 11/4/2026 3:42 AM, Rafael J. Wysocki wrote:
> Hi,
>
> This is an update of
>
> https://lore.kernel.org/linux-pm/5162355.31r3eYUQgx@rafael.j.wysocki/
>
> that modifies the first two patches in the series (to address Sashiko
> findings) and drops the last one.
>
> This series fixes issues related to the synchronization between cpufreq
> and the intel_pstate driver with system suspend/resume mentioned here:
>
> https://lore.kernel.org/linux-pm/CAJZ5v0hT6aoX4tuJM+rO_5iequFc_7rEXCoaFnHoJBaH3JP4KA@mail.gmail.com/
>
> The first patch actually prevents governor operations from being
> carried out on suspended cpufreq policies.
>
> The second one forces the driver .target() callback to be invoked on
> the first frequency update after cpufreq policy resume.
>
> The third one causes intel_pstate to invalidate the cached last
> P-state value during suspend.
>
> Thanks!
>
>
Reviewed-by: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>
>
>
--
Thx and BRs,
Zhongqiu Han
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH v2 0/3] cpufreq: Fix synchronization with system suspend/resume
2026-11-03 19:42 [PATCH v2 0/3] cpufreq: Fix synchronization with system suspend/resume Rafael J. Wysocki
` (5 preceding siblings ...)
2026-11-04 2:44 ` Zhongqiu Han
@ 2026-11-04 4:19 ` Viresh Kumar
2026-11-04 4:38 ` Doug Smythies
2026-11-04 12:18 ` Christian Loehle
8 siblings, 0 replies; 15+ messages in thread
From: Viresh Kumar @ 2026-11-04 4:19 UTC (permalink / raw)
To: Rafael J. Wysocki
Cc: Linux PM, Christian Loehle, Doug Smythies, Zak,
Srinivas Pandruvada, Mario Limonciello
On 03-11-26, 20:42, Rafael J. Wysocki wrote:
> Hi,
>
> This is an update of
>
> https://lore.kernel.org/linux-pm/5162355.31r3eYUQgx@rafael.j.wysocki/
>
> that modifies the first two patches in the series (to address Sashiko
> findings) and drops the last one.
>
> This series fixes issues related to the synchronization between cpufreq
> and the intel_pstate driver with system suspend/resume mentioned here:
>
> https://lore.kernel.org/linux-pm/CAJZ5v0hT6aoX4tuJM+rO_5iequFc_7rEXCoaFnHoJBaH3JP4KA@mail.gmail.com/
>
> The first patch actually prevents governor operations from being
> carried out on suspended cpufreq policies.
>
> The second one forces the driver .target() callback to be invoked on
> the first frequency update after cpufreq policy resume.
>
> The third one causes intel_pstate to invalidate the cached last
> P-state value during suspend.
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
--
viresh
^ permalink raw reply [flat|nested] 15+ messages in thread* RE: [PATCH v2 0/3] cpufreq: Fix synchronization with system suspend/resume
2026-11-03 19:42 [PATCH v2 0/3] cpufreq: Fix synchronization with system suspend/resume Rafael J. Wysocki
` (6 preceding siblings ...)
2026-11-04 4:19 ` Viresh Kumar
@ 2026-11-04 4:38 ` Doug Smythies
2026-11-04 12:18 ` Christian Loehle
8 siblings, 0 replies; 15+ messages in thread
From: Doug Smythies @ 2026-11-04 4:38 UTC (permalink / raw)
To: 'Rafael J. Wysocki', 'Linux PM'
Cc: 'Viresh Kumar', 'Christian Loehle', 'Zak',
'Srinivas Pandruvada', 'Mario Limonciello',
Doug Smythies
On 2026.11.03 12:42 : Rafael wrote:
> Hi,
>
> This is an update of
>
> https://lore.kernel.org/linux-pm/5162355.31r3eYUQgx@rafael.j.wysocki/
>
> that modifies the first two patches in the series (to address Sashiko
> findings) and drops the last one.
>
> This series fixes issues related to the synchronization between cpufreq
> and the intel_pstate driver with system suspend/resume mentioned here:
>
> https://lore.kernel.org/linux-pm/CAJZ5v0hT6aoX4tuJM+rO_5iequFc_7rEXCoaFnHoJBaH3JP4KA@mail.gmail.com/
>
> The first patch actually prevents governor operations from being
> carried out on suspended cpufreq policies.
>
> The second one forces the driver .target() callback to be invoked on
> the first frequency update after cpufreq policy resume.
>
> The third one causes intel_pstate to invalidate the cached last
> P-state value during suspend.
>
> Thanks!
Tested-by: Doug Smythies <dsmythies@telus.net>
Test computer: Test computer: i5-10600K, 6 cores, 12 CPUs, HWP disabled, passive mode.
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH v2 0/3] cpufreq: Fix synchronization with system suspend/resume
2026-11-03 19:42 [PATCH v2 0/3] cpufreq: Fix synchronization with system suspend/resume Rafael J. Wysocki
` (7 preceding siblings ...)
2026-11-04 4:38 ` Doug Smythies
@ 2026-11-04 12:18 ` Christian Loehle
8 siblings, 0 replies; 15+ messages in thread
From: Christian Loehle @ 2026-11-04 12:18 UTC (permalink / raw)
To: Rafael J. Wysocki, Linux PM
Cc: Viresh Kumar, Doug Smythies, Zak, Srinivas Pandruvada,
Mario Limonciello
On 11/3/26 19:42, Rafael J. Wysocki wrote:
> Hi,
>
> This is an update of
>
> https://lore.kernel.org/linux-pm/5162355.31r3eYUQgx@rafael.j.wysocki/
>
> that modifies the first two patches in the series (to address Sashiko
> findings) and drops the last one.
>
> This series fixes issues related to the synchronization between cpufreq
> and the intel_pstate driver with system suspend/resume mentioned here:
>
> https://lore.kernel.org/linux-pm/CAJZ5v0hT6aoX4tuJM+rO_5iequFc_7rEXCoaFnHoJBaH3JP4KA@mail.gmail.com/
>
> The first patch actually prevents governor operations from being
> carried out on suspended cpufreq policies.
>
> The second one forces the driver .target() callback to be invoked on
> the first frequency update after cpufreq policy resume.
>
> The third one causes intel_pstate to invalidate the cached last
> P-state value during suspend.
>
> Thanks!
>
>
>
Tested-by: Christian Loehle <christian.loehle@arm.com>
AmpereOne: cppc_cpufreq, s2idle
AMD Ryzen 5 7430U, amd-pstate active/passive/guided, S3
AMD Ryzen 3 3300U: acpi-cpufreq, S3
Radxa Orion O6: cppc_cpufreq, PM test stages only
^ permalink raw reply [flat|nested] 15+ messages in thread