From patchwork Mon Apr 23 13:41:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Martin X-Patchwork-Id: 133997 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp1014011lji; Mon, 23 Apr 2018 06:41:39 -0700 (PDT) X-Google-Smtp-Source: AIpwx48FcjaNvkRVsBOW4G5ljLtGl2vVcPPpL9Ek36J1qmmkBp5sCC65z8iuaN6L8mkoU56bnw5X X-Received: by 10.99.96.193 with SMTP id u184mr13511581pgb.122.1524490899705; Mon, 23 Apr 2018 06:41:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524490899; cv=none; d=google.com; s=arc-20160816; b=nabYJbWS0m8UiLVnaLg4zinqf7pZ5xY9WmXDrO6my4pUUOeRlNlU/LIeP2MseunZLQ 6y1lk9+Jprws7nWEGcQdKeCBE8Yqfhm92as+k2wZr9LuXmC+OkLJXiWr9bokGYJWwSME hOcsQsywJWWdr5rK+lFZd+ezwgTeIm7qowTiyG6x21DiD15dSwq8ZyBQs5C0G3JPSk5t e/GkexOvB+EUpVKTT8TeGTOVde3JcKGVllWMWoHyzfFijX/O9ZnZfaS92P0m+uu+N6w8 VRfRXUjRN2G6J5esTiDaDHbwZTZ9mKjNwQK96bk2st6Cy977OUGTgolCUlcXS7WGxqBG X25g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=vW/IfCPYY1Mb5UEhW7bBrdPGNBO887P5cqMHlqyGx0M=; b=WojiL+VNWIOiH7YsX4i014rtQlgyeCU1aN9DYCO1oZu4a+sLxDSRKqG7PV0hdSsQJi 5CYRi3TQ1IlQ4cvhMf7bQtECWGXPcE0ZyE5eNkHreemIP7DhdcWft32GLXLmtAPGRKv2 YVyxMzNHQ3mmhBZG2nKe3eCKdr3P2ABJCD3EPiAxFHXUmapn1uYOPn8kKHNGhlYmLpJW 8n4YMz2/+hLJCWQKQdmPEZv80tAZ9T0MxNO/NyRBUeJOUqI7cZv9iTJkCpk5zIJPJNKI 9bs5qluBjeewjrzjp+Tc+nNGget1jdOMYNSoSwFtZDnrdyI+wF/UYpqgqjPBWvCGio9T QxHw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-serial-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-serial-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 o65si11001108pfo.20.2018.04.23.06.41.39; Mon, 23 Apr 2018 06:41:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-serial-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-serial-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-serial-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755398AbeDWNlh (ORCPT + 2 others); Mon, 23 Apr 2018 09:41:37 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:41022 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755396AbeDWNle (ORCPT ); Mon, 23 Apr 2018 09:41:34 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 77A5E15AD; Mon, 23 Apr 2018 06:41:34 -0700 (PDT) Received: from e103592.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6A01B3F4FF; Mon, 23 Apr 2018 06:41:33 -0700 (PDT) From: Dave Martin To: linux-arm-kernel@lists.infradead.org Cc: linux-serial@vger.kernel.org, Russell King , Linus Walleij , Peter Maydell , Wei Xu Subject: [RFC PATCH v3] tty: pl011: Avoid spuriously stuck-off interrupts Date: Mon, 23 Apr 2018 14:41:28 +0100 Message-Id: <1524490888-849-2-git-send-email-Dave.Martin@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1524490888-849-1-git-send-email-Dave.Martin@arm.com> References: <1524490888-849-1-git-send-email-Dave.Martin@arm.com> Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org 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. This patch does not attempt to address the case where the RX FIFO fills faster than it can be drained: that is a pathological condition that is beyond the scope of the driver to work around. Users cannot expect this to work unless they enable hardware flow control. [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 --- Changes since RFC v2: * Drain the RX FIFO explicitly on startup. This reduces the complexity of the changes, but should still fix the underlying problem. Characters present in the RX FIFO before the kernel boots will now be lost. However it was always poor practice to rely on such characters being processed by the kernel, since UART initialisation and RX FIFO overruns can always lead to data loss or corruption in any case. --- drivers/tty/serial/amba-pl011.c | 9 +++++++++ 1 file changed, 9 insertions(+) -- 2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-serial" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c index 4b40a5b..73e6f44 100644 --- a/drivers/tty/serial/amba-pl011.c +++ b/drivers/tty/serial/amba-pl011.c @@ -1676,6 +1676,15 @@ static int pl011_hwinit(struct uart_port *port) uap, REG_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 FIFO explicitly to fix this: + */ + while (!(pl011_read(uap, REG_FR) & UART01x_FR_RXFE)) + pl011_read(uap, REG_DR); + + /* * Save interrupts enable mask, and enable RX interrupts in case if * the interrupt is used for NMI entry. */