From patchwork Tue Jun 11 12:32:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 166449 Delivered-To: patches@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp2300627ilk; Tue, 11 Jun 2019 05:32:39 -0700 (PDT) X-Received: by 2002:a2e:2411:: with SMTP id k17mr10934236ljk.136.1560256359166; Tue, 11 Jun 2019 05:32:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560256359; cv=none; d=google.com; s=arc-20160816; b=bwYGpQr6iDpJpgKDaVLdcB+8qlhO46UHzarAH5nO7XxNuKczAdgcZ5Puoe1K2AVmDA nf/CkoZSnHbJ7mfUN32qqDKivpJ0zRZ5/S3lny6vjsMotFuyIJ6RgKDHgKzIB70akX0r ZOdKDr9xedW90/PKvC1WWhisV0bXtfjoSuphAkgGqtCRliicmE3nwrdXG59DwgKW2jHo AWvh93gdG5DJlDx7WoAsBjoukYlJU1p0GSyDNagE5e8PkVR9Wh+a3PLc/K40KVTebpGE 0G/XjmlbnM1lTIN2lmx5JNg0ndVXQRXajDWoDEKGbwdJZZyaJ9MGDlwE9WptqFQ5kaRQ oc+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature; bh=HU9V86GjpX1Lj12E8HWKI4k2gg4I+vpQIUImDCvzWsk=; b=xZZIu6nLtMR+MNHwA4n2Irhu3N0E6jw6LeTQVwnnt6Jwl7LIGqm/7pVhDp+iXLFLMn qhgVY3uxsjJ5ZzDaVkaTYJSUcD+F2zlwnko2HpT4I6hh4EIZTT//keTzDTDKepVc5Pap ji6Li9y9cCZNmkr2aw4M+fdcPwiPpPmrvxj4vp548PPT5VwlYioPbLW2qtLHpUzN4PqP 7ycyPDzLRmB68DEIo/cpAiyz++yZIesn9t8kMCzvKP0uSI4+joP5XXwtPC/7PfymF7lC +xDKT/7iZnDrCTzLYF3G97aq7/e5K6+RVE5yexMkf0Z9xg1qHM+6ea65ChnT4j4AfDy6 CP2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Yg8wAqxt; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id n1sor3488347lfg.31.2019.06.11.05.32.38 for (Google Transport Security); Tue, 11 Jun 2019 05:32:39 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Yg8wAqxt; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=HU9V86GjpX1Lj12E8HWKI4k2gg4I+vpQIUImDCvzWsk=; b=Yg8wAqxtQ164zzGBJZ+PSgz4OXKHa+BMpdSLeROa+LthHzMbkjsycGsXdulp1vuBt8 wFcx8V53bpgpwEdomtgsYfi9jG6nCbdKwNPdiipsd59bPELpBhN5Cy6P9pvBuK9QT931 wDKtuzLKIPtSOkC98IQtTSI1/IFFeFq48SB6L/f17m8wYzTTPc6Lhx1e1bYnjV5LviTM dPEZbj0uSf1XRAgY+vERPKPWe4nU/BY4V7cwDpQsIjrdTinPdUg4f3TdmT+CPIBENWLf F6wxj5Uk1QciZygwjIt1FPTVduN/tRKsmvmZ1mjOXEZv8Uf8d//P5iZwwnjGEWMpYt4V ezIA== 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=HU9V86GjpX1Lj12E8HWKI4k2gg4I+vpQIUImDCvzWsk=; b=fwKkhTNx4314ZREhj0Z7O+Q5W/c/tj9PSDItBCo7mtjHCdtioaIWaDLg6QUDjjaqbZ rIuknc74QjXdIp9V8WgVBkfXeK260d/295pfC9VLZVttKDhzNUtQOqbWynQsKEufraQj 7NfVGGRmylAzLmtqyiKBFBC2dqaDw3jP1HagP4LHKc6Vyx51C8HxD4gdfjQBZUmab0aa qRhFKFVEczTrbO5z6i+SMMmpAudYpPv4TpxMw1ZL9eNzRJO7pqTdqkAHLsNb7bTwN5qI 81XOxGDi1H25emtfxgzkVfPohLF7VB/2IzvBmLWIL5wFNwfj/aDLlcEEaf8Y9DEf5RK7 bNZg== X-Gm-Message-State: APjAAAUVsik+4kupOrH5Ds2KTePiadeAF/gYFmY0YChIYdcohFfIpSKd ICOC9isFGyhTazNrOaQbF+nKwiN6 X-Google-Smtp-Source: APXvYqyr2XAwpPPGK8DQ5jtLb+Bh0lIdk3lLxo3JrCyUxs9sNBmrrWH/obZnkRHF9jPP1YigO5UxhA== X-Received: by 2002:ac2:4312:: with SMTP id l18mr32475375lfh.139.1560256358658; Tue, 11 Jun 2019 05:32:38 -0700 (PDT) Return-Path: Received: from uffe-XPS-13-9360.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id m4sm2570653ljc.56.2019.06.11.05.32.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Jun 2019 05:32:37 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson , Douglas Anderson Cc: Adrian Hunter , Brian Norris , Shawn Lin , Guenter Roeck , Heiko Stuebner , Kalle Valo , linux-wireless@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH] mmc: core: Prevent processing SDIO IRQs when the card is suspended Date: Tue, 11 Jun 2019 14:32:21 +0200 Message-Id: <20190611123221.11580-1-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 Processing of SDIO IRQs must obviously be prevented while the card is system suspended, otherwise we may end up trying to communicate with an uninitialized SDIO card. Reports throughout the years shows that this is not only a theoretical problem, but a real issue. So, let's finally fix this problem, by keeping track of the state for the card and bail out before processing the SDIO IRQ, in case the card is suspended. Cc: stable@vger.kernel.org Reported-by: Douglas Anderson Signed-off-by: Ulf Hansson --- This has only been compile tested so far, any help for real test on HW is greatly appreciated. Note that, this is only the initial part of what is needed to make power management of SDIO card more robust, but let's start somewhere and continue to improve things. The next step I am looking at right now, is to make sure the SDIO IRQ is turned off during system suspend, unless it's supported as a system wakeup (and enabled to be used). --- drivers/mmc/core/sdio.c | 7 +++++++ drivers/mmc/core/sdio_irq.c | 4 ++++ 2 files changed, 11 insertions(+) -- 2.17.1 diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c index d1aa1c7577bb..9951295d3220 100644 --- a/drivers/mmc/core/sdio.c +++ b/drivers/mmc/core/sdio.c @@ -937,6 +937,10 @@ static int mmc_sdio_pre_suspend(struct mmc_host *host) */ static int mmc_sdio_suspend(struct mmc_host *host) { + /* Prevent processing of SDIO IRQs in suspended state. */ + mmc_card_set_suspended(host->card); + cancel_delayed_work_sync(&host->sdio_irq_work); + mmc_claim_host(host); if (mmc_card_keep_power(host) && mmc_card_wake_sdio_irq(host)) @@ -985,6 +989,9 @@ static int mmc_sdio_resume(struct mmc_host *host) err = sdio_enable_4bit_bus(host->card); } + /* Allow SDIO IRQs to be processed again. */ + mmc_card_clr_suspended(host->card); + if (!err && host->sdio_irqs) { if (!(host->caps2 & MMC_CAP2_SDIO_IRQ_NOTHREAD)) wake_up_process(host->sdio_irq_thread); diff --git a/drivers/mmc/core/sdio_irq.c b/drivers/mmc/core/sdio_irq.c index 931e6226c0b3..9f54a259a1b3 100644 --- a/drivers/mmc/core/sdio_irq.c +++ b/drivers/mmc/core/sdio_irq.c @@ -34,6 +34,10 @@ static int process_sdio_pending_irqs(struct mmc_host *host) unsigned char pending; struct sdio_func *func; + /* Don't process SDIO IRQs if the card is suspended. */ + if (mmc_card_suspended(card)) + return 0; + /* * Optimization, if there is only 1 function interrupt registered * and we know an IRQ was signaled then call irq handler directly.