Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp1600622imd; Sun, 4 Nov 2018 06:06:52 -0800 (PST) X-Google-Smtp-Source: AJdET5eWLNOLu55uMyX0LpRnY1v5zf6/LaU+15L6W4QXWuRkvhyPioGHu2xT9Z25rLZLkwAGcnKb X-Received: by 2002:a62:583:: with SMTP id 125-v6mr18531317pff.186.1541340412606; Sun, 04 Nov 2018 06:06:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541340412; cv=none; d=google.com; s=arc-20160816; b=DSHES+u5RLMSfqOe2Dyt4Tsl0ESETJ0mlts2hnUEOxa+S3WJfulmzdPeMmjyUZUsbr pnaoMvxs1iLwZllMlXOGLw18OdwqX94Oq4Wwlv+Z097JRXPkKH34qqQQL4FrIl1bXjcC o8ff7InNGJ3NS1a+C7dSxwZK7ZVOYEK31ewUgcmbcnqWtHKT0FTDrFkvpshcmnYUMa32 xbK8YpuviZlYdYNv3IJs84QmlEQbnwj7hKXuMzIMN18Q97AVLk5JAy0XBtMmqjQFaVMy +fKniqwD2CAiJpNrQ6uoF52aL5cvFdxQQOnQMBaZSH1C1JkgzKyF+DYBls8rkEiD9AQ0 CPbg== 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:dkim-signature; bh=I9OBdUVb2MYyFMD3DCEC47eR4jmDi1F3iIyYHRHWR5Q=; b=0S/X053MLnf/50WIs+hwtHdyKdqd418D2tQ2+o/SMiOAGtm704NcfRjEiYJLd00Gbf d/pUxXgx7UXWrXWaFnNaiXixNRL8Sr0TuG5XSmX9ibfF2UaYva4DzokGMs5ADfFDn5zD ek0kDDODQIkoz0UwKjKs1PUI1RrDPKkkfU0ZF86rN2lH2senZbvteYYnx4L1CgV+yJ06 G+7SNgF83+gTjOFB0RZ3fcb+wZBK7Lxk4aRTHegHBVwCx2zTgNg5LqeATevzrDgWyVec HCXvq6pfePzMOyks7oB16GixttSsfU/1IMc1mKN+jZoBjlD+RPSNuRr9Ey1G51P9DRDc 8RvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bRkbVGt7; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ay8-v6si38304582plb.235.2018.11.04.06.06.37; Sun, 04 Nov 2018 06:06:52 -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; dkim=pass header.i=@kernel.org header.s=default header.b=bRkbVGt7; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731082AbeKDXUz (ORCPT + 99 others); Sun, 4 Nov 2018 18:20:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:45438 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730371AbeKDXHd (ORCPT ); Sun, 4 Nov 2018 18:07:33 -0500 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 6022C2086C; Sun, 4 Nov 2018 13:52:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541339549; bh=676F8azaXKn1LWI8d4rmHSJMwkmr1KsR1W5Jdl6LBdg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bRkbVGt7fGYO8lPF3nqZStrTXKCWVPITM5Gzdu11eT2XLIk7KAZ0jbq96GEdXeQUO EI8DGarjAhhQFnuIrHJw2KPMdKKY60YchQ5ZlhdwMU4y1qFOhvkRhQzFAXk29OfGjX 68jpDk0fCR5nh054EeGRIyDIlDd5k3hg1QMsWPt0= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Phil Elwell , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH AUTOSEL 4.19 44/57] sc16is7xx: Fix for multi-channel stall Date: Sun, 4 Nov 2018 08:51:31 -0500 Message-Id: <20181104135144.88324-44-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181104135144.88324-1-sashal@kernel.org> References: <20181104135144.88324-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Phil Elwell [ Upstream commit 8344498721059754e09d30fe255a12dab8fb03ef ] The SC16IS752 is a dual-channel device. The two channels are largely independent, but the IRQ signals are wired together as an open-drain, active low signal which will be driven low while either of the channels requires attention, which can be for significant periods of time until operations complete and the interrupt can be acknowledged. In that respect it is should be treated as a true level-sensitive IRQ. The kernel, however, needs to be able to exit interrupt context in order to use I2C or SPI to access the device registers (which may involve sleeping). Therefore the interrupt needs to be masked out or paused in some way. The usual way to manage sleeping from within an interrupt handler is to use a threaded interrupt handler - a regular interrupt routine does the minimum amount of work needed to triage the interrupt before waking the interrupt service thread. If the threaded IRQ is marked as IRQF_ONESHOT the kernel will automatically mask out the interrupt until the thread runs to completion. The sc16is7xx driver used to use a threaded IRQ, but a patch switched to using a kthread_worker in order to set realtime priorities on the handler thread and for other optimisations. The end result is non-threaded IRQ that schedules some work then returns IRQ_HANDLED, making the kernel think that all IRQ processing has completed. The work-around to prevent a constant stream of interrupts is to mark the interrupt as edge-sensitive rather than level-sensitive, but interpreting an active-low source as a falling-edge source requires care to prevent a total cessation of interrupts. Whereas an edge-triggering source will generate a new edge for every interrupt condition a level-triggering source will keep the signal at the interrupting level until it no longer requires attention; in other words, the host won't see another edge until all interrupt conditions are cleared. It is therefore vital that the interrupt handler does not exit with an outstanding interrupt condition, otherwise the kernel will not receive another interrupt unless some other operation causes the interrupt state on the device to be cleared. The existing sc16is7xx driver has a very simple interrupt "thread" (kthread_work job) that processes interrupts on each channel in turn until there are no more. If both channels are active and the first channel starts interrupting while the handler for the second channel is running then it will not be detected and an IRQ stall ensues. This could be handled easily if there was a shared IRQ status register, or a convenient way to determine if the IRQ had been deasserted for any length of time, but both appear to be lacking. Avoid this problem (or at least make it much less likely to happen) by reducing the granularity of per-channel interrupt processing to one condition per iteration, only exiting the overall loop when both channels are no longer interrupting. Signed-off-by: Phil Elwell Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/serial/sc16is7xx.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c index 243c96025053..47b41159a8bc 100644 --- a/drivers/tty/serial/sc16is7xx.c +++ b/drivers/tty/serial/sc16is7xx.c @@ -657,7 +657,7 @@ static void sc16is7xx_handle_tx(struct uart_port *port) uart_write_wakeup(port); } -static void sc16is7xx_port_irq(struct sc16is7xx_port *s, int portno) +static bool sc16is7xx_port_irq(struct sc16is7xx_port *s, int portno) { struct uart_port *port = &s->p[portno].port; @@ -666,7 +666,7 @@ static void sc16is7xx_port_irq(struct sc16is7xx_port *s, int portno) iir = sc16is7xx_port_read(port, SC16IS7XX_IIR_REG); if (iir & SC16IS7XX_IIR_NO_INT_BIT) - break; + return false; iir &= SC16IS7XX_IIR_ID_MASK; @@ -688,16 +688,23 @@ static void sc16is7xx_port_irq(struct sc16is7xx_port *s, int portno) port->line, iir); break; } - } while (1); + } while (0); + return true; } static void sc16is7xx_ist(struct kthread_work *ws) { struct sc16is7xx_port *s = to_sc16is7xx_port(ws, irq_work); - int i; - for (i = 0; i < s->devtype->nr_uart; ++i) - sc16is7xx_port_irq(s, i); + while (1) { + bool keep_polling = false; + int i; + + for (i = 0; i < s->devtype->nr_uart; ++i) + keep_polling |= sc16is7xx_port_irq(s, i); + if (!keep_polling) + break; + } } static irqreturn_t sc16is7xx_irq(int irq, void *dev_id) -- 2.17.1