Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp715543pxb; Tue, 5 Apr 2022 20:02:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwG+caXhCn60oZXP884rQ7oYL74PaIjVOwWOt1AmFU1HGUijsOF4uc2ciE4ByM9fMYbnOQY X-Received: by 2002:a17:90b:4f8c:b0:1c7:2217:e980 with SMTP id qe12-20020a17090b4f8c00b001c72217e980mr7348066pjb.17.1649214154430; Tue, 05 Apr 2022 20:02:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649214154; cv=none; d=google.com; s=arc-20160816; b=smKAw2iU1qiuhgXx3BOOu3Cy/G+OChk/ubHpTyaQV7MaiO17k77HM6/P2q+B33664A ZuQw3QLijMr23Pfci1TeWvv+763Tr9vmFHdy8CzXjpDwAMONqdHjGlPjJLtVj+PRwhFu P3tqoSP8s5mDSW20X+EEugeLyXx0o9SaIGmiyJsHRCkzQ4r9gTDRjK+oXdAccReVpv0h PwnlpwL/5tZ3QnvdHa7B7yGz9OK+YBP9NDvh1qYwyKg75plF4+lH039jrAFfnl6cUjkX NdU3/PirhTyJyO9uQZJk+daP2UmyX0yjJ8PEgS3AmA1X7DXxNjrPgC+cx8HOMy+ODEiq 07sQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4OEsoXVp8/ji0+CNmhzn5Xhzm+1mzmUEfOk1sd2Rtg0=; b=cBqXEurSuBmFjc5LNqhOSqRkvNgUHeIF/jsul6qDrE+CVdfx51/Tmoo8FRiBdSlZTK MIt38Dqjve3dFK9pYaG28mFKFIEhVRUZKyiychmz2EFft3nx0qIWxdP3t2rfZWRvORLY yuQj5+rt2Myt/pxM31SS+6ky+EP6hBUJEwaApT1vtNDV44SNbnAnrgHUJfcg/jmf4h94 PTQhhLGZzt4N+J9N7CwM/vtxV2QOgOBYNIESsgud6N+rO9geJz2SSQuC9fxcrbpVYeo/ NosfnyxHK4NtNM9NpzCY/c7BKHxmsC2q6DVpQUtsxgbyujYKpViOmqIqDcGLH2rGCK+f YMDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=b8RavTK8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id n1-20020a170902d2c100b00153b2d16531si2884232plc.313.2022.04.05.20.02.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 20:02:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=b8RavTK8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 93A7210C52C; Tue, 5 Apr 2022 19:47:20 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232946AbiDEH4b (ORCPT + 99 others); Tue, 5 Apr 2022 03:56:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233604AbiDEHsJ (ORCPT ); Tue, 5 Apr 2022 03:48:09 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12EC6BB; Tue, 5 Apr 2022 00:46:12 -0700 (PDT) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 9513E616C3; Tue, 5 Apr 2022 07:46:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9FE6AC340EE; Tue, 5 Apr 2022 07:46:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649144771; bh=lyl/QYeOAOaVkyrba6LwCYjzbpaPtg3ddCAsSWp4+5E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b8RavTK8u/uTq2akVAfBvp1Bnvyovuz0Q96DlE9m4EpWNHy6pwC7cUC84FxkB7nxY VKSt8gAzYcaK55VKxT/hSPvB03PAAkdiDPsMn0qcq9gR4zDh8Evay5uRFOpyceH10l izT/NWFlWNWnmtwVc98ItR+x3eFf63NCzmf7glUY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shawn Guo , Ulf Hansson , "Rafael J. Wysocki" Subject: [PATCH 5.17 0165/1126] PM: domains: Fix sleep-in-atomic bug caused by genpd_debug_remove() Date: Tue, 5 Apr 2022 09:15:12 +0200 Message-Id: <20220405070412.439906409@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070407.513532867@linuxfoundation.org> References: <20220405070407.513532867@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 commit f6bfe8b5b2c2a5ac8bd2fc7bca3706e6c3fc26d8 upstream. 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 Reviewed-by: Ulf Hansson Cc: 5.11+ # 5.11+ Signed-off-by: Rafael J. Wysocki Signed-off-by: Greg Kroah-Hartman --- drivers/base/power/domain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -2058,9 +2058,9 @@ static int genpd_remove(struct generic_p 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);