Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1747295pxa; Thu, 20 Aug 2020 20:51:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzNznXkIwVVnVs2PMhHVLw0mqL+VRbHuecM37W4aFVWhvQTMym/DK14HeGoGkVZxJRSEHH X-Received: by 2002:a17:906:4696:: with SMTP id a22mr1043902ejr.154.1597981914179; Thu, 20 Aug 2020 20:51:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597981914; cv=none; d=google.com; s=arc-20160816; b=J8/MWC+bvEsOCsQ7TXGP0ecUTa8zek2RQiwMZjiBOufiIlIxTtWsGU6LwOvqqC+gja paNabkOpbjtILAxebQKN9JbdQcBHMrXQbBq7RJnhyPm3r5YuDCfwfLEk+HneCZ6x3SAb NADVZt9CHPkNHI/VZtJSjtGG583RJwKSAwSRFa7HwzioJIDAw16NGp/pDiBbm6OCs47a dZUArLjlHEMS9SVBuljKmYOIKC4ejZd987MbxnD0GTY1bq8OP2nCXUEu7z6S7n+i0cyP CfeL+BbrtKUyp5aPjrMPb0gmCibdcHnB7/MDzhldkgvAAQnQehPKrkIeDpJ94HcyU7gC ix9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :mime-version:dkim-signature; bh=VfRUxNe0v9ungW2Q4oPm5sMofYfp+0WBB84AMnNxuvk=; b=h5A65plUwDj1zXcAm/TF5oT2MOS6zh7TM8uOq5976hRCKWgf3JDC6JSuFD6/zZmTFS 5kiWYkWqMfrvQ4CFRLrB03FEqzujpb1rGVsxFTwhHOdcaiF+xsY1ThMyzpS7+TwJL5cM qOnPyKjnXhiq01z31r5uGQ0mTd4LR31gTyxIGxTatvgrfZwxpwx2LFOzJNrH8wOSW0NC vPF5rjwVO4VY4aBaWfRMqcqv/XZeoadBasgJy1UAlOLwFLjbmFBa33QPbr8XFLyByVQz rkM3tboQohlAgIfFODxJ8oFFSjqTZUJZTeEt4hEfcBnGNTpkpjk0ftmR4qvjDLE53yet 2ZAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="nbJ9/g8E"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l11si453235ejx.280.2020.08.20.20.51.31; Thu, 20 Aug 2020 20:51:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="nbJ9/g8E"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727780AbgHUDuv (ORCPT + 99 others); Thu, 20 Aug 2020 23:50:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727050AbgHUDuu (ORCPT ); Thu, 20 Aug 2020 23:50:50 -0400 Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40DDFC061385 for ; Thu, 20 Aug 2020 20:50:50 -0700 (PDT) Received: by mail-ed1-x543.google.com with SMTP id w2so333708edv.7 for ; Thu, 20 Aug 2020 20:50:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to:cc; bh=VfRUxNe0v9ungW2Q4oPm5sMofYfp+0WBB84AMnNxuvk=; b=nbJ9/g8EO3PckYqqNKRJY3YXUsCQFfcV2oX4t9pBlcXpukqSKnMZSsfLr477xei5in sRK5D0f0kJM9fr6mrEzWy4lClKFjq6dA4F7RcD1nzwx0Yo7gafrMQNxlyl1ZQQg7IiJS 76mV3gpYB2K5aP+skHGGDB2ycfNDpThJPquTB3lU/XyWC2I9edROAxcvBLpj9WWikc0V DjXgKx2YO2W96eZQ1+H0tn07OGl2Dayws0JAhTrfftAKXjPnJDU3tEnfhs5eSNzgp/GM tnuw96nJUlXAFnxDgOA6jVtNgBTO8k9TA1Dc9fd6UZZj03ZgqyrThuPveqF+Y9602Ilk Q/1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=VfRUxNe0v9ungW2Q4oPm5sMofYfp+0WBB84AMnNxuvk=; b=pXJbwv3ltvOgW7YMOhMISh3qEoN3wvuF3mqWnZ/JyELLOlSJRV80PB6yqRVsHqRPl8 dA+ezbBT3ZpSBpVhmNRKW0TSLGXBUQrp4+Qn94bPVBOsV0beSKVOjGJguLtQH3IpVSLE CU4xI+GiTE8k9BOOidB8fjdXOWv2zYn8MLpO/F9+Kyp/6nbymLkiSzbtAG7Wa/cS74fV 10T4wdf0L5KJuqmLMaBbo4sOIWmDCnc5d6uSnRMqsmc5k7589IDCRnwqQ6w9pl1LiLVV SLL1by87hLBYJ6gJ0dtYacqh6ehkDgR9WNk8raXQ98xtcF3MJwuFX4BR3n4HE5l5oLQY qu2w== X-Gm-Message-State: AOAM530N2amg50SzbjUt4IFr7+FkfMvFMeyMfY37Cete18RZKTCOYh5L SL/w+7pwA2s1BYgXpO6arKqpPpUlA5FILYbrIKpreIQQJ2Y= X-Received: by 2002:a50:fc02:: with SMTP id i2mr951234edr.121.1597981848303; Thu, 20 Aug 2020 20:50:48 -0700 (PDT) MIME-Version: 1.0 From: Dong Aisheng Date: Fri, 21 Aug 2020 11:35:37 +0800 Message-ID: Subject: Lockdep warning caused by "driver core: Fix sleeping in invalid context during device link deletion" To: open list , linux@roeck-us.net, gregkh , saravanak@google.com, m.szyprowski@samsung.com, naresh.kamboju@linaro.org Cc: dl-linux-imx , "moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE" , Dong Aisheng , Shawn Guo , Sascha Hauer Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi ALL, We met the below WARNING during system suspend on an iMX6Q SDB board with the latest linus/master branch (v5.9-rc1+) and next-20200820. v5.8 kernel is ok. So i did bisect and finally found it's caused by the patch below. Reverting it can get rid of the warning, but I wonder if there may be other potential issues. Any ideas? Defconfig used is: imx_v6_v7_defconfig commit 843e600b8a2b01463c4d873a90b2c2ea8033f1f6 Author: Saravana Kannan Date: Thu Jul 16 14:45:23 2020 -0700 driver core: Fix sleeping in invalid context during device link deletion Marek and Guenter reported that commit 287905e68dd2 ("driver core: Expose device link details in sysfs") caused sleeping/scheduling while atomic warnings. BUG: sleeping function called from invalid context at kernel/locking/mutex.c:935 in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 12, name: kworker/0:1 2 locks held by kworker/0:1/12: #0: ee8074a8 ((wq_completion)rcu_gp){+.+.}-{0:0}, at: process_one_work+0x174/0x7dc #1: ee921f20 ((work_completion)(&sdp->work)){+.+.}-{0:0}, at: process_one_work+0x174/0x7dc Preemption disabled at: [] srcu_invoke_callbacks+0xc0/0x154 ----- 8< ----- SNIP [] (device_del) from [] (device_unregister+0x24/0x64) [] (device_unregister) from [] (srcu_invoke_callbacks+0xcc/0x154) [] (srcu_invoke_callbacks) from [] (process_one_work+0x234/0x7dc) [] (process_one_work) from [] (worker_thread+0x44/0x51c) [] (worker_thread) from [] (kthread+0x158/0x1a0) [] (kthread) from [] (ret_from_fork+0x14/0x20) Exception stack(0xee921fb0 to 0xee921ff8) This was caused by the device link device being released in the context of srcu_invoke_callbacks(). There is no need to wait till the RCU callback to release the device link device. So release the device earlier and move the call_srcu() into the device release code. That way, the memory will get freed only after the device is released AND the RCU callback is called. Fixes: 287905e68dd2 ("driver core: Expose device link details in sysfs") Reported-by: Marek Szyprowski Reported-by: Guenter Roeck Reported-by: Naresh Kamboju Signed-off-by: Saravana Kannan Tested-by: Marek Szyprowski Tested-by: Guenter Roeck Link: https://lore.kernel.org/r/20200716214523.2924704-1-saravanak@google.com Signed-off-by: Greg Kroah-Hartman Error log: # echo mem > /sys/power/state [ 39.111865] PM: suspend entry (deep) [ 39.148650] Filesystems sync: 0.032 seconds [ 39.154034] [ 39.155537] ====================================================== [ 39.161723] WARNING: possible circular locking dependency detected [ 39.167911] 5.9.0-rc1-00103-g7eac66d0456f #37 Not tainted [ 39.173315] ------------------------------------------------------ [ 39.179500] sh/647 is trying to acquire lock: [ 39.183862] c15a310c (dpm_list_mtx){+.+.}-{3:3}, at: dpm_for_each_dev+0x20/0x5c [ 39.191200] [ 39.191200] but task is already holding lock: [ 39.197036] c15a37e4 (fw_lock){+.+.}-{3:3}, at: fw_pm_notify+0x90/0xd4 [ 39.203582] [ 39.203582] which lock already depends on the new lock. [ 39.203582] [ 39.211763] [ 39.211763] the existing dependency chain (in reverse order) is: [ 39.219249] [ 39.219249] -> #2 (fw_lock){+.+.}-{3:3}: [ 39.224673] mutex_lock_nested+0x1c/0x24 [ 39.229126] firmware_uevent+0x18/0xa0 [ 39.233411] dev_uevent+0xc4/0x1f8 [ 39.237343] uevent_show+0x98/0x114 [ 39.241362] dev_attr_show+0x18/0x48 [ 39.245472] sysfs_kf_seq_show+0x84/0xec [ 39.249927] seq_read+0x138/0x550 [ 39.253774] vfs_read+0x94/0x164 [ 39.257529] ksys_read+0x60/0xe8 [ 39.261288] ret_fast_syscall+0x0/0x28 [ 39.265564] 0xbed7c808 [ 39.268538] [ 39.268538] -> #1 (kn->active#3){++++}-{0:0}: [ 39.274391] kernfs_remove_by_name_ns+0x40/0x94 [ 39.279450] device_del+0x144/0x3fc [ 39.283467] __device_link_del+0x4c/0x70 [ 39.287919] device_link_remove+0x5c/0x8c [ 39.292464] _regulator_put.part.0+0x104/0x1dc [ 39.297436] regulator_put+0x2c/0x3c [ 39.299731] regulator regulator.5: Failed to increase supply voltage: -110 [ 39.301544] release_nodes+0x1b4/0x204 [ 39.301553] really_probe+0x104/0x3b4 [ 39.316881] driver_probe_device+0x58/0xb4 [ 39.321506] device_driver_attach+0x58/0x60 [ 39.326217] __driver_attach+0x58/0xd0 [ 39.330499] bus_for_each_dev+0x74/0xbc [ 39.334863] bus_add_driver+0x150/0x1dc [ 39.339227] driver_register+0x74/0x108 [ 39.343599] i2c_register_driver+0x38/0x8c [ 39.348227] do_one_initcall+0x84/0x3b4 [ 39.352598] kernel_init_freeable+0x154/0x1e4 [ 39.357485] kernel_init+0x8/0x118 [ 39.361415] ret_from_fork+0x14/0x20 [ 39.365518] 0x0 [ 39.367883] [ 39.367883] -> #0 (dpm_list_mtx){+.+.}-{3:3}: [ 39.373740] lock_acquire+0xe0/0x4ec [ 39.377848] __mutex_lock+0x94/0x9d0 [ 39.381952] mutex_lock_nested+0x1c/0x24 [ 39.386405] dpm_for_each_dev+0x20/0x5c [ 39.390769] fw_pm_notify+0xa4/0xd4 [ 39.394795] notifier_call_chain+0x48/0x80 [ 39.399420] __blocking_notifier_call_chain+0x48/0x64 [ 39.405003] __pm_notifier_call_chain+0x20/0x3c [ 39.410063] pm_suspend+0x1ac/0x438 [ 39.414080] state_store+0x68/0xc8 [ 39.418013] kernfs_fop_write+0x10c/0x22c [ 39.419741] cpu cpu0: failed to scale vddpu up: -110 [ 39.422551] vfs_write+0xbc/0x1d8 [ 39.422559] ksys_write+0x60/0xe8 [ 39.427529] cpufreq: __target_index: Failed to change cpu frequency: -110 [ 39.431362] ret_fast_syscall+0x0/0x28 [ 39.431368] 0xbeec8958 [ 39.431372] [ 39.431372] other info that might help us debug this: [ 39.431372] [ 39.431375] Chain exists of: [ 39.431375] dpm_list_mtx --> kn->active#3 --> fw_lock [ 39.431375] [ 39.431390] Possible unsafe locking scenario: [ 39.431390] [ 39.431394] CPU0 CPU1 [ 39.431398] ---- ---- [ 39.431401] lock(fw_lock); [ 39.431412] lock(kn->active#3); [ 39.490528] lock(fw_lock); [ 39.495934] lock(dpm_list_mtx); [ 39.499255] [ 39.499255] *** DEADLOCK *** [ 39.499255] [ 39.505181] 6 locks held by sh/647: [ 39.508675] #0: ecf48a84 (sb_writers#4){.+.+}-{0:0}, at: vfs_write+0x14c/0x1d8 [ 39.516007] #1: ed2ced48 (&of->mutex){+.+.}-{3:3}, at: kernfs_fop_write+0xd0/0x22c [ 39.523684] #2: ec1ff960 (kn->active#90){.+.+}-{0:0}, at: kernfs_fop_write+0xd8/0x22c [ 39.531620] #3: c151c4e8 (system_transition_mutex){+.+.}-{3:3}, at: pm_suspend+0x11c/0x438 [ 39.539991] #4: c151e3f4 ((pm_chain_head).rwsem){++++}-{3:3}, at: __blocking_notifier_call_chain+0x2c/0x64 [ 39.549753] usb_otg_vbus: disabling [ 39.549755] #5: c15a37e4 (fw_lock){+.+.}-{3:3}, at: fw_pm_notify+0x90/0xd4 [ 39.553264] wm8962-supply: disabling [ 39.560214] [ 39.560214] stack backtrace: [ 39.560225] CPU: 0 PID: 647 Comm: sh Not tainted 5.9.0-rc1-00103-g7eac66d0456f #37 [ 39.560230] Hardware name: Freescale i.MX6 Quad/DualLite (Device Tree) [ 39.560260] [] (unwind_backtrace) from [] (show_stack+0x10/0x14) [ 39.560287] [] (show_stack) from [] (dump_stack+0xe4/0x118) [ 39.597365] [] (dump_stack) from [] (check_noncircular+0x130/0x1e4) [ 39.605386] [] (check_noncircular) from [] (__lock_acquire+0x161c/0x31b0) [ 39.613923] [] (__lock_acquire) from [] (lock_acquire+0xe0/0x4ec) [ 39.621772] [] (lock_acquire) from [] (__mutex_lock+0x94/0x9d0) [ 39.629445] [] (__mutex_lock) from [] (mutex_lock_nested+0x1c/0x24) [ 39.637463] [] (mutex_lock_nested) from [] (dpm_for_each_dev+0x20/0x5c) [ 39.645828] [] (dpm_for_each_dev) from [] (fw_pm_notify+0xa4/0xd4) [ 39.653762] [] (fw_pm_notify) from [] (notifier_call_chain+0x48/0x80) [ 39.661954] [] (notifier_call_chain) from [] (__blocking_notifier_call_chain+0x48/0x64) [ 39.671709] [] (__blocking_notifier_call_chain) from [] (__pm_notifier_call_chain+0x20/0x3c) [ 39.679740] cpu cpu0: failed to scale vddpu up: -110 [ 39.681897] [] (__pm_notifier_call_chain) from [] (pm_suspend+0x1ac/0x438) [ 39.686859] cpufreq: __target_index: Failed to change cpu frequency: -110 [ 39.695473] [] (pm_suspend) from [] (state_store+0x68/0xc8) [ 39.695490] [] (state_store) from [] (kernfs_fop_write+0x10c/0x22c) [ 39.695506] [] (kernfs_fop_write) from [] (vfs_write+0xbc/0x1d8) [ 39.695524] [] (vfs_write) from [] (ksys_write+0x60/0xe8) [ 39.704844] VGEN1: disabling [ 39.709627] [] (ksys_write) from [] (ret_fast_syscall+0x0/0x28) [ 39.743035] Exception stack(0xed573fa8 to 0xed573ff0) [ 39.748098] 3fa0: 00000004 01d3caf8 00000001 01d3caf8 00000004 00000000 [ 39.756286] 3fc0: 00000004 01d3caf8 b6f40340 00000004 b6ed6c8c 00000000 00000000 00000000 [ 39.764470] 3fe0: 00000004 beec8958 b6e75d4f b6e01d16 [ 39.770874] VGEN2: disabling [ 39.776106] VGEN3: disabling [ 69.590256] cfg80211: failed to load regulatory.db [ 69.590312] Freezing user space processes ... (elapsed 0.008 seconds) done. [ 69.606341] OOM killer disabled. [ 69.609599] Freezing remaining freezable tasks ... (elapsed 0.001 seconds) done. [ 69.619021] printk: Suspending console(s) (use no_console_suspend to debug)