From 3e9c93293700df05f185be21a67b5c76956b06d7 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Fri, 20 Nov 2020 09:52:35 +0100 Subject: [PATCH] 4.14-stable patches added patches: i2c-imx-fix-external-abort-on-interrupt-in-exit-paths.patch i2c-imx-use-clk-notifier-for-rate-changes.patch --- ...nal-abort-on-interrupt-in-exit-paths.patch | 118 +++++++++++++++++ ...mx-use-clk-notifier-for-rate-changes.patch | 122 ++++++++++++++++++ queue-4.14/series | 2 + 3 files changed, 242 insertions(+) create mode 100644 queue-4.14/i2c-imx-fix-external-abort-on-interrupt-in-exit-paths.patch create mode 100644 queue-4.14/i2c-imx-use-clk-notifier-for-rate-changes.patch diff --git a/queue-4.14/i2c-imx-fix-external-abort-on-interrupt-in-exit-paths.patch b/queue-4.14/i2c-imx-fix-external-abort-on-interrupt-in-exit-paths.patch new file mode 100644 index 00000000000..d0391a462b0 --- /dev/null +++ b/queue-4.14/i2c-imx-fix-external-abort-on-interrupt-in-exit-paths.patch @@ -0,0 +1,118 @@ +From foo@baz Fri Nov 20 09:47:34 AM CET 2020 +From: Krzysztof Kozlowski +Date: Sun, 20 Sep 2020 23:12:38 +0200 +Subject: i2c: imx: Fix external abort on interrupt in exit paths + +From: Krzysztof Kozlowski + +commit e50e4f0b85be308a01b830c5fbdffc657e1a6dd0 upstream + +If interrupt comes late, during probe error path or device remove (could +be triggered with CONFIG_DEBUG_SHIRQ), the interrupt handler +i2c_imx_isr() will access registers with the clock being disabled. This +leads to external abort on non-linefetch on Toradex Colibri VF50 module +(with Vybrid VF5xx): + + Unhandled fault: external abort on non-linefetch (0x1008) at 0x8882d003 + Internal error: : 1008 [#1] ARM + Modules linked in: + CPU: 0 PID: 1 Comm: swapper Not tainted 5.7.0 #607 + Hardware name: Freescale Vybrid VF5xx/VF6xx (Device Tree) + (i2c_imx_isr) from [<8017009c>] (free_irq+0x25c/0x3b0) + (free_irq) from [<805844ec>] (release_nodes+0x178/0x284) + (release_nodes) from [<80580030>] (really_probe+0x10c/0x348) + (really_probe) from [<80580380>] (driver_probe_device+0x60/0x170) + (driver_probe_device) from [<80580630>] (device_driver_attach+0x58/0x60) + (device_driver_attach) from [<805806bc>] (__driver_attach+0x84/0xc0) + (__driver_attach) from [<8057e228>] (bus_for_each_dev+0x68/0xb4) + (bus_for_each_dev) from [<8057f3ec>] (bus_add_driver+0x144/0x1ec) + (bus_add_driver) from [<80581320>] (driver_register+0x78/0x110) + (driver_register) from [<8010213c>] (do_one_initcall+0xa8/0x2f4) + (do_one_initcall) from [<80c0100c>] (kernel_init_freeable+0x178/0x1dc) + (kernel_init_freeable) from [<80807048>] (kernel_init+0x8/0x110) + (kernel_init) from [<80100114>] (ret_from_fork+0x14/0x20) + +Additionally, the i2c_imx_isr() could wake up the wait queue +(imx_i2c_struct->queue) before its initialization happens. + +The resource-managed framework should not be used for interrupt handling, +because the resource will be released too late - after disabling clocks. +The interrupt handler is not prepared for such case. + +Fixes: 1c4b6c3bcf30 ("i2c: imx: implement bus recovery") +Cc: +Signed-off-by: Krzysztof Kozlowski +Acked-by: Oleksij Rempel +Signed-off-by: Wolfram Sang +Signed-off-by: Sudip Mukherjee +Signed-off-by: Greg Kroah-Hartman +--- + drivers/i2c/busses/i2c-imx.c | 24 +++++++++++++----------- + 1 file changed, 13 insertions(+), 11 deletions(-) + +--- a/drivers/i2c/busses/i2c-imx.c ++++ b/drivers/i2c/busses/i2c-imx.c +@@ -1111,14 +1111,6 @@ static int i2c_imx_probe(struct platform + return ret; + } + +- /* Request IRQ */ +- ret = devm_request_irq(&pdev->dev, irq, i2c_imx_isr, IRQF_SHARED, +- pdev->name, i2c_imx); +- if (ret) { +- dev_err(&pdev->dev, "can't claim irq %d\n", irq); +- goto clk_disable; +- } +- + /* Init queue */ + init_waitqueue_head(&i2c_imx->queue); + +@@ -1137,6 +1129,14 @@ static int i2c_imx_probe(struct platform + if (ret < 0) + goto rpm_disable; + ++ /* Request IRQ */ ++ ret = request_threaded_irq(irq, i2c_imx_isr, NULL, IRQF_SHARED, ++ pdev->name, i2c_imx); ++ if (ret) { ++ dev_err(&pdev->dev, "can't claim irq %d\n", irq); ++ goto rpm_disable; ++ } ++ + /* Set up clock divider */ + i2c_imx->bitrate = IMX_I2C_BIT_RATE; + ret = of_property_read_u32(pdev->dev.of_node, +@@ -1179,13 +1179,12 @@ static int i2c_imx_probe(struct platform + + clk_notifier_unregister: + clk_notifier_unregister(i2c_imx->clk, &i2c_imx->clk_change_nb); ++ free_irq(irq, i2c_imx); + rpm_disable: + pm_runtime_put_noidle(&pdev->dev); + pm_runtime_disable(&pdev->dev); + pm_runtime_set_suspended(&pdev->dev); + pm_runtime_dont_use_autosuspend(&pdev->dev); +- +-clk_disable: + clk_disable_unprepare(i2c_imx->clk); + return ret; + } +@@ -1193,7 +1192,7 @@ clk_disable: + static int i2c_imx_remove(struct platform_device *pdev) + { + struct imx_i2c_struct *i2c_imx = platform_get_drvdata(pdev); +- int ret; ++ int irq, ret; + + ret = pm_runtime_get_sync(&pdev->dev); + if (ret < 0) +@@ -1213,6 +1212,9 @@ static int i2c_imx_remove(struct platfor + imx_i2c_write_reg(0, i2c_imx, IMX_I2C_I2SR); + + clk_notifier_unregister(i2c_imx->clk, &i2c_imx->clk_change_nb); ++ irq = platform_get_irq(pdev, 0); ++ if (irq >= 0) ++ free_irq(irq, i2c_imx); + clk_disable_unprepare(i2c_imx->clk); + + pm_runtime_put_noidle(&pdev->dev); diff --git a/queue-4.14/i2c-imx-use-clk-notifier-for-rate-changes.patch b/queue-4.14/i2c-imx-use-clk-notifier-for-rate-changes.patch new file mode 100644 index 00000000000..e52c7b31a20 --- /dev/null +++ b/queue-4.14/i2c-imx-use-clk-notifier-for-rate-changes.patch @@ -0,0 +1,122 @@ +From foo@baz Fri Nov 20 09:47:34 AM CET 2020 +From: Lucas Stach +Date: Thu, 8 Mar 2018 14:25:17 +0100 +Subject: i2c: imx: use clk notifier for rate changes + +From: Lucas Stach + +commit 90ad2cbe88c22d0215225ab9594eeead0eb24fde upstream + +Instead of repeatedly calling clk_get_rate for each transfer, register +a clock notifier to update the cached divider value each time the clock +rate actually changes. + +Signed-off-by: Lucas Stach +Reviewed-by: Philipp Zabel +Signed-off-by: Wolfram Sang +Signed-off-by: Sudip Mukherjee +Signed-off-by: Greg Kroah-Hartman +--- + drivers/i2c/busses/i2c-imx.c | 32 +++++++++++++++++++++++++------- + 1 file changed, 25 insertions(+), 7 deletions(-) + +--- a/drivers/i2c/busses/i2c-imx.c ++++ b/drivers/i2c/busses/i2c-imx.c +@@ -194,6 +194,7 @@ struct imx_i2c_dma { + struct imx_i2c_struct { + struct i2c_adapter adapter; + struct clk *clk; ++ struct notifier_block clk_change_nb; + void __iomem *base; + wait_queue_head_t queue; + unsigned long i2csr; +@@ -468,15 +469,14 @@ static int i2c_imx_acked(struct imx_i2c_ + return 0; + } + +-static void i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx) ++static void i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx, ++ unsigned int i2c_clk_rate) + { + struct imx_i2c_clk_pair *i2c_clk_div = i2c_imx->hwdata->clk_div; +- unsigned int i2c_clk_rate; + unsigned int div; + int i; + + /* Divider value calculation */ +- i2c_clk_rate = clk_get_rate(i2c_imx->clk); + if (i2c_imx->cur_clk == i2c_clk_rate) + return; + +@@ -511,6 +511,20 @@ static void i2c_imx_set_clk(struct imx_i + #endif + } + ++static int i2c_imx_clk_notifier_call(struct notifier_block *nb, ++ unsigned long action, void *data) ++{ ++ struct clk_notifier_data *ndata = data; ++ struct imx_i2c_struct *i2c_imx = container_of(&ndata->clk, ++ struct imx_i2c_struct, ++ clk); ++ ++ if (action & POST_RATE_CHANGE) ++ i2c_imx_set_clk(i2c_imx, ndata->new_rate); ++ ++ return NOTIFY_OK; ++} ++ + static int i2c_imx_start(struct imx_i2c_struct *i2c_imx) + { + unsigned int temp = 0; +@@ -518,8 +532,6 @@ static int i2c_imx_start(struct imx_i2c_ + + dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__); + +- i2c_imx_set_clk(i2c_imx); +- + imx_i2c_write_reg(i2c_imx->ifdr, i2c_imx, IMX_I2C_IFDR); + /* Enable I2C controller */ + imx_i2c_write_reg(i2c_imx->hwdata->i2sr_clr_opcode, i2c_imx, IMX_I2C_I2SR); +@@ -1131,6 +1143,9 @@ static int i2c_imx_probe(struct platform + "clock-frequency", &i2c_imx->bitrate); + if (ret < 0 && pdata && pdata->bitrate) + i2c_imx->bitrate = pdata->bitrate; ++ i2c_imx->clk_change_nb.notifier_call = i2c_imx_clk_notifier_call; ++ clk_notifier_register(i2c_imx->clk, &i2c_imx->clk_change_nb); ++ i2c_imx_set_clk(i2c_imx, clk_get_rate(i2c_imx->clk)); + + /* Set up chip registers to defaults */ + imx_i2c_write_reg(i2c_imx->hwdata->i2cr_ien_opcode ^ I2CR_IEN, +@@ -1141,12 +1156,12 @@ static int i2c_imx_probe(struct platform + ret = i2c_imx_init_recovery_info(i2c_imx, pdev); + /* Give it another chance if pinctrl used is not ready yet */ + if (ret == -EPROBE_DEFER) +- goto rpm_disable; ++ goto clk_notifier_unregister; + + /* Add I2C adapter */ + ret = i2c_add_numbered_adapter(&i2c_imx->adapter); + if (ret < 0) +- goto rpm_disable; ++ goto clk_notifier_unregister; + + pm_runtime_mark_last_busy(&pdev->dev); + pm_runtime_put_autosuspend(&pdev->dev); +@@ -1162,6 +1177,8 @@ static int i2c_imx_probe(struct platform + + return 0; /* Return OK */ + ++clk_notifier_unregister: ++ clk_notifier_unregister(i2c_imx->clk, &i2c_imx->clk_change_nb); + rpm_disable: + pm_runtime_put_noidle(&pdev->dev); + pm_runtime_disable(&pdev->dev); +@@ -1195,6 +1212,7 @@ static int i2c_imx_remove(struct platfor + imx_i2c_write_reg(0, i2c_imx, IMX_I2C_I2CR); + imx_i2c_write_reg(0, i2c_imx, IMX_I2C_I2SR); + ++ clk_notifier_unregister(i2c_imx->clk, &i2c_imx->clk_change_nb); + clk_disable_unprepare(i2c_imx->clk); + + pm_runtime_put_noidle(&pdev->dev); diff --git a/queue-4.14/series b/queue-4.14/series index 222dc1f107d..0ccbf9e8916 100644 --- a/queue-4.14/series +++ b/queue-4.14/series @@ -6,3 +6,5 @@ powerpc-implement-user_access_begin-and-friends.patch powerpc-fix-__clear_user-with-kuap-enabled.patch powerpc-uaccess-evaluate-macro-arguments-once-before-user-access-is-allowed.patch powerpc-64s-flush-l1d-after-user-accesses.patch +i2c-imx-use-clk-notifier-for-rate-changes.patch +i2c-imx-fix-external-abort-on-interrupt-in-exit-paths.patch -- 2.47.3