From patchwork Thu May 8 23:20:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Fenkart X-Patchwork-Id: 4139451 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 6375EBFF02 for ; Thu, 8 May 2014 23:21:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 895A0202DD for ; Thu, 8 May 2014 23:21:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B104C202E5 for ; Thu, 8 May 2014 23:21:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755980AbaEHXV1 (ORCPT ); Thu, 8 May 2014 19:21:27 -0400 Received: from mail-ee0-f46.google.com ([74.125.83.46]:34105 "EHLO mail-ee0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755887AbaEHXV0 (ORCPT ); Thu, 8 May 2014 19:21:26 -0400 Received: by mail-ee0-f46.google.com with SMTP id t10so2095986eei.5 for ; Thu, 08 May 2014 16:21:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wmPJO3ChdY2tQ944IHksy93e8E7DOFAFtX5dcFoaAT0=; b=veNnKD0b/Fhd8wRbem95Q//oKf5rmmCAXMjmxWtgXCheW/qnJnC1x9CxX/5evQ/u16 SlRbbG9AxJyWt8G0K0Yulkuja/ih3XQLJpHM5W90lyvXmLPtCaN2EizQMp1+8NxYRiYQ mscMhQiklN0H03zNkcjpntT+mA0snm0wYOn5J3UBe3p7X/cjtSrrA3leRKtXXdslEER5 YHSyKtd30S1hlqODMDTG5q6Pk/DiiVqyXD1+FUArC2+AZyU2V4ph9PIgA4T/6B4PVZhU KpXrEqR355PvkDgO7dMZZ/+5zcFiU8k2S3yQc2Zulgb7QT6DX54JntREKzlSAJPvEKlJ F6HA== X-Received: by 10.14.215.9 with SMTP id d9mr8881730eep.64.1399591285538; Thu, 08 May 2014 16:21:25 -0700 (PDT) Received: from localhost (13-242.62-81.cust.bluewin.ch. [81.62.242.13]) by mx.google.com with ESMTPSA id m42sm7319257eex.21.2014.05.08.16.21.24 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 08 May 2014 16:21:25 -0700 (PDT) From: Andreas Fenkart To: Tony Lindgren Cc: Chris Ball , Grant Likely , Felipe Balbi , Balaji T K , Andreas Mueller , zonque@gmail.com, galak@codeaurora.org, linux-doc@vger.kernel.org, linux-mmc@vger.kernel.org, linux-omap@vger.kernel.org, Andreas Fenkart Subject: [PATCH v11 5/7] mmc: omap_hsmmc: abort runtime suspend if pending sdio irq detected Date: Fri, 9 May 2014 01:20:32 +0200 Message-Id: <1399591234-13089-5-git-send-email-afenkart@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1399591234-13089-1-git-send-email-afenkart@gmail.com> References: <1399591018-12930-1-git-send-email-afenkart@gmail.com> <1399591234-13089-1-git-send-email-afenkart@gmail.com> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham 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 On multicores, an sdio irq handler could be running in parallel to runtime suspend. In the worst case it could be waiting for the spinlock held by the runtime suspend. When runtime suspend is complete and the functional clock (fclk) turned off, the irq handler will continue and cause a SIGBUS on the first register access. Signed-off-by: Andreas Fenkart Acked-by: Balaji T K diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c index 14857d7..47a5982 100644 --- a/drivers/mmc/host/omap_hsmmc.c +++ b/drivers/mmc/host/omap_hsmmc.c @@ -134,6 +134,9 @@ static void apply_clk_hack(struct device *dev) #define SRD (1 << 26) #define SOFTRESET (1 << 1) +/* PSTATE */ +#define DLEV_DAT(x) (1 << (20 + (x))) + /* Interrupt masks for IE and ISE register */ #define CC_EN (1 << 0) #define TC_EN (1 << 1) @@ -2455,6 +2458,7 @@ static int omap_hsmmc_runtime_suspend(struct device *dev) { struct omap_hsmmc_host *host; unsigned long flags; + int ret = 0; host = platform_get_drvdata(to_platform_device(dev)); omap_hsmmc_context_save(host); @@ -2466,14 +2470,29 @@ static int omap_hsmmc_runtime_suspend(struct device *dev) /* disable sdio irq handling to prevent race */ OMAP_HSMMC_WRITE(host->base, ISE, 0); OMAP_HSMMC_WRITE(host->base, IE, 0); - OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR); + + if (!(OMAP_HSMMC_READ(host->base, PSTATE) & DLEV_DAT(1))) { + /* + * dat1 line low, pending sdio irq + * race condition: possible irq handler running on + * multi-core, abort + */ + dev_dbg(dev, "pending sdio irq, abort suspend\n"); + OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR); + OMAP_HSMMC_WRITE(host->base, ISE, CIRQ_EN); + OMAP_HSMMC_WRITE(host->base, IE, CIRQ_EN); + pm_runtime_mark_last_busy(dev); + ret = -EBUSY; + goto abort; + } WARN_ON(host->flags & HSMMC_WAKE_IRQ_ENABLED); enable_irq(host->wake_irq); host->flags |= HSMMC_WAKE_IRQ_ENABLED; } +abort: spin_unlock_irqrestore(&host->irq_lock, flags); - return 0; + return ret; } static int omap_hsmmc_runtime_resume(struct device *dev)