public inbox for linux-mmc@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mmc: core: Fix deadlock when the CONFIG_MMC_UNSAFE_RESUME is not defined
@ 2011-11-22 11:30 Sujit Reddy Thumma
  2011-11-22 15:43 ` Ulf Hansson
  0 siblings, 1 reply; 3+ messages in thread
From: Sujit Reddy Thumma @ 2011-11-22 11:30 UTC (permalink / raw)
  To: linux-mmc, ulf.hansson; +Cc: Sujit Reddy Thumma, cjb

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.

Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
---
 drivers/mmc/core/core.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 271efea..8adbadf 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -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;
 		}
-- 
Sent by a consultant of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.


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

* Re: [PATCH] mmc: core: Fix deadlock when the CONFIG_MMC_UNSAFE_RESUME is not defined
  2011-11-22 11:30 [PATCH] mmc: core: Fix deadlock when the CONFIG_MMC_UNSAFE_RESUME is not defined Sujit Reddy Thumma
@ 2011-11-22 15:43 ` Ulf Hansson
  2011-11-23  3:13   ` Sujit Reddy Thumma
  0 siblings, 1 reply; 3+ messages in thread
From: Ulf Hansson @ 2011-11-22 15:43 UTC (permalink / raw)
  To: Sujit Reddy Thumma; +Cc: linux-mmc@vger.kernel.org, cjb@laptop.org

Sujit Reddy Thumma wrote:
> 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.
> 
> Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
> ---
>  drivers/mmc/core/core.c |    4 +++-
>  1 files changed, 3 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
> index 271efea..8adbadf 100644
> --- a/drivers/mmc/core/core.c
> +++ b/drivers/mmc/core/core.c
> @@ -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)"

>  				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.

> -			mmc_do_release_host(host);
>  		} else {
>  			err = -EBUSY;
>  		}

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

Br
Ulf Hansson


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

* Re: [PATCH] mmc: core: Fix deadlock when the CONFIG_MMC_UNSAFE_RESUME is not defined
  2011-11-22 15:43 ` Ulf Hansson
@ 2011-11-23  3:13   ` Sujit Reddy Thumma
  0 siblings, 0 replies; 3+ messages in thread
From: Sujit Reddy Thumma @ 2011-11-23  3:13 UTC (permalink / raw)
  To: Ulf Hansson; +Cc: linux-mmc@vger.kernel.org, cjb@laptop.org

On 11/22/2011 9:13 PM, Ulf Hansson wrote:
> Sujit Reddy Thumma wrote:
>> 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.
>>
>> Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
>> ---
>> drivers/mmc/core/core.c | 4 +++-
>> 1 files changed, 3 insertions(+), 1 deletions(-)
>>
>> diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
>> index 271efea..8adbadf 100644
>> --- a/drivers/mmc/core/core.c
>> +++ b/drivers/mmc/core/core.c
>> @@ -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.

>
>> 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

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

end of thread, other threads:[~2011-11-23  3:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-22 11:30 [PATCH] mmc: core: Fix deadlock when the CONFIG_MMC_UNSAFE_RESUME is not defined Sujit Reddy Thumma
2011-11-22 15:43 ` Ulf Hansson
2011-11-23  3:13   ` Sujit Reddy Thumma

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