From: "Borah, Chaitanya Kumar" <chaitanya.kumar.borah@intel.com>
To: Mika Kahola <mika.kahola@intel.com>,
<intel-gfx@lists.freedesktop.org>,
<intel-xe@lists.freedesktop.org>
Cc: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Subject: Re: [core-for-CI] powercap: intel_rapl: Fix possible recursive lock warning
Date: Thu, 18 Dec 2025 10:06:43 +0530 [thread overview]
Message-ID: <a49db7f3-b0f8-49e8-b818-ddad61f64262@intel.com> (raw)
In-Reply-To: <20251217092057.1231895-1-mika.kahola@intel.com>
Hi Mika,
On 12/17/2025 2:50 PM, Mika Kahola wrote:
> From: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
>
> With the RAPL PMU addition, there is a recursive locking when CPU online
> callback function calls rapl_package_add_pmu(). Here cpu_hotplug_lock
> is already acquired by cpuhp_thread_fun() and rapl_package_add_pmu()
> tries to acquire again.
There is a slightly different version of the patch that got merged. we
should perhaps push that
https://lore.kernel.org/linux-pm/CAJZ5v0h4SPvp97iU9ibXrnjqKOQ7GZOtUPb9ZGj80=O5pfukYQ@mail.gmail.com/T/#t
Also you will need to add your signed off and add
References: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/15462
==
Chaitanya
>
> <4>[ 8.197433] ============================================
> <4>[ 8.197437] WARNING: possible recursive locking detected
> <4>[ 8.197440] 6.19.0-rc1-lgci-xe-xe-4242-05b7c58b3367dca84+ #1 Not tainted
> <4>[ 8.197444] --------------------------------------------
> <4>[ 8.197447] cpuhp/0/20 is trying to acquire lock:
> <4>[ 8.197450] ffffffff83487870 (cpu_hotplug_lock){++++}-{0:0}, at:
> rapl_package_add_pmu+0x37/0x370 [intel_rapl_common]
> <4>[ 8.197463]
> but task is already holding lock:
> <4>[ 8.197466] ffffffff83487870 (cpu_hotplug_lock){++++}-{0:0}, at:
> cpuhp_thread_fun+0x6d/0x290
> <4>[ 8.197477]
> other info that might help us debug this:
> <4>[ 8.197480] Possible unsafe locking scenario:
>
> <4>[ 8.197483] CPU0
> <4>[ 8.197485] ----
> <4>[ 8.197487] lock(cpu_hotplug_lock);
> <4>[ 8.197490] lock(cpu_hotplug_lock);
> <4>[ 8.197493]
> *** DEADLOCK ***
> ..
> ..
> <4>[ 8.197542] __lock_acquire+0x146e/0x2790
> <4>[ 8.197548] lock_acquire+0xc4/0x2c0
> <4>[ 8.197550] ? rapl_package_add_pmu+0x37/0x370 [intel_rapl_common]
> <4>[ 8.197556] cpus_read_lock+0x41/0x110
> <4>[ 8.197558] ? rapl_package_add_pmu+0x37/0x370 [intel_rapl_common]
> <4>[ 8.197561] rapl_package_add_pmu+0x37/0x370 [intel_rapl_common]
> <4>[ 8.197565] rapl_cpu_online+0x85/0x87 [intel_rapl_msr]
> <4>[ 8.197568] ? __pfx_rapl_cpu_online+0x10/0x10 [intel_rapl_msr]
> <4>[ 8.197570] cpuhp_invoke_callback+0x41f/0x6c0
> <4>[ 8.197573] ? cpuhp_thread_fun+0x6d/0x290
> <4>[ 8.197575] cpuhp_thread_fun+0x1e2/0x290
> <4>[ 8.197578] ? smpboot_thread_fn+0x26/0x290
> <4>[ 8.197581] smpboot_thread_fn+0x12f/0x290
> <4>[ 8.197584] ? __pfx_smpboot_thread_fn+0x10/0x10
> <4>[ 8.197586] kthread+0x11f/0x250
> <4>[ 8.197589] ? __pfx_kthread+0x10/0x10
> <4>[ 8.197592] ret_from_fork+0x344/0x3a0
> <4>[ 8.197595] ? __pfx_kthread+0x10/0x10
> <4>[ 8.197597] ret_from_fork_asm+0x1a/0x30
> <4>[ 8.197604] </TASK>
>
> Fix this issue in the same way as rapl powercap package domain is added
> from the same CPU online callback by introducing another interface which
> doesn't call cpu_read_lock(). Add rapl_package_add_pmu_locked() which
> doesn't call cpu_read_lock(). The original rapl_package_add_pmu() still
> calls cpu_read_lock() for TPMI RAPL.
>
> Fixes: 748d6ba43afd ("powercap: intel_rapl: Enable MSR-based RAPL PMU support")
> Reported-by: Borah, Chaitanya Kumar <chaitanya.kumar.borah@intel.com>
> Closes: https://lore.kernel.org/linux-pm/5427ede1-57a0-43d1-99f3-8ca4b0643e82@intel.com/T/#u
> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
> ---
> drivers/powercap/intel_rapl_common.c | 15 ++++++++++++---
> drivers/powercap/intel_rapl_msr.c | 2 +-
> include/linux/intel_rapl.h | 2 ++
> 3 files changed, 15 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/powercap/intel_rapl_common.c b/drivers/powercap/intel_rapl_common.c
> index b9d87e56cbbc..27eaf0d4265f 100644
> --- a/drivers/powercap/intel_rapl_common.c
> +++ b/drivers/powercap/intel_rapl_common.c
> @@ -2032,7 +2032,7 @@ static int rapl_pmu_update(struct rapl_package *rp)
> return ret;
> }
>
> -int rapl_package_add_pmu(struct rapl_package *rp)
> +int rapl_package_add_pmu_locked(struct rapl_package *rp)
> {
> struct rapl_package_pmu_data *data = &rp->pmu_data;
> int idx;
> @@ -2040,8 +2040,6 @@ int rapl_package_add_pmu(struct rapl_package *rp)
> if (rp->has_pmu)
> return -EEXIST;
>
> - guard(cpus_read_lock)();
> -
> for (idx = 0; idx < rp->nr_domains; idx++) {
> struct rapl_domain *rd = &rp->domains[idx];
> int domain = rd->id;
> @@ -2091,6 +2089,17 @@ int rapl_package_add_pmu(struct rapl_package *rp)
>
> return rapl_pmu_update(rp);
> }
> +EXPORT_SYMBOL_GPL(rapl_package_add_pmu_locked);
> +
> +int rapl_package_add_pmu(struct rapl_package *rp)
> +{
> + if (rp->has_pmu)
> + return -EEXIST;
> +
> + guard(cpus_read_lock)();
> +
> + return rapl_package_add_pmu_locked(rp);
> +}
> EXPORT_SYMBOL_GPL(rapl_package_add_pmu);
>
> void rapl_package_remove_pmu(struct rapl_package *rp)
> diff --git a/drivers/powercap/intel_rapl_msr.c b/drivers/powercap/intel_rapl_msr.c
> index 0ce1096b6314..ef3435de1926 100644
> --- a/drivers/powercap/intel_rapl_msr.c
> +++ b/drivers/powercap/intel_rapl_msr.c
> @@ -82,7 +82,7 @@ static int rapl_cpu_online(unsigned int cpu)
> if (IS_ERR(rp))
> return PTR_ERR(rp);
> if (rapl_msr_pmu)
> - rapl_package_add_pmu(rp);
> + rapl_package_add_pmu_locked(rp);
> }
> cpumask_set_cpu(cpu, &rp->cpumask);
> return 0;
> diff --git a/include/linux/intel_rapl.h b/include/linux/intel_rapl.h
> index e9ade2ff4af6..68fea61ca77d 100644
> --- a/include/linux/intel_rapl.h
> +++ b/include/linux/intel_rapl.h
> @@ -214,9 +214,11 @@ void rapl_remove_package(struct rapl_package *rp);
>
> #ifdef CONFIG_PERF_EVENTS
> int rapl_package_add_pmu(struct rapl_package *rp);
> +int rapl_package_add_pmu_locked(struct rapl_package *rp);
> void rapl_package_remove_pmu(struct rapl_package *rp);
> #else
> static inline int rapl_package_add_pmu(struct rapl_package *rp) { return 0; }
> +static inline int rapl_package_add_pmu_locked(struct rapl_package *rp) { return 0; }
> static inline void rapl_package_remove_pmu(struct rapl_package *rp) { }
> #endif
>
next prev parent reply other threads:[~2025-12-18 4:36 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-17 9:20 [core-for-CI] powercap: intel_rapl: Fix possible recursive lock warning Mika Kahola
2025-12-17 10:56 ` ✓ i915.CI.BAT: success for " Patchwork
2025-12-17 12:58 ` ✓ i915.CI.Full: " Patchwork
2025-12-18 4:36 ` Borah, Chaitanya Kumar [this message]
-- strict thread matches above, loose matches on Subject: below --
2025-12-18 13:59 [core-for-CI] " Mika Kahola
2025-12-18 15:21 ` Mika Kahola
2025-12-19 8:47 ` Hogander, Jouni
2025-12-19 9:00 ` Nautiyal, Ankit K
2025-12-19 8:57 ` Nautiyal, Ankit K
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=a49db7f3-b0f8-49e8-b818-ddad61f64262@intel.com \
--to=chaitanya.kumar.borah@intel.com \
--cc=intel-gfx@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=mika.kahola@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