* [PATCH v2] i2c: jz4780: Cache host clock rate at probe to prevent CCF prepare_lock deadlock
@ 2026-07-19 20:19 H. Nikolaus Schaller
2026-07-27 20:59 ` Andi Shyti
0 siblings, 1 reply; 3+ messages in thread
From: H. Nikolaus Schaller @ 2026-07-19 20:19 UTC (permalink / raw)
To: Paul Cercueil, Andi Shyti
Cc: linux-mips, linux-i2c, linux-kernel, letux-kernel,
H. Nikolaus Schaller, stable
Fix a severe AB/BA deadlock between the Common Clock Framework (CCF)
and the I2C adapter lock, which triggers when an I2C-controlled clock
generator client (like the Si5351) is registered or modified under the CCF.
During an i2c client clock (generator) frequency change, the CCF acquires its global
'prepare_lock' mutex and the driver calls i2c_transfer() to update the client's
chip registers, stalling for the adapter's I2C bus lock.
Concurrently, an independent, parallel transfer on the same bus (e.g., a GPIO
expander handling LEDs) can hold the I2C adapter lock. Inside this parallel
transfer path, jz4780_i2c_set_speed() calls clk_get_rate() on the host
controller's input clock to calculate bus timings. This call attempts to acquire
the blocked CCF 'prepare_lock', creating a circular dependency that freezes
the system.
The jz4780 host controller clock itself is static and never changes at runtime.
However, calling clk_get_rate() inside the active transfer path introduces
an unnecessary dependency on the CCF internal locks.
Eliminate this synchronous clk_get_rate() call from the active transfer
path by caching the static host peripheral clock rate once - inside the private
jz4780_i2c structure during jz4780_i2c_probe(). Update jz4780_i2c_set_speed()
to use this cached value, safely decoupling active I2C transactions from the
CCF internal locks without any risk of stale timings.
Assisted-by web based Google AI (pinpointing the bug and writing the message).
Fixes: ba92222ed63a12 ("i2c: jz4780: Add i2c bus controller driver for Ingenic JZ4780")
Cc: stable@vger.kernel.org
Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com>
---
drivers/i2c/busses/i2c-jz4780.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/i2c/busses/i2c-jz4780.c b/drivers/i2c/busses/i2c-jz4780.c
index 664a5471d93357..695be3b2146085 100644
--- a/drivers/i2c/busses/i2c-jz4780.c
+++ b/drivers/i2c/busses/i2c-jz4780.c
@@ -141,6 +141,7 @@ struct jz4780_i2c {
void __iomem *iomem;
int irq;
struct clk *clk;
+ unsigned long clk_rate_khz;
struct i2c_adapter adap;
const struct ingenic_i2c_config *cdata;
@@ -246,7 +247,7 @@ static int jz4780_i2c_set_target(struct jz4780_i2c *i2c, unsigned char address)
static int jz4780_i2c_set_speed(struct jz4780_i2c *i2c)
{
- int dev_clk_khz = clk_get_rate(i2c->clk) / 1000;
+ int dev_clk_khz = i2c->clk_rate_khz;
int cnt_high = 0; /* HIGH period count of the SCL clock */
int cnt_low = 0; /* LOW period count of the SCL clock */
int cnt_period = 0; /* period count of the SCL clock */
@@ -796,6 +797,8 @@ static int jz4780_i2c_probe(struct platform_device *pdev)
if (IS_ERR(i2c->clk))
return PTR_ERR(i2c->clk);
+ i2c->clk_rate_khz = clk_get_rate(i2c->clk) / 1000;
+
ret = of_property_read_u32(pdev->dev.of_node, "clock-frequency",
&clk_freq);
if (ret) {
--
2.55.0
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v2] i2c: jz4780: Cache host clock rate at probe to prevent CCF prepare_lock deadlock
2026-07-19 20:19 [PATCH v2] i2c: jz4780: Cache host clock rate at probe to prevent CCF prepare_lock deadlock H. Nikolaus Schaller
@ 2026-07-27 20:59 ` Andi Shyti
2026-07-31 6:04 ` H. Nikolaus Schaller
0 siblings, 1 reply; 3+ messages in thread
From: Andi Shyti @ 2026-07-27 20:59 UTC (permalink / raw)
To: H. Nikolaus Schaller
Cc: Paul Cercueil, linux-mips, linux-i2c, linux-kernel, letux-kernel, stable
Hi Nikolaus,
On Sun, Jul 19, 2026 at 10:19:43PM +0200, H. Nikolaus Schaller wrote:
> Fix a severe AB/BA deadlock between the Common Clock Framework (CCF)
> and the I2C adapter lock, which triggers when an I2C-controlled clock
> generator client (like the Si5351) is registered or modified under the CCF.
>
> During an i2c client clock (generator) frequency change, the CCF acquires its global
> 'prepare_lock' mutex and the driver calls i2c_transfer() to update the client's
> chip registers, stalling for the adapter's I2C bus lock.
>
> Concurrently, an independent, parallel transfer on the same bus (e.g., a GPIO
> expander handling LEDs) can hold the I2C adapter lock. Inside this parallel
> transfer path, jz4780_i2c_set_speed() calls clk_get_rate() on the host
> controller's input clock to calculate bus timings. This call attempts to acquire
> the blocked CCF 'prepare_lock', creating a circular dependency that freezes
> the system.
>
> The jz4780 host controller clock itself is static and never changes at runtime.
>
> However, calling clk_get_rate() inside the active transfer path introduces
> an unnecessary dependency on the CCF internal locks.
>
> Eliminate this synchronous clk_get_rate() call from the active transfer
> path by caching the static host peripheral clock rate once - inside the private
> jz4780_i2c structure during jz4780_i2c_probe(). Update jz4780_i2c_set_speed()
> to use this cached value, safely decoupling active I2C transactions from the
> CCF internal locks without any risk of stale timings.
>
> Assisted-by web based Google AI (pinpointing the bug and writing the message).
>
> Fixes: ba92222ed63a12 ("i2c: jz4780: Add i2c bus controller driver for Ingenic JZ4780")
> Cc: stable@vger.kernel.org
> Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com>
To be clear, I wasn't against the patch itself, I just didn't
like the commit log and I raised questions coming just from
reading the log.
In this v2 you are missing the changelog, please, don't forget
next time to add it.
I merged your patch in i2c/i2c-fixes.
Thanks,
Andi
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v2] i2c: jz4780: Cache host clock rate at probe to prevent CCF prepare_lock deadlock
2026-07-27 20:59 ` Andi Shyti
@ 2026-07-31 6:04 ` H. Nikolaus Schaller
0 siblings, 0 replies; 3+ messages in thread
From: H. Nikolaus Schaller @ 2026-07-31 6:04 UTC (permalink / raw)
To: Andi Shyti
Cc: Paul Cercueil, linux-mips, linux-i2c, linux-kernel, letux-kernel, stable
Hi Andi,
> Am 27.07.2026 um 22:59 schrieb Andi Shyti <andi.shyti@kernel.org>:
>
> Hi Nikolaus,
>
>> Fixes: ba92222ed63a12 ("i2c: jz4780: Add i2c bus controller driver for Ingenic JZ4780")
>> Cc: stable@vger.kernel.org
>> Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com>
>
> To be clear, I wasn't against the patch itself, I just didn't
> like the commit log and I raised questions coming just from
> reading the log.
Sorry that I did not get this because I could not see a question.
> In this v2 you are missing the changelog, please, don't forget
> next time to add it.
That is the downside of too much automation on our side. It did
not properly catch the case of a single patch without cover letter.
So the changelog is in the suppressed cover letter...
Here for the records:
PATCH V2 2026-07-19 22:19:42:
Changes:
1) improved the commit message to clearly separate between i2c host clock rate
and the clock rate of the clock generator which is controlled through i2c
Suggested-by: andi.shyti@kernel.org
2a) changed to clk_rate_khz (and moved the division by 1000 to probe)
2b) fixed the variable type and name definition (wrong spacing/tabs)
Suggested-by: paul@crapouillou.net
PATCH V1 2026-07-10 08:58:35:
initial version.
>
> I merged your patch in i2c/i2c-fixes.
Thank you very much.
BR,
Nikolaus
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-07-31 6:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-19 20:19 [PATCH v2] i2c: jz4780: Cache host clock rate at probe to prevent CCF prepare_lock deadlock H. Nikolaus Schaller
2026-07-27 20:59 ` Andi Shyti
2026-07-31 6:04 ` H. Nikolaus Schaller
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®