From patchwork Wed Nov 7 07:00:46 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shinya Kuribayashi X-Patchwork-Id: 1708381 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id E46B6DFB7A for ; Wed, 7 Nov 2012 07:03:27 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TVzdF-0007re-U5; Wed, 07 Nov 2012 07:01:05 +0000 Received: from relmlor2.renesas.com ([210.160.252.172]) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TVzd2-0007k8-6p for linux-arm-kernel@lists.infradead.org; Wed, 07 Nov 2012 07:00:50 +0000 Received: from relmlir2.idc.renesas.com ([10.200.68.152]) by relmlor2.idc.renesas.com ( SJSMS) with ESMTP id <0MD300HUYVHAZK40@relmlor2.idc.renesas.com> for linux-arm-kernel@lists.infradead.org; Wed, 07 Nov 2012 16:00:46 +0900 (JST) Received: from relmlac1.idc.renesas.com ([10.200.69.21]) by relmlir2.idc.renesas.com ( SJSMS) with ESMTP id <0MD3006NBVHAVRG0@relmlir2.idc.renesas.com> for linux-arm-kernel@lists.infradead.org; Wed, 07 Nov 2012 16:00:46 +0900 (JST) Received: by relmlac1.idc.renesas.com (Postfix, from userid 0) id B015580193; Wed, 07 Nov 2012 16:00:46 +0900 (JST) Received: from relmlac1.idc.renesas.com (localhost [127.0.0.1]) by relmlac1.idc.renesas.com (Postfix) with ESMTP id A477D80177; Wed, 07 Nov 2012 16:00:46 +0900 (JST) Received: from relmlii1.idc.renesas.com [10.200.68.65] by relmlac1.idc.renesas.com with ESMTP id SAA20485; Wed, 07 Nov 2012 16:00:46 +0900 X-IronPort-AV: E=Sophos; i="4.80,727,1344178800"; d="scan'208"; a="105177253" Received: from unknown (HELO [10.161.64.55]) ([10.161.64.55]) by relmlii1.idc.renesas.com with ESMTP; Wed, 07 Nov 2012 16:00:46 +0900 Message-id: <509A071E.7070206@renesas.com> Date: Wed, 07 Nov 2012 16:00:46 +0900 From: Shinya Kuribayashi User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:16.0) Gecko/20121026 Thunderbird/16.0.2 MIME-version: 1.0 To: lethal@linux-sh.org, magnus.damm@gmail.com, alan@linux.intel.com, gregkh@linuxfoundation.org Subject: [PATCH 09/10] serial: sh-sci: add locking to console write function to avoid SMP lockup References: <509A0658.1010503@renesas.com> In-reply-to: <509A0658.1010503@renesas.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121107_020049_051115_B0D25ACB X-CRM114-Status: GOOD ( 15.48 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: rjw@sisk.pl, takashi.yoshii.zj@renesas.com, linux-arm-kernel@lists.infradead.org, linux-serial@vger.kernel.org, linux-sh@vger.kernel.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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 |commit ef605fdb33883d687cff5ba75095a91b313b4966 |Author: Rabin Vincent |Date: Tue Jan 17 11:52:28 2012 +0100 | | serial: amba-pl011: lock console writes against interrupts |commit 9ec1882df244c4ee1baa692676fef5e8b0f5487d |Author: Xinyu Chen |Date: Mon Aug 27 09:36:51 2012 +0200 | | tty: serial: imx: console write routing is unsafe on SMP --- drivers/tty/serial/sh-sci.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index 502fa47..0b8d029 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -2202,7 +2202,21 @@ 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); @@ -2210,6 +2224,13 @@ static void serial_console_write(struct console *co, const char *s, 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)