From patchwork Wed Mar 21 19:27:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 10300179 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C2C12602B3 for ; Wed, 21 Mar 2018 19:28:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA79C29060 for ; Wed, 21 Mar 2018 19:28:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9EEF829071; Wed, 21 Mar 2018 19:28:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0615F29060 for ; Wed, 21 Mar 2018 19:28:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753201AbeCUT2s (ORCPT ); Wed, 21 Mar 2018 15:28:48 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:42400 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753076AbeCUT2k (ORCPT ); Wed, 21 Mar 2018 15:28:40 -0400 Received: by mail-qt0-f193.google.com with SMTP id q11so6495723qtl.9 for ; Wed, 21 Mar 2018 12:28:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vanguardiasur-com-ar.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qPSnQo8Fvk3KQ1TpaLjazN5Q//B2aJlpJq/5Gx/pvSg=; b=pRv7XScY5yBV3Gwtq2NhztFtYIJQTHBCzGb3M0DOuOfytnFis5FsHqcZpbdvfa/16i TH/NKQ2AZBftYSYFt+wjYv6Mfya5NjQjBl5lGapC7XEk+fQTJn5vdR9sD5xeODfJtuWM ILxTLUqoHh6EVamcuXBdBmiUvnXnceBoLltYEc6rGAIwFoU8dve68sYm0O/aJbdOVggX YXNjisj7a7bkaziTIz5ifMVYgcS++rglvoIMd+wahBI7ofi1JUxaKwSf0EPv9uozocEi 3RH1cmBtecehTOA7gKwU7hdbpaW+3b8eIfwt0xUVjVfKo6YfOspM3vAhpntx3iTPCl3j UdLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qPSnQo8Fvk3KQ1TpaLjazN5Q//B2aJlpJq/5Gx/pvSg=; b=Djc2HOhyW6xnCVcf3tlqz/UTjsEi14DxqA2WCw1bqPC/hYKRWJCKdRBlqc26zNAoN0 uEcFmueB3zIJClu4B7jeXfcfgkhbmm8ms8cSMB4iME2WmKFgyoxQSYZ9ghuFs7Ywh7NY JRriqyCMPn7Rm12cgaNMk4RT6+IUOwccKjJON6mF8WSGThrEaQcshVv1ydv5eByPrM/P k8t8bDzd8buh+nCLZEgz/UZvPAnBVMkbJRbJ09XNegbxjGCGJzw7jupFKtaKaFQ2Kevp 8RgCy8wZ9i9y3al+kUsO6S85Sk4wk1iXn9X4KzYafkn9orTcw+1xIHMif06eqV7CVUM0 sCtg== X-Gm-Message-State: AElRT7GsXbhFIGa1P4EbTb6lmqXF5oHWV/5ggLOw5UMceHvldURxihLk 9XZphTClWMguEhFDp448t7iScQ== X-Google-Smtp-Source: AG47ELux32y7hcRDntIkJxqDPbWSYBV6KBfzrn7KSdb9xUffRU9c8xBrR+GiQ3NBCz9FuH5XYGtIIQ== X-Received: by 10.200.62.10 with SMTP id z10mr31810684qtf.15.1521660519572; Wed, 21 Mar 2018 12:28:39 -0700 (PDT) Received: from localhost.localdomain ([190.210.56.45]) by smtp.gmail.com with ESMTPSA id h184sm3859601qkc.78.2018.03.21.12.28.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Mar 2018 12:28:38 -0700 (PDT) From: Ezequiel Garcia To: Mathieu Malaterre , Ulf Hansson , Paul Cercueil Cc: linux-mmc@vger.kernel.org, linux-mips@linux-mips.org, James Hogan , kernel@collabora.com, Alex Smith , stable@vger.kernel.org Subject: [PATCH 01/14] mmc: jz4740: Fix race condition in IRQ mask update Date: Wed, 21 Mar 2018 16:27:28 -0300 Message-Id: <20180321192741.25872-2-ezequiel@vanguardiasur.com.ar> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180321192741.25872-1-ezequiel@vanguardiasur.com.ar> References: <20180321192741.25872-1-ezequiel@vanguardiasur.com.ar> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Alex Smith A spinlock is held while updating the internal copy of the IRQ mask, but not while writing it to the actual IMASK register. After the lock is released, an IRQ can occur before the IMASK register is written. If handling this IRQ causes the mask to be changed, when the handler returns back to the middle of the first mask update, a stale value will be written to the mask register. If this causes an IRQ to become unmasked that cannot have its status cleared by writing a 1 to it in the IREG register, e.g. the SDIO IRQ, then we can end up stuck with the same IRQ repeatedly being fired but not handled. Normally the MMC IRQ handler attempts to clear any unexpected IRQs by writing IREG, but for those that cannot be cleared in this way then the IRQ will just repeatedly fire. This was resulting in lockups after a while of using Wi-Fi on the CI20 (GitHub issue #19). Resolve by holding the spinlock until after the IMASK register has been updated. Cc: stable@vger.kernel.org Link: https://github.com/MIPS/CI20_linux/issues/19 Fixes: 61bfbdb85687 ("MMC: Add support for the controller on JZ4740 SoCs.") Tested-by: Mathieu Malaterre Signed-off-by: Alex Smith --- drivers/mmc/host/jz4740_mmc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mmc/host/jz4740_mmc.c b/drivers/mmc/host/jz4740_mmc.c index 712e08d9a45e..a0168e9e4fce 100644 --- a/drivers/mmc/host/jz4740_mmc.c +++ b/drivers/mmc/host/jz4740_mmc.c @@ -362,9 +362,9 @@ static void jz4740_mmc_set_irq_enabled(struct jz4740_mmc_host *host, host->irq_mask &= ~irq; else host->irq_mask |= irq; - spin_unlock_irqrestore(&host->lock, flags); writew(host->irq_mask, host->base + JZ_REG_MMC_IMASK); + spin_unlock_irqrestore(&host->lock, flags); } static void jz4740_mmc_clock_enable(struct jz4740_mmc_host *host,