Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4503894ybx; Mon, 4 Nov 2019 14:29:31 -0800 (PST) X-Google-Smtp-Source: APXvYqxaIPQ0cS+sEsXBXinS6oQu4su+Y8xFDQlm+04tstdLdk8vWovgGuIYBDSogDgm6th2O265 X-Received: by 2002:a50:fb18:: with SMTP id d24mr32254474edq.216.1572906571653; Mon, 04 Nov 2019 14:29:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572906571; cv=none; d=google.com; s=arc-20160816; b=Tk+QTEmfqsE3J2AFsbwcIbmigutrLZcV9UDjJRmlFbGjqwhn+Z3jpRYF/0fOJq83T9 uS4gUkScI3hgwTpcpdpqnGgyo3EwPnef5jEf6+trE4bjTI7AbP9U3Qx5UcceuTVGH7Wd 0KY3qqnvxa+rlLkkRUWx8a7ZYb0YdpP7jKTxIRle7bdoqF4vgffC8zPSvc0R/6heoscQ EMah6g92/HPrVsSh18ovVWnC1xQLeVYpr3Jn5iqNtkKgztSHxKURKlZ/qKQiqEfiJDxf b5OJR/1PdzpNe2t7F3clzHdOTwGBf01EDN7ueIspOri/d7XMYuqg70Zh0FFKqCr/2v/9 Kc4A== 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=Zzn6d1m3kphrY3UGNykBIkNYvWrPchJ8txMa2dy7aC0=; b=Bpv9t4qfmpmoEAZBvsk4ZUeywGjDrkKPjzH+r3t4Yv+ztgwHym3Fjdl6+LVRa8u+bb J1Ou0vzzq8/q1AuMT54vwi7+iaXrcfkrY7uxwyASfEkh9HU2XYAOgW04CaU1IlReUGXo k8BEcX3zsR72cWhOhf3IaVSKA1l3JMNgG7OiTaXDstUX5A5M9kyW51Aua78YwFuyRyXe gw0Wk4yUz+c26d+yaxVMCDeQG31xsmUbNf2IlIXByk0ZELcKSRK9f0ORR6rktYdPRs2H H158kiFkehRIzy5BgeFIehdBxj8Af+ALpPP8LpkgMwhLO6413PgcCw9EBVLpH4dVREwJ IWYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DpOnQJnb; 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 bq21si12054575ejb.432.2019.11.04.14.29.08; Mon, 04 Nov 2019 14:29:31 -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=DpOnQJnb; 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 S2387631AbfKDVuM (ORCPT + 99 others); Mon, 4 Nov 2019 16:50:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:41992 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387612AbfKDVuI (ORCPT ); Mon, 4 Nov 2019 16:50:08 -0500 Received: from localhost (6.204-14-84.ripe.coltfrance.com [84.14.204.6]) (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 949AB20B7C; Mon, 4 Nov 2019 21:50:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572904207; bh=YnOH5UOiRqAiRkkA15Hq10x2syJJp4e27ylZz2Jyqhc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DpOnQJnbCGVvllSaWUg31E/Yw2XGrPx8kyTSn/2ieBZkMvUkKRp/TEpTeT/m1fse8 fWij/HWvInZnh5wKxsp/P+0skPTh55HX9Dpgs0FZ7nokzm4EcWi3e2JarxOTVgh7tX 8BwTls+bYn1MkpAJgHjzunT31VgPpxpdsATLNdaE= 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.9 05/62] sc16is7xx: Fix for "Unexpected interrupt: 8" Date: Mon, 4 Nov 2019 22:44:27 +0100 Message-Id: <20191104211906.994783878@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191104211901.387893698@linuxfoundation.org> References: <20191104211901.387893698@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Phil Elwell [ Upstream commit 30ec514d440cf2c472c8e4b0079af2c731f71a3e ] The SC16IS752 has an Enhanced Feature Register which is aliased at the same address as the Interrupt Identification Register; accessing it requires that a magic value is written to the Line Configuration Register. If an interrupt is raised while the EFR is mapped in then the ISR won't be able to access the IIR, leading to the "Unexpected interrupt" error messages. Avoid the problem by claiming a mutex around accesses to the EFR register, also claiming the mutex in the interrupt handler work item (this is equivalent to disabling interrupts to interlock against a non-threaded interrupt handler). See: https://github.com/raspberrypi/linux/issues/2529 Signed-off-by: Phil Elwell Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/serial/sc16is7xx.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c index 82451bb6622bd..f80a88d107d7f 100644 --- a/drivers/tty/serial/sc16is7xx.c +++ b/drivers/tty/serial/sc16is7xx.c @@ -332,6 +332,7 @@ struct sc16is7xx_port { struct kthread_worker kworker; struct task_struct *kworker_task; struct kthread_work irq_work; + struct mutex efr_lock; struct sc16is7xx_one p[0]; }; @@ -503,6 +504,21 @@ static int sc16is7xx_set_baud(struct uart_port *port, int baud) div /= 4; } + /* In an amazing feat of design, the Enhanced Features Register shares + * the address of the Interrupt Identification Register, and is + * switched in by writing a magic value (0xbf) to the Line Control + * Register. Any interrupt firing during this time will see the EFR + * where it expects the IIR to be, leading to "Unexpected interrupt" + * messages. + * + * Prevent this possibility by claiming a mutex while accessing the + * EFR, and claiming the same mutex from within the interrupt handler. + * This is similar to disabling the interrupt, but that doesn't work + * because the bulk of the interrupt processing is run as a workqueue + * job in thread context. + */ + mutex_lock(&s->efr_lock); + lcr = sc16is7xx_port_read(port, SC16IS7XX_LCR_REG); /* Open the LCR divisors for configuration */ @@ -518,6 +534,8 @@ static int sc16is7xx_set_baud(struct uart_port *port, int baud) /* Put LCR back to the normal mode */ sc16is7xx_port_write(port, SC16IS7XX_LCR_REG, lcr); + mutex_unlock(&s->efr_lock); + sc16is7xx_port_update(port, SC16IS7XX_MCR_REG, SC16IS7XX_MCR_CLKSEL_BIT, prescaler); @@ -700,6 +718,8 @@ static void sc16is7xx_ist(struct kthread_work *ws) { struct sc16is7xx_port *s = to_sc16is7xx_port(ws, irq_work); + mutex_lock(&s->efr_lock); + while (1) { bool keep_polling = false; int i; @@ -709,6 +729,8 @@ static void sc16is7xx_ist(struct kthread_work *ws) if (!keep_polling) break; } + + mutex_unlock(&s->efr_lock); } static irqreturn_t sc16is7xx_irq(int irq, void *dev_id) @@ -903,6 +925,9 @@ static void sc16is7xx_set_termios(struct uart_port *port, if (!(termios->c_cflag & CREAD)) port->ignore_status_mask |= SC16IS7XX_LSR_BRK_ERROR_MASK; + /* As above, claim the mutex while accessing the EFR. */ + mutex_lock(&s->efr_lock); + sc16is7xx_port_write(port, SC16IS7XX_LCR_REG, SC16IS7XX_LCR_CONF_MODE_B); @@ -924,6 +949,8 @@ static void sc16is7xx_set_termios(struct uart_port *port, /* Update LCR register */ sc16is7xx_port_write(port, SC16IS7XX_LCR_REG, lcr); + mutex_unlock(&s->efr_lock); + /* Get baud rate generator configuration */ baud = uart_get_baud_rate(port, termios, old, port->uartclk / 16 / 4 / 0xffff, @@ -1186,6 +1213,7 @@ static int sc16is7xx_probe(struct device *dev, s->regmap = regmap; s->devtype = devtype; dev_set_drvdata(dev, s); + mutex_init(&s->efr_lock); kthread_init_worker(&s->kworker); kthread_init_work(&s->irq_work, sc16is7xx_ist); -- 2.20.1