From patchwork Tue May 1 23:47:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evan Green X-Patchwork-Id: 10374635 X-Patchwork-Delegate: agross@codeaurora.org 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 234FF6032A for ; Tue, 1 May 2018 23:47:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 11B3528C9A for ; Tue, 1 May 2018 23:47:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 069C728D60; Tue, 1 May 2018 23:47:37 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=unavailable 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 8A05C28D32 for ; Tue, 1 May 2018 23:47:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751265AbeEAXre (ORCPT ); Tue, 1 May 2018 19:47:34 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:33626 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751455AbeEAXrd (ORCPT ); Tue, 1 May 2018 19:47:33 -0400 Received: by mail-pg0-f67.google.com with SMTP id i194-v6so9274718pgd.0 for ; Tue, 01 May 2018 16:47:32 -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; bh=9k+AAxpRv51bodsx34jQ8YdfDtQk2H14epF1GMrzWbI=; b=FU40PX6OazN7//7Mr7asFJFasdqMS7d1pohjGSO6cs8dXlP2BeUZ57u8kERDEvnViq PjZ4N98S5xS/pPXBAzaWl4ScuVMNRdt//F6KNpaltqxop8bSw0DHzHJYDJ35KRlXUfHt c0cYA4uomXTrtbjTaXb726s+/qIq34CaqZU90= 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; bh=9k+AAxpRv51bodsx34jQ8YdfDtQk2H14epF1GMrzWbI=; b=MKb4ywwkGkzfcTcoox+JWfch5JfFda2mZ7MQg8HtyfF43ocq6WRfG5g3fwKwem9q+S k/CkyZB+Oj7ENn/SwXC5KgzvgOxdu09D8Mfpwbi4liDkwK8Lt/kVAM6vp5PKbJYxgz+5 sktpaHvwBczE+0DROq9yjEp4QTiYMMMgxItpSNOGwken5QDvUKCrqWxzNzojS9RKLNd/ lE9/dQTHfAvsq76DXnVqTrb67TnGWNGy958WKxgPP2U9IHtdSFP8oIDdow0VI+4edOcp W8soIxaIyhrX798QqSNB588KkPK3tqKawqFsNQgBL1bXTdmKGf5kFy82ZM+JA3SbWZbg AEcg== X-Gm-Message-State: ALQs6tBAJvtIXysXEB4RPajGz5SUcYTTpn9DXcWpYonwzKhseZk8T8FE 6oScNjQGIISkIhSCKSqJxp0a3w== X-Google-Smtp-Source: AB8JxZr2727h6toiio+0+8tTEfarVhBHJWk/Du29x/Hxs77kI84r1fdDrhHqLiJFrJOzGBO7nyEPXA== X-Received: by 10.98.91.2 with SMTP id p2mr9263855pfb.96.1525218452516; Tue, 01 May 2018 16:47:32 -0700 (PDT) Received: from evgreen2.mtv.corp.google.com ([2620:0:1000:1c10:8298:e6e2:13fe:c706]) by smtp.gmail.com with ESMTPSA id x2sm24961189pfk.113.2018.05.01.16.47.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 01 May 2018 16:47:31 -0700 (PDT) From: Evan Green To: Adrian Hunter , Ulf Hansson , linux-mmc@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Evan Green Subject: [PATCH RFC] mmc: sdhci: Don't get card-detect without preemption Date: Tue, 1 May 2018 16:47:21 -0700 Message-Id: <20180501234721.187135-1-evgreen@chromium.org> X-Mailer: git-send-email 2.13.5 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For a controller with SDHCI_QUIRK_NO_CARD_NO_RESET, there are several conditions where sdhci_do_reset is called under a spinlock with interrupts disabled. The card detect is often a GPIO, which might sleep. Avoid asking for the card detect status if interrupts are disabled to prevent a warning like the following: [ 2.480199] Call trace: [ 2.480218] [] dump_backtrace+0x0/0x228 [ 2.480224] [] show_stack+0x20/0x28 [ 2.480235] [] dump_stack+0x90/0xb0 [ 2.480245] [] ___might_sleep+0x110/0x128 [ 2.480248] [] __might_sleep+0x78/0x88 [ 2.480260] [] gpiod_get_raw_value_cansleep+0x2c/0xc4 [ 2.480269] [] mmc_gpio_get_cd+0x3c/0x68 [ 2.480275] [] sdhci_get_cd+0x20/0x98 [ 2.480280] [] sdhci_do_reset+0x50/0x88 [ 2.480283] [] sdhci_tasklet_finish+0x1a8/0x270 [ 2.480292] [] tasklet_action+0x90/0xf4 [ 2.480296] [] __do_softirq+0x1c8/0x360 [ 2.480300] [] irq_exit+0x88/0xd0 --- I discovered this warning while trying to bring up SD, somewhat unsuccessfully, on a new device, and hit this error path. This change is not ideal as it only makes a best effort to adhere to the quirk, but may in some cases end up resetting the controller with no card present. Another option I considered was trying to call sdhci_do_reset within only sleepable contexts. I actually got as far as converting the tasklet to a work queue, and deferring the reset to the end of the function in sdhci_request_done. But 1) I'm not sure if that deferral was actually safe, and 2) we call sdhci_do_reset from under the lock in several other places, such as sdhci_card_event and sdhci_cqe_disable. Finally, I also considered calling the non-_maysleep gpio functions in mmc_gpio_get_cd. I assume this is not workable as someone somewhere has put a card detect off of a PMIC or GPIO expander. Any advice? --- drivers/mmc/host/sdhci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 759278dd317d..c5273acf6987 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -210,7 +210,7 @@ static void sdhci_do_reset(struct sdhci_host *host, u8 mask) if (host->quirks & SDHCI_QUIRK_NO_CARD_NO_RESET) { struct mmc_host *mmc = host->mmc; - if (!mmc->ops->get_cd(mmc)) + if (preemptible() && !mmc->ops->get_cd(mmc)) return; }