From: "Benoît Monin" <benoit.monin@bootlin.com>
To: Thomas Bogendoerfer <tsbogend@alpha.franken.de>,
Daniel Lezcano <daniel.lezcano@kernel.org>,
Thomas Gleixner <tglx@kernel.org>,
Dragan Mladjenovic <dragan.mladjenovic@syrmia.com>,
Chao-ying Fu <cfu@wavecomp.com>,
Aleksandar Rikalo <arikalo@gmail.com>,
Paul Burton <paulburton@kernel.org>
Cc: "Vladimir Kondratiev" <vladimir.kondratiev@mobileye.com>,
"Tawfik Bayouk" <tawfik.bayouk@mobileye.com>,
"Gregory CLEMENT" <gregory.clement@bootlin.com>,
"Théo Lebrun" <theo.lebrun@bootlin.com>,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org,
"Benoît Monin" <benoit.monin@bootlin.com>
Subject: [PATCH v2 1/5] irqchip/mips-gic: Fix unbalanced cm_core_lock in for_each_online_cpu_gic()
Date: Mon, 10 Aug 2026 16:25:38 +0200 [thread overview]
Message-ID: <20260810-sync-gic-counters-v2-1-dfe8b2c376b0@bootlin.com> (raw)
In-Reply-To: <20260810-sync-gic-counters-v2-0-dfe8b2c376b0@bootlin.com>
Commit d9e2ed610a60 ("irqchip/mips-gic: Support multi-cluster in
for_each_online_cpu_gic()") added a gic_unlock_cluster() call to the
macro's loop increment, which unconditionally invokes
mips_cm_unlock_other() on multi-cluster systems. However nothing in the
loop ever acquires the corresponding mips_cm_lock_other(), so on
multi-cluster hardware every invocation of for_each_online_cpu_gic()
releases an unheld per-CPU cm_core_lock.
With CONFIG_PROVE_LOCKING this triggers a "bad unlock balance detected"
warning at boot, e.g. from gic_irq_domain_map() while mapping local
interrupts. Only the first occurrence is reported, since the first
warning permanently disables lockdep (debug_locks = 0); the unbalanced
release itself silently persists.
Fix this by moving both the acquire and release into
__gic_with_next_online_cpu() so they stay balanced. When advancing to a
CPU in a remote cluster, lock the CM redirect block for that cluster via
mips_cm_lock_other(); when leaving a remote cluster (or finishing the
iteration) release it with mips_cm_unlock_other(). Local-cluster CPUs
require no locking, so single-cluster systems are unaffected. This also
makes the redirect region behave correctly when accessing local register
blocks of CPUs in other clusters.
Drop the now-unused gic_unlock_cluster() helper and its call from the
for_each_online_cpu_gic() increment.
Fixes: d9e2ed610a60 ("irqchip/mips-gic: Support multi-cluster in for_each_online_cpu_gic()")
Signed-off-by: Benoît Monin <benoit.monin@bootlin.com>
---
drivers/irqchip/irq-mips-gic.c | 20 ++++++--------------
1 file changed, 6 insertions(+), 14 deletions(-)
diff --git a/drivers/irqchip/irq-mips-gic.c b/drivers/irqchip/irq-mips-gic.c
index 19a57c5e2b2e..3b31cbcbed6f 100644
--- a/drivers/irqchip/irq-mips-gic.c
+++ b/drivers/irqchip/irq-mips-gic.c
@@ -70,6 +70,10 @@ static int __gic_with_next_online_cpu(int prev)
{
unsigned int cpu;
+ /* Release the redirect/other region lock to the previous CPU, if any. */
+ if (prev >= 0)
+ mips_cm_unlock_other();
+
/* Discover the next online CPU */
cpu = cpumask_next(prev, cpu_online_mask);
@@ -77,23 +81,12 @@ static int __gic_with_next_online_cpu(int prev)
if (cpu >= nr_cpu_ids)
return cpu;
- /*
- * Move the access lock to the next CPU's GIC local register block.
- *
- * Set GIC_VL_OTHER. Since the caller holds gic_lock nothing can
- * clobber the written value.
- */
- write_gic_vl_other(mips_cm_vp_id(cpu));
+ /* Lock access to redirect/other region to the next CPU */
+ mips_cm_lock_other_cpu(cpu, CM_GCR_Cx_OTHER_BLOCK_LOCAL);
return cpu;
}
-static inline void gic_unlock_cluster(void)
-{
- if (mips_cps_multicluster_cpus())
- mips_cm_unlock_other();
-}
-
/**
* for_each_online_cpu_gic() - Iterate over online CPUs, access local registers
* @cpu: An integer variable to hold the current CPU number
@@ -108,7 +101,6 @@ static inline void gic_unlock_cluster(void)
guard(raw_spinlock_irqsave)(gic_lock); \
for ((cpu) = __gic_with_next_online_cpu(-1); \
(cpu) < nr_cpu_ids; \
- gic_unlock_cluster(), \
(cpu) = __gic_with_next_online_cpu(cpu))
/**
--
2.55.0
next prev parent reply other threads:[~2026-08-10 14:26 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-10 14:25 [PATCH v2 0/5] MIPS: GIC clocksource/irqchip improvements and fixes for multi-cluster systems Benoît Monin
2026-08-10 14:25 ` Benoît Monin [this message]
2026-08-10 14:25 ` [PATCH v2 2/5] irqchip/mips-gic: Fix recursive acquisition of gic_lock in gic_set_affinity() Benoît Monin
2026-08-10 14:25 ` [PATCH v2 3/5] irqchip/mips-gic: Enable interrupt when moving affinity across clusters Benoît Monin
2026-08-10 14:25 ` [PATCH v2 4/5] clocksource: mips-gic-timer: Set next GIC event on the correct VP Benoît Monin
2026-08-10 14:25 ` [PATCH v2 5/5] clocksource: mips-gic-timer: Use local counter on synced multi-cluster systems Benoît Monin
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=20260810-sync-gic-counters-v2-1-dfe8b2c376b0@bootlin.com \
--to=benoit.monin@bootlin.com \
--cc=arikalo@gmail.com \
--cc=cfu@wavecomp.com \
--cc=daniel.lezcano@kernel.org \
--cc=dragan.mladjenovic@syrmia.com \
--cc=gregory.clement@bootlin.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=paulburton@kernel.org \
--cc=tawfik.bayouk@mobileye.com \
--cc=tglx@kernel.org \
--cc=theo.lebrun@bootlin.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=tsbogend@alpha.franken.de \
--cc=vladimir.kondratiev@mobileye.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