Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp878581pxk; Thu, 17 Sep 2020 20:07:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmHICUQRtXY/g67GI0rIr2yFE30KObMCWT8xd3HJNS3it40qGh78Zy74qJw788BlQfTYrv X-Received: by 2002:a05:6402:6d3:: with SMTP id n19mr35727381edy.381.1600398460789; Thu, 17 Sep 2020 20:07:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600398460; cv=none; d=google.com; s=arc-20160816; b=jF1JK7Y2H4QTC2NbiBCmMYj7ee+2tw3BaXYegiJ5Qt0rIM41/T7Rbq/EsCDOqTP/hN Dpykt7W3acwOFN5FKaj76nk9ezF10LExMcg/ZapQYE6/Fu/s/+wTsvQFAQmZSYDEmTug nV2Q5O5auHA+K7XmBPk/ApoWHDJrOPg6Cte7nt4et7/kKBS5DMReE40WgqixgkfXAPtJ KcHjnxoTgryIs04YVOXA/Xg4bbZLgSI/p8L8vD2G29BzHTkVWAyO65DHmq6Z0fpcT7eS wFb5O7iM1qpEUS2qJrjhCGxMCQTrhPYFKoO+nAAEfnBVH/TYm9XeYuLFAmIdu/EUs0Wl icig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ANSP73c4tryOq+JPw4mssWW1UGcYSvAmuZyYf7RX9Rg=; b=yMVaPhWMrQsZx5uhpR0XVLzpdAfyLYuhk47jMautqLF6wesAsAF90lVqCcBXznjQax cTVHRgNyaxu88pR8w+BIw8cz0ZJBDawyEv26xqiiYCwyKqE2BY/kRUJ+fhCHs4bleBFF saPcpu4u1GxJ/pOJ1uMCcPgYfZchKSBw9skjWzTTwnP1i+VEhN8k4gdZ8w1OXAlSj1ZQ 8hQk8e5bfQSIanLkjvwEQ3lxuAv7AyL6A9SyFRuSfeT9FST9rOArnduTOt0rPx/219Uk KpY6xfugAusmEHUHlD/cjxltsN9Z2ZQdLnosIlYzT8L3ZUp5LDChuaHjK1D4oxCSpQvz N5ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=i+aViYLj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h6si1247035ejx.417.2020.09.17.20.07.17; Thu, 17 Sep 2020 20:07:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=i+aViYLj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729527AbgIRDDY (ORCPT + 99 others); Thu, 17 Sep 2020 23:03:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:53046 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727441AbgIRCFE (ORCPT ); Thu, 17 Sep 2020 22:05:04 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 791502389E; Fri, 18 Sep 2020 02:05:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394704; bh=siXwj0rYJfM0A6UG/dYuL14jfRWRzsXpgV4XZWY0O6g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i+aViYLjJyD68ZzH4MmGNweIMZMcHljzS7qzVzvjXP5Ytn2JGvXRsaS4DEPmkfHqj 3eHqefQdeuv0q85cOGyYRviqY4CFhPPgcwGyeEBd8RNSJogcDIMBrHl8ESyK7+63i4 dXclKS+7QbDBNwEQnCb6eGo1wg5fKd70/mmtv2zk= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Vignesh Raghavendra , Greg Kroah-Hartman , Sasha Levin , linux-serial@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 190/330] serial: 8250_port: Don't service RX FIFO if throttled Date: Thu, 17 Sep 2020 21:58:50 -0400 Message-Id: <20200918020110.2063155-190-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vignesh Raghavendra [ Upstream commit f19c3f6c8109b8bab000afd35580929958e087a9 ] When port's throttle callback is called, it should stop pushing any more data into TTY buffer to avoid buffer overflow. This means driver has to stop HW from receiving more data and assert the HW flow control. For UARTs with auto HW flow control (such as 8250_omap) manual assertion of flow control line is not possible and only way is to allow RX FIFO to fill up, thus trigger auto HW flow control logic. Therefore make sure that 8250 generic IRQ handler does not drain data when port is stopped (i.e UART_LSR_DR is unset in read_status_mask). Not servicing, RX FIFO would trigger auto HW flow control when FIFO occupancy reaches preset threshold, thus halting RX. Since, error conditions in UART_LSR register are cleared just by reading the register, data has to be drained in case there are FIFO errors, else error information will lost. Signed-off-by: Vignesh Raghavendra Link: https://lore.kernel.org/r/20200319103230.16867-2-vigneshr@ti.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/serial/8250/8250_port.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c index 90f09ed6e5ad3..5b673077639ba 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -1816,6 +1816,7 @@ int serial8250_handle_irq(struct uart_port *port, unsigned int iir) unsigned char status; unsigned long flags; struct uart_8250_port *up = up_to_u8250p(port); + bool skip_rx = false; if (iir & UART_IIR_NO_INT) return 0; @@ -1824,7 +1825,20 @@ int serial8250_handle_irq(struct uart_port *port, unsigned int iir) status = serial_port_in(port, UART_LSR); - if (status & (UART_LSR_DR | UART_LSR_BI)) { + /* + * If port is stopped and there are no error conditions in the + * FIFO, then don't drain the FIFO, as this may lead to TTY buffer + * overflow. Not servicing, RX FIFO would trigger auto HW flow + * control when FIFO occupancy reaches preset threshold, thus + * halting RX. This only works when auto HW flow control is + * available. + */ + if (!(status & (UART_LSR_FIFOE | UART_LSR_BRK_ERROR_BITS)) && + (port->status & (UPSTAT_AUTOCTS | UPSTAT_AUTORTS)) && + !(port->read_status_mask & UART_LSR_DR)) + skip_rx = true; + + if (status & (UART_LSR_DR | UART_LSR_BI) && !skip_rx) { if (!up->dma || handle_rx_dma(up, iir)) status = serial8250_rx_chars(up, status); } -- 2.25.1