Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2952923imu; Mon, 19 Nov 2018 08:32:53 -0800 (PST) X-Google-Smtp-Source: AJdET5dXMnaxGKCb8BRVY+EaJY4mlT5jh50VrEIGVGaHqx9QEbSIfpkL6IcCDeP+8bWKfwSO2tRO X-Received: by 2002:a62:3647:: with SMTP id d68-v6mr23847132pfa.66.1542645173254; Mon, 19 Nov 2018 08:32:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542645173; cv=none; d=google.com; s=arc-20160816; b=uqP4cezg7tPLG6zbAwxwlSqWIEiZ47QMpf2oKeLhsGs4yG/S4L3flbsu4pJ9yrphNz CZqviqRjkDrvbtOytx2ZxSpPDwRxlVhqreSvxFAU+3D4CJVAcWwSslxOXcdjWFaqGmb/ o/J/FOw4iy85KelF2n9/YRc6mK2V2UCHU+Jt6ICNeNLo00rAW3Zx2jq3ahkf5M2O/t8c 9dzIMnefmTJNYVFaP0EKSZBT/lA3S8aYU5Yi/Eelm8nq+TjreXpgjRCf9uzhBaTNgcN+ wSlDY3n15wTCQSr3XBTXDG5Yh9EYlz3Ck5sUsbIGWTQT/v39FOdjdIccD8G3qnOubepu 1F0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=q7H1MmCKYQ3K7JEdUuretmwxSqbj9thdMFY1D4aCWDU=; b=M13kh4K/5Wx+POHdjXLlN79z6l8gLyyuBr0S7nHpSrbWSgbz5+u/0vQsTDbXoBGWgA n3//0cNa2tW9vhGqyANY4qtARqz3B82Esyz2tp5uoHBUSHmsMhck3UDgyS4ShYMCfIDp jnX3FSSb4W1pOx3awqg9Q+JAgQPKEfwJ2WyJ95os9/uod0G20/fyrAysnswdOVTSzOoG 8tPcnYsbiEZQhmqaQdUTmjClzKGyUTP5ZhXMAun0hxj4TI3LwSgJKuHIT6hXEeaxLqhA ZlSaLLJTxTUmigLfOvUHPTDPIKCbZXY+mGH/J2eTfHwqIFVLXl1Eqi7cXBNrpnyCf2sk t7tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wijqyBOD; 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 28si18776848pgw.364.2018.11.19.08.32.37; Mon, 19 Nov 2018 08:32:53 -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=wijqyBOD; 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 S1730422AbeKTCzd (ORCPT + 99 others); Mon, 19 Nov 2018 21:55:33 -0500 Received: from mail.kernel.org ([198.145.29.99]:53292 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730385AbeKTCzc (ORCPT ); Mon, 19 Nov 2018 21:55:32 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6033320989; Mon, 19 Nov 2018 16:31:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542645085; bh=VKO6F/2cQ7T1Uq1myZwttRuNaREy1hEhvkxsGiriV2I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wijqyBODBeAqSMm8GXuAySRJA9ssiMGJyCCgT3LmN6glWJvQMiDlqlb/rBHFgagWu 6F/tKX/2Z1HDw1GXBjjdwtbKUdPZl6LtWFoo0aPTkfN23r50TtbLI54IMwyz+0Ym4s 1hZvHP7KCC3K+LLH8R0OriHhmmY2VBMXSMgXmDQ0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Phil Elwell , Sasha Levin Subject: [PATCH 4.19 031/205] sc16is7xx: Fix for multi-channel stall Date: Mon, 19 Nov 2018 17:25:38 +0100 Message-Id: <20181119162623.095827395@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181119162616.586062722@linuxfoundation.org> References: <20181119162616.586062722@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ 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 Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/sc16is7xx.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) --- a/drivers/tty/serial/sc16is7xx.c +++ b/drivers/tty/serial/sc16is7xx.c @@ -657,7 +657,7 @@ static void sc16is7xx_handle_tx(struct u 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 sc 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 sc 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)