linux-arm-msm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] block: Fix possible sleep in invalid context
@ 2013-07-01 15:28 Sujit Reddy Thumma
  2013-07-01 22:17 ` Andrew Morton
  2013-07-02  3:04 ` Aaron Lu
  0 siblings, 2 replies; 6+ messages in thread
From: Sujit Reddy Thumma @ 2013-07-01 15:28 UTC (permalink / raw)
  To: Aaron Lu, Jens Axboe
  Cc: linux-pm, linux-scsi, stable, Sujit Reddy Thumma, linux-arm-msm,
	linux-kernel

When block runtime PM is enabled following warning is seen
while resuming the device.

BUG: sleeping function called from invalid context at
.../drivers/base/power/runtime.c:923
in_atomic(): 1, irqs_disabled(): 128, pid: 12, name: kworker/0:1
[<c0014448>] (unwind_backtrace+0x0/0x120) from
[<c03120e4>] (__pm_runtime_suspend+0x34/0xa0) from
[<c021c33c>] (blk_post_runtime_resume+0x4c/0x5c) from
[<c03297cc>] (scsi_runtime_resume+0x90/0xb4) from
[<c0310940>] (__rpm_callback+0x30/0x58) from
[<c0310980>] (rpm_callback+0x18/0x28) from
[<c0311ab0>] (rpm_resume+0x3dc/0x540) from
[<c03120a4>] (pm_runtime_work+0x8c/0x98) from
[<c007767c>] (process_one_work+0x238/0x3e4) from
[<c0077b90>] (worker_thread+0x1ac/0x2ac) from
[<c007cfdc>] (kthread+0x88/0x94) from
[<c000ece0>] (kernel_thread_exit+0x0/0x8)

Fix this by releasing spin_lock_irq() before calling
pm_runtime_autosuspend() in blk_post_runtime_resume().

Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
Cc: stable@vger.kernel.org
---
 block/blk-core.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/block/blk-core.c b/block/blk-core.c
index 33c33bc..2456116 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -3159,16 +3159,18 @@ EXPORT_SYMBOL(blk_pre_runtime_resume);
  */
 void blk_post_runtime_resume(struct request_queue *q, int err)
 {
-	spin_lock_irq(q->queue_lock);
 	if (!err) {
+		spin_lock_irq(q->queue_lock);
 		q->rpm_status = RPM_ACTIVE;
 		__blk_run_queue(q);
 		pm_runtime_mark_last_busy(q->dev);
+		spin_unlock_irq(q->queue_lock);
 		pm_runtime_autosuspend(q->dev);
 	} else {
+		spin_lock_irq(q->queue_lock);
 		q->rpm_status = RPM_SUSPENDED;
+		spin_unlock_irq(q->queue_lock);
 	}
-	spin_unlock_irq(q->queue_lock);
 }
 EXPORT_SYMBOL(blk_post_runtime_resume);
 #endif
-- 
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation.


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

* Re: [PATCH] block: Fix possible sleep in invalid context
  2013-07-01 15:28 [PATCH] block: Fix possible sleep in invalid context Sujit Reddy Thumma
