blob: 19de62f43e22ca3ab36b570d9b67cec637c3ae62 [file] [log] [blame]
From 439c3f10f31567aff16fafc298c536451b2bb77a Mon Sep 17 00:00:00 2001
From: "Rafael J. Wysocki" <>
Date: Wed, 9 Oct 2019 01:29:10 +0200
Subject: [PATCH] cpufreq: Avoid cpufreq_suspend() deadlock on system shutdown
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
commit 65650b35133ff20f0c9ef0abd5c3c66dbce3ae57 upstream.
It is incorrect to set the cpufreq syscore shutdown callback pointer
to cpufreq_suspend(), because that function cannot be run in the
syscore stage of system shutdown for two reasons: (a) it may attempt
to carry out actions depending on devices that have already been shut
down at that point and (b) the RCU synchronization carried out by it
may not be able to make progress then.
The latter issue has been present since commit 45975c7d21a1 ("rcu:
Define RCU-sched API in terms of RCU for Tree RCU PREEMPT builds"),
but the former one has been there since commit 90de2a4aa9f3 ("cpufreq:
suspend cpufreq governors on shutdown") regardless.
Fix that by dropping cpufreq_syscore_ops altogether and making
device_shutdown() call cpufreq_suspend() directly before shutting
down devices, which is along the lines of what system-wide power
management does.
Fixes: 45975c7d21a1 ("rcu: Define RCU-sched API in terms of RCU for Tree RCU PREEMPT builds")
Fixes: 90de2a4aa9f3 ("cpufreq: suspend cpufreq governors on shutdown")
Reported-by: Ville Syrjälä <>
Tested-by: Ville Syrjälä <>
Signed-off-by: Rafael J. Wysocki <>
Acked-by: Viresh Kumar <>
Cc: 4.0+ <> # 4.0+
Signed-off-by: Paul Gortmaker <>
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 2dc0123cbba1..1a4f4f00a96e 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -9,6 +9,7 @@
#include <linux/acpi.h>
+#include <linux/cpufreq.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/fwnode.h>
@@ -3119,6 +3120,8 @@ void device_shutdown(void)
+ cpufreq_suspend();
* Walk the devices list backward, shutting down each in turn.
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index e84bf0eb7239..f702de720d91 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -2673,14 +2673,6 @@ int cpufreq_unregister_driver(struct cpufreq_driver *driver)
- * Stop cpufreq at shutdown to make sure it isn't holding any locks
- * or mutexes when secondary CPUs are halted.
- */
-static struct syscore_ops cpufreq_syscore_ops = {
- .shutdown = cpufreq_suspend,
struct kobject *cpufreq_global_kobject;
@@ -2692,8 +2684,6 @@ static int __init cpufreq_core_init(void)
cpufreq_global_kobject = kobject_create_and_add("cpufreq", &cpu_subsys.dev_root->kobj);
- register_syscore_ops(&cpufreq_syscore_ops);
return 0;
module_param(off, int, 0444);