i2c: imx: Avoid deadlock between clk_prepare_lock and i2c bus lock#40
Open
boesec wants to merge 1 commit intonxp-imx:lf-6.6.yfrom
Open
i2c: imx: Avoid deadlock between clk_prepare_lock and i2c bus lock#40boesec wants to merge 1 commit intonxp-imx:lf-6.6.yfrom
boesec wants to merge 1 commit intonxp-imx:lf-6.6.yfrom
Conversation
During deferred probing, clock registration can call into i2c (e.g. via pcf85063_clkout_recalc_rate() using regmap_i2c_read()) while the I2C bus lock is held. In parallel, the i.MX I2C transfer path calls clk_get_rate() from i2c_imx_start() while holding the same bus lock. clk_get_rate() takes clk_prepare_lock, which can already be held by the clock framework while invoking notifiers. This results in an ABBA deadlock between clk_prepare_lock and the I2C bus lock, stalling deferred probe. This patch fixes the issue by caching the clock rate in the notifier callback and removing the `clk_get_rate()` call from the transfer path. Signed-off-by: Christoph Boese <boesesc@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
During deferred probing, clock registration can call into i2c (e.g. via pcf85063_clkout_recalc_rate() using regmap_i2c_read()) while the I2C bus lock is held. In parallel, the i.MX I2C transfer path calls clk_get_rate() from i2c_imx_start() while holding the same bus lock.
This seems to be a rare corner case, but it is definitely reproducible. For us, a workaround for this is e.g. setting a fixed clock rate to RTC which avoids a call on clk_get_rate. We first encounter this issue after a kernel update to 6.6.
This patch fixed it for us entirely.
Since this issue was was introduced by 0e94d44 which is only in here, not in mainline, I assume this is the place to fix it?
Hung-task-probing-6.6.log
@wangxiaoningnxp