Skip to content

Commit

Permalink
serial: sh-sci: add locking to console write function to avoid SMP lo…
Browse files Browse the repository at this point in the history
…ckup

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>
  • Loading branch information
Shinya Kuribayashi authored and gregkh committed Nov 16, 2012
1 parent 8c66d6d commit 40f70c0
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion drivers/tty/serial/sh-sci.c
Original file line number Diff line number Diff line change
Expand Up @@ -2203,14 +2203,35 @@ static void serial_console_write(struct console *co, const char *s,
{
struct sci_port *sci_port = &sci_ports[co->index];
struct uart_port *port = &sci_port->port;
unsigned short bits;
unsigned short bits, ctrl;
unsigned long flags;
int locked = 1;

local_irq_save(flags);
if (port->sysrq)
locked = 0;
else if (oops_in_progress)
locked = spin_trylock(&port->lock);
else
spin_lock(&port->lock);

/* first save the SCSCR then disable the interrupts */
ctrl = serial_port_in(port, SCSCR);
serial_port_out(port, SCSCR, sci_port->cfg->scscr);

uart_console_write(port, s, count, serial_console_putchar);

/* wait until fifo is empty and last bit has been transmitted */
bits = SCxSR_TDxE(port) | SCxSR_TEND(port);
while ((serial_port_in(port, SCxSR) & bits) != bits)
cpu_relax();

/* restore the SCSCR */
serial_port_out(port, SCSCR, ctrl);

if (locked)
spin_unlock(&port->lock);
local_irq_restore(flags);
}

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

0 comments on commit 40f70c0

Please sign in to comment.