Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3318271imu; Sun, 11 Nov 2018 12:15:13 -0800 (PST) X-Google-Smtp-Source: AJdET5dCQLDMDdUos4xOfOP3koCW2sl85T6xTqnCdht60AJ841217PrUSVkrWCXbVqnwOTOca89j X-Received: by 2002:a63:134f:: with SMTP id 15mr8563675pgt.19.1541967313719; Sun, 11 Nov 2018 12:15:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541967313; cv=none; d=google.com; s=arc-20160816; b=vaucZxHiFdvsVkdIH5e12g6oGB2FLfPwOsbrK/ldVodhmUzgHpTiv9jTokF4uC+P/W habDUqnYk8F+vwanIAUhHmmyTAr9hV1Acd4zDT11eimkAjYHaL+EO3FGdym/4y81HOky 99wiXO3Jh1+ecs8LAnx+HAzmdzcb4oXj0otgTrQ6Fc3IBrq8pRi6xoed3f3jlLdlQDRm 2rHj8dDblYswl5n8JJtKwfvhkO+QPzSudIZtaLG3YL4j2ZcCFVn6mD22TMWkcFM+5hiF 12nJfYf71/9y+0ex+rQ0LMdvcuYAg1xRz7URiadOGh6RSZAJ+85PdcIt4LEbV2XiqeUH ACEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=aafOCE6GATTFn9+FaBmp2wBzd5LtnNe7jRqCiXwkubI=; b=U1zOtX1vCJY8MByJ8D3+EbfASPO5YgPWf5ItIHpHnSMyowTqKiK7HJvwuz8m39vjmT wZDTjsjDz6VVcmPBORr7OmIhcn0afCSzmXY2pZMnyVjeSKx6tbBaQSTSaqfqO+vwjwkJ l6S4rcQ0EihleUICxyMUJNZf4HgKIkz39wAPh1/0NRLzG2clyg72cqV1MaG1DsBkIWY/ P0KbHcPmxCOEZq60TotMqx1KdH6e/eV5MUHwNjaHBKxxdfBkdor0z0gEBZtBwzXspait DQokPV9xiRgGRk2WD+n72EfJw4RsHdrSOLOZ5bau9bOxMOWIBD/g0d2T9vLha32cLx8Z AReA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s3-v6si8275718pfm.85.2018.11.11.12.14.58; Sun, 11 Nov 2018 12:15:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731711AbeKLGEI (ORCPT + 99 others); Mon, 12 Nov 2018 01:04:08 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:52884 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726816AbeKLGEH (ORCPT ); Mon, 12 Nov 2018 01:04:07 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLvtB-0000oG-Pv; Sun, 11 Nov 2018 19:59:21 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsO-0001Po-Qn; Sun, 11 Nov 2018 19:58:32 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Dave Martin" , "Greg Kroah-Hartman" , "Wei Xu" , "Linus Walleij" , "Russell King" , "Peter Maydell" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 047/366] tty: pl011: Avoid spuriously stuck-off interrupts In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.61-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Dave Martin commit 4a7e625ce50412a7711efa0f2ef0b96ce3826759 upstream. Commit 9b96fbacda34 ("serial: PL011: clear pending interrupts") clears the RX and receive timeout interrupts on pl011 startup, to avoid a screaming-interrupt scenario that can occur when the firmware or bootloader leaves these interrupts asserted. This has been noted as an issue when running Linux on qemu [1]. Unfortunately, the above fix seems to lead to potential misbehaviour if the RX FIFO interrupt is asserted _non_ spuriously on driver startup, if the RX FIFO is also already full to the trigger level. Clearing the RX FIFO interrupt does not change the FIFO fill level. In this scenario, because the interrupt is now clear and because the FIFO is already full to the trigger level, no new assertion of the RX FIFO interrupt can occur unless the FIFO is drained back below the trigger level. This never occurs because the pl011 driver is waiting for an RX FIFO interrupt to tell it that there is something to read, and does not read the FIFO at all until that interrupt occurs. Thus, simply clearing "spurious" interrupts on startup may be misguided, since there is no way to be sure that the interrupts are truly spurious, and things can go wrong if they are not. This patch instead clears the interrupt condition by draining the RX FIFO during UART startup, after clearing any potentially spurious interrupt. This should ensure that an interrupt will definitely be asserted if the RX FIFO subsequently becomes sufficiently full. The drain is done at the point of enabling interrupts only. This means that it will occur any time the UART is newly opened through the tty layer. It will not apply to polled-mode use of the UART by kgdboc: since that scenario cannot use interrupts by design, this should not matter. kgdboc will interact badly with "normal" use of the UART in any case: this patch makes no attempt to paper over such issues. This patch does not attempt to address the case where the RX FIFO fills faster than it can be drained: that is a pathological hardware design problem that is beyond the scope of the driver to work around. As a failsafe, the number of poll iterations for draining the FIFO is limited to twice the FIFO size. This will ensure that the kernel at least boots even if it is impossible to drain the FIFO for some reason. [1] [Qemu-devel] [Qemu-arm] [PATCH] pl011: do not put into fifo before enabled the interruption https://lists.gnu.org/archive/html/qemu-devel/2018-01/msg06446.html Reported-by: Wei Xu Cc: Russell King Cc: Linus Walleij Cc: Peter Maydell Fixes: 9b96fbacda34 ("serial: PL011: clear pending interrupts") Signed-off-by: Dave Martin Tested-by: Wei Xu Signed-off-by: Greg Kroah-Hartman [bwh: Backported to 3.16: - Open-code pl011_read() - s/REG_/UART01x_/ - Adjust context] Signed-off-by: Ben Hutchings --- drivers/tty/serial/amba-pl011.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) --- a/drivers/tty/serial/amba-pl011.c +++ b/drivers/tty/serial/amba-pl011.c @@ -1531,6 +1531,7 @@ static int pl011_startup(struct uart_por struct uart_amba_port *uap = (struct uart_amba_port *)port; unsigned int cr, lcr_h, fbrd, ibrd; int retval; + unsigned int i; retval = pl011_hwinit(port); if (retval) @@ -1595,6 +1596,20 @@ static int pl011_startup(struct uart_por /* Clear out any spuriously appearing RX interrupts */ writew(UART011_RTIS | UART011_RXIS, uap->port.membase + UART011_ICR); + + /* + * RXIS is asserted only when the RX FIFO transitions from below + * to above the trigger threshold. If the RX FIFO is already + * full to the threshold this can't happen and RXIS will now be + * stuck off. Drain the RX FIFO explicitly to fix this: + */ + for (i = 0; i < uap->fifosize * 2; ++i) { + if (readw(uap->port.membase + UART01x_FR) & UART01x_FR_RXFE) + break; + + readw(uap->port.membase + UART01x_DR); + } + uap->im = UART011_RTIM; if (!pl011_dma_rx_running(uap)) uap->im |= UART011_RXIM;