public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 001/001] mmcblk: Fix deadlock when cleanup is called from resume
@ 2008-07-08 20:10 San Mehat
  2008-07-09  4:58 ` Pierre Ossman
  0 siblings, 1 reply; 2+ messages in thread
From: San Mehat @ 2008-07-08 20:10 UTC (permalink / raw)
  To: drzeus-mmc; +Cc: linux-kernel


  When CONFIG_UNSAFE_RESUME is used, we may need to cleanup
  (and call kthread_stop) when threads are still frozen. To fix this
  deadlock, push cleanup off to a work-queue.

  Signed-off-by: San Mehat <san@android.com>

---
 drivers/mmc/card/queue.c |   36 ++++++++++++++++++++++++++++++++++--
 1 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c
index 972738f..908e3cf 100644
--- a/drivers/mmc/card/queue.c
+++ b/drivers/mmc/card/queue.c
@@ -14,6 +14,7 @@
 #include <linux/freezer.h>
 #include <linux/kthread.h>
 #include <linux/scatterlist.h>
+#include <linux/workqueue.h>
 
 #include <linux/mmc/card.h>
 #include <linux/mmc/host.h>
@@ -23,6 +24,11 @@
 
 #define MMC_QUEUE_SUSPENDED	(1 << 0)
 
+static void mq_cleanup_work(struct work_struct *work);
+static DECLARE_WORK(mq_cleanup_worker, mq_cleanup_work);
+static struct mmc_queue *cleanup_mq;
+static DEFINE_SPINLOCK(mq_cleanup_lock);
+
 /*
  * Prepare a MMC request. This just filters out odd stuff.
  */
@@ -217,9 +223,36 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card, spinlock_t *lock
 
 void mmc_cleanup_queue(struct mmc_queue *mq)
 {
-	struct request_queue *q = mq->queue;
 	unsigned long flags;
 
+	BUG_ON(!mq);
+
+	/*
+	 * The actual cleanup is done from a work_queue because if you
+	 * thread_stop() while resuming, you'll deadlock.
+	 */
+	spin_lock_irqsave(&mq_cleanup_lock, flags);
+	cleanup_mq = mq;
+	schedule_work(&mq_cleanup_worker);
+	spin_unlock_irqrestore(&mq_cleanup_lock, flags);
+}
+EXPORT_SYMBOL(mmc_cleanup_queue);
+
+static void mq_cleanup_work(struct work_struct *work)
+{
+	struct mmc_queue *mq;
+	unsigned long flags;
+	struct request_queue *q;
+
+	spin_lock_irqsave(&mq_cleanup_lock, flags);
+	mq = cleanup_mq;
+	cleanup_mq = NULL;
+	spin_unlock_irqrestore(&mq_cleanup_lock, flags);
+
+	BUG_ON(!mq);
+
+	q = mq->queue;
+
 	/* Mark that we should start throwing out stragglers */
 	spin_lock_irqsave(q->queue_lock, flags);
 	q->queuedata = NULL;
@@ -246,7 +279,6 @@ void mmc_cleanup_queue(struct mmc_queue *mq)
 
 	mq->card = NULL;
 }
-EXPORT_SYMBOL(mmc_cleanup_queue);
 
 /**
  * mmc_queue_suspend - suspend a MMC request queue

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

* Re: [PATCH 001/001] mmcblk: Fix deadlock when cleanup is called from resume
  2008-07-08 20:10 [PATCH 001/001] mmcblk: Fix deadlock when cleanup is called from resume San Mehat
@ 2008-07-09  4:58 ` Pierre Ossman
  0 siblings, 0 replies; 2+ messages in thread
From: Pierre Ossman @ 2008-07-09  4:58 UTC (permalink / raw)
  To: San Mehat; +Cc: linux-kernel

On Tue, 8 Jul 2008 13:10:11 -0700
san@google.com (San Mehat) wrote:

> 
>   When CONFIG_UNSAFE_RESUME is used, we may need to cleanup
>   (and call kthread_stop) when threads are still frozen. To fix this
>   deadlock, push cleanup off to a work-queue.
> 
>   Signed-off-by: San Mehat <san@android.com>
> 

I appreciate patches, but sending me something based on 2.6.21 is
hardly helpful. This particular problem was solved over a year ago in
mainline.

Rgds
-- 
     -- Pierre Ossman

  Linux kernel, MMC maintainer        http://www.kernel.org
  rdesktop, core developer          http://www.rdesktop.org

  WARNING: This correspondence is being monitored by the
  Swedish government. Make sure your server uses encryption
  for SMTP traffic and consider using PGP for end-to-end
  encryption.

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

end of thread, other threads:[~2008-07-09  4:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-08 20:10 [PATCH 001/001] mmcblk: Fix deadlock when cleanup is called from resume San Mehat
2008-07-09  4:58 ` Pierre Ossman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox