From patchwork Fri Apr 3 18:13:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 6159521 Return-Path: X-Original-To: patchwork-linux-rockchip@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 05CF5BF4A7 for ; Fri, 3 Apr 2015 18:14:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1FE6D202F0 for ; Fri, 3 Apr 2015 18:14:13 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3F576203C3 for ; Fri, 3 Apr 2015 18:14:12 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ye66d-0004wP-LS; Fri, 03 Apr 2015 18:14:11 +0000 Received: from mail-ig0-x22a.google.com ([2607:f8b0:4001:c05::22a]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ye66X-0004iX-34 for linux-rockchip@lists.infradead.org; Fri, 03 Apr 2015 18:14:06 +0000 Received: by igcau2 with SMTP id au2so68757715igc.1 for ; Fri, 03 Apr 2015 11:13:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=crtqmLuj1prcygpKbkSbB+OCsUTppDsRBqNKMMMS0xQ=; b=mWLMORVLkjZNyX+vIhDti/rIQ5zKeotGOg2dBvrKcNI7I8Hy4BdhOzoj5aUeN3kjH1 QAHtvbJt6APMY+FlxpDsv6ggJLOCBIKkChhjsAZDSwatoxGoNlgN06EF8tQydYFHbahH RAaCOmyTwTRWzMjWmosYneLtdmyoFAHovPPvg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=crtqmLuj1prcygpKbkSbB+OCsUTppDsRBqNKMMMS0xQ=; b=WkZ9wkapAF34ilXYqIMIE96SQhl2/ty5XPrVqaGCOt2lRorvgugUUfo004O5AzH3Dl KTKQB7yxLzBpJEN1UeuwSDH0i0I9hfKnh2YubBG7Nd43ZLzohe5MS3L9vwZg/RZ9iSd4 NIB3Z3Imr0nQ9xrPoBr0pnK/mIku3kdd5llEO2vIReEln7HAbat4LIM8VbIqmG2BVtTm VG4UzqFw2wgD3vNLTwZZ9wcTIzOSSCuu7ByplIaMpV2/o3FVKPgIyzEFPGARNRHQ3e5N c2y8L46lUcO/vTPK+rRV0C7WvKN8PtfwKD5HbkVmDghsMVm/rmBLiANggtF5yeK6B70s G17A== X-Gm-Message-State: ALoCoQld9Q7a9QEQgUOzvjUwaBSWoG5SidpmXZ4c+Rcwll/Qxnm1ZkkDDVKvamdi/81n9AimSmgD X-Received: by 10.42.198.143 with SMTP id eo15mr5568033icb.8.1428084823101; Fri, 03 Apr 2015 11:13:43 -0700 (PDT) Received: from tictac.mtv.corp.google.com ([172.22.65.76]) by mx.google.com with ESMTPSA id 37sm2321629ioj.0.2015.04.03.11.13.42 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 03 Apr 2015 11:13:42 -0700 (PDT) From: Doug Anderson To: Jaehoon Chung , Seungwon Jeon , Ulf Hansson Subject: [PATCH 3/3] mmc: dw_mmc: Add locking around cmd11 timer Date: Fri, 3 Apr 2015 11:13:07 -0700 Message-Id: <1428084787-8710-3-git-send-email-dianders@chromium.org> X-Mailer: git-send-email 2.2.0.rc0.207.ga3a616c In-Reply-To: <1428084787-8710-1-git-send-email-dianders@chromium.org> References: <1428084787-8710-1-git-send-email-dianders@chromium.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150403_111405_305314_9D1B91CC X-CRM114-Status: GOOD ( 13.28 ) X-Spam-Score: -0.8 (/) Cc: Addy Ke , Heiko Stuebner , Andrew Bresticker , linux-mmc@vger.kernel.org, Doug Anderson , linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, Alim Akhtar , Sonny Rao , javier.martinez@collabora.co.uk, Alexandru Stan X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP It is possible for the cmd11 interrupt to fire and delete the cmd11_timer before the cmd11_timer was actually setup. Let's fix this race by adding a few spinlocks. Note that the race wasn't seen in practice without adding some printk statements, but it still seems wise to fix. Fixes: 5c935165da79 ("mmc: dw_mmc: Add a timeout for sending CMD11") Signed-off-by: Doug Anderson --- drivers/mmc/host/dw_mmc.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c index 357ef04..105a602 100644 --- a/drivers/mmc/host/dw_mmc.c +++ b/drivers/mmc/host/dw_mmc.c @@ -1022,14 +1022,23 @@ static void __dw_mci_start_request(struct dw_mci *host, dw_mci_start_command(host, cmd, cmdflags); if (cmd->opcode == SD_SWITCH_VOLTAGE) { + unsigned long irqflags; + /* * Databook says to fail after 2ms w/ no response, but evidence * shows that sometimes the cmd11 interrupt takes over 130ms. * We'll set to 500ms, plus an extra jiffy just in case jiffies * is just about to roll over. + * + * We do this whole thing under spinlock and only if the + * command hasn't already completed (indicating the the irq + * already ran so we don't want the timeout). */ - mod_timer(&host->cmd11_timer, - jiffies + msecs_to_jiffies(500) + 1); + spin_lock_irqsave(&host->irq_lock, irqflags); + if (!test_bit(EVENT_CMD_COMPLETE, &host->pending_events)) + mod_timer(&host->cmd11_timer, + jiffies + msecs_to_jiffies(500) + 1); + spin_unlock_irqrestore(&host->irq_lock, irqflags); } if (mrq->stop) @@ -2170,11 +2179,20 @@ static irqreturn_t dw_mci_interrupt(int irq, void *dev_id) /* Check volt switch first, since it can look like an error */ if ((host->state == STATE_SENDING_CMD11) && (pending & SDMMC_INT_VOLT_SWITCH)) { - del_timer(&host->cmd11_timer); + unsigned long irqflags; mci_writel(host, RINTSTS, SDMMC_INT_VOLT_SWITCH); pending &= ~SDMMC_INT_VOLT_SWITCH; + + /* + * Hold the lock; we know cmd11_timer can't be kicked + * off after the lock is released, so safe to delete. + */ + spin_lock_irqsave(&host->irq_lock, irqflags); dw_mci_cmd_interrupt(host, pending); + spin_unlock_irqrestore(&host->irq_lock, irqflags); + + del_timer(&host->cmd11_timer); } if (pending & DW_MCI_CMD_ERROR_FLAGS) {