@ 2013-07-01 22:17 ` Andrew Morton
  2013-07-01 22:24   ` James Bottomley
  2013-07-02  3:04 ` Aaron Lu
  1 sibling, 1 reply; 6+ messages in thread
From: Andrew Morton @ 2013-07-01 22:17 UTC (permalink / raw)
  To: Sujit Reddy Thumma
  Cc: Aaron Lu, Jens Axboe, linux-pm, linux-scsi, stable, linux-arm-msm,
	linux-kernel

On Mon,  1 Jul 2013 20:58:35 +0530 Sujit Reddy Thumma <sthumma@codeaurora.org> wrote:

> When block runtime PM is enabled following warning is seen
> while resuming the device.
> 
> BUG: sleeping function called from invalid context at
> .../drivers/base/power/runtime.c:923
> in_atomic(): 1, irqs_disabled(): 128, pid: 12, name: kworker/0:1
> [<c0014448>] (unwind_backtrace+0x0/0x120) from
> [<c03120e4>] (__pm_runtime_suspend+0x34/0xa0) from
> [<c021c33c>] (blk_post_runtime_resume+0x4c/0x5c) from
> [<c03297cc>] (scsi_runtime_resume+0x90/0xb4) from
> [<c0310940>] (__rpm_callback+0x30/0x58) from
> [<c0310980>] (rpm_callback+0x18/0x28) from
> [<c0311ab0>] (rpm_resume+0x3dc/0x540) from
> [<c03120a4>] (pm_runtime_work+0x8c/0x98) from
> [<c007767c>] (process_one_work+0x238/0x3e4) from
> [<c0077b90>] (worker_thread+0x1ac/0x2ac) from
> [<c007cfdc>] (kthread+0x88/0x94) from
> [<c000ece0>] (kernel_thread_exit+0x0/0x8)
> 
> Fix this by releasing spin_lock_irq() before calling
> pm_runtime_autosuspend() in blk_post_runtime_resume().
> 
> --- a/block/blk-core.c
> +++ b/block/blk-core.c
> @@ -3159,16 +3159,18 @@ EXPORT_SYMBOL(blk_pre_runtime_resume);
>   */
>  void blk_post_runtime_resume(struct request_queue *q, int err)
>  {
> -	spin_lock_irq(q->queue_lock);
>  	if (!err) {
> +		spin_lock_irq(q->queue_lock);
>  		q->rpm_status = RPM_ACTIVE;
>  		__blk_run_queue(q);
>  		pm_runtime_mark_last_busy(q->dev);
> +		spin_unlock_irq(q->queue_lock);
>  		pm_runtime_autosuspend(q->dev);
>  	} else {
> +		spin_lock_irq(q->queue_lock);
>  		q->rpm_status = RPM_SUSPENDED;
> +		spin_unlock_irq(q->queue_lock);
>  	}
> -	spin_unlock_irq(q->queue_lock);
>  }
>  EXPORT_SYMBOL(blk_post_runtime_resume);
>  #endif

I suppose we can do this cleanly enough:

--- a/block/blk-core.c~block-fix-possible-sleep-in-invalid-context-fix
+++ a/block/blk-core.c
@@ -3159,15 +3159,14 @@ EXPORT_SYMBOL(blk_pre_runtime_resume);
  */
 void blk_post_runtime_resume(struct request_queue *q, int err)
 {
+	spin_lock_irq(q->queue_lock);
 	if (!err) {
-		spin_lock_irq(q->queue_lock);
 		q->rpm_status = RPM_ACTIVE;
 		__blk_run_queue(q);
 		pm_runtime_mark_last_busy(q->dev);
 		spin_unlock_irq(q->queue_lock);
 		pm_request_autosuspend(q->dev);
 	} else {
-		spin_lock_irq(q->queue_lock);
 		q->rpm_status = RPM_SUSPENDED;
 		spin_unlock_irq(q->queue_lock);
 	}
_


I wonder if we actually need locking around that second write to
q->rpm_status.


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

* Re: [PATCH] block: Fix possible sleep in invalid context
  2013-07-01 22:17 ` Andrew Morton
@ 2013-07-01 22:24   ` James Bottomley
  2013-07-01 22:30     ` Andrew Morton
  0 siblings, 1 reply; 6+ messages in thread
From: James Bottomley @ 2013-07-01 22:24 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Sujit Reddy Thumma, Aaron Lu, Jens Axboe, linux-pm, linux-scsi,
	stable, linux-arm-msm, linux-kernel

On Mon, 2013-07-01 at 15:17 -0700, Andrew Morton wrote:
> On Mon,  1 Jul 2013 20:58:35 +0530 Sujit Reddy Thumma <sthumma@codeaurora.org> wrote:
> 
> > When block runtime PM is enabled following warning is seen
> > while resuming the device.
> > 
> > BUG: sleeping function called from invalid context at
> > .../drivers/base/power/runtime.c:923
> > in_atomic(): 1, irqs_disabled(): 128, pid: 12, name: kworker/0:1
> > [<c0014448>] (unwind_backtrace+0x0/0x120) from
> > [<c03120e4>] (__pm_runtime_suspend+0x34/0xa0) from
> > [<c021c33c>] (blk_post_runtime_resume+0x4c/0x5c) from
> > [<c03297cc>] (scsi_runtime_resume+0x90/0xb4) from
> > [<c0310940>] (__rpm_callback+0x30/0x58) from
> > [<c0310980>] (rpm_callback+0x18/0x28) from
> > [<c0311ab0>] (rpm_resume+0x3dc/0x540) from
> > [<c03120a4>] (pm_runtime_work+0x8c/0x98) from
> > [<c007767c>] (process_one_work+0x238/0x3e4) from
> > [<c0077b90>] (worker_thread+0x1ac/0x2ac) from
> > [<c007cfdc>] (kthread+0x88/0x94) from
> > [<c000ece0>] (kernel_thread_exit+0x0/0x8)
> > 
> > Fix this by releasing spin_lock_irq() before calling
> > pm_runtime_autosuspend() in blk_post_runtime_resume().
> > 
> > --- a/block/blk-core.c
> > +++ b/block/blk-core.c
> > @@ -3159,16 +3159,18 @@ EXPORT_SYMBOL(blk_pre_runtime_resume);
> >   */
> >  void blk_post_runtime_resume(struct request_queue *q, int err)
> >  {
> > -	spin_lock_irq(q->queue_lock);
> >  	if (!err) {
> > +		spin_lock_irq(q->queue_lock);
> >  		q->rpm_status = RPM_ACTIVE;
> >  		__blk_run_queue(q);
> >  		pm_runtime_mark_last_busy(q->dev);
> > +		spin_unlock_irq(q->queue_lock);
> >  		pm_runtime_autosuspend(q->dev);
> >  	} else {
> > +		spin_lock_irq(q->queue_lock);
> >  		q->rpm_status = RPM_SUSPENDED;
> > +		spin_unlock_irq(q->queue_lock);
> >  	}
> > -	spin_unlock_irq(q->queue_lock);
> >  }
> >  EXPORT_SYMBOL(blk_post_runtime_resume);
> >  #endif
> 
> I suppose we can do this cleanly enough:
> 
> --- a/block/blk-core.c~block-fix-possible-sleep-in-invalid-context-fix
> +++ a/block/blk-core.c
> @@ -3159,15 +3159,14 @@ EXPORT_SYMBOL(blk_pre_runtime_resume);
>   */
>  void blk_post_runtime_resume(struct request_queue *q, int err)
>  {
> +	spin_lock_irq(q->queue_lock);
>  	if (!err) {
> -		spin_lock_irq(q->queue_lock);
>  		q->rpm_status = RPM_ACTIVE;
>  		__blk_run_queue(q);
>  		pm_runtime_mark_last_busy(q->dev);
>  		spin_unlock_irq(q->queue_lock);
>  		pm_request_autosuspend(q->dev);
>  	} else {
> -		spin_lock_irq(q->queue_lock);
>  		q->rpm_status = RPM_SUSPENDED;
>  		spin_unlock_irq(q->queue_lock);
>  	}
> _
> 
> 
> I wonder if we actually need locking around that second write to
> q->rpm_status.

Shouldn't: it's an int, which makes it a 32 bit quantity we believe to
have atomic write properties on every platform.

James

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

* Re: [PATCH] block: Fix possible sleep in invalid context
  2013-07-01 22:24   ` James Bottomley
@ 2013-07-01 22:30     ` Andrew Morton
  0 siblings, 0 replies; 6+ messages in thread
From: Andrew Morton @ 2013-07-01 22:30 UTC (permalink / raw)
  To: James Bottomley
  Cc: Sujit Reddy Thumma, Aaron Lu, Jens Axboe, linux-pm, linux-scsi,
	stable, linux-arm-msm, linux-kernel

On Mon, 01 Jul 2013 15:24:11 -0700 James Bottomley <James.Bottomley@hansenpartnership.com> wrote:

> > --- a/block/blk-core.c~block-fix-possible-sleep-in-invalid-context-fix
> > +++ a/block/blk-core.c
> > @@ -3159,15 +3159,14 @@ EXPORT_SYMBOL(blk_pre_runtime_resume);
> >   */
> >  void blk_post_runtime_resume(struct request_queue *q, int err)
> >  {
> > +	spin_lock_irq(q->queue_lock);
> >  	if (!err) {
> > -		spin_lock_irq(q->queue_lock);
> >  		q->rpm_status = RPM_ACTIVE;
> >  		__blk_run_queue(q);
> >  		pm_runtime_mark_last_busy(q->dev);
> >  		spin_unlock_irq(q->queue_lock);
> >  		pm_request_autosuspend(q->dev);
> >  	} else {
> > -		spin_lock_irq(q->queue_lock);
> >  		q->rpm_status = RPM_SUSPENDED;
> >  		spin_unlock_irq(q->queue_lock);
> >  	}
> > _
> > 
> > 
> > I wonder if we actually need locking around that second write to
> > q->rpm_status.
> 
> Shouldn't: it's an int, which makes it a 32 bit quantity we believe to
> have atomic write properties on every platform.

Yes, but.  If there's some other code path which does:

	spin_lock(queue_lock);
	x = q->rpm_status;
	...
	y = q->rpm_status;
	...
	<assumes x == y>
	spin_unlock(queue_lock);

then it blows up if we make the suggested change.  Stranger things have
happened...


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

* Re: [PATCH] block: Fix possible sleep in invalid context
  2013-07-01 15:28 [PATCH] block: Fix possible sleep in invalid context Sujit Reddy Thumma
  2013-07-01 22:17 ` Andrew Morton
@ 2013-07-02  3:04 ` Aaron Lu
  2013-07-02  3:27   ` Sujit Reddy Thumma
  1 sibling, 1 reply; 6+ messages in thread
From: Aaron Lu @ 2013-07-02  3:04 UTC (permalink / raw)
  To: Sujit Reddy Thumma
  Cc: Jens Axboe, linux-pm, linux-scsi, stable, linux-arm-msm,
	linux-kernel, 'James Bottomley', Andrew Morton

On 07/01/2013 11:28 PM, Sujit Reddy Thumma wrote:
> When block runtime PM is enabled following warning is seen
> while resuming the device.
> 
> BUG: sleeping function called from invalid context at
> .../drivers/base/power/runtime.c:923
> in_atomic(): 1, irqs_disabled(): 128, pid: 12, name: kworker/0:1
> [<c0014448>] (unwind_backtrace+0x0/0x120) from
> [<c03120e4>] (__pm_runtime_suspend+0x34/0xa0) from
> [<c021c33c>] (blk_post_runtime_resume+0x4c/0x5c) from
> [<c03297cc>] (scsi_runtime_resume+0x90/0xb4) from
> [<c0310940>] (__rpm_callback+0x30/0x58) from
> [<c0310980>] (rpm_callback+0x18/0x28) from
> [<c0311ab0>] (rpm_resume+0x3dc/0x540) from
> [<c03120a4>] (pm_runtime_work+0x8c/0x98) from
> [<c007767c>] (process_one_work+0x238/0x3e4) from
> [<c0077b90>] (worker_thread+0x1ac/0x2ac) from
> [<c007cfdc>] (kthread+0x88/0x94) from
> [<c000ece0>] (kernel_thread_exit+0x0/0x8)
> 
> Fix this by releasing spin_lock_irq() before calling
> pm_runtime_autosuspend() in blk_post_runtime_resume().

Hi Sujit,

Thanks for testing out block layer runtime PM!

As for the problem here, it is already fixed by:

commit c60855cdb976c632b3bf8922eeab8a0e78edfc04
Author: Aaron Lu <aaron.lu@intel.com>
Date:   Fri May 17 15:47:20 2013 +0800

    blkpm: avoid sleep when holding queue lock

-Aaron

> 
> Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
> Cc: stable@vger.kernel.org
> ---
>  block/blk-core.c |    6 ++++--
>  1 files changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/block/blk-core.c b/block/blk-core.c
> index 33c33bc..2456116 100644
> --- a/block/blk-core.c
> +++ b/block/blk-core.c
> @@ -3159,16 +3159,18 @@ EXPORT_SYMBOL(blk_pre_runtime_resume);
>   */
>  void blk_post_runtime_resume(struct request_queue *q, int err)
>  {
> -	spin_lock_irq(q->queue_lock);
>  	if (!err) {
> +		spin_lock_irq(q->queue_lock);
>  		q->rpm_status = RPM_ACTIVE;
>  		__blk_run_queue(q);
>  		pm_runtime_mark_last_busy(q->dev);
> +		spin_unlock_irq(q->queue_lock);
>  		pm_runtime_autosuspend(q->dev);
>  	} else {
> +		spin_lock_irq(q->queue_lock);
>  		q->rpm_status = RPM_SUSPENDED;
> +		spin_unlock_irq(q->queue_lock);
>  	}
> -	spin_unlock_irq(q->queue_lock);
>  }
>  EXPORT_SYMBOL(blk_post_runtime_resume);
>  #endif
> 

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

* Re: [PATCH] block: Fix possible sleep in invalid context
  2013-07-02  3:04 ` Aaron Lu
@ 2013-07-02  3:27   ` Sujit Reddy Thumma
  0 siblings, 0 replies; 6+ messages in thread
From: Sujit Reddy Thumma @ 2013-07-02  3:27 UTC (permalink / raw)
  To: Aaron Lu
  Cc: Jens Axboe, linux-pm, linux-scsi, stable, linux-arm-msm,
	linux-kernel, 'James Bottomley', Andrew Morton

On 7/2/2013 8:34 AM, Aaron Lu wrote:
>> Fix this by releasing spin_lock_irq() before calling
>> >pm_runtime_autosuspend() in blk_post_runtime_resume().
> Hi Sujit,
>
> Thanks for testing out block layer runtime PM!
>
> As for the problem here, it is already fixed by:
>
> commit c60855cdb976c632b3bf8922eeab8a0e78edfc04
> Author: Aaron Lu<aaron.lu@intel.com>
> Date:   Fri May 17 15:47:20 2013 +0800
>
>      blkpm: avoid sleep when holding queue lock

Thanks Aaron. I see that is merged in 3.10-rc6.
Please ignore this patch.

-- 
Regards,
Sujit

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

end of thread, other threads:[~2013-07-02  3:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-01 15:28 [PATCH] block: Fix possible sleep in invalid context Sujit Reddy Thumma
2013-07-01 22:17 ` Andrew Morton
2013-07-01 22:24   ` James Bottomley
2013-07-01 22:30     ` Andrew Morton
2013-07-02  3:04 ` Aaron Lu
2013-07-02  3:27   ` 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;
as well as URLs for NNTP newsgroup(s).