* [PATCH] mmc: sdhci: don't read cd-gpio while holding spinlock
@ 2014-03-20 18:47 Andrew Bresticker
2014-03-21 6:45 ` Adrian Hunter
2014-03-24 1:43 ` [PATCH V2] " Andrew Bresticker
0 siblings, 2 replies; 7+ messages in thread
From: Andrew Bresticker @ 2014-03-20 18:47 UTC (permalink / raw)
To: Chris Ball; +Cc: Ulf Hansson, linux-mmc, linux-kernel, Andrew Bresticker
mmc_request() reads the cd-gpio via mmc_gpio_get_cd(), which can sleep,
while holding host->lock. This may result in the following BUG:
BUG: spinlock wrong CPU on CPU#2, kworker/u8:16/4296
lock: 0xea6b9c80, .magic: dead4ead, .owner: kworker/u8:16/4296, .owner_cpu: 0
CPU: 2 PID: 4296 Comm: kworker/u8:16 Tainted: G C 3.10.18 #137
Workqueue: kmmcd mmc_rescan
[<8020cf8c>] (unwind_backtrace+0x0/0x118) from [<8020a0c8>] (show_stack+0x20/0x24)
[<8020a0c8>] (show_stack+0x20/0x24) from [<8075e5b8>] (dump_stack+0x20/0x28)
[<8075e5b8>] (dump_stack+0x20/0x28) from [<804184a8>] (spin_dump+0x80/0x94)
[<804184a8>] (spin_dump+0x80/0x94) from [<804184e8>] (spin_bug+0x2c/0x30)
[<804184e8>] (spin_bug+0x2c/0x30) from [<80418790>] (do_raw_spin_unlock+0x94/0xd4)
[<80418790>] (do_raw_spin_unlock+0x94/0xd4) from [<80761a44>] (_raw_spin_unlock_irqrestore+0x1c/0x24)
[<80761a44>] (_raw_spin_unlock_irqrestore+0x1c/0x24) from [<805ff66c>] (sdhci_request+0x1c8/0x1d0)
[<805ff66c>] (sdhci_request+0x1c8/0x1d0) from [<805ebb5c>] (mmc_start_request+0xec/0xf4)
[<805ebb5c>] (mmc_start_request+0xec/0xf4) from [<805ebcbc>] (mmc_wait_for_req+0x80/0xf4)
...
Read the cd-gpio before acquiring the spinlock instead.
Signed-off-by: Andrew Bresticker <abrestic@chromium.org>
---
drivers/mmc/host/sdhci.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index 04a5e25..f2ef978 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -1340,6 +1340,7 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
u32 tuning_opcode;
host = mmc_priv(mmc);
+ present = mmc_gpio_get_cd(host->mmc);
sdhci_runtime_pm_get(host);
@@ -1371,7 +1372,6 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
* zero: cd-gpio is used, and card is removed
* one: cd-gpio is used, and card is present
*/
- present = mmc_gpio_get_cd(host->mmc);
if (present < 0) {
/* If polling, assume that the card is always present. */
if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION)
--
1.9.0.279.gdc9e3eb
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] mmc: sdhci: don't read cd-gpio while holding spinlock
2014-03-20 18:47 [PATCH] mmc: sdhci: don't read cd-gpio while holding spinlock Andrew Bresticker
@ 2014-03-21 6:45 ` Adrian Hunter
2014-03-22 1:38 ` Andrew Bresticker
2014-03-24 1:43 ` [PATCH V2] " Andrew Bresticker
1 sibling, 1 reply; 7+ messages in thread
From: Adrian Hunter @ 2014-03-21 6:45 UTC (permalink / raw)
To: Andrew Bresticker; +Cc: Chris Ball, Ulf Hansson, linux-mmc, linux-kernel
On 20.03.2014 20:47, Andrew Bresticker wrote:
> mmc_request() reads the cd-gpio via mmc_gpio_get_cd(), which can sleep,
> while holding host->lock. This may result in the following BUG:
>
> BUG: spinlock wrong CPU on CPU#2, kworker/u8:16/4296
> lock: 0xea6b9c80, .magic: dead4ead, .owner: kworker/u8:16/4296, .owner_cpu: 0
> CPU: 2 PID: 4296 Comm: kworker/u8:16 Tainted: G C 3.10.18 #137
> Workqueue: kmmcd mmc_rescan
> [<8020cf8c>] (unwind_backtrace+0x0/0x118) from [<8020a0c8>] (show_stack+0x20/0x24)
> [<8020a0c8>] (show_stack+0x20/0x24) from [<8075e5b8>] (dump_stack+0x20/0x28)
> [<8075e5b8>] (dump_stack+0x20/0x28) from [<804184a8>] (spin_dump+0x80/0x94)
> [<804184a8>] (spin_dump+0x80/0x94) from [<804184e8>] (spin_bug+0x2c/0x30)
> [<804184e8>] (spin_bug+0x2c/0x30) from [<80418790>] (do_raw_spin_unlock+0x94/0xd4)
> [<80418790>] (do_raw_spin_unlock+0x94/0xd4) from [<80761a44>] (_raw_spin_unlock_irqrestore+0x1c/0x24)
> [<80761a44>] (_raw_spin_unlock_irqrestore+0x1c/0x24) from [<805ff66c>] (sdhci_request+0x1c8/0x1d0)
> [<805ff66c>] (sdhci_request+0x1c8/0x1d0) from [<805ebb5c>] (mmc_start_request+0xec/0xf4)
> [<805ebb5c>] (mmc_start_request+0xec/0xf4) from [<805ebcbc>] (mmc_wait_for_req+0x80/0xf4)
> ...
>
> Read the cd-gpio before acquiring the spinlock instead.
The same problem appears to be in sdhci_card_event() which calls
sdhci_do_get_cd() under spinlock which then calls mmc_gpio_get_cd()
Will you fix that too?
>
> Signed-off-by: Andrew Bresticker <abrestic@chromium.org>
> ---
> drivers/mmc/host/sdhci.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
> index 04a5e25..f2ef978 100644
> --- a/drivers/mmc/host/sdhci.c
> +++ b/drivers/mmc/host/sdhci.c
> @@ -1340,6 +1340,7 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
> u32 tuning_opcode;
>
> host = mmc_priv(mmc);
> + present = mmc_gpio_get_cd(host->mmc);
>
> sdhci_runtime_pm_get(host);
>
> @@ -1371,7 +1372,6 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
> * zero: cd-gpio is used, and card is removed
> * one: cd-gpio is used, and card is present
> */
> - present = mmc_gpio_get_cd(host->mmc);
> if (present < 0) {
> /* If polling, assume that the card is always present. */
> if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION)
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mmc: sdhci: don't read cd-gpio while holding spinlock
2014-03-21 6:45 ` Adrian Hunter
@ 2014-03-22 1:38 ` Andrew Bresticker
0 siblings, 0 replies; 7+ messages in thread
From: Andrew Bresticker @ 2014-03-22 1:38 UTC (permalink / raw)
To: Adrian Hunter
Cc: Chris Ball, Ulf Hansson, linux-mmc@vger.kernel.org,
linux-kernel@vger.kernel.org
On Thu, Mar 20, 2014 at 11:45 PM, Adrian Hunter <adrian.hunter@intel.com> wrote:
> On 20.03.2014 20:47, Andrew Bresticker wrote:
>> mmc_request() reads the cd-gpio via mmc_gpio_get_cd(), which can sleep,
>> while holding host->lock. This may result in the following BUG:
>>
>> BUG: spinlock wrong CPU on CPU#2, kworker/u8:16/4296
>> lock: 0xea6b9c80, .magic: dead4ead, .owner: kworker/u8:16/4296, .owner_cpu: 0
>> CPU: 2 PID: 4296 Comm: kworker/u8:16 Tainted: G C 3.10.18 #137
>> Workqueue: kmmcd mmc_rescan
>> [<8020cf8c>] (unwind_backtrace+0x0/0x118) from [<8020a0c8>] (show_stack+0x20/0x24)
>> [<8020a0c8>] (show_stack+0x20/0x24) from [<8075e5b8>] (dump_stack+0x20/0x28)
>> [<8075e5b8>] (dump_stack+0x20/0x28) from [<804184a8>] (spin_dump+0x80/0x94)
>> [<804184a8>] (spin_dump+0x80/0x94) from [<804184e8>] (spin_bug+0x2c/0x30)
>> [<804184e8>] (spin_bug+0x2c/0x30) from [<80418790>] (do_raw_spin_unlock+0x94/0xd4)
>> [<80418790>] (do_raw_spin_unlock+0x94/0xd4) from [<80761a44>] (_raw_spin_unlock_irqrestore+0x1c/0x24)
>> [<80761a44>] (_raw_spin_unlock_irqrestore+0x1c/0x24) from [<805ff66c>] (sdhci_request+0x1c8/0x1d0)
>> [<805ff66c>] (sdhci_request+0x1c8/0x1d0) from [<805ebb5c>] (mmc_start_request+0xec/0xf4)
>> [<805ebb5c>] (mmc_start_request+0xec/0xf4) from [<805ebcbc>] (mmc_wait_for_req+0x80/0xf4)
>> ...
>>
>> Read the cd-gpio before acquiring the spinlock instead.
>
> The same problem appears to be in sdhci_card_event() which calls
> sdhci_do_get_cd() under spinlock which then calls mmc_gpio_get_cd()
>
> Will you fix that too?
Yes, will do.
Thanks,
Andrew
>
>
>>
>> Signed-off-by: Andrew Bresticker <abrestic@chromium.org>
>> ---
>> drivers/mmc/host/sdhci.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
>> index 04a5e25..f2ef978 100644
>> --- a/drivers/mmc/host/sdhci.c
>> +++ b/drivers/mmc/host/sdhci.c
>> @@ -1340,6 +1340,7 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
>> u32 tuning_opcode;
>>
>> host = mmc_priv(mmc);
>> + present = mmc_gpio_get_cd(host->mmc);
>>
>> sdhci_runtime_pm_get(host);
>>
>> @@ -1371,7 +1372,6 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
>> * zero: cd-gpio is used, and card is removed
>> * one: cd-gpio is used, and card is present
>> */
>> - present = mmc_gpio_get_cd(host->mmc);
>> if (present < 0) {
>> /* If polling, assume that the card is always present. */
>> if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION)
>>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH V2] mmc: sdhci: don't read cd-gpio while holding spinlock
2014-03-20 18:47 [PATCH] mmc: sdhci: don't read cd-gpio while holding spinlock Andrew Bresticker
2014-03-21 6:45 ` Adrian Hunter
@ 2014-03-24 1:43 ` Andrew Bresticker
2014-03-24 6:19 ` Adrian Hunter
1 sibling, 1 reply; 7+ messages in thread
From: Andrew Bresticker @ 2014-03-24 1:43 UTC (permalink / raw)
To: Chris Ball
Cc: Ulf Hansson, linux-mmc, linux-kernel, Adrian Hunter,
Andrew Bresticker
sdhci_request() and sdhci_card_event() read the cd-gpio via
mmc_gpio_get_cd(), which can sleep, while holding host->lock.
This may result in the following BUG:
BUG: spinlock wrong CPU on CPU#2, kworker/u8:16/4296
lock: 0xea6b9c80, .magic: dead4ead, .owner: kworker/u8:16/4296, .owner_cpu: 0
CPU: 2 PID: 4296 Comm: kworker/u8:16 Tainted: G C 3.10.18 #137
Workqueue: kmmcd mmc_rescan
[<8020cf8c>] (unwind_backtrace+0x0/0x118) from [<8020a0c8>] (show_stack+0x20/0x24)
[<8020a0c8>] (show_stack+0x20/0x24) from [<8075e5b8>] (dump_stack+0x20/0x28)
[<8075e5b8>] (dump_stack+0x20/0x28) from [<804184a8>] (spin_dump+0x80/0x94)
[<804184a8>] (spin_dump+0x80/0x94) from [<804184e8>] (spin_bug+0x2c/0x30)
[<804184e8>] (spin_bug+0x2c/0x30) from [<80418790>] (do_raw_spin_unlock+0x94/0xd4)
[<80418790>] (do_raw_spin_unlock+0x94/0xd4) from [<80761a44>] (_raw_spin_unlock_irqrestore+0x1c/0x24)
[<80761a44>] (_raw_spin_unlock_irqrestore+0x1c/0x24) from [<805ff66c>] (sdhci_request+0x1c8/0x1d0)
[<805ff66c>] (sdhci_request+0x1c8/0x1d0) from [<805ebb5c>] (mmc_start_request+0xec/0xf4)
[<805ebb5c>] (mmc_start_request+0xec/0xf4) from [<805ebcbc>] (mmc_wait_for_req+0x80/0xf4)
...
Read the cd-gpio before acquiring the spinlock instead.
Signed-off-by: Andrew Bresticker <abrestic@chromium.org>
---
drivers/mmc/host/sdhci.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index 04a5e25..328b250 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -1340,6 +1340,7 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
u32 tuning_opcode;
host = mmc_priv(mmc);
+ present = mmc_gpio_get_cd(host->mmc);
sdhci_runtime_pm_get(host);
@@ -1371,7 +1372,6 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
* zero: cd-gpio is used, and card is removed
* one: cd-gpio is used, and card is present
*/
- present = mmc_gpio_get_cd(host->mmc);
if (present < 0) {
/* If polling, assume that the card is always present. */
if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION)
@@ -2082,15 +2082,16 @@ static void sdhci_card_event(struct mmc_host *mmc)
{
struct sdhci_host *host = mmc_priv(mmc);
unsigned long flags;
+ int present;
/* First check if client has provided their own card event */
if (host->ops->card_event)
host->ops->card_event(host);
+ present = sdhci_get_cd(mmc);
spin_lock_irqsave(&host->lock, flags);
- /* Check host->mrq first in case we are runtime suspended */
- if (host->mrq && !sdhci_do_get_cd(host)) {
+ if (host->mrq && !present) {
pr_err("%s: Card removed during transfer!\n",
mmc_hostname(host->mmc));
pr_err("%s: Resetting controller.\n",
--
1.9.1.423.g4596e3a
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH V2] mmc: sdhci: don't read cd-gpio while holding spinlock
2014-03-24 1:43 ` [PATCH V2] " Andrew Bresticker
@ 2014-03-24 6:19 ` Adrian Hunter
2014-03-24 16:18 ` Andrew Bresticker
0 siblings, 1 reply; 7+ messages in thread
From: Adrian Hunter @ 2014-03-24 6:19 UTC (permalink / raw)
To: Andrew Bresticker; +Cc: Chris Ball, Ulf Hansson, linux-mmc, linux-kernel
On 24.03.2014 03:43, Andrew Bresticker wrote:
> sdhci_request() and sdhci_card_event() read the cd-gpio via
> mmc_gpio_get_cd(), which can sleep, while holding host->lock.
> This may result in the following BUG:
>
> BUG: spinlock wrong CPU on CPU#2, kworker/u8:16/4296
> lock: 0xea6b9c80, .magic: dead4ead, .owner: kworker/u8:16/4296, .owner_cpu: 0
> CPU: 2 PID: 4296 Comm: kworker/u8:16 Tainted: G C 3.10.18 #137
> Workqueue: kmmcd mmc_rescan
> [<8020cf8c>] (unwind_backtrace+0x0/0x118) from [<8020a0c8>] (show_stack+0x20/0x24)
> [<8020a0c8>] (show_stack+0x20/0x24) from [<8075e5b8>] (dump_stack+0x20/0x28)
> [<8075e5b8>] (dump_stack+0x20/0x28) from [<804184a8>] (spin_dump+0x80/0x94)
> [<804184a8>] (spin_dump+0x80/0x94) from [<804184e8>] (spin_bug+0x2c/0x30)
> [<804184e8>] (spin_bug+0x2c/0x30) from [<80418790>] (do_raw_spin_unlock+0x94/0xd4)
> [<80418790>] (do_raw_spin_unlock+0x94/0xd4) from [<80761a44>] (_raw_spin_unlock_irqrestore+0x1c/0x24)
> [<80761a44>] (_raw_spin_unlock_irqrestore+0x1c/0x24) from [<805ff66c>] (sdhci_request+0x1c8/0x1d0)
> [<805ff66c>] (sdhci_request+0x1c8/0x1d0) from [<805ebb5c>] (mmc_start_request+0xec/0xf4)
> [<805ebb5c>] (mmc_start_request+0xec/0xf4) from [<805ebcbc>] (mmc_wait_for_req+0x80/0xf4)
> ...
>
> Read the cd-gpio before acquiring the spinlock instead.
>
> Signed-off-by: Andrew Bresticker <abrestic@chromium.org>
> ---
> drivers/mmc/host/sdhci.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
> index 04a5e25..328b250 100644
> --- a/drivers/mmc/host/sdhci.c
> +++ b/drivers/mmc/host/sdhci.c
> @@ -1340,6 +1340,7 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
> u32 tuning_opcode;
>
> host = mmc_priv(mmc);
> + present = mmc_gpio_get_cd(host->mmc);
>
> sdhci_runtime_pm_get(host);
>
> @@ -1371,7 +1372,6 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
> * zero: cd-gpio is used, and card is removed
> * one: cd-gpio is used, and card is present
> */
> - present = mmc_gpio_get_cd(host->mmc);
> if (present < 0) {
> /* If polling, assume that the card is always present. */
> if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION)
> @@ -2082,15 +2082,16 @@ static void sdhci_card_event(struct mmc_host *mmc)
> {
> struct sdhci_host *host = mmc_priv(mmc);
> unsigned long flags;
> + int present;
>
> /* First check if client has provided their own card event */
> if (host->ops->card_event)
> host->ops->card_event(host);
>
> + present = sdhci_get_cd(mmc);
Shouldn't that be sdhci_do_get_cd(mmc) ?
> spin_lock_irqsave(&host->lock, flags);
>
> - /* Check host->mrq first in case we are runtime suspended */
> - if (host->mrq && !sdhci_do_get_cd(host)) {
> + if (host->mrq && !present) {
> pr_err("%s: Card removed during transfer!\n",
> mmc_hostname(host->mmc));
> pr_err("%s: Resetting controller.\n",
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH V2] mmc: sdhci: don't read cd-gpio while holding spinlock
2014-03-24 6:19 ` Adrian Hunter
@ 2014-03-24 16:18 ` Andrew Bresticker
2014-03-25 8:25 ` Adrian Hunter
0 siblings, 1 reply; 7+ messages in thread
From: Andrew Bresticker @ 2014-03-24 16:18 UTC (permalink / raw)
To: Adrian Hunter
Cc: Chris Ball, Ulf Hansson, linux-mmc@vger.kernel.org,
linux-kernel@vger.kernel.org
On Sun, Mar 23, 2014 at 11:19 PM, Adrian Hunter <adrian.hunter@intel.com> wrote:
> On 24.03.2014 03:43, Andrew Bresticker wrote:
>> sdhci_request() and sdhci_card_event() read the cd-gpio via
>> mmc_gpio_get_cd(), which can sleep, while holding host->lock.
>> This may result in the following BUG:
>>
>> BUG: spinlock wrong CPU on CPU#2, kworker/u8:16/4296
>> lock: 0xea6b9c80, .magic: dead4ead, .owner: kworker/u8:16/4296, .owner_cpu: 0
>> CPU: 2 PID: 4296 Comm: kworker/u8:16 Tainted: G C 3.10.18 #137
>> Workqueue: kmmcd mmc_rescan
>> [<8020cf8c>] (unwind_backtrace+0x0/0x118) from [<8020a0c8>] (show_stack+0x20/0x24)
>> [<8020a0c8>] (show_stack+0x20/0x24) from [<8075e5b8>] (dump_stack+0x20/0x28)
>> [<8075e5b8>] (dump_stack+0x20/0x28) from [<804184a8>] (spin_dump+0x80/0x94)
>> [<804184a8>] (spin_dump+0x80/0x94) from [<804184e8>] (spin_bug+0x2c/0x30)
>> [<804184e8>] (spin_bug+0x2c/0x30) from [<80418790>] (do_raw_spin_unlock+0x94/0xd4)
>> [<80418790>] (do_raw_spin_unlock+0x94/0xd4) from [<80761a44>] (_raw_spin_unlock_irqrestore+0x1c/0x24)
>> [<80761a44>] (_raw_spin_unlock_irqrestore+0x1c/0x24) from [<805ff66c>] (sdhci_request+0x1c8/0x1d0)
>> [<805ff66c>] (sdhci_request+0x1c8/0x1d0) from [<805ebb5c>] (mmc_start_request+0xec/0xf4)
>> [<805ebb5c>] (mmc_start_request+0xec/0xf4) from [<805ebcbc>] (mmc_wait_for_req+0x80/0xf4)
>> ...
>>
>> Read the cd-gpio before acquiring the spinlock instead.
>>
>> Signed-off-by: Andrew Bresticker <abrestic@chromium.org>
>> ---
>> drivers/mmc/host/sdhci.c | 7 ++++---
>> 1 file changed, 4 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
>> index 04a5e25..328b250 100644
>> --- a/drivers/mmc/host/sdhci.c
>> +++ b/drivers/mmc/host/sdhci.c
>> @@ -1340,6 +1340,7 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
>> u32 tuning_opcode;
>>
>> host = mmc_priv(mmc);
>> + present = mmc_gpio_get_cd(host->mmc);
>>
>> sdhci_runtime_pm_get(host);
>>
>> @@ -1371,7 +1372,6 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
>> * zero: cd-gpio is used, and card is removed
>> * one: cd-gpio is used, and card is present
>> */
>> - present = mmc_gpio_get_cd(host->mmc);
>> if (present < 0) {
>> /* If polling, assume that the card is always present. */
>> if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION)
>> @@ -2082,15 +2082,16 @@ static void sdhci_card_event(struct mmc_host *mmc)
>> {
>> struct sdhci_host *host = mmc_priv(mmc);
>> unsigned long flags;
>> + int present;
>>
>> /* First check if client has provided their own card event */
>> if (host->ops->card_event)
>> host->ops->card_event(host);
>>
>> + present = sdhci_get_cd(mmc);
>
> Shouldn't that be sdhci_do_get_cd(mmc) ?
No I do mean shdic_get_cd(). We might be runtime suspended so we need
sdhci_get_cd() to increment the device usage count and do a runtime
resume if necessary.
>
>> spin_lock_irqsave(&host->lock, flags);
>>
>> - /* Check host->mrq first in case we are runtime suspended */
>> - if (host->mrq && !sdhci_do_get_cd(host)) {
>> + if (host->mrq && !present) {
>> pr_err("%s: Card removed during transfer!\n",
>> mmc_hostname(host->mmc));
>> pr_err("%s: Resetting controller.\n",
>>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH V2] mmc: sdhci: don't read cd-gpio while holding spinlock
2014-03-24 16:18 ` Andrew Bresticker
@ 2014-03-25 8:25 ` Adrian Hunter
0 siblings, 0 replies; 7+ messages in thread
From: Adrian Hunter @ 2014-03-25 8:25 UTC (permalink / raw)
To: Chris Ball
Cc: Andrew Bresticker, Ulf Hansson, linux-mmc@vger.kernel.org,
linux-kernel@vger.kernel.org
On 24.03.2014 18:18, Andrew Bresticker wrote:
> On Sun, Mar 23, 2014 at 11:19 PM, Adrian Hunter <adrian.hunter@intel.com> wrote:
>> On 24.03.2014 03:43, Andrew Bresticker wrote:
>>> sdhci_request() and sdhci_card_event() read the cd-gpio via
>>> mmc_gpio_get_cd(), which can sleep, while holding host->lock.
>>> This may result in the following BUG:
>>>
>>> BUG: spinlock wrong CPU on CPU#2, kworker/u8:16/4296
>>> lock: 0xea6b9c80, .magic: dead4ead, .owner: kworker/u8:16/4296, .owner_cpu: 0
>>> CPU: 2 PID: 4296 Comm: kworker/u8:16 Tainted: G C 3.10.18 #137
>>> Workqueue: kmmcd mmc_rescan
>>> [<8020cf8c>] (unwind_backtrace+0x0/0x118) from [<8020a0c8>] (show_stack+0x20/0x24)
>>> [<8020a0c8>] (show_stack+0x20/0x24) from [<8075e5b8>] (dump_stack+0x20/0x28)
>>> [<8075e5b8>] (dump_stack+0x20/0x28) from [<804184a8>] (spin_dump+0x80/0x94)
>>> [<804184a8>] (spin_dump+0x80/0x94) from [<804184e8>] (spin_bug+0x2c/0x30)
>>> [<804184e8>] (spin_bug+0x2c/0x30) from [<80418790>] (do_raw_spin_unlock+0x94/0xd4)
>>> [<80418790>] (do_raw_spin_unlock+0x94/0xd4) from [<80761a44>] (_raw_spin_unlock_irqrestore+0x1c/0x24)
>>> [<80761a44>] (_raw_spin_unlock_irqrestore+0x1c/0x24) from [<805ff66c>] (sdhci_request+0x1c8/0x1d0)
>>> [<805ff66c>] (sdhci_request+0x1c8/0x1d0) from [<805ebb5c>] (mmc_start_request+0xec/0xf4)
>>> [<805ebb5c>] (mmc_start_request+0xec/0xf4) from [<805ebcbc>] (mmc_wait_for_req+0x80/0xf4)
>>> ...
>>>
>>> Read the cd-gpio before acquiring the spinlock instead.
>>>
>>> Signed-off-by: Andrew Bresticker <abrestic@chromium.org>
>>> ---
>>> drivers/mmc/host/sdhci.c | 7 ++++---
>>> 1 file changed, 4 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
>>> index 04a5e25..328b250 100644
>>> --- a/drivers/mmc/host/sdhci.c
>>> +++ b/drivers/mmc/host/sdhci.c
>>> @@ -1340,6 +1340,7 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
>>> u32 tuning_opcode;
>>>
>>> host = mmc_priv(mmc);
>>> + present = mmc_gpio_get_cd(host->mmc);
>>>
>>> sdhci_runtime_pm_get(host);
>>>
>>> @@ -1371,7 +1372,6 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
>>> * zero: cd-gpio is used, and card is removed
>>> * one: cd-gpio is used, and card is present
>>> */
>>> - present = mmc_gpio_get_cd(host->mmc);
>>> if (present < 0) {
>>> /* If polling, assume that the card is always present. */
>>> if (host->quirks & SDHCI_QUIRK_BROKEN_CARD_DETECTION)
>>> @@ -2082,15 +2082,16 @@ static void sdhci_card_event(struct mmc_host *mmc)
>>> {
>>> struct sdhci_host *host = mmc_priv(mmc);
>>> unsigned long flags;
>>> + int present;
>>>
>>> /* First check if client has provided their own card event */
>>> if (host->ops->card_event)
>>> host->ops->card_event(host);
>>>
>>> + present = sdhci_get_cd(mmc);
>>
>> Shouldn't that be sdhci_do_get_cd(mmc) ?
>
> No I do mean shdic_get_cd(). We might be runtime suspended so we need
> sdhci_get_cd() to increment the device usage count and do a runtime
> resume if necessary.
Very true.
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
>
>>
>>> spin_lock_irqsave(&host->lock, flags);
>>>
>>> - /* Check host->mrq first in case we are runtime suspended */
>>> - if (host->mrq && !sdhci_do_get_cd(host)) {
>>> + if (host->mrq && !present) {
>>> pr_err("%s: Card removed during transfer!\n",
>>> mmc_hostname(host->mmc));
>>> pr_err("%s: Resetting controller.\n",
>>>
>>
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2014-03-25 8:25 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-20 18:47 [PATCH] mmc: sdhci: don't read cd-gpio while holding spinlock Andrew Bresticker
2014-03-21 6:45 ` Adrian Hunter
2014-03-22 1:38 ` Andrew Bresticker
2014-03-24 1:43 ` [PATCH V2] " Andrew Bresticker
2014-03-24 6:19 ` Adrian Hunter
2014-03-24 16:18 ` Andrew Bresticker
2014-03-25 8:25 ` Adrian Hunter
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).