Re: [linux-pm] [Bug 10030] Suspend doesn't work when SD card is inserted

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Rafael J. Wysocki <rjw@...>
Cc: pm list <linux-pm@...>, Zdenek Kabelac <zdenek.kabelac@...>, Kernel development list <linux-kernel@...>, Pierre Ossman <drzeus-mmc@...>
Date: Sunday, February 24, 2008 - 12:26 am

On Sat, 23 Feb 2008, Alan Stern wrote:


In fact this turns out to be exactly the problem with the MMC
subsystem.  It uses a dedicated workqueue (kmmcd) to handle state
changes, and mmc_suspend_host() does a flush_workqueue().  If the
workqueue contains an entry to register or unregister a device, this is
guaranteed to deadlock -- and that's exactly what happens when Zdenek 
inserts or removes a card during the disk-drive spindown time of a 
system sleep.

It looks like the best solution is for mmc_suspend_host() not to flush
the workqueue; instead the workqueue should prevent itself from
running during a suspend.  Right now the easiest way to accomplish this
is for the workqueue routines (mmc_detect() and siblings) to acquire
the mmc_host's device semaphore.  If in the future the MMC subsystem
adds dynamic PM support then a more complicated arrangement will be 
needed.

So the patch below, in combination with the previous patch, might just 
fix the whole problem.

Alan Stern



Index: usb-2.6/drivers/mmc/core/core.c
===================================================================
--- usb-2.6.orig/drivers/mmc/core/core.c
+++ usb-2.6/drivers/mmc/core/core.c
@@ -731,8 +731,6 @@ void mmc_stop_host(struct mmc_host *host
  */
 int mmc_suspend_host(struct mmc_host *host, pm_message_t state)
 {
-	mmc_flush_scheduled_work();
-
 	mmc_bus_get(host);
 	if (host->bus_ops && !host->bus_dead) {
 		if (host->bus_ops->suspend)
Index: usb-2.6/drivers/mmc/core/mmc.c
===================================================================
--- usb-2.6.orig/drivers/mmc/core/mmc.c
+++ usb-2.6/drivers/mmc/core/mmc.c
@@ -441,6 +441,7 @@ static void mmc_detect(struct mmc_host *
 	BUG_ON(!host);
 	BUG_ON(!host->card);
 
+	down(&mmc_classdev(host)->sem);
 	mmc_claim_host(host);
 
 	/*
@@ -449,6 +450,7 @@ static void mmc_detect(struct mmc_host *
 	err = mmc_send_status(host->card, NULL);
 
 	mmc_release_host(host);
+	up(&mmc_classdev(host)->sem);
 
 	if (err) {
 		mmc_remove(host);
Index: usb-2.6/drivers/mmc/core/sd.c
===================================================================
--- usb-2.6.orig/drivers/mmc/core/sd.c
+++ usb-2.6/drivers/mmc/core/sd.c
@@ -500,6 +500,7 @@ static void mmc_sd_detect(struct mmc_hos
 	BUG_ON(!host);
 	BUG_ON(!host->card);
 
+	down(&mmc_classdev(host)->sem);
 	mmc_claim_host(host);
 
 	/*
@@ -508,6 +509,7 @@ static void mmc_sd_detect(struct mmc_hos
 	err = mmc_send_status(host->card, NULL);
 
 	mmc_release_host(host);
+	up(&mmc_classdev(host)->sem);
 
 	if (err) {
 		mmc_sd_remove(host);
Index: usb-2.6/drivers/mmc/core/sdio.c
===================================================================
--- usb-2.6.orig/drivers/mmc/core/sdio.c
+++ usb-2.6/drivers/mmc/core/sdio.c
@@ -195,6 +195,7 @@ static void mmc_sdio_detect(struct mmc_h
 	BUG_ON(!host);
 	BUG_ON(!host->card);
 
+	down(&mmc_classdev(host)->sem);
 	mmc_claim_host(host);
 
 	/*
@@ -203,6 +204,7 @@ static void mmc_sdio_detect(struct mmc_h
 	err = mmc_select_card(host->card);
 
 	mmc_release_host(host);
+	up(&mmc_classdev(host)->sem);
 
 	if (err) {
 		mmc_sdio_remove(host);

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: [Bug 10030] Suspend doesn't work when SD card is inserted, Rafael J. Wysocki, (Wed Feb 20, 6:15 pm)
Re: [Bug 10030] Suspend doesn't work when SD card is inserted, Rafael J. Wysocki, (Wed Feb 20, 8:02 pm)
Re: [Bug 10030] Suspend doesn't work when SD card is inserted, Rafael J. Wysocki, (Thu Feb 21, 12:38 pm)
Re: [Bug 10030] Suspend doesn't work when SD card is inserted, Rafael J. Wysocki, (Thu Feb 21, 6:47 pm)
Re: [Bug 10030] Suspend doesn't work when SD card is inserted, Rafael J. Wysocki, (Fri Feb 22, 9:30 pm)
Re: [Bug 10030] Suspend doesn't work when SD card is inserted, Rafael J. Wysocki, (Sat Feb 23, 4:16 pm)
Re: [Bug 10030] Suspend doesn't work when SD card is inserted, Rafael J. Wysocki, (Sat Feb 23, 8:19 pm)
Re: [linux-pm] [Bug 10030] Suspend doesn't work when SD card..., Alan Stern, (Sun Feb 24, 12:26 am)
Re: [linux-pm] [Bug 10030] Suspend doesn't work when SD card..., Rafael J. Wysocki, (Sun Feb 24, 10:00 am)
Re: [Bug 10030] Suspend doesn't work when SD card is inserted, Rafael J. Wysocki, (Mon Feb 25, 7:40 am)
Re: [Bug 10030] Suspend doesn't work when SD card is inserted, Rafael J. Wysocki, (Sun Feb 24, 6:21 pm)
Re: [Bug 10030] Suspend doesn't work when SD card is inserted, Rafael J. Wysocki, (Mon Feb 25, 7:41 am)
Re: [Bug 10030] Suspend doesn't work when SD card is inserted, Rafael J. Wysocki, (Sun Feb 24, 9:51 am)
Re: [Bug 10030] Suspend doesn't work when SD card is inserted, Rafael J. Wysocki, (Sun Feb 24, 4:09 pm)
Re: [Bug 10030] Suspend doesn't work when SD card is inserted, Rafael J. Wysocki, (Sun Feb 24, 9:33 am)
Re: [Bug 10030] Suspend doesn't work when SD card is inserted, Rafael J. Wysocki, (Sun Feb 24, 4:25 pm)
Re: [Bug 10030] Suspend doesn't work when SD card is inserted, Rafael J. Wysocki, (Sun Feb 24, 4:56 pm)
Re: [Bug 10030] Suspend doesn't work when SD card is inserted, Rafael J. Wysocki, (Sun Feb 24, 6:18 pm)
Re: [Bug 10030] Suspend doesn't work when SD card is inserted, Rafael J. Wysocki, (Wed Feb 20, 6:41 pm)
Re: [Bug 10030] Suspend doesn't work when SD card is inserted, Rafael J. Wysocki, (Wed Feb 20, 4:58 pm)