From: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>,
Daniel Lezcano <daniel.lezcano@kernel.org>,
Zhang Rui <rui.zhang@intel.com>,
Lukasz Luba <lukasz.luba@arm.com>,
Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Cc: linux-pm@vger.kernel.org, linux-api@vger.kernel.org,
linux-kernel@vger.kernel.org, ricardo.neri@intel.com,
Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
Subject: [PATCH 11/13] thermal: intel: dpti: Serialize updates to the directed interrupt state
Date: Mon, 09 Nov 2026 19:36:38 -0800 [thread overview]
Message-ID: <20261109-dpti-custom-cpu-v1-11-ead8e2d2067e@linux.intel.com> (raw)
In-Reply-To: <20261109-dpti-custom-cpu-v1-0-ead8e2d2067e@linux.intel.com>
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@linux.intel.com>
---
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
next prev parent reply other threads:[~2026-11-10 3:36 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 3:36 [PATCH 00/13] thermal: intel: dpti: Direct the package thermal interrupt to a chosen CPU Ricardo Neri
2026-11-10 3:36 ` [PATCH 01/13] thermal: intel: Keep directed package interrupts off after syscore shutdown Ricardo Neri
2026-11-10 3:36 ` [PATCH 02/13] thermal: intel: Prefix log messages via pr_fmt() Ricardo Neri
2026-11-10 3:36 ` [PATCH 03/13] thermal: intel: Move the sysfs device helpers next to their callers Ricardo Neri
2026-11-10 3:36 ` [PATCH 04/13] thermal: intel: dpti: Adopt the dpti_ prefix and the owner terminology Ricardo Neri
2026-11-10 3:36 ` [PATCH 05/13] thermal: intel: dpti: Tear down DPTI only during boot Ricardo Neri
2026-11-10 3:36 ` [PATCH 06/13] thermal: intel: dpti: Introduce struct dpti_pkg for per-package state Ricardo Neri
2026-11-10 3:36 ` [PATCH 07/13] thermal: intel: dpti: Configure the local CPU by value Ricardo Neri
2026-11-10 3:36 ` [PATCH 08/13] thermal: intel: dpti: Factor the programming sequence out into a helper Ricardo Neri
2026-11-10 3:36 ` [PATCH 09/13] thermal: intel: dpti: Program the directed interrupt on the target CPU Ricardo Neri
2026-11-10 3:36 ` [PATCH 10/13] thermal: intel: dpti: Add rank-based owner selection Ricardo Neri
2026-11-10 3:36 ` Ricardo Neri [this message]
2026-11-10 3:36 ` [PATCH 12/13] thermal: intel: dpti: Avoid nohz_full CPUs when possible Ricardo Neri
2026-11-10 3:36 ` [PATCH 13/13] thermal: intel: dpti: Add sysfs control of interrupt owner Ricardo Neri
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=20261109-dpti-custom-cpu-v1-11-ead8e2d2067e@linux.intel.com \
--to=ricardo.neri-calderon@linux.intel.com \
--cc=daniel.lezcano@kernel.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lukasz.luba@arm.com \
--cc=rafael@kernel.org \
--cc=ricardo.neri@intel.com \
--cc=rui.zhang@intel.com \
--cc=srinivas.pandruvada@linux.intel.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
all inboxes | Powered by JetHome®