i2c: lpi2c: Avoid calling clk_get_rate during transfer
Subsystems (4)
PATCH 1/1 i2c: lpi2c: Avoid calling clk_get_rate during transfer
From: Alexander Stein <[email protected]>
[ Upstream commit 4268254a39484fc11ba991ae148bacbe75d9cc0a ]
Instead of repeatedly calling clk_get_rate for each transfer, lock the clock rate and cache the value.
A deadlock has been observed while adding tlv320aic32x4 audio codec to the system. When this clock provider adds its clock, the clk mutex is locked already, it needs to access i2c, which in return needs the mutex for clk_get_rate as well.
--- drivers/i2c/busses/i2c-imx-lpi2c.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/i2c/busses/i2c-imx-lpi2c.c +7 -3
@@ -99,6 +99,7 @@ struct lpi2c_imx_struct {__u8 *rx_buf;__u8 *tx_buf;struct completion complete; +unsigned long rate_per;unsigned int msglen;unsigned int delivered;unsigned int block_data;
@@ -207,9 +208,7 @@ static int lpi2c_imx_config(struct lpi2c_imx_struct *lpi2c_imx)lpi2c_imx_set_mode (lpi2c_imx); - clk_rate =clk_get_rate (lpi2c_imx->clks[0 ].clk); -if (!clk_rate) -return -EINVAL ; + clk_rate = lpi2c_imx->rate_per;if (lpi2c_imx->mode ==HS || lpi2c_imx->mode ==ULTRA_FAST ) filt =0 ;
@@ -590,6 +589,11 @@ static int lpi2c_imx_probe(struct platform_device *pdev)if (ret)return ret; + lpi2c_imx->rate_per =clk_get_rate (lpi2c_imx->clks[0 ].clk); +if (!lpi2c_imx->rate_per) +return dev_err_probe (&pdev->dev, -EINVAL , +"can't get I2C peripheral clock rate\n" ); +pm_runtime_set_autosuspend_delay (&pdev->dev,I2C_PM_TIMEOUT );pm_runtime_use_autosuspend (&pdev->dev);pm_runtime_get_noresume (&pdev->dev);
Signature · 1 line
2.43.0
Sasha Levin
maintainer[ Sasha's backport helper bot ]
Hi,
The upstream commit SHA1 provided is correct: 4268254a39484fc11ba991ae148bacbe75d9cc0a
WARNING: Author mismatch between patch and upstream commit:
Backport author: Bin Lan <[email protected]> Commit author: Alexander Stein <[email protected]>
Status in newer kernel trees:
6.12.y | Present (exact SHA1)
Note: The patch differs from the upstream commit:
---
tmp/tmp.iHtz9hU7o1 renamed from - +12 -14
@@ -1,3 +1,5 @@ +[ Upstream commit 4268254a39484fc11ba991ae148bacbe75d9cc0a ] + Instead of repeatedly calling clk_get_rate for each transfer, lock the clock rate and cache the value. A deadlock has been observed while adding tlv320aic32x4 audio codec to
@@ -9,12 +11,14 @@ Reviewed-by: Uwe Kleine-König <[email protected]> Reviewed-by: Andi Shyti <[email protected]> Signed-off-by: Andi Shyti <[email protected]> +[ Resolve minor conflicts to fix CVE-2024-40965 ] +Signed-off-by: Bin Lan <[email protected]> --- - drivers/i2c/busses/i2c-imx-lpi2c.c | 19 ++++++++++++++++--- - 1 file changed, 16 insertions(+), 3 deletions(-) + drivers/i2c/busses/i2c-imx-lpi2c.c | 10 +++++++--- + 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c b/drivers/i2c/busses/i2c-imx-lpi2c.c -index 6d72e4e126dde..36e8f6196a87b 100644 +index 678b30e90492..5d4f04a3c6d3 100644 --- a/drivers/i2c/busses/i2c-imx-lpi2c.c +++ b/drivers/i2c/busses/i2c-imx-lpi2c.c @@ -99,6 +99,7 @@ struct lpi2c_imx_struct {
@@ -25,7 +29,7 @@ unsigned int msglen; unsigned int delivered; unsigned int block_data; -@@ -212,9 +213,7 @@ static int lpi2c_imx_config(struct lpi2c_imx_struct *lpi2c_imx) +@@ -207,9 +208,7 @@ static int lpi2c_imx_config(struct lpi2c_imx_struct *lpi2c_imx) lpi2c_imx_set_mode(lpi2c_imx);
@@ -36,19 +40,10 @@ if (lpi2c_imx->mode == HS || lpi2c_imx->mode == ULTRA_FAST) filt = 0; -@@ -611,6 +610,20 @@ static int lpi2c_imx_probe(struct platform_device *pdev) +@@ -590,6 +589,11 @@ static int lpi2c_imx_probe(struct platform_device *pdev) if (ret) return ret; -+ /* -+ * Lock the parent clock rate to avoid getting parent clock upon -+ * each transfer -+ */ -+ ret = devm_clk_rate_exclusive_get(&pdev->dev, lpi2c_imx->clks[0].clk); -+ if (ret) -+ return dev_err_probe(&pdev->dev, ret, -+ "can't lock I2C peripheral clock rate\n"); -+ + lpi2c_imx->rate_per = clk_get_rate(lpi2c_imx->clks[0].clk); + if (!lpi2c_imx->rate_per) + return dev_err_probe(&pdev->dev, -EINVAL,
@@ -57,3 +52,6 @@ pm_runtime_set_autosuspend_delay(&pdev->dev, I2C_PM_TIMEOUT); pm_runtime_use_autosuspend(&pdev->dev); pm_runtime_get_noresume(&pdev->dev); +-- +2.43.0 +
---
Results of testing on various branches:
| Branch | Patch Apply | Build Test | |---------------------------|-------------|------------| | stable/linux-6.12.y | Failed | N/A | | stable/linux-6.11.y | Failed | N/A | | stable/linux-6.6.y | Success | Success | | stable/linux-6.1.y | Failed | N/A | | stable/linux-5.15.y | Failed | N/A | | stable/linux-5.10.y | Failed | N/A | | stable/linux-5.4.y | Failed | N/A | | stable/linux-4.19.y | Failed | N/A |
Hi All,
Please ignore this email for I forget to add the kernel version.
B.R.
Bin Lan
Quoted 97 lines · Sasha Levin
CAUTION: This email comes from a non Wind River email account!
Do not click links or open attachments unless you recognize the sender and know the content is safe.[ Sasha's backport helper bot ]
Hi,
The upstream commit SHA1 provided is correct:
4268254a39484fc11ba991ae148bacbe75d9cc0aWARNING: Author mismatch between patch and upstream commit:
Backport author: Bin Lan <[email protected]> Commit author: Alexander Stein <[email protected]>Status in newer kernel trees:
6.12.y | Present (exact SHA1)Note: The patch differs from the upstream commit:
---tmp/tmp.iHtz9hU7o1 2024-11-20 22:19:46.508471414 -0500 renamed from - 2024-11-20 22:19:46.512390713 -0500 +12
-15@@ -1,3 +1,5 @@ +[ Upstream commit 4268254a39484fc11ba991ae148bacbe75d9cc0a ] + Instead of repeatedly calling clk_get_rate for each transfer, lock the clock rate and cache the value. A deadlock has been observed while adding tlv320aic32x4 audio codec to@@ -9,12 +11,14 @@ Reviewed-by: Uwe Kleine-König <[email protected]> Reviewed-by: Andi Shyti <[email protected]> Signed-off-by: Andi Shyti <[email protected]> +[ Resolve minor conflicts to fix CVE-2024-40965 ] +Signed-off-by: Bin Lan <[email protected]> --- - drivers/i2c/busses/i2c-imx-lpi2c.c | 19 ++++++++++++++++--- - 1 file changed, 16 insertions(+), 3 deletions(-) + drivers/i2c/busses/i2c-imx-lpi2c.c | 10 +++++++--- + 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c b/drivers/i2c/busses/i2c-imx-lpi2c.c -index 6d72e4e126dde..36e8f6196a87b 100644 +index 678b30e90492..5d4f04a3c6d3 100644 --- a/drivers/i2c/busses/i2c-imx-lpi2c.c +++ b/drivers/i2c/busses/i2c-imx-lpi2c.c @@ -99,6 +99,7 @@ struct lpi2c_imx_struct {@@ -25,7 +29,7 @@ unsigned int msglen; unsigned int delivered; unsigned int block_data; -@@ -212,9 +213,7 @@ static int lpi2c_imx_config(struct lpi2c_imx_struct *lpi2c_imx) +@@ -207,9 +208,7 @@ static int lpi2c_imx_config(struct lpi2c_imx_struct *lpi2c_imx) lpi2c_imx_set_mode(lpi2c_imx);@@ -36,19 +40,10 @@ if (lpi2c_imx->mode == HS || lpi2c_imx->mode == ULTRA_FAST) filt = 0; -@@ -611,6 +610,20 @@ static int lpi2c_imx_probe(struct platform_device *pdev) +@@ -590,6 +589,11 @@ static int lpi2c_imx_probe(struct platform_device *pdev) if (ret) return ret; -+ /* -+ * Lock the parent clock rate to avoid getting parent clock upon -+ * each transfer -+ */ -+ ret = devm_clk_rate_exclusive_get(&pdev->dev, lpi2c_imx->clks[0].clk); -+ if (ret) -+ return dev_err_probe(&pdev->dev, ret, -+ "can't lock I2C peripheral clock rate\n"); -+ + lpi2c_imx->rate_per = clk_get_rate(lpi2c_imx->clks[0].clk); + if (!lpi2c_imx->rate_per) + return dev_err_probe(&pdev->dev, -EINVAL,@@ -57,3 +52,6 @@ pm_runtime_set_autosuspend_delay(&pdev->dev, I2C_PM_TIMEOUT); pm_runtime_use_autosuspend(&pdev->dev); pm_runtime_get_noresume(&pdev->dev); +-- +2.43.0 + ---Results of testing on various branches:
| Branch | Patch Apply | Build Test | |---------------------------|-------------|------------| | stable/linux-6.12.y | Failed | N/A | | stable/linux-6.11.y | Failed | N/A | | stable/linux-6.6.y | Success | Success | | stable/linux-6.1.y | Failed | N/A | | stable/linux-5.15.y | Failed | N/A | | stable/linux-5.10.y | Failed | N/A | | stable/linux-5.4.y | Failed | N/A | | stable/linux-4.19.y | Failed | N/A |