From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EAAF8C433EF for ; Tue, 24 May 2022 13:41:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To: Subject:MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=MCo+wfxHKBi1eD0h3EZuwDf9M7iSI1eTZKRnTfKysZI=; b=nZ0SorKUq/dI1d ufSHyDQ+X8Q53RJEdZmlsQxtK0BEbXXkEj3XEEI2w9n6StFKopnJ2b7JDg7jUPrlwntXF1lSw0jP6 Lwxf11b5XILlyL5r9J74SnKcHjqeirii75x7zDdVUHnBmZmxhF3cBKxE6m4I6T2+MoUk6bvUNbD2K ZgRkfLvDix5M7YOKIyFi0uc4VE/5Vprt0C2uIW50OGyZbkl+tiHSxUUxLsdIIoQXXOc12qB+AUnMw iIMMuj7BfzAOrmuwOdZJet+gdRyOuW/Ap8oSExPNitjGz8t8SMV3bkUxi6QbE4GAEsKOSTqx26aoh jjFGEpxRaKWto+em8JQA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ntUn4-0088bJ-Gp; Tue, 24 May 2022 13:41:38 +0000 Received: from bhuna.collabora.co.uk ([46.235.227.227]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ntUn1-0088aM-AW for linux-riscv@lists.infradead.org; Tue, 24 May 2022 13:41:37 +0000 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dmitry.osipenko) with ESMTPSA id DC3DB1F442E3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1653399691; bh=qpTUo3+rCDoRa3ZgqFQh1I4V9k0JzWGh76jPDBVw0m4=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=hRMXxgmEZeDfWxnLgiCfIjezbE8Yst9du0UI+7few0qFS4O6SzexhgUtNR81+UMa0 KYtGAP7WoJvvCbjb1r9vYJeBeLntuikTxHhQ2xX4GkSM65ZWF51SWtZtKkvG2GsFyp ee6wNZ4HuinXH/33e8XTqRPnuFRbKCyO2LU4lEig5MXDWQ8Ifwaf0vGosGA3FpGoOu ZY9sVSFR31S/Hc7aRsnDGFMQGEBGJznHN/aWQ9jbnVbO6PcOxcFGWQQ7E0fiyfa2yi ZaixIuXh19f/Vi/OJQtn0gKlBU/bhD2aoxUDefuGeAsRvNKuYRcUhucApE0L9xde3E WNH0ic23yweUA== Message-ID: Date: Tue, 24 May 2022 16:41:23 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH v8 07/27] kernel/reboot: Add kernel_can_power_off() Content-Language: en-US To: Geert Uytterhoeven Cc: Thierry Reding , Jonathan Hunter , Russell King , Catalin Marinas , Will Deacon , Guo Ren , Greg Ungerer , Joshua Thompson , Thomas Bogendoerfer , Sebastian Reichel , Linus Walleij , Philipp Zabel , Greentime Hu , Vincent Chen , "James E.J. Bottomley" , Helge Deller , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Paul Walmsley , Palmer Dabbelt , Albert Ou , Yoshinori Sato , Rich Felker , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , the arch/x86 maintainers , "H. Peter Anvin" , Boris Ostrovsky , Juergen Gross , Stefano Stabellini , "Rafael J. Wysocki" , Len Brown , Santosh Shilimkar , Krzysztof Kozlowski , Liam Girdwood , Mark Brown , Pavel Machek , Lee Jones , Andrew Morton , Guenter Roeck , Daniel Lezcano , Andy Shevchenko , Ulf Hansson , =?UTF-8?B?TWljaGHFgiBNaXJvc8WCYXc=?= , Linux Kernel Mailing List , linux-csky@vger.kernel.org, "linux-ia64@vger.kernel.org" , linux-m68k , "open list:BROADCOM NVRAM DRIVER" , Parisc List , linux-riscv , Linux-sh list , xen-devel@lists.xenproject.org, ACPI Devel Maling List , Linux PM list , linux-tegra , Linux-Renesas References: <20220509233235.995021-1-dmitry.osipenko@collabora.com> <20220509233235.995021-8-dmitry.osipenko@collabora.com> From: Dmitry Osipenko In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220524_064135_740623_B3C05018 X-CRM114-Status: GOOD ( 29.96 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On 5/24/22 16:14, Geert Uytterhoeven wrote: > Hi Dmitry, > > On Tue, May 10, 2022 at 1:33 AM Dmitry Osipenko > wrote: >> Add kernel_can_power_off() helper that replaces open-coded checks of >> the global pm_power_off variable. This is a necessary step towards >> supporting chained power-off handlers. >> >> Signed-off-by: Dmitry Osipenko > > Thanks for your patch, which is now commit 0e2110d2e910e44c > ("kernel/reboot: Add kernel_can_power_off()") in pm/linux-next. > > This causes the "poweroff" command (Debian nfsroot) to no longer > cleanly halt the system on arm32 systems, but fail with a panic > instead: > > -reboot: System halted > +reboot: Power down > +Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000000 > +CPU: 0 PID: 1 Comm: systemd-shutdow Not tainted > 5.18.0-rc7-shmobile-00007-g0e2110d2e910 #1274 > +Hardware name: Generic R-Car Gen2 (Flattened Device Tree) > + unwind_backtrace from show_stack+0x10/0x14 > + show_stack from dump_stack_lvl+0x40/0x4c > + dump_stack_lvl from panic+0xf4/0x330 > + panic from do_exit+0x1c8/0x8e4 > + do_exit from __do_sys_reboot+0x174/0x1fc > + __do_sys_reboot from ret_fast_syscall+0x0/0x54 > +Exception stack(0xf0815fa8 to 0xf0815ff0) > +5fa0: 004e6954 00000000 fee1dead 28121969 4321fedc f0d94600 > +5fc0: 004e6954 00000000 00000000 00000058 befa0c78 00000000 befa0c10 004e56f8 > +5fe0: 00000058 befa0b6c b6ec8d45 b6e4a746 > +---[ end Kernel panic - not syncing: Attempted to kill init! > exitcode=0x00000000 ]--- > > On arm64, "poweroff" causes a clean "reboot: Power down" before/after. > > On both arm32 and arm64, the same handlers are registered: > - SYS_OFF_MODE_POWER_OFF_PREPARE: legacy_pm_power_off_prepare > - SYS_OFF_MODE_POWER_OFF: legacy_pm_power_off > > On both arm32 and arm64, legacy_pm_power_off_prepare() is called. > On both arm32 and arm64, legacy_pm_power_off() does not seem to > be called. > > On arm32, both pm_power_off_prepare and pm_power_off are NULL. > On arm64, pm_power_off_prepare is NULL, and > pm_power_off is psci_sys_poweroff. > > Do you have a clue? > Thanks! Thank you, Geert! I see the problem, the kernel_can_power_off() checks whether power-off handler is registered, but it's always registered because legacy_pm_power_off is registered unconditionally. So it causes trouble for platforms that don't have power-off handler installed at all. All platforms that I tested have a power-off handler, so now wonder that I didn't notice this before. This change should fix the problem, please give it a try: --- 8< --- diff --git a/kernel/reboot.c b/kernel/reboot.c index 0bdc64ecf4f6..2d55b8bdb444 100644 --- a/kernel/reboot.c +++ b/kernel/reboot.c @@ -569,22 +569,6 @@ static int legacy_pm_power_off(struct sys_off_data *data) return NOTIFY_DONE; } -/* - * Register sys-off handlers for legacy PM callbacks. This allows legacy - * PM callbacks co-exist with the new sys-off API. - * - * TODO: Remove legacy handlers once all legacy PM users will be switched - * to the sys-off based APIs. - */ -static int __init legacy_pm_init(void) -{ - register_sys_off_handler(SYS_OFF_MODE_POWER_OFF, SYS_OFF_PRIO_DEFAULT, - legacy_pm_power_off, NULL); - - return 0; -} -core_initcall(legacy_pm_init); - static void do_kernel_power_off_prepare(void) { blocking_notifier_call_chain(&power_off_prep_handler_list, 0, NULL); @@ -670,6 +654,18 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd, if (ret) return ret; + /* + * Register sys-off handler for the legacy PM callback. This allows + * legacy PM callbacks co-exist with the new sys-off API. + * + * TODO: Remove legacy handler once all legacy PM users will be + * switched to the sys-off based APIs. + */ + if (pm_power_off) + register_sys_off_handler(SYS_OFF_MODE_POWER_OFF, + SYS_OFF_PRIO_DEFAULT, + legacy_pm_power_off, NULL); + /* Instead of trying to make the power_off code look like * halt when pm_power_off is not set do it the easy way. */ -- Best regards, Dmitry _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv