From patchwork Mon Jul 1 22:17:12 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 2810281 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E0C4FBF4A1 for ; Mon, 1 Jul 2013 22:17:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F12C8201D5 for ; Mon, 1 Jul 2013 22:17:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E211B201CA for ; Mon, 1 Jul 2013 22:17:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755789Ab3GAWRO (ORCPT ); Mon, 1 Jul 2013 18:17:14 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:49980 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755740Ab3GAWRN (ORCPT ); Mon, 1 Jul 2013 18:17:13 -0400 Received: from akpm3.mtv.corp.google.com (unknown [216.239.45.95]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 53C9398F; Mon, 1 Jul 2013 22:17:13 +0000 (UTC) Date: Mon, 1 Jul 2013 15:17:12 -0700 From: Andrew Morton To: Sujit Reddy Thumma Cc: Aaron Lu , Jens Axboe , linux-pm@vger.kernel.org, linux-scsi@vger.kernel.org, stable@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] block: Fix possible sleep in invalid context Message-Id: <20130701151712.f453745bc0c587f449cc3214@linux-foundation.org> In-Reply-To: <1372692515-31969-1-git-send-email-sthumma@codeaurora.org> References: <1372692515-31969-1-git-send-email-sthumma@codeaurora.org> X-Mailer: Sylpheed 3.2.0beta5 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Mon, 1 Jul 2013 20:58:35 +0530 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 > [] (unwind_backtrace+0x0/0x120) from > [] (__pm_runtime_suspend+0x34/0xa0) from > [] (blk_post_runtime_resume+0x4c/0x5c) from > [] (scsi_runtime_resume+0x90/0xb4) from > [] (__rpm_callback+0x30/0x58) from > [] (rpm_callback+0x18/0x28) from > [] (rpm_resume+0x3dc/0x540) from > [] (pm_runtime_work+0x8c/0x98) from > [] (process_one_work+0x238/0x3e4) from > [] (worker_thread+0x1ac/0x2ac) from > [] (kthread+0x88/0x94) from > [] (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); }