Skip to content

Commit 40f70c0

Browse files
Shinya Kuribayashigregkh
authored andcommitted
serial: sh-sci: add locking to console write function to avoid SMP lockup
Symptom: When entering the suspend with Android logcat running, printk() call gets stuck and never returns. The issue can be observed at printk()s on nonboot CPUs when going to offline with their interrupts disabled, and never seen at boot CPU (core0 in our case). Details: serial_console_write() lacks of appropriate spinlock handling. In SMP systems, as long as sci_transmit_chars() is being processed at one CPU core, serial_console_write() can stuck at the other CPU core(s), when it tries to access to the same serial port _without_ a proper locking. serial_console_write() waits for the transmit FIFO getting empty, while sci_transmit_chars() writes data to the FIFO. In general, peripheral interrupts are routed to boot CPU (core0) by Linux ARM standard affinity settings. SCI(F) interrupts are handled by core0, so sci_transmit_chars() is processed on core0 as well. When logcat is running, it writes enormous log data to the kernel at every moment, forever. So core0 can repeatedly continue to process sci_transmit_chars() in its interrupt handler, which eventually makes the other CPU core(s) stuck at serial_console_write(). Looking at serial/8250.c, this is a known console write lockup issue with SMP kernels. Fix the sh-sci driver in the same way 8250.c does. Signed-off-by: Shinya Kuribayashi <shinya.kuribayashi.px@renesas.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 8c66d6d commit 40f70c0

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

drivers/tty/serial/sh-sci.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2203,14 +2203,35 @@ static void serial_console_write(struct console *co, const char *s,
22032203
{
22042204
struct sci_port *sci_port = &sci_ports[co->index];
22052205
struct uart_port *port = &sci_port->port;
2206-
unsigned short bits;
2206+
unsigned short bits, ctrl;
2207+
unsigned long flags;
2208+
int locked = 1;
2209+
2210+
local_irq_save(flags);
2211+
if (port->sysrq)
2212+
locked = 0;
2213+
else if (oops_in_progress)
2214+
locked = spin_trylock(&port->lock);
2215+
else
2216+
spin_lock(&port->lock);
2217+
2218+
/* first save the SCSCR then disable the interrupts */
2219+
ctrl = serial_port_in(port, SCSCR);
2220+
serial_port_out(port, SCSCR, sci_port->cfg->scscr);
22072221

22082222
uart_console_write(port, s, count, serial_console_putchar);
22092223

22102224
/* wait until fifo is empty and last bit has been transmitted */
22112225
bits = SCxSR_TDxE(port) | SCxSR_TEND(port);
22122226
while ((serial_port_in(port, SCxSR) & bits) != bits)
22132227
cpu_relax();
2228+
2229+
/* restore the SCSCR */
2230+
serial_port_out(port, SCSCR, ctrl);
2231+
2232+
if (locked)
2233+
spin_unlock(&port->lock);
2234+
local_irq_restore(flags);
22142235
}
22152236

22162237
static int __devinit serial_console_setup(struct console *co, char *options)

0 commit comments

Comments
 (0)