diff options
author | Geert Uytterhoeven <geert+renesas@glider.be> | 2016-01-05 13:36:37 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2016-01-08 00:08:05 -0500 |
commit | ff1cab374ad98f4b9f408525ca9c08992b4ed784 (patch) | |
tree | 2219e5bb1c37db2b612ccb7c1b86f146aeccada7 | |
parent | f658f21c65d1d8a8c93d1a6505e86c285bb7897e (diff) |
serial: sh-sci: Remove cpufreq notifier to fix crash/deadlock
The BSP team noticed that there is spin/mutex lock issue on sh-sci when
CPUFREQ is used. The issue is that the notifier function may call
mutex_lock() while the spinlock is held, which can lead to a BUG().
This may happen if CPUFREQ is changed while another CPU calls
clk_get_rate().
Taking the spinlock was added to the notifier function in commit
e552de2413edad1a ("sh-sci: add platform device private data"), to
protect the list of serial ports against modification during traversal.
At that time the Common Clock Framework didn't exist yet, and
clk_get_rate() just returned clk->rate without taking a mutex.
Note that since commit d535a2305facf9b4 ("serial: sh-sci: Require a
device per port mapping."), there's no longer a list of serial ports to
traverse, and taking the spinlock became superfluous.
To fix the issue, just remove the cpufreq notifier:
1. The notifier doesn't work correctly: all it does is update stored
clock rates; it does not update the divider in the hardware.
The divider will only be updated when calling sci_set_termios().
I believe this was broken back in 2004, when the old
drivers/char/sh-sci.c driver (where the notifier did update the
divider) was replaced by drivers/serial/sh-sci.c (where the
notifier just updated port->uartclk).
Cfr. full-history-linux commits 6f8deaef2e9675d9 ("[PATCH] sh: port
sh-sci driver to the new API") and 3f73fe878dc9210a ("[PATCH]
Remove old sh-sci driver").
2. On modern SoCs, the sh-sci parent clock rate is no longer related
to the CPU clock rate anyway, so using a cpufreq notifier is
futile.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/tty/serial/sh-sci.c | 42 |
1 files changed, 0 insertions, 42 deletions
diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index 5f2a03acb5d9..4646a9f531ad 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c | |||
@@ -39,7 +39,6 @@ | |||
39 | #include <linux/major.h> | 39 | #include <linux/major.h> |
40 | #include <linux/module.h> | 40 | #include <linux/module.h> |
41 | #include <linux/mm.h> | 41 | #include <linux/mm.h> |
42 | #include <linux/notifier.h> | ||
43 | #include <linux/of.h> | 42 | #include <linux/of.h> |
44 | #include <linux/platform_device.h> | 43 | #include <linux/platform_device.h> |
45 | #include <linux/pm_runtime.h> | 44 | #include <linux/pm_runtime.h> |
@@ -124,8 +123,6 @@ struct sci_port { | |||
124 | struct timer_list rx_timer; | 123 | struct timer_list rx_timer; |
125 | unsigned int rx_timeout; | 124 | unsigned int rx_timeout; |
126 | #endif | 125 | #endif |
127 | |||
128 | struct notifier_block freq_transition; | ||
129 | }; | 126 | }; |
130 | 127 | ||
131 | #define SCI_NPORTS CONFIG_SERIAL_SH_SCI_NR_UARTS | 128 | #define SCI_NPORTS CONFIG_SERIAL_SH_SCI_NR_UARTS |
@@ -1666,32 +1663,6 @@ static irqreturn_t sci_mpxed_interrupt(int irq, void *ptr) | |||
1666 | return ret; | 1663 | return ret; |
1667 | } | 1664 | } |
1668 | 1665 | ||
1669 | /* | ||
1670 | * Here we define a transition notifier so that we can update all of our | ||
1671 | * ports' baud rate when the peripheral clock changes. | ||
1672 | */ | ||
1673 | static int sci_notifier(struct notifier_block *self, | ||
1674 | unsigned long phase, void *p) | ||
1675 | { | ||
1676 | struct sci_port *sci_port; | ||
1677 | unsigned long flags; | ||
1678 | unsigned int i; | ||
1679 | |||
1680 | sci_port = container_of(self, struct sci_port, freq_transition); | ||
1681 | |||
1682 | if (phase == CPUFREQ_POSTCHANGE) { | ||
1683 | struct uart_port *port = &sci_port->port; | ||
1684 | |||
1685 | spin_lock_irqsave(&port->lock, flags); | ||
1686 | for (i = 0; i < SCI_NUM_CLKS; i++) | ||
1687 | sci_port->clk_rates[i] = | ||
1688 | clk_get_rate(sci_port->clks[i]); | ||
1689 | spin_unlock_irqrestore(&port->lock, flags); | ||
1690 | } | ||
1691 | |||
1692 | return NOTIFY_OK; | ||
1693 | } | ||
1694 | |||
1695 | static const struct sci_irq_desc { | 1666 | static const struct sci_irq_desc { |
1696 | const char *desc; | 1667 | const char *desc; |
1697 | irq_handler_t handler; | 1668 | irq_handler_t handler; |
@@ -2811,9 +2782,6 @@ static int sci_remove(struct platform_device *dev) | |||
2811 | { | 2782 | { |
2812 | struct sci_port *port = platform_get_drvdata(dev); | 2783 | struct sci_port *port = platform_get_drvdata(dev); |
2813 | 2784 | ||
2814 | cpufreq_unregister_notifier(&port->freq_transition, | ||
2815 | CPUFREQ_TRANSITION_NOTIFIER); | ||
2816 | |||
2817 | uart_remove_one_port(&sci_uart_driver, &port->port); | 2785 | uart_remove_one_port(&sci_uart_driver, &port->port); |
2818 | 2786 | ||
2819 | sci_cleanup_single(port); | 2787 | sci_cleanup_single(port); |
@@ -2965,16 +2933,6 @@ static int sci_probe(struct platform_device *dev) | |||
2965 | if (ret) | 2933 | if (ret) |
2966 | return ret; | 2934 | return ret; |
2967 | 2935 | ||
2968 | sp->freq_transition.notifier_call = sci_notifier; | ||
2969 | |||
2970 | ret = cpufreq_register_notifier(&sp->freq_transition, | ||
2971 | CPUFREQ_TRANSITION_NOTIFIER); | ||
2972 | if (unlikely(ret < 0)) { | ||
2973 | uart_remove_one_port(&sci_uart_driver, &sp->port); | ||
2974 | sci_cleanup_single(sp); | ||
2975 | return ret; | ||
2976 | } | ||
2977 | |||
2978 | #ifdef CONFIG_SH_STANDARD_BIOS | 2936 | #ifdef CONFIG_SH_STANDARD_BIOS |
2979 | sh_bios_gdb_detach(); | 2937 | sh_bios_gdb_detach(); |
2980 | #endif | 2938 | #endif |