Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp8917991ioo; Sat, 4 Jun 2022 23:45:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvN2bmCCzILbtnk0XVDNQvBHTkyUIpxNyFrmcV+gTVDweU05bmvFhdYtIpJpFGQhdI4wnY X-Received: by 2002:a17:903:1210:b0:15e:8373:d4b8 with SMTP id l16-20020a170903121000b0015e8373d4b8mr18469369plh.11.1654411525160; Sat, 04 Jun 2022 23:45:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654411525; cv=none; d=google.com; s=arc-20160816; b=lGv0me5PYKNuPY/2PZesebcChcwTl3qu1wndK4JkRpN+/HXehhcfYq4Q7cQRXDPpKW cKXnBmKXZhdUtBSHJxrR2f8fkyJlv25EhRtgnDt8IlZUeZlCwNlL1dIbjfv7BBiJ0j6B ZV0VgoBj5LC+abVR83KT45MsqwodFASY4eUE/BbO36OQUbgJfqoqJPRb1ixjlsyeWkM0 L/rm0Fs2IPEYu1n5hlt2JBAOos49WTSNOO7HVZayBJP8COb+zyNEKooL4Jb59UcxwdO1 rQmANtiyBFlhUcRhYDGKC7+Nqi5VSKmjSs3xRcWB4QIWDQaRq6ymuq/vur45hCfCVHkI a2Eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=ZebXCvVgYyoDD7R+hexZUA6pHVkZP2KZ/lhCRG9v1Nw=; b=U+PCARMf7YtIz8KGM6TG2tq4WrWWXxVKk6DuzjHcC//Pxd2nElK4pGlN0BLajlcHk9 cRhT2hYpdSyW3HtiisdtxRUG59P2BcWWJCIrXgcymzO63VkFeE7njfV8wwrAQe9IzG/h QsqJpkeZheRjIyGCuhpPWjrUi8wtw9YI2/GwaRGHxz0PDZ8Cbd9TDZW27gu0gH8CYm6T cDhmU9LwJYdpZx+H4QMXFQP+IyZEZKO9cDbwzAI2Bu6tfXFrFrDglDrOtE6/YrPe2BiU 3oDk14Btznda/11qoPcaVpygPDZuNBnDWobI7Ndry9jFunl8N8vuZ9+l/dZ5Ib2qvFKH yPaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b="SKhU/q9W"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q36-20020a17090a4fa700b001cac1e802d5si16255544pjh.82.2022.06.04.23.45.13; Sat, 04 Jun 2022 23:45:25 -0700 (PDT) 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=@ellerman.id.au header.s=201909 header.b="SKhU/q9W"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243264AbiFECBi (ORCPT + 99 others); Sat, 4 Jun 2022 22:01:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236737AbiFECBe (ORCPT ); Sat, 4 Jun 2022 22:01:34 -0400 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A00D04C402 for ; Sat, 4 Jun 2022 19:01:32 -0700 (PDT) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4LG0GZ74KWz4xD8; Sun, 5 Jun 2022 12:01:26 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ellerman.id.au; s=201909; t=1654394487; bh=ZebXCvVgYyoDD7R+hexZUA6pHVkZP2KZ/lhCRG9v1Nw=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=SKhU/q9WEzDGPnswYIpnFpNztIfIGHL0Vw9SnjJGCGwl4292sdSAj+JPj4A5xkzQb B+y7yf7HOYRhAFgS4FVK1Tub7rZqA/nsXwbNOsJFgdbfvBM7sIZHD4SD7kFL0RzFkh 4LAZuDBJ2i+GfAD0qdoBjleSWz7y3T0/nVDNPuVFtorZf3m6oBOfj9s66A2CtkfvCC W1+3qpbYbqxrMo+T6K2Yxddet2CdAE2SRRRfV3eF8sxv1HkTH+reURjf75ivPf0bqu Q0yL9l09vNrOMBoVQI5ppwupEBNnxca/NZZL6J6wgQOW+K2G2tsvoHRJ8kqMmlDtuR Ikh4iERgGVRCA== From: Michael Ellerman To: Dmitry Osipenko , "Rafael J . Wysocki" , Geert Uytterhoeven Cc: linux-kernel@vger.kernel.org, Subject: Re: [PATCH v1] kernel/reboot: Change registration order of legacy power-off handler In-Reply-To: <20220524212118.425702-1-dmitry.osipenko@collabora.com> References: <20220524212118.425702-1-dmitry.osipenko@collabora.com> Date: Sun, 05 Jun 2022 12:01:22 +1000 Message-ID: <8735gjq365.fsf@mpe.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,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 Dmitry Osipenko writes: > We're unconditionally registering sys-off handler for the legacy > pm_power_off() callback, this causes problem for platforms that don't > use power-off handlers at all and should be halted. Now reboot syscall > assumes that there is a power-off handler installed and tries to power > off system instead of halting it. > > To fix the trouble, move the handler's registration to the reboot syscall > and check the pm_power_off() presence. I'm seeing a qemu virtual machine (ppce500) fail to power off using the gpio-poweroff driver. I bisected it to this commit. I think the problem is that the machine is going via kernel_power_off(), not sys_reboot(), and so legacy_pm_power_off() has not been registered. If I just put the core_initcall back then it works as before. Not sure if that's a safe change in general though. cheers > Fixes: 0e2110d2e910 ("kernel/reboot: Add kernel_can_power_off()") > Reported-by: Geert Uytterhoeven > Tested-by: Geert Uytterhoeven > Signed-off-by: Dmitry Osipenko > --- > kernel/reboot.c | 33 +++++++++++++++++---------------- > 1 file changed, 17 insertions(+), 16 deletions(-) > > diff --git a/kernel/reboot.c b/kernel/reboot.c > index 0bdc64ecf4f6..a091145ee710 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); > @@ -646,6 +630,7 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd, > void __user *, arg) > { > struct pid_namespace *pid_ns = task_active_pid_ns(current); > + struct sys_off_handler *sys_off = NULL; > char buffer[256]; > int ret = 0; > > @@ -670,6 +655,21 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd, > if (ret) > return ret; > > + /* > + * 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); > + if (IS_ERR(sys_off)) > + return PTR_ERR(sys_off); > + } > + > /* Instead of trying to make the power_off code look like > * halt when pm_power_off is not set do it the easy way. > */ > @@ -727,6 +727,7 @@ SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd, > break; > } > mutex_unlock(&system_transition_mutex); > + unregister_sys_off_handler(sys_off); > return ret; > } > > -- > 2.35.3