DORMANTno replies REVIEWED: 3 (0M)

[PATCH] serial: amba-pl011: lock console writes against interrupts

From: Linus Walleij <hidden>
Date: 2012-01-17 10:52:28
Also in: linux-serial
Subsystem: arm primecell uart pl010 and pl011 drivers, the rest, tty layer and serial drivers · Maintainers: Russell King, Linus Torvalds, Greg Kroah-Hartman, Jiri Slaby

From: Rabin Vincent <redacted>

Protect against pl011_console_write() and the interrupt for
the console UART running concurrently on different CPUs.

Otherwise the console_write could spin for a long time
waiting for the UART to become not busy, while the other
CPU continuously services UART interrupts and keeps the
UART busy.

The checks for sysrq and oops_in_progress are taken
from 8250.c.

Cc: stable at kernel.org
Signed-off-by: Rabin Vincent <redacted>
Reviewed-by: Srinidhi Kasagar <redacted>
Reviewed-by: Bibek Basu <redacted>
Reviewed-by: Shreshtha Kumar Sahu <redacted>
Signed-off-by: Linus Walleij <redacted>
---
 drivers/tty/serial/amba-pl011.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c
index 6958594..89178b4 100644
--- a/drivers/tty/serial/amba-pl011.c
+++ b/drivers/tty/serial/amba-pl011.c
@@ -1740,9 +1740,19 @@ pl011_console_write(struct console *co, const char *s, unsigned int count)
 {
 	struct uart_amba_port *uap = amba_ports[co->index];
 	unsigned int status, old_cr, new_cr;
+	unsigned long flags;
+	int locked = 1;
 
 	clk_enable(uap->clk);
 
+	local_irq_save(flags);
+	if (uap->port.sysrq)
+		locked = 0;
+	else if (oops_in_progress)
+		locked = spin_trylock(&uap->port.lock);
+	else
+		spin_lock(&uap->port.lock);
+
 	/*
 	 *	First save the CR then disable the interrupts
 	 */
@@ -1762,6 +1772,10 @@ pl011_console_write(struct console *co, const char *s, unsigned int count)
 	} while (status & UART01x_FR_BUSY);
 	writew(old_cr, uap->port.membase + UART011_CR);
 
+	if (locked)
+		spin_unlock(&uap->port.lock);
+	local_irq_restore(flags);
+
 	clk_disable(uap->clk);
 }
 
-- 
1.7.8
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help