From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796333410; b=QGuBMOtgL+6BC7kZohebJi6EWGHwIQ8w1IfmeWhpwqgmW7DjUtH27/MtgZ++ecG1F0pw cvppiC92ISA6uhH1bFa+mt+mu5aMjmSUt8//j8LHCvak0DGOzJzctGsfsGrw0i8hSN0Lr HA1CGReiPx+VH8xrsZyA4oH3ybwqA7nQuh2PJo8IcvdIMuYkFiJ/ljLi4eWCTUC0QhP5P zZ/fWC7Kvjapx9OoR9KuujHu/9vveShQ2iIyHPW+u4npdIi2B0uXDDaWJB7F8rDTrew3M GbAMC5Z1gcpt2Zew+GKE8osqiF+FP7k6V5CyzBOIfCIRna4ApgQ1MiH63AmwVMcKgow== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796333410; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=C60x04PwYFdmOeEwmJClSMWLpAof9GNXP7YqgN58rtI=; b=P1EG0AN6RCoLFEoHkn4HxSzzwb8QSXvM0cqaS49HBWrfTALHDY9eYwJEFu2qM72LzX4m sIuJxnkNNZkalppl7mqfXEdfU780mbbLe0g1uXKDoNWqndg5wQ5F+1Nm4bJgOfG6PSLC5 UNv149Z903qRCgK1Wq5pGBcib9UhrhUrdoK89MY4Uxu7iHv0u9VkWUBJZ9SWxP4lHn/fw JjZio4KhcC1mHPtUmGJmT+1Uo+Ola8HQ4XP2iZo+Ube0MtMXuMdaJTAo82iRZ0JXrSa1g /Grd3wBbj2bbuzRlvykz3otpPqaMhxb+jURfBrq0oR0ScMxiEnFIgXCANmuuGyS3yqA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=rmU9isDu; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 71DE6606A32D for ; Thu, 3 Dec 2026 21:30:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=rmU9isDu Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06B811F000C2; Thu, 3 Dec 2026 21:30:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796333410; bh=C60x04PwYFdmOeEwmJClSMWLpAof9GNXP7YqgN58rtI=; h=Date:To:From:In-Reply-To:References:Subject; b=rmU9isDuVt5NTnBq9D9wEV7Qn9NXQTACJg+LNgIkpqJI1a6byCZ6bGtux73bC/6ZI RpToPZYexVearqi48++ew82z6BJRT0n1yoiOXRCILqut7It8zsopfbQ/EjpozWuZku BQ7F8/Jy/SI/NmwgJyLLW88sKnp9KGdnIX+Wb6RI= Date: Thu, 03 Dec 2026 13:30:09 -0800 To: mm-commits@vger.kernel.org,rafael@kernel.org,pmladek@suse.com, oleg@redhat.com,jcmvbkbc@gmail.com,dmitry.osipenko@collabora.com, chris@zankel.net,afd@ti.com,bradley.morgan@linux.dev, akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20261126214754.3630965-3-bradley.morgan@linux.dev> References: <20261126214754.3630965-3-bradley.morgan@linux.dev> Subject: + reboot-register-legacy-pm_power_off-once-at-boot.patch added to mm-nonmm-unstable branch Message-Id: <20261203213010.06B811F000C2@smtp.kernel.org> X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list The patch titled Subject: reboot: register legacy pm_power_off once at boot has been added to the -mm mm-nonmm-unstable branch. Its filename is reboot-register-legacy-pm_power_off-once-at-boot.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/reboot-register-legacy-pm_power_off-once-at-boot.patch This patch will later appear in the mm-nonmm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: Bradley Morgan Subject: reboot: register legacy pm_power_off once at boot Date: Thu, 26 Nov 2026 21:47:54 +0000 In do_kernel_power_off(), the legacy pm_power_off wrapper gets registered on the fly and unregistered right after walking the poweroff chain. If pm_power_off is set, calling do_kernel_power_off() from xmon while system_state is still SYSTEM_RUNNING ends up calling kzalloc_obj() with GFP_KERNEL in atomic context, and on arches like arm64 or x86 that disable IRQs and stop the other CPUs before calling it, returning from pm_power_off() hits synchronize_rcu() in unregister_sys_off_handler() with interrupts disabled and secondary CPUs halted. To fix this, register legacy_pm_power_off once at core_initcall using a static notifier_block at priority SYS_OFF_PRIO_DEFAULT - 1 so default priority handlers still run ahead of it, and count registered SYS_OFF_MODE_POWER_OFF handlers in power_off_handlers so kernel_can_power_off() does not treat the static wrapper as a real one. Link: https://patch.msgid.link/20261126214754.3630965-3-bradley.morgan@linux.dev Fixes: 2b8c612c6102 ("kernel/reboot: Fix powering off using a non-syscall code paths") Signed-off-by: Bradley Morgan Signed-off-by: Andrew Morton Cc: Rafael J . Wysocki Cc: Dmitry Osipenko Cc: Max Filippov Cc: Chris Zankel Cc: Andrew Davis Cc: Oleg Nesterov Cc: Petr Mladek kernel/reboot.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) --- a/kernel/reboot.c~reboot-register-legacy-pm_power_off-once-at-boot +++ a/kernel/reboot.c @@ -347,6 +347,7 @@ static BLOCKING_NOTIFIER_HEAD(power_off_ * to power off system. */ static ATOMIC_NOTIFIER_HEAD(power_off_handler_list); +static atomic_t power_off_handlers; static int sys_off_notify(struct notifier_block *nb, unsigned long mode, void *cmd) @@ -493,6 +494,9 @@ register_sys_off_handler(enum sys_off_mo return ERR_PTR(err); } + if (mode == SYS_OFF_MODE_POWER_OFF) + atomic_inc(&power_off_handlers); + return handler; } EXPORT_SYMBOL_GPL(register_sys_off_handler); @@ -520,6 +524,9 @@ void unregister_sys_off_handler(struct s /* sanity check, shall never happen */ WARN_ON(err); + if (!err && handler->mode == SYS_OFF_MODE_POWER_OFF) + atomic_dec(&power_off_handlers); + free_sys_off_handler(handler); } EXPORT_SYMBOL_GPL(unregister_sys_off_handler); @@ -660,7 +667,8 @@ void unregister_platform_power_off(void } EXPORT_SYMBOL_GPL(unregister_platform_power_off); -static int legacy_pm_power_off(struct sys_off_data *data) +static int legacy_pm_power_off(struct notifier_block *nb, + unsigned long mode, void *cmd) { if (pm_power_off) pm_power_off(); @@ -668,6 +676,20 @@ static int legacy_pm_power_off(struct sy return NOTIFY_DONE; } +static struct notifier_block legacy_pm_power_off_nb = { + .notifier_call = legacy_pm_power_off, + .priority = SYS_OFF_PRIO_DEFAULT - 1, +}; + +/* Keep pm_power_off static so do_kernel_power_off() cannot sleep */ +static int __init legacy_pm_init(void) +{ + atomic_notifier_chain_register(&power_off_handler_list, + &legacy_pm_power_off_nb); + 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); @@ -683,23 +705,7 @@ static void do_kernel_power_off_prepare( */ void do_kernel_power_off(void) { - struct sys_off_handler *sys_off = NULL; - - /* - * Register sys-off handlers for legacy PM callback. This allows - * legacy PM callbacks temporary 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. - */ - if (pm_power_off) - sys_off = register_sys_off_handler(SYS_OFF_MODE_POWER_OFF, - SYS_OFF_PRIO_DEFAULT, - legacy_pm_power_off, NULL); - atomic_notifier_call_chain(&power_off_handler_list, 0, NULL); - - unregister_sys_off_handler(sys_off); } /** @@ -710,8 +716,7 @@ void do_kernel_power_off(void) */ bool kernel_can_power_off(void) { - return !atomic_notifier_call_chain_is_empty(&power_off_handler_list) || - pm_power_off; + return atomic_read(&power_off_handlers) > 0 || pm_power_off; } EXPORT_SYMBOL_GPL(kernel_can_power_off); _ Patches currently in -mm which might be from bradley.morgan@linux.dev are reboot-fix-platform-sys_off-handler-reuse-with-null-cb_data.patch reboot-register-legacy-pm_power_off-once-at-boot.patch