diff options
author | Xinyu Chen <xinyu.chen@freescale.com> | 2012-08-27 03:36:51 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-09-05 15:44:44 -0400 |
commit | 9ec1882df244c4ee1baa692676fef5e8b0f5487d (patch) | |
tree | c324ffa8ce389ed628f05ba3c5e9fde1eeb90537 | |
parent | fea7a08acb13524b47711625eebea40a0ede69a0 (diff) |
tty: serial: imx: console write routing is unsafe on SMP
The console feature's write routing is unsafe on SMP with
the startup/shutdown call.
There could be several consumers of the console
* the kernel printk
* the init process using /dev/kmsg to call printk to show log
* shell, which open /dev/console and write with sys_write()
The shell goes into the normal uart open/write routing,
but the other two go into the console operations.
The open routing calls imx serial startup, which will write USR1/2
register without any lock and critical with imx_console_write call.
Add a spin_lock for startup/shutdown/console_write routing.
This patch is a port from Freescale's Android kernel.
Signed-off-by: Xinyu Chen <xinyu.chen@freescale.com>
Tested-by: Dirk Behme <dirk.behme@de.bosch.com>
CC: Sascha Hauer <s.hauer@pengutronix.de>
Acked-by: Shawn Guo <shawn.guo@linaro.org>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/tty/serial/imx.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index d5c689d6217e..908178fc5a33 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c | |||
@@ -754,6 +754,7 @@ static int imx_startup(struct uart_port *port) | |||
754 | } | 754 | } |
755 | } | 755 | } |
756 | 756 | ||
757 | spin_lock_irqsave(&sport->port.lock, flags); | ||
757 | /* | 758 | /* |
758 | * Finally, clear and enable interrupts | 759 | * Finally, clear and enable interrupts |
759 | */ | 760 | */ |
@@ -807,7 +808,6 @@ static int imx_startup(struct uart_port *port) | |||
807 | /* | 808 | /* |
808 | * Enable modem status interrupts | 809 | * Enable modem status interrupts |
809 | */ | 810 | */ |
810 | spin_lock_irqsave(&sport->port.lock,flags); | ||
811 | imx_enable_ms(&sport->port); | 811 | imx_enable_ms(&sport->port); |
812 | spin_unlock_irqrestore(&sport->port.lock,flags); | 812 | spin_unlock_irqrestore(&sport->port.lock,flags); |
813 | 813 | ||
@@ -837,10 +837,13 @@ static void imx_shutdown(struct uart_port *port) | |||
837 | { | 837 | { |
838 | struct imx_port *sport = (struct imx_port *)port; | 838 | struct imx_port *sport = (struct imx_port *)port; |
839 | unsigned long temp; | 839 | unsigned long temp; |
840 | unsigned long flags; | ||
840 | 841 | ||
842 | spin_lock_irqsave(&sport->port.lock, flags); | ||
841 | temp = readl(sport->port.membase + UCR2); | 843 | temp = readl(sport->port.membase + UCR2); |
842 | temp &= ~(UCR2_TXEN); | 844 | temp &= ~(UCR2_TXEN); |
843 | writel(temp, sport->port.membase + UCR2); | 845 | writel(temp, sport->port.membase + UCR2); |
846 | spin_unlock_irqrestore(&sport->port.lock, flags); | ||
844 | 847 | ||
845 | if (USE_IRDA(sport)) { | 848 | if (USE_IRDA(sport)) { |
846 | struct imxuart_platform_data *pdata; | 849 | struct imxuart_platform_data *pdata; |
@@ -869,12 +872,14 @@ static void imx_shutdown(struct uart_port *port) | |||
869 | * Disable all interrupts, port and break condition. | 872 | * Disable all interrupts, port and break condition. |
870 | */ | 873 | */ |
871 | 874 | ||
875 | spin_lock_irqsave(&sport->port.lock, flags); | ||
872 | temp = readl(sport->port.membase + UCR1); | 876 | temp = readl(sport->port.membase + UCR1); |
873 | temp &= ~(UCR1_TXMPTYEN | UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN); | 877 | temp &= ~(UCR1_TXMPTYEN | UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN); |
874 | if (USE_IRDA(sport)) | 878 | if (USE_IRDA(sport)) |
875 | temp &= ~(UCR1_IREN); | 879 | temp &= ~(UCR1_IREN); |
876 | 880 | ||
877 | writel(temp, sport->port.membase + UCR1); | 881 | writel(temp, sport->port.membase + UCR1); |
882 | spin_unlock_irqrestore(&sport->port.lock, flags); | ||
878 | } | 883 | } |
879 | 884 | ||
880 | static void | 885 | static void |
@@ -1217,6 +1222,9 @@ imx_console_write(struct console *co, const char *s, unsigned int count) | |||
1217 | struct imx_port *sport = imx_ports[co->index]; | 1222 | struct imx_port *sport = imx_ports[co->index]; |
1218 | struct imx_port_ucrs old_ucr; | 1223 | struct imx_port_ucrs old_ucr; |
1219 | unsigned int ucr1; | 1224 | unsigned int ucr1; |
1225 | unsigned long flags; | ||
1226 | |||
1227 | spin_lock_irqsave(&sport->port.lock, flags); | ||
1220 | 1228 | ||
1221 | /* | 1229 | /* |
1222 | * First, save UCR1/2/3 and then disable interrupts | 1230 | * First, save UCR1/2/3 and then disable interrupts |
@@ -1242,6 +1250,8 @@ imx_console_write(struct console *co, const char *s, unsigned int count) | |||
1242 | while (!(readl(sport->port.membase + USR2) & USR2_TXDC)); | 1250 | while (!(readl(sport->port.membase + USR2) & USR2_TXDC)); |
1243 | 1251 | ||
1244 | imx_port_ucrs_restore(&sport->port, &old_ucr); | 1252 | imx_port_ucrs_restore(&sport->port, &old_ucr); |
1253 | |||
1254 | spin_unlock_irqrestore(&sport->port.lock, flags); | ||
1245 | } | 1255 | } |
1246 | 1256 | ||
1247 | /* | 1257 | /* |