linux-mmc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mmc: sdhci-bcm-kona: Fix locking in sdhci_bcm_kona_sd_card_emulate()
@ 2014-03-06  4:25 Markus Mayer
  2014-03-19  7:22 ` Christian Daudt
  0 siblings, 1 reply; 2+ messages in thread
From: Markus Mayer @ 2014-03-06  4:25 UTC (permalink / raw)
  To: Chris Ball, Matt Porter, Christian Daudt
  Cc: Linux MMC List, Linux Kernel Mailing List

Since sdhci_bcm_kona_sd_card_emulate() can be called from interrupt
context, we must use a spinlock instead of a mutex. This change
essentially restores the way things worked before the change to
mutexes in http://www.spinics.net/lists/linux-mmc/msg20276.html.

Without this change, we see "scheduling while atomic" errors.

Signed-off-by: Markus Mayer <markus.mayer@linaro.org>
---
 drivers/mmc/host/sdhci-bcm-kona.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/mmc/host/sdhci-bcm-kona.c b/drivers/mmc/host/sdhci-bcm-kona.c
index 7a190fe..f1b0a62 100644
--- a/drivers/mmc/host/sdhci-bcm-kona.c
+++ b/drivers/mmc/host/sdhci-bcm-kona.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013 Broadcom Corporation
+ * Copyright (C) 2013-2014 Broadcom Corporation
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -53,7 +53,7 @@
 #define KONA_MMC_AUTOSUSPEND_DELAY		(50)
 
 struct sdhci_bcm_kona_dev {
-	struct mutex	write_lock; /* protect back to back writes */
+	spinlock_t write_lock; /* protect back to back writes */
 };
 
 
@@ -135,7 +135,7 @@ static int sdhci_bcm_kona_sd_card_emulate(struct sdhci_host *host, int insert)
 	 * insert-removal.
 	 * We keep 20uS
 	 */
-	mutex_lock(&kona_dev->write_lock);
+	spin_lock_bh(&kona_dev->write_lock);
 	udelay(20);
 	val = sdhci_readl(host, KONA_SDHOST_CORESTAT);
 
@@ -153,7 +153,7 @@ static int sdhci_bcm_kona_sd_card_emulate(struct sdhci_host *host, int insert)
 		val &= ~KONA_SDHOST_CD_SW;
 		sdhci_writel(host, val, KONA_SDHOST_CORESTAT);
 	}
-	mutex_unlock(&kona_dev->write_lock);
+	spin_unlock_bh(&kona_dev->write_lock);
 
 	return 0;
 }
@@ -247,7 +247,7 @@ static int sdhci_bcm_kona_probe(struct platform_device *pdev)
 	pltfm_priv = sdhci_priv(host);
 
 	kona_dev = sdhci_pltfm_priv(pltfm_priv);
-	mutex_init(&kona_dev->write_lock);
+	spin_lock_init(&kona_dev->write_lock);
 
 	mmc_of_parse(host->mmc);
 
-- 
1.9.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] mmc: sdhci-bcm-kona: Fix locking in sdhci_bcm_kona_sd_card_emulate()
  2014-03-06  4:25 [PATCH] mmc: sdhci-bcm-kona: Fix locking in sdhci_bcm_kona_sd_card_emulate() Markus Mayer
@ 2014-03-19  7:22 ` Christian Daudt
  0 siblings, 0 replies; 2+ messages in thread
From: Christian Daudt @ 2014-03-19  7:22 UTC (permalink / raw)
  To: Markus Mayer
  Cc: Chris Ball, Matt Porter, Linux MMC List,
	Linux Kernel Mailing List

On Wed, Mar 5, 2014 at 8:25 PM, Markus Mayer <markus.mayer@linaro.org> wrote:
> Since sdhci_bcm_kona_sd_card_emulate() can be called from interrupt
> context, we must use a spinlock instead of a mutex. This change
> essentially restores the way things worked before the change to
> mutexes in http://www.spinics.net/lists/linux-mmc/msg20276.html.
>
> Without this change, we see "scheduling while atomic" errors.
>
> Signed-off-by: Markus Mayer <markus.mayer@linaro.org>
> ---

So digging back in memory (since I no longer have the
broadcom-internal email threads on this topic), I think I recall what
the problem is. card_event is being called directly from
mmc_gpio_cd_irqt, which is atomic context. My plan for this was to
delay the card_event callback into the mmc_rescan worker, as that
would have 2 nice results: remove the callback from atomic context
which it doesn't need to be in, and put it in line with the debounced
rescan (which I think it should be). I made mention of that option in
this thread (https://lkml.org/lkml/2013/8/19/539) but seems I never
followed up with code...
 Something along the lines of the (untested) code below might do the trick:

diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 098374b..d4ffba8 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -2421,6 +2421,11 @@ void mmc_rescan(struct work_struct *work)
  container_of(work, struct mmc_host, detect.work);
  int i;

+ if (host->trigger_card_event && host->ops->card_event) {
+ host->ops->card_event(host);
+ host->trigger_card_event = 0;
+ }
+
  if (host->rescan_disable)
  return;

diff --git a/drivers/mmc/core/slot-gpio.c b/drivers/mmc/core/slot-gpio.c
index 46596b71..fc648ae 100644
--- a/drivers/mmc/core/slot-gpio.c
+++ b/drivers/mmc/core/slot-gpio.c
@@ -29,9 +29,7 @@ static irqreturn_t mmc_gpio_cd_irqt(int irq, void *dev_id)
  /* Schedule a card detection after a debounce timeout */
  struct mmc_host *host = dev_id;

- if (host->ops->card_event)
- host->ops->card_event(host);
-
+ host->trigger_card_event = 1;
  mmc_detect_change(host, msecs_to_jiffies(200));

  return IRQ_HANDLED;
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
index 99f5709..0b6bddf 100644
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -322,6 +322,8 @@ struct mmc_host {
  int rescan_disable; /* disable card detection */
  int rescan_entered; /* used with nonremovable devices */

+ int trigger_card_event; /* card_event necessary */
+
  struct mmc_card *card; /* device attached to this host */

  wait_queue_head_t wq;


Of course there are (a few) more users of card_event callback than
bcm_kona that need to be confirmed ok such a change
 Thanks,
   csd

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-03-19  7:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-06  4:25 [PATCH] mmc: sdhci-bcm-kona: Fix locking in sdhci_bcm_kona_sd_card_emulate() Markus Mayer
2014-03-19  7:22 ` Christian Daudt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).