Skip to contentSkip to conversation

mmc: core: Fix deadlock when the CONFIG_MMC_UNSAFE_RESUME is not defined

PATCH Superseded Sujit Reddy Thumma 2 participants 3 messages Nov 22, 2011 – Nov 23, 2011 MMC, SD and SDIO

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmc: core: Fix deadlock when the CONFIG_MMC_UNSAFE_RESUME is not defined

mmc_suspend_host() tries to claim host during suspend and release it only when the bus suspend operation is compeleted. If CONFIG_MMC_UNSAFE_RESUME is defined and the host is flagged as removable, mmc_suspend_host() tries to remove the card. In this process, the file system sync can get blocked trying to acquire host which is already claimed by mmc_suspend_host() causing deadlock.

Fix this deadlock by releasing host before ->remove() is called.

---
 drivers/mmc/core/core.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/mmc/core/core.c +3 -1
index 271efea..8adbadf 100644
@@ -2338,6 +2338,7 @@ int mmc_suspend_host(struct mmc_host *host)
 				 * We simply "remove" the card in this case.
 				 * It will be redetected on resume.
 				 */
+				mmc_do_release_host(host);
 				if (host->bus_ops->remove)
 					host->bus_ops->remove(host);
 				mmc_claim_host(host);
@@ -2346,8 +2347,9 @@ int mmc_suspend_host(struct mmc_host *host)
 				mmc_release_host(host);
 				host->pm_flags = 0;
 				err = 0;
+			} else {
+				mmc_do_release_host(host);
 			}
-			mmc_do_release_host(host);
 		} else {
 			err = -EBUSY;
 		}
Signature · 2 lines
Sent by a consultant of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#1 lore raw
Quoted 20 lines · Sujit Reddy Thumma

mmc_suspend_host() tries to claim host during suspend and release it only when the bus suspend operation is compeleted. If CONFIG_MMC_UNSAFE_RESUME is defined and the host is flagged as removable, mmc_suspend_host() tries to remove the card. In this process, the file system sync can get blocked trying to acquire host which is already claimed by mmc_suspend_host() causing deadlock.

Fix this deadlock by releasing host before ->remove() is called.

---
 drivers/mmc/core/core.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/mmc/core/core.c +0 -0
index 271efea..8adbadf 100644

drivers/mmc/core/core.c int mmc_suspend_host(struct mmc_host *host) · line 2341

Quoted 4 lines
drivers/mmc/core/core.c +1 -0
@@ -2338,6 +2338,7 @@ int mmc_suspend_host(struct mmc_host *host)
 				 * We simply "remove" the card in this case.
 				 * It will be redetected on resume.
 				 */
+				mmc_do_release_host(host);

Instead of having an "else" below move mmc_do_release_host to be done before "if (err == -ENOSYS || !host->bus_ops->resume)"

drivers/mmc/core/core.c int mmc_suspend_host(struct mmc_host *host) · line 2352

Quoted 10 lines
drivers/mmc/core/core.c +2 -0
 				if (host->bus_ops->remove)
 					host->bus_ops->remove(host);
 				mmc_claim_host(host);
@@ -2346,8 +2347,9 @@ int mmc_suspend_host(struct mmc_host *host)
 				mmc_release_host(host);
 				host->pm_flags = 0;
 				err = 0;
+			} else {
+				mmc_do_release_host(host);
 			}

Remove else statement entirely.

drivers/mmc/core/core.c int mmc_suspend_host(struct mmc_host *host) · line 2355

Quoted 4 lines
drivers/mmc/core/core.c +0 -1
-			mmc_do_release_host(host);
 		} else {
 			err = -EBUSY;
 		}

Otherwise it looks good to me! Thanks, for fixing this issue!

Br
Ulf Hansson

#2 lore raw
Quoted 16 lines · Ulf Hansson
Quoted 15 lines · Sujit Reddy Thumma

mmc_suspend_host() tries to claim host during suspend and release it only when the bus suspend operation is compeleted. If CONFIG_MMC_UNSAFE_RESUME is defined and the host is flagged as removable, mmc_suspend_host() tries to remove the card. In this process, the file system sync can get blocked trying to acquire host which is already claimed by mmc_suspend_host() causing deadlock.

Fix this deadlock by releasing host before ->remove() is called.

---
drivers/mmc/core/core.c | 4 +++-

1 files changed, 3 insertions(+), 1 deletions(-)
Quoted 12 lines

drivers/mmc/core/core.c int mmc_suspend_host(struct mmc_host *host) · line 2341

Quoted 9 lines
drivers/mmc/core/core.c +1 -0
index 271efea..8adbadf 100644
@@ -2338,6 +2338,7 @@ int mmc_suspend_host(struct mmc_host *host)
 * We simply "remove" the card in this case.
 * It will be redetected on resume.
 */
+ mmc_do_release_host(host);

Instead of having an "else" below move mmc_do_release_host to be done before "if (err == -ENOSYS || !host->bus_ops->resume)"

Sure.

Quoted 13 lines

drivers/mmc/core/core.c int mmc_suspend_host(struct mmc_host *host) · line 2352

Quoted 11 lines
drivers/mmc/core/core.c +2 -0
 if (host->bus_ops->remove)
 host->bus_ops->remove(host);
 mmc_claim_host(host);
@@ -2346,8 +2347,9 @@ int mmc_suspend_host(struct mmc_host *host)
 mmc_release_host(host);
 host->pm_flags = 0;
 err = 0;
+ } else {
+ mmc_do_release_host(host);
 }

Remove else statement entirely.

Okay. Will do it.

Thanks,
Sujit