Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp56947pxm; Fri, 25 Feb 2022 03:59:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJw4i39Ha8zHKHntFtLg44FoyRRzzGcaCQzm41SnocqgqDGEnq7FJX8njdgFaiTkyIzC75SP X-Received: by 2002:a05:6a00:14d5:b0:4df:c6b0:3101 with SMTP id w21-20020a056a0014d500b004dfc6b03101mr7466570pfu.45.1645790342238; Fri, 25 Feb 2022 03:59:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645790342; cv=none; d=google.com; s=arc-20160816; b=gSMG3Q7SMZevR6+prGJy08trQ0jyL+7skQHu1cs+va/Nqp5lIa7Orpr92SkUK6U/8p 7sO3grtOJtJflv8Td/NIXtkHJLcU8jiYoE2tUIoAeS+sQUNyVeqJ5Ktgc+LT0TDaP8DA OFJqHX8NtqhZgzfYz1fk2PNoAJIcF3OwxeKB6MeOE+RxErCFs0DNOQM8ceGR95I36k/p LjMLHpAkde1Fa6WPRHC4SLUcMnyD0Le5dN6yqse1L3Xfa7Nne6Zna2NxrqlN3u/7PcJ0 NUzUTpCYOeCr0ywni5TAvkMHXozvXDQcMsQ6dHI5w5h3EsUvBx38jw2z3YwsduH6o3xA f/0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=TEFef5k1IA/h4vT4K7MoOhkQEhiDC5bKljGY7fIE92o=; b=MLdJv5C52p0UuCYqKDquvj/pp0NQCzGnttBRj5ouFIou5VRkgRL01El7AvcSJwRq7d 20B/FRsS+MVhcJbTwhI1PC/y6Pf5z+V+ckdfng1XCLays6rcJEAvr/nL2s2J4ynmGs+i rg43oFzv+dlZKRzTzebkbRoXYUlFO8+iWRAQEm4X7ooE/u/hS8fKjo/D8DUUkVx2Y8AO ImlAKIVqnFK31m7gsJDuw5zMwXNxttYmPp6s5RZlULpDQA1ATf8eJlq9NZqKjzWw7Six zeCCY3Hh+sR0n+h5rumKoqxHaLZkEbep/1miDHamjxsTIPw3DRb5c86t5Zrr1w8gSpAE qepA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aUK0CzG7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mw4-20020a17090b4d0400b001bcaac63327si6619189pjb.166.2022.02.25.03.58.48; Fri, 25 Feb 2022 03:59:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aUK0CzG7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237921AbiBYGs6 (ORCPT + 99 others); Fri, 25 Feb 2022 01:48:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237027AbiBYGs5 (ORCPT ); Fri, 25 Feb 2022 01:48:57 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2213718C794; Thu, 24 Feb 2022 22:48:26 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id CD646B82B2D; Fri, 25 Feb 2022 06:48:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6ADAC340E7; Fri, 25 Feb 2022 06:48:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645771703; bh=4K1giYj+12R2Kkj5i0ab94fJZmq/YtPl2GIZQ2+Qasg=; h=From:To:Cc:Subject:Date:From; b=aUK0CzG7NxKCUcI/2x7fYYZvO53D/IAyGrnExUV/vj9O1nVxs04eGkTlmANqnTENI I5FQgVCJn0yUENmgtdAqRKKudHSx2LCXtLyFzpVrFN3lzUpEza5oP372D8ZjUoHaLf yuJ5oraug0bm8f4Fz8xHNSQNOAILKECLQLUouYgf/i6VaZcxkKOwA2AZtVpMFvCsen LEB1Vz9uO5eIZNmmeNXxrbKLJU2DicwbmiBczjHmq+qGmJ/+VZNg964szy3qZM/AQf y80v3+mD0WIuW4e8/GmDcptAcbmx+ctknTHUHCNXKhCofq2pKQhdU5ui04OfG7km/p mHOl1FtcbHhwQ== From: Shawn Guo To: "Rafael J . Wysocki" Cc: Kevin Hilman , Ulf Hansson , Thierry Strudel , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Shawn Guo Subject: [PATCH] PM: domains: Fix sleep-in-atomic bug caused by genpd_debug_remove() Date: Fri, 25 Feb 2022 14:48:15 +0800 Message-Id: <20220225064815.444571-1-shawnguo@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Shawn Guo When a genpd with GENPD_FLAG_IRQ_SAFE gets removed, the following sleep-in-atomic bug will be seen, as genpd_debug_remove() will be called with a spinlock being held. [ 0.029183] BUG: sleeping function called from invalid context at kernel/locking/rwsem.c:1460 [ 0.029204] in_atomic(): 1, irqs_disabled(): 128, non_block: 0, pid: 1, name: swapper/0 [ 0.029219] preempt_count: 1, expected: 0 [ 0.029230] CPU: 1 PID: 1 Comm: swapper/0 Not tainted 5.17.0-rc4+ #489 [ 0.029245] Hardware name: Thundercomm TurboX CM2290 (DT) [ 0.029256] Call trace: [ 0.029265] dump_backtrace.part.0+0xbc/0xd0 [ 0.029285] show_stack+0x3c/0xa0 [ 0.029298] dump_stack_lvl+0x7c/0xa0 [ 0.029311] dump_stack+0x18/0x34 [ 0.029323] __might_resched+0x10c/0x13c [ 0.029338] __might_sleep+0x4c/0x80 [ 0.029351] down_read+0x24/0xd0 [ 0.029363] lookup_one_len_unlocked+0x9c/0xcc [ 0.029379] lookup_positive_unlocked+0x10/0x50 [ 0.029392] debugfs_lookup+0x68/0xac [ 0.029406] genpd_remove.part.0+0x12c/0x1b4 [ 0.029419] of_genpd_remove_last+0xa8/0xd4 [ 0.029434] psci_cpuidle_domain_probe+0x174/0x53c [ 0.029449] platform_probe+0x68/0xe0 [ 0.029462] really_probe+0x190/0x430 [ 0.029473] __driver_probe_device+0x90/0x18c [ 0.029485] driver_probe_device+0x40/0xe0 [ 0.029497] __driver_attach+0xf4/0x1d0 [ 0.029508] bus_for_each_dev+0x70/0xd0 [ 0.029523] driver_attach+0x24/0x30 [ 0.029534] bus_add_driver+0x164/0x22c [ 0.029545] driver_register+0x78/0x130 [ 0.029556] __platform_driver_register+0x28/0x34 [ 0.029569] psci_idle_init_domains+0x1c/0x28 [ 0.029583] do_one_initcall+0x50/0x1b0 [ 0.029595] kernel_init_freeable+0x214/0x280 [ 0.029609] kernel_init+0x2c/0x13c [ 0.029622] ret_from_fork+0x10/0x20 It doesn't seem necessary to call genpd_debug_remove() with the lock, so move it out from locking to fix the problem. Fixes: 718072ceb211 ("PM: domains: create debugfs nodes when adding power domains") Signed-off-by: Shawn Guo --- drivers/base/power/domain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 5db704f02e71..7e8039d1884c 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -2058,9 +2058,9 @@ static int genpd_remove(struct generic_pm_domain *genpd) kfree(link); } - genpd_debug_remove(genpd); list_del(&genpd->gpd_list_node); genpd_unlock(genpd); + genpd_debug_remove(genpd); cancel_work_sync(&genpd->power_off_work); if (genpd_is_cpu_domain(genpd)) free_cpumask_var(genpd->cpus); -- 2.25.1