Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp825131rwb; Sun, 6 Nov 2022 14:36:05 -0800 (PST) X-Google-Smtp-Source: AMsMyM6jdLwMJWCeMvHS1VO8aIIAFDEMoYyyzEysZ01JkZvzBOkad0r9TIj4WrGSL8m5nkVfc5s2 X-Received: by 2002:aa7:8b46:0:b0:56c:349f:191e with SMTP id i6-20020aa78b46000000b0056c349f191emr46447911pfd.29.1667774165294; Sun, 06 Nov 2022 14:36:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667774165; cv=none; d=google.com; s=arc-20160816; b=cY3cRZw57WTlHuni4co7f0L2SRPycDWNiV8RTPldqdOFhj7YuAqBIBnCWXHuWOTjBy ZrbrGQ/+mlJjdYjcl7BsW9AYpCUGovQdpS/ETkRmKyyCaNBITes/+SYjRTR1H/PL8Lcq GBEtWy5buNM0Ysvtxs5JZGil0vfB5ketOzZPPxXZx4iZc8SDnFM6Snq/WAeIbbDXbPZO poq7oznR/SCTJ19Oamk33dcgtM0xSg1BUWoSwK7OlBAWiPtUCqcEx8zLD8Sn55Zp/0cq yBho/Tup463VCXrsAqUkRKXSx7XsW1vXRfv2PfuZ0p8wMTojA5y7nT6Faoc4jyrYI0Z/ lxtQ== 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=PMV8Fxe1HVO/Mxh9tHMcX2GugUNscShVLQUo44/y8Uk=; b=xhbDsQEx/jZ/A/o3pzkT+/ZJh//R5HmJUgDhejCGCwLQVKK1f0wIphk+bz21bfz4v5 4LUlFUJtFjjn0lgaGAbAmAMN0U0z3U7CbaHq26i3eTuZuKInNdUvIGK8Tms3SEtUwyJw rhtZZhpxz5EaiS8HpGs2gYkL1PXLhqKPXq8i/Nf1FKEiCiNwSHwKbhRrwE+S6cyPVEWH ZSFoIzJcXlD70rQZkUE/Tud3IGkLXka5cS54CVKaqxedItuUt7v9pBp8BH79ACZNrlye 2vqdi9w0TYlvaDA+bT0gVn1PjPl2RQFA2xSG8Q9PgyKA9Hra1afU08ECB/TYDSQbpHoQ hLlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Py9eb5IK; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ip8-20020a17090b314800b00212ee661e5bsi9265177pjb.153.2022.11.06.14.35.51; Sun, 06 Nov 2022 14:36:05 -0800 (PST) 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=@collabora.com header.s=mail header.b=Py9eb5IK; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230214AbiKFW26 (ORCPT + 96 others); Sun, 6 Nov 2022 17:28:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230143AbiKFW2z (ORCPT ); Sun, 6 Nov 2022 17:28:55 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 066779FCD for ; Sun, 6 Nov 2022 14:28:55 -0800 (PST) Received: from [192.168.2.238] (109-252-117-140.nat.spd-mgts.ru [109.252.117.140]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: dmitry.osipenko) by madras.collabora.co.uk (Postfix) with ESMTPSA id 2481E660226C; Sun, 6 Nov 2022 22:28:53 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1667773733; bh=aLC82hYUdpoSkhtiTndL8qGiojFW9ZfDhBbsDDusSNg=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=Py9eb5IKIzJFg3JgXl5J76l4OcKs0nnM4Bn3M5aiuU1i6PLyutFzFakokzChDdsnA ofIXxZBOho1h98aaTTw5yzMvmk0413A5qcCuhI4gVyOYffHgM/qrB3pjBPsZkn6RQh UODpDqtFyPXI0PxaCS0nTlJDK1T7/r3tr0PpD9nT2f/CZ3PbY2HitBndAscuVBVMch S82KoD0A6MQlZ7tQKoEJc8L0vObrqV14Vjlv7WERo0vPJrHkitxEn/5YPH1yQK3lSF ibhuNlg2eaNnb/ljS+XP4IotSHCMeaw6Ag2+sTfVTqAcWBMzl6vK5SxTTg+AWMbEG3 SGWn8KTc/YHWw== Message-ID: <02d127e1-adbb-3cc0-5da2-de3f961918a3@collabora.com> Date: Mon, 7 Nov 2022 01:28:50 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.1 Subject: Re: [PATCH 1/2] kernel/reboot: Use the static sys-off handler for any priority Content-Language: en-US To: Samuel Holland , "Rafael J . Wysocki" , Mark Rutland , Lorenzo Pieralisi Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org References: <20221105214841.7828-1-samuel@sholland.org> <20221105214841.7828-2-samuel@sholland.org> From: Dmitry Osipenko In-Reply-To: <20221105214841.7828-2-samuel@sholland.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS 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 On 11/6/22 00:48, Samuel Holland wrote: > commit 587b9bfe0668 ("kernel/reboot: Use static handler for > register_platform_power_off()") addded a statically-allocated handler > so register_sys_off_handler() could be called before the slab allocator > is available. > > That behavior was limited to the SYS_OFF_PRIO_PLATFORM priority. > However, it is also required for handlers such as PSCI on ARM, which > needs to be registered at SYS_OFF_PRIO_FIRMWARE. Currently, this call > stack crashes: > > start_kernel() > setup_arch() > psci_dt_init() > psci_0_2_init() > register_sys_off_handler() > kmem_cache_alloc() > > Generalize the code to use the statically-allocated handler for the > first registration, regardless of priority. Check .sys_off_cb for > conflicts instead of .cb_data; some callbacks (e.g. firmware) do not > need any per-instance data, so .cb_data could be NULL. > > Signed-off-by: Samuel Holland > --- > > kernel/reboot.c | 10 ++++------ > 1 file changed, 4 insertions(+), 6 deletions(-) > > diff --git a/kernel/reboot.c b/kernel/reboot.c > index 3bba88c7ffc6..38c18d4f0a36 100644 > --- a/kernel/reboot.c > +++ b/kernel/reboot.c > @@ -327,7 +327,7 @@ 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 early_sys_off_handler; > > static struct sys_off_handler *alloc_sys_off_handler(int priority) > { > @@ -338,10 +338,8 @@ static struct sys_off_handler *alloc_sys_off_handler(int priority) > * Platforms like m68k can't allocate sys_off handler dynamically > * at the early boot time because memory allocator isn't available yet. > */ > - if (priority == SYS_OFF_PRIO_PLATFORM) { > - handler = &platform_sys_off_handler; > - if (handler->cb_data) > - return ERR_PTR(-EBUSY); > + if (!early_sys_off_handler.sys_off_cb) { > + handler = &early_sys_off_handler; > } else { > if (system_state > SYSTEM_RUNNING) > flags = GFP_ATOMIC; > @@ -358,7 +356,7 @@ static struct sys_off_handler *alloc_sys_off_handler(int priority) > > static void free_sys_off_handler(struct sys_off_handler *handler) > { > - if (handler == &platform_sys_off_handler) > + if (handler == &early_sys_off_handler) > memset(handler, 0, sizeof(*handler)); > else > kfree(handler); Reviewed-by: Dmitry Osipenko -- Best regards, Dmitry