Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1703491ybi; Wed, 17 Jul 2019 20:25:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqxMwfy63Rmt+qMhyTQVJKkDOjU9RnSOBVDVq+q0wup4urJ0IpTYhHW7kx+YSUtI1r0DNAWa X-Received: by 2002:a65:690e:: with SMTP id s14mr31263492pgq.47.1563420355476; Wed, 17 Jul 2019 20:25:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563420355; cv=none; d=google.com; s=arc-20160816; b=atm2zLkwr/JX6t0mWZLx3phCgJvy2CJXq3X+MtiixGXkx68KQFMyP2SY6Oxbc1hE2X ehsr3rHRTEyGi2MpnY2V1eAsfyzLvkIWoSYnvnkMcEIlentbj68kGuHZPfp5VwHaBN4S eruQVj2WKmvVYvTzsev4+d7vCe6tyNuaNBnSSwyfV8S38yUFg4S5mPWgI8mg6E0j3n8u QdM3Ffb7cy6W7sFilcDpPLLQzU843qqQc17/tnc7KSVI162clm4MXRu/qfoluGkaAaMT CIAveuSA01DYwXeAI01ddtsqUKq6S6N1qmo5OKUYnQgYX7d271fI4HyN+fSJSfp/8TSQ OJow== 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=du7gdXP58mjIrMB6Ag6Q2WIL+gQvmAzLoFAe1qt+7KM=; b=BB43b6Uc/th1ex7KGyvHfW+aas2alM1WURCCeO8PcIhvXTVvlRJdX7T5c4z6oeqhRO UcjGVqw+FdW3P8AEhN+v5+72cfKvOj+gmyyenPZLKLwkLGqFvCbFxfPe/mGOXX5hmfD3 GV30GHDpASnAJbsVgJtLIK6WUpbwbBO5LrSqu3YT+CN4ujJ69oVcFQzqX3kPIzbVemmy EtFhS1DTu9qgL8ZGTEq8wCnshbvPUcPC4oxHpRXwdI6KKUEj1lpn0B+WlZefJuYO6sl3 p2ghAK5oYHXdCJyqc8af5pNAyGVQ9+/8PoK09WhdS+d4XbNBrPfoXS0j7xAPVsaUDu/U O7CA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="r/dOjItu"; 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 b20si291443pfo.108.2019.07.17.20.25.39; Wed, 17 Jul 2019 20:25:55 -0700 (PDT) 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="r/dOjItu"; 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 S2390161AbfGRDIK (ORCPT + 99 others); Wed, 17 Jul 2019 23:08:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:39968 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390121AbfGRDII (ORCPT ); Wed, 17 Jul 2019 23:08:08 -0400 Received: from localhost (115.42.148.210.bf.2iij.net [210.148.42.115]) (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 DC1222077C; Thu, 18 Jul 2019 03:08:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563419287; bh=f/vlrT7KsR6TjfdCOFeh2Y7lHRcriwJ9EhQmW6ho/Fg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r/dOjItufsb3B1irYOkaHJY794TFl61FQewh4AYssjm1h8s3gEM933OdF1bNBiWZa Ae6JATLUWx6mI3VvJSm1aLfe0ykmS3cMwOG6Av2duB0HVoWxTLT0rkd1tJcf87kCwa hKgEX2Qx8VVnovkT7KkvvRMRQbstliQ0vcPzXdmE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nicolas Boichat , Sean Wang , Linus Walleij , Sasha Levin Subject: [PATCH 4.19 28/47] pinctrl: mediatek: Update cur_mask in mask/mask ops Date: Thu, 18 Jul 2019 12:01:42 +0900 Message-Id: <20190718030051.111797703@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190718030045.780672747@linuxfoundation.org> References: <20190718030045.780672747@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 [ Upstream commit 9d957a959bc8c3dfe37572ac8e99affb5a885965 ] During suspend/resume, mtk_eint_mask may be called while wake_mask is active. For example, this happens if a wake-source with an active interrupt handler wakes the system: irq/pm.c:irq_pm_check_wakeup would disable the interrupt, so that it can be handled later on in the resume flow. However, this may happen before mtk_eint_do_resume is called: in this case, wake_mask is loaded, and cur_mask is restored from an older copy, re-enabling the interrupt, and causing an interrupt storm (especially for level interrupts). Step by step, for a line that has both wake and interrupt enabled: 1. cur_mask[irq] = 1; wake_mask[irq] = 1; EINT_EN[irq] = 1 (interrupt enabled at hardware level) 2. System suspends, resumes due to that line (at this stage EINT_EN == wake_mask) 3. irq_pm_check_wakeup is called, and disables the interrupt => EINT_EN[irq] = 0, but we still have cur_mask[irq] = 1 4. mtk_eint_do_resume is called, and restores EINT_EN = cur_mask, so it reenables EINT_EN[irq] = 1 => interrupt storm as the driver is not yet ready to handle the interrupt. This patch fixes the issue in step 3, by recording all mask/unmask changes in cur_mask. This also avoids the need to read the current mask in eint_do_suspend, and we can remove mtk_eint_chip_read_mask function. The interrupt will be re-enabled properly later on, sometimes after mtk_eint_do_resume, when the driver is ready to handle it. Fixes: 58a5e1b64bb0 ("pinctrl: mediatek: Implement wake handler and suspend resume") Signed-off-by: Nicolas Boichat Acked-by: Sean Wang Signed-off-by: Linus Walleij Signed-off-by: Sasha Levin --- drivers/pinctrl/mediatek/mtk-eint.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/drivers/pinctrl/mediatek/mtk-eint.c b/drivers/pinctrl/mediatek/mtk-eint.c index b9f3c02ba59d..564cfaee129d 100644 --- a/drivers/pinctrl/mediatek/mtk-eint.c +++ b/drivers/pinctrl/mediatek/mtk-eint.c @@ -113,6 +113,8 @@ static void mtk_eint_mask(struct irq_data *d) void __iomem *reg = mtk_eint_get_offset(eint, d->hwirq, eint->regs->mask_set); + eint->cur_mask[d->hwirq >> 5] &= ~mask; + writel(mask, reg); } @@ -123,6 +125,8 @@ static void mtk_eint_unmask(struct irq_data *d) void __iomem *reg = mtk_eint_get_offset(eint, d->hwirq, eint->regs->mask_clr); + eint->cur_mask[d->hwirq >> 5] |= mask; + writel(mask, reg); if (eint->dual_edge[d->hwirq]) @@ -217,19 +221,6 @@ static void mtk_eint_chip_write_mask(const struct mtk_eint *eint, } } -static void mtk_eint_chip_read_mask(const struct mtk_eint *eint, - void __iomem *base, u32 *buf) -{ - int port; - void __iomem *reg; - - for (port = 0; port < eint->hw->ports; port++) { - reg = base + eint->regs->mask + (port << 2); - buf[port] = ~readl_relaxed(reg); - /* Mask is 0 when irq is enabled, and 1 when disabled. */ - } -} - static int mtk_eint_irq_request_resources(struct irq_data *d) { struct mtk_eint *eint = irq_data_get_irq_chip_data(d); @@ -384,7 +375,6 @@ static void mtk_eint_irq_handler(struct irq_desc *desc) int mtk_eint_do_suspend(struct mtk_eint *eint) { - mtk_eint_chip_read_mask(eint, eint->base, eint->cur_mask); mtk_eint_chip_write_mask(eint, eint->base, eint->wake_mask); return 0; -- 2.20.1