Received: by 2002:a19:771d:0:0:0:0:0 with SMTP id s29csp1253190lfc; Wed, 1 Jun 2022 13:09:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxE8aBnRa8sQob0W0YM2aApmrtWwj8oAV5KH2GbLINMeFBVKbi7PR0IU2B5GlWy65wqGNam X-Received: by 2002:a17:902:ce11:b0:15f:4acc:f1fb with SMTP id k17-20020a170902ce1100b0015f4accf1fbmr1107524plg.76.1654114188294; Wed, 01 Jun 2022 13:09:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654114188; cv=none; d=google.com; s=arc-20160816; b=vF0Ego+SMS1LPb7dJGWLzUwpmY43ehAzSmniGGoyfLLJTrY9l+C9GAck2+3sz7CNKc vfeBLsRrFcmEtBfl56EUszkftTXlalofYESbcEnUXzoke5X5dhXO6NzxuT3SY6B7Dd3B YSVl2resj5BFv+uROZNifO+4CWPMTe/lRqD8uxHWM7qvbZz38ASHvMMjoMXJCGBlHiml gAxK7xCrPoBqOGvtp6whWcYWaXGJsGuSLDAFRzD1vLQKDp1dXsIcxTN0SzthvAPShqTQ kIQlEKIm3yhFW0E+bt4h3zsuveC2xBqiB823wZd5h2hUt5/lSRgBHOQMCcyDx2WnGO9j v5iA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=GzFscbWDM9/OCBr4W+PRS8l288jgnjYCvJk6qO+0hnU=; b=0n1n2fgaMAFOwHXFqoW1dDnVp75ksro1Aj1n4yNrQTfu3KiIQpqzyo02V4qNWH9E0h Vq7jtQA0t39HB/Cp2qMWGl8gEjpNj9NmccP1LhorW4ERf99Vq+hKyoR0i+zXu4/MmXHE UqN3s/b2Y1kbavtafuP+b/awgkfCzlSQqWAklTYmXlKFDHwJXOJ3u6D7sTq6vP2LrbWF tMeXv3tV/5leRkZHeF2vCNNnirYD0/liG22se6yYoxV0ShEuCBRiedtFVjdmSjqhn9G9 sI9G5ClP2CoTcQyCzJTh6eqnL01lHV8WOuONC+JVsCNO1Dflm3waY1IILAYs7x2t6g1s GRzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=iw1cl93D; 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=collabora.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id y17-20020a656c11000000b003f60a39c6b6si3282018pgu.812.2022.06.01.13.09.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 13:09:48 -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=@collabora.com header.s=mail header.b=iw1cl93D; 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=collabora.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 82A7F235250; Wed, 1 Jun 2022 12:25:03 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347988AbiEaVZJ (ORCPT + 99 others); Tue, 31 May 2022 17:25:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347989AbiEaVZC (ORCPT ); Tue, 31 May 2022 17:25:02 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFD149CF26; Tue, 31 May 2022 14:25:00 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dmitry.osipenko) with ESMTPSA id 4C9F21F43F0B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1654032299; bh=dWPjJiUcTEsCTwSVeYSxHnF1/ruJ13+dt9/M97DHXpY=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=iw1cl93DawB1wUr9b6KkZdHCFs5+L/GBohLHlROEAOks05zME/v6MXMPk6D7ui5Yi RNRHdZFdzCLwhRjjb38P9M6JexB3Wbp2yKOPr5eeU8sVg/8ntyHzURiHlZSY6J8Cm9 q6oV/gJyO14M2ElVzYwoEuvi7LeAOBJpJO7JVAQIQbIk2iZISrAGCD8WEks6N0mo8W PABIM3KRc5wMYvZgEpozGR6zO7yQLUE2dke3U5CmMfjFhmLTkzt3Ddgs0XBxEfDRJn c+JlwyAdHThzhqLupTWaB45a5dOVfxT+a6WiHu8uAbSXS41ExvvXWl05U0ZRpjuSZP ldNnEXKzwDRFg== Message-ID: Date: Wed, 1 Jun 2022 00:24:49 +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 16/27] m68k: Switch to new sys-off handler API 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 References: <20220509233235.995021-1-dmitry.osipenko@collabora.com> <20220509233235.995021-17-dmitry.osipenko@collabora.com> From: Dmitry Osipenko In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=unavailable 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 On 5/31/22 22:04, Geert Uytterhoeven wrote: > Hi Dmitry, > > On Tue, May 10, 2022 at 1:34 AM Dmitry Osipenko > wrote: >> Kernel now supports chained power-off handlers. Use >> register_power_off_handler() that registers power-off handlers and >> do_kernel_power_off() that invokes chained power-off handlers. Legacy >> pm_power_off() will be removed once all drivers will be converted to >> the new sys-off API. >> >> Normally arch code should adopt only the do_kernel_power_off() at first, >> but m68k is a special case because it uses pm_power_off() "inside out", >> i.e. pm_power_off() invokes machine_power_off() [in fact it does nothing], >> while it's machine_power_off() that should invoke the pm_power_off(), and >> thus, we can't convert platforms to the new API separately. There are only >> two platforms changed here, so it's not a big deal. >> >> Acked-by: Geert Uytterhoeven >> Reviewed-by: Michał Mirosław >> Signed-off-by: Dmitry Osipenko > > Thanks for your patch, which is now commit f0f7e5265b3b37b0 > ("m68k: Switch to new sys-off handler API") upstream. > >> --- a/arch/m68k/emu/natfeat.c >> +++ b/arch/m68k/emu/natfeat.c >> @@ -15,6 +15,7 @@ >> #include >> #include >> #include >> +#include >> #include >> #include >> #include >> @@ -90,5 +91,5 @@ void __init nf_init(void) >> pr_info("NatFeats found (%s, %lu.%lu)\n", buf, version >> 16, >> version & 0xffff); >> >> - mach_power_off = nf_poweroff; >> + register_platform_power_off(nf_poweroff); > > Unfortunately nothing is registered, as this is called very early > (from setup_arch(), before the memory allocator is available. > Hence register_sys_off_handler() fails with -ENOMEM, and poweroff > stops working. > > Possible solutions: > - As at most one handler can be registered, > register_platform_power_off() could use a static struct sys_off_handler > instance, > - Keep mach_power_off, and call register_platform_power_off() later. > > Anything else? > Thanks! > >> --- a/arch/m68k/mac/config.c >> +++ b/arch/m68k/mac/config.c >> @@ -12,6 +12,7 @@ >> >> #include >> #include >> +#include >> #include >> #include >> #include >> @@ -140,7 +141,6 @@ void __init config_mac(void) >> mach_hwclk = mac_hwclk; >> mach_reset = mac_reset; >> mach_halt = mac_poweroff; >> - mach_power_off = mac_poweroff; >> #if IS_ENABLED(CONFIG_INPUT_M68K_BEEP) >> mach_beep = mac_mksound; >> #endif >> @@ -160,6 +160,8 @@ void __init config_mac(void) >> >> if (macintosh_config->ident == MAC_MODEL_IICI) >> mach_l2_flush = via_l2_flush; >> + >> + register_platform_power_off(mac_poweroff); >> } > > This must have the same problem. The static variant should be better, IMO. I'm not sure whether other platforms won't face the same problem once they will start using register_platform_power_off(). I'll send the fix, thank you for the testing! --- >8 --- diff --git a/kernel/reboot.c b/kernel/reboot.c index a091145ee710..4fea05d387dc 100644 --- a/kernel/reboot.c +++ b/kernel/reboot.c @@ -315,6 +315,37 @@ static int sys_off_notify(struct notifier_block *nb, return handler->sys_off_cb(&data); } +static struct sys_off_handler platform_sys_off_handler; + +static struct sys_off_handler *alloc_sys_off_handler(int priority) +{ + struct sys_off_handler *handler; + + /* + * Platforms like m68k can't allocate sys_off handler dynamically + * at the early boot time. + */ + if (priority == SYS_OFF_PRIO_PLATFORM) { + handler = &platform_sys_off_handler; + if (handler->cb_data) + return ERR_PTR(-EBUSY); + } else { + handler = kzalloc(sizeof(*handler), GFP_KERNEL); + if (!handler) + return ERR_PTR(-ENOMEM); + } + + return handler; +} + +static void free_sys_off_handler(struct sys_off_handler *handler) +{ + if (handler == &platform_sys_off_handler) + memset(handler, 0, sizeof(*handler)); + else + kfree(handler); +} + /** * register_sys_off_handler - Register sys-off handler * @mode: Sys-off mode @@ -345,9 +376,9 @@ register_sys_off_handler(enum sys_off_mode mode, struct sys_off_handler *handler; int err; - handler = kzalloc(sizeof(*handler), GFP_KERNEL); - if (!handler) - return ERR_PTR(-ENOMEM); + handler = alloc_sys_off_handler(priority); + if (IS_ERR(handler)) + return handler; switch (mode) { case SYS_OFF_MODE_POWER_OFF_PREPARE: @@ -364,7 +395,7 @@ register_sys_off_handler(enum sys_off_mode mode, break; default: - kfree(handler); + free_sys_off_handler(handler); return ERR_PTR(-EINVAL); } @@ -391,7 +422,7 @@ register_sys_off_handler(enum sys_off_mode mode, } if (err) { - kfree(handler); + free_sys_off_handler(handler); return ERR_PTR(err); } @@ -422,7 +453,7 @@ void unregister_sys_off_handler(struct sys_off_handler *handler) /* sanity check, shall never happen */ WARN_ON(err); - kfree(handler); + free_sys_off_handler(handler); } EXPORT_SYMBOL_GPL(unregister_sys_off_handler);