[PATCH 11/13] thermal: intel: dpti: Serialize updates to the directed interrupt state
From: Ricardo Neri
Date: Mon Nov 09 2026 - 22:41:22 EST
dpti_pkgs[] is written from the CPU hotplug callbacks, from the init and
cleanup paths, and from the syscore callbacks. None of those can run
concurrently with one another: the array needs no lock of its own today.
A sysfs interface to select the owner will access dpti_pkgs[] concurrently
with the CPU hotplug callbacks. Introduce dpti_mutex to serialize them. The
mutex is always taken inside the CPU hotplug lock, never the other way
around.
dpti_shut_down needs the same protection. The syscore shutdown callback
sets it with CPU hotplug disabled, which keeps out the CPU hotplug
callbacks but not a sysfs writer. Set it under the mutex too.
No functional change intended: until the sysfs writer lands, there is only
one class of writer, so the mutex is never contended.
Signed-off-by: Ricardo Neri <ricardo.neri-calderon@xxxxxxxxxxxxxxx>
---
drivers/thermal/intel/therm_throt.c | 30 +++++++++++++++++++++++-------
1 file changed, 23 insertions(+), 7 deletions(-)
diff --git a/drivers/thermal/intel/therm_throt.c b/drivers/thermal/intel/therm_throt.c
index 97c205dab1b6..c418471cf8f4 100644
--- a/drivers/thermal/intel/therm_throt.c
+++ b/drivers/thermal/intel/therm_throt.c
@@ -26,6 +26,7 @@
#include <linux/export.h>
#include <linux/delay.h>
#include <linux/types.h>
+#include <linux/mutex.h>
#include <linux/init.h>
#include <linux/smp.h>
#include <linux/sysfs.h>
@@ -569,16 +570,17 @@ struct dpti_pkg {
};
/*
- * Accessed from CPU hotplug callbacks and from code that runs while CPU
- * hotplug is inactive: the init and cleanup paths as well as syscore callbacks.
- * No extra locking needed.
+ * Serializes updates to dpti_pkgs[] and dpti_shut_down. To avoid deadlock, a
+ * path that needs both this mutex and the CPU hotplug lock always takes the
+ * hotplug lock first.
*/
+static DEFINE_MUTEX(dpti_mutex);
+
static struct dpti_pkg *dpti_pkgs;
/*
- * Set by the syscore shutdown callback before it disables the directed
- * interrupt, so that no CPU hotplug operation enables it again on the way to
- * kexec.
+ * Set under dpti_mutex by the syscore shutdown callback before it disables
+ * DPTI, so that no owner update enables it again on the way to kexec.
*/
static bool dpti_shut_down;
@@ -624,6 +626,10 @@ static struct dpti_pkg *dpti_pkg_of_cpu_nocheck(unsigned int cpu)
return &dpti_pkgs[topology_logical_package_id(cpu)];
}
+/*
+ * Reads dpti_pkgs[] without dpti_mutex: the syscore callers run with
+ * interrupts disabled on the only online CPU.
+ */
static bool dpti_cpu_is_owner(unsigned int cpu)
{
u16 pkg_id;
@@ -647,6 +653,8 @@ static void dpti_clear_all(void)
if (!dpti_supported())
return;
+ guard(mutex)(&dpti_mutex);
+
/*
* No need to reset the owners: callers free dpti_pkgs[] or have shut
* DPTI down.
@@ -699,6 +707,7 @@ static unsigned int dpti_select_cpu(unsigned int pkg_cpu, unsigned int skip,
unsigned int cpu, pin, best = nr_cpu_ids;
lockdep_assert_cpus_held();
+ lockdep_assert_held(&dpti_mutex);
/*
* Choose the user-pinned CPU if available: it is online and not going
@@ -745,6 +754,8 @@ static int dpti_update_owner(unsigned int cpu)
unsigned int new_cpu, old_cpu;
int ret;
+ lockdep_assert_held(&dpti_mutex);
+
if (dpti_shut_down)
return 0;
@@ -786,6 +797,8 @@ static int dpti_online(unsigned int cpu)
if (ret)
return ret;
+ guard(mutex)(&dpti_mutex);
+
/*
* A CPU coming online may be a better owner than the one currently
* programmed.
@@ -802,6 +815,8 @@ static void dpti_offline(unsigned int cpu)
if (dpti_lookup_pkg_id(cpu, &pkg_id))
return;
+ guard(mutex)(&dpti_mutex);
+
if (dpti_shut_down)
return;
@@ -866,7 +881,8 @@ static int dpti_syscore_suspend(void *data)
static void dpti_syscore_shutdown(void *data)
{
- dpti_shut_down = true;
+ scoped_guard(mutex, &dpti_mutex)
+ dpti_shut_down = true;
dpti_clear_all();
}
--
2.43.0