From patchwork Tue Oct 20 20:35:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grygorii Strashko X-Patchwork-Id: 7450311 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CBC209F302 for ; Tue, 20 Oct 2015 20:35:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C2EBB20867 for ; Tue, 20 Oct 2015 20:35:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 621BC20866 for ; Tue, 20 Oct 2015 20:35:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752796AbbJTUfX (ORCPT ); Tue, 20 Oct 2015 16:35:23 -0400 Received: from bear.ext.ti.com ([192.94.94.41]:59149 "EHLO bear.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752035AbbJTUfV (ORCPT ); Tue, 20 Oct 2015 16:35:21 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id t9KKZ7a6008684; Tue, 20 Oct 2015 15:35:07 -0500 Received: from DLEE70.ent.ti.com (dlemailx.itg.ti.com [157.170.170.113]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id t9KKZ7EM031111; Tue, 20 Oct 2015 15:35:07 -0500 Received: from dflp32.itg.ti.com (10.64.6.15) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.3.224.2; Tue, 20 Oct 2015 15:35:06 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id t9KKZ5LO021222; Tue, 20 Oct 2015 15:35:06 -0500 From: Grygorii Strashko To: , "Rafael J. Wysocki" , , CC: Sekhar Nori , , , Grygorii Strashko Subject: [4.1.3-rt10][RFC PATCH] PM / sleep: freeze: fix bug "sleeping function called from invalid context" Date: Tue, 20 Oct 2015 23:35:03 +0300 Message-ID: <1445373303-26264-1-git-send-email-grygorii.strashko@ti.com> X-Mailer: git-send-email 2.5.1 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 With 4.1 RT-kernel on TI ARM dra7-evm the below error report is displayed each time system is woken up from sleep state: BUG: sleeping function called from invalid context at kernel/locking/rtmutex.c:917 in_atomic(): 1, irqs_disabled(): 128, pid: 142, name: sh INFO: lockdep is turned off. irq event stamp: 11575 hardirqs last enabled at (11575): [] _raw_spin_unlock_irq+0x24/0x68 hardirqs last disabled at (11574): [] _raw_spin_lock_irq+0x18/0x4c softirqs last enabled at (0): [] copy_process.part.54+0x3f4/0x1930 softirqs last disabled at (0): [< (null)>] (null) Preemption disabled at:[< (null)>] (null) CPU: 0 PID: 142 Comm: sh Not tainted 4.1.10-rt8-01710-g6c5fab9 #61 Hardware name: Generic DRA74X (Flattened Device Tree) [] (unwind_backtrace) from [] (show_stack+0x10/0x14) [] (show_stack) from [] (dump_stack+0x7c/0x98) [] (dump_stack) from [] (rt_spin_lock+0x20/0x60) [] (rt_spin_lock) from [] (freeze_wake+0x10/0x58) [] (freeze_wake) from [] (irq_pm_check_wakeup+0x40/0x48) [] (irq_pm_check_wakeup) from [] (irq_may_run+0x20/0x48) [] (irq_may_run) from [] (handle_level_irq+0x40/0x160) [] (handle_level_irq) from [] (generic_handle_irq+0x28/0x3c) [] (generic_handle_irq) from [] (pcs_irq_handle+0x6c/0x8c) [] (pcs_irq_handle) from [] (pcs_irq_chain_handler+0x30/0x88) [] (pcs_irq_chain_handler) from [] (generic_handle_irq+0x28/0x3c) [] (generic_handle_irq) from [] (omap_prcm_irq_handler+0xc4/0x1a8) [] (omap_prcm_irq_handler) from [] (generic_handle_irq+0x28/0x3c) [] (generic_handle_irq) from [] (__handle_domain_irq+0x8c/0x120) [] (__handle_domain_irq) from [] (gic_handle_irq+0x20/0x60) [] (gic_handle_irq) from [] (__irq_svc+0x44/0x90) Exception stack(0xeca49dc8 to 0xeca49e10) 9dc0: c00a2e38 ec9fae00 00000100 00000000 c12fb80c 00000003 9de0: 00000000 c0b396a0 c0a70804 c0896b20 c0896ae8 00000000 00000000 eca49e10 9e00: c00a2e38 c00a2e3c 60000013 ffffffff [] (__irq_svc) from [] (arch_suspend_enable_irqs+0xc/0x10) [] (arch_suspend_enable_irqs) from [] (suspend_enter+0x2f8/0xce4) [] (suspend_enter) from [] (suspend_devices_and_enter+0xd4/0x648) [] (suspend_devices_and_enter) from [] (enter_state+0x6a0/0x1030) [] (enter_state) from [] (pm_suspend+0x14/0x74) [] (pm_suspend) from [] (state_store+0x64/0xb8) [] (state_store) from [] (kernfs_fop_write+0xb8/0x19c) [] (kernfs_fop_write) from [] (__vfs_write+0x20/0xd8) [] (__vfs_write) from [] (vfs_write+0x90/0x164) [] (vfs_write) from [] (SyS_write+0x44/0x9c) [] (SyS_write) from [] (ret_fast_syscall+0x0/0x1c) The root cause of issue is freeze_wake() which is called from atomic context (HW IRQ handler). The call path: gic_handle_irq - omap_prcm_irq_handler - pcs_irq_chain_handler - [...] - handle_level_irq - irq_may_run - irq_pm_check_wakeup - freeze_wake - spin_lock_irqsave(&suspend_freeze_lock,..); Hence, fix this issue by doing the following: - convert suspend_freeze_lock to raw lock; - convert suspend_freeze_wait_head to simple waitqueue; - move pm_wakeup_pending() out of region, protected by suspend_freeze_lock; Signed-off-by: Grygorii Strashko --- kernel/power/suspend.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c index db920b1..0e94058 100644 --- a/kernel/power/suspend.c +++ b/kernel/power/suspend.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "power.h" @@ -37,10 +38,10 @@ const char *pm_states[PM_SUSPEND_MAX]; static const struct platform_suspend_ops *suspend_ops; static const struct platform_freeze_ops *freeze_ops; -static DECLARE_WAIT_QUEUE_HEAD(suspend_freeze_wait_head); +static DEFINE_SWAIT_HEAD(suspend_freeze_wait_head); enum freeze_state __read_mostly suspend_freeze_state; -static DEFINE_SPINLOCK(suspend_freeze_lock); +static DEFINE_RAW_SPINLOCK(suspend_freeze_lock); void freeze_set_ops(const struct platform_freeze_ops *ops) { @@ -56,12 +57,12 @@ static void freeze_begin(void) static void freeze_enter(void) { - spin_lock_irq(&suspend_freeze_lock); if (pm_wakeup_pending()) goto out; + raw_spin_lock_irq(&suspend_freeze_lock); suspend_freeze_state = FREEZE_STATE_ENTER; - spin_unlock_irq(&suspend_freeze_lock); + raw_spin_unlock_irq(&suspend_freeze_lock); get_online_cpus(); cpuidle_resume(); @@ -70,30 +71,30 @@ static void freeze_enter(void) wake_up_all_idle_cpus(); pr_debug("PM: suspend-to-idle\n"); /* Make the current CPU wait so it can enter the idle loop too. */ - wait_event(suspend_freeze_wait_head, - suspend_freeze_state == FREEZE_STATE_WAKE); + swait_event(suspend_freeze_wait_head, + suspend_freeze_state == FREEZE_STATE_WAKE); pr_debug("PM: resume from suspend-to-idle\n"); cpuidle_pause(); put_online_cpus(); - spin_lock_irq(&suspend_freeze_lock); + raw_spin_lock_irq(&suspend_freeze_lock); out: suspend_freeze_state = FREEZE_STATE_NONE; - spin_unlock_irq(&suspend_freeze_lock); + raw_spin_unlock_irq(&suspend_freeze_lock); } void freeze_wake(void) { unsigned long flags; - spin_lock_irqsave(&suspend_freeze_lock, flags); + raw_spin_lock_irqsave(&suspend_freeze_lock, flags); if (suspend_freeze_state > FREEZE_STATE_NONE) { suspend_freeze_state = FREEZE_STATE_WAKE; - wake_up(&suspend_freeze_wait_head); + swait_wake(&suspend_freeze_wait_head); } - spin_unlock_irqrestore(&suspend_freeze_lock, flags); + raw_spin_unlock_irqrestore(&suspend_freeze_lock, flags); } EXPORT_SYMBOL_GPL(freeze_wake);