mmc: sdhci: Fix SDIO IRQ thread deadlock
authorAdrian Hunter <adrian.hunter@intel.com>
Mon, 27 May 2019 11:45:55 +0000 (14:45 +0300)
committerUlf Hansson <ulf.hansson@linaro.org>
Tue, 28 May 2019 20:02:05 +0000 (22:02 +0200)
Since commit c07a48c26519 ("mmc: sdhci: Remove finish_tasklet"), the IRQ
thread might be used to complete requests, but the IRQ thread is also used
to process SDIO card interrupts. This can cause a deadlock when the SDIO
processing tries to access the card since that would also require the IRQ
thread. Change SDHCI to use sdio_signal_irq() to schedule a work item
instead. That also requires implementing the ->ack_sdio_irq() mmc host op.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Fixes: c07a48c26519 ("mmc: sdhci: Remove finish_tasklet")
Reported-by: Brian Masney <masneyb@onstation.org>
Tested-by: Brian Masney <masneyb@onstation.org>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
drivers/mmc/host/sdhci.c

index 97158344b862874963d2e800690badfd738e4a86..0cd5f2ce98df845cfb2a0b0cfaeacf02fd989b71 100644 (file)
@@ -2137,6 +2137,17 @@ void sdhci_enable_sdio_irq(struct mmc_host *mmc, int enable)
 }
 EXPORT_SYMBOL_GPL(sdhci_enable_sdio_irq);
 
+static void sdhci_ack_sdio_irq(struct mmc_host *mmc)
+{
+       struct sdhci_host *host = mmc_priv(mmc);
+       unsigned long flags;
+
+       spin_lock_irqsave(&host->lock, flags);
+       if (host->flags & SDHCI_SDIO_IRQ_ENABLED)
+               sdhci_enable_sdio_irq_nolock(host, true);
+       spin_unlock_irqrestore(&host->lock, flags);
+}
+
 int sdhci_start_signal_voltage_switch(struct mmc_host *mmc,
                                      struct mmc_ios *ios)
 {
@@ -2585,6 +2596,7 @@ static const struct mmc_host_ops sdhci_ops = {
        .get_ro         = sdhci_get_ro,
        .hw_reset       = sdhci_hw_reset,
        .enable_sdio_irq = sdhci_enable_sdio_irq,
+       .ack_sdio_irq    = sdhci_ack_sdio_irq,
        .start_signal_voltage_switch    = sdhci_start_signal_voltage_switch,
        .prepare_hs400_tuning           = sdhci_prepare_hs400_tuning,
        .execute_tuning                 = sdhci_execute_tuning,
@@ -3087,8 +3099,7 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
                if ((intmask & SDHCI_INT_CARD_INT) &&
                    (host->ier & SDHCI_INT_CARD_INT)) {
                        sdhci_enable_sdio_irq_nolock(host, false);
-                       host->thread_isr |= SDHCI_INT_CARD_INT;
-                       result = IRQ_WAKE_THREAD;
+                       sdio_signal_irq(host->mmc);
                }
 
                intmask &= ~(SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE |
@@ -3160,15 +3171,6 @@ static irqreturn_t sdhci_thread_irq(int irq, void *dev_id)
                mmc_detect_change(mmc, msecs_to_jiffies(200));
        }
 
-       if (isr & SDHCI_INT_CARD_INT) {
-               sdio_run_irqs(host->mmc);
-
-               spin_lock_irqsave(&host->lock, flags);
-               if (host->flags & SDHCI_SDIO_IRQ_ENABLED)
-                       sdhci_enable_sdio_irq_nolock(host, true);
-               spin_unlock_irqrestore(&host->lock, flags);
-       }
-
        return IRQ_HANDLED;
 }