From patchwork Sun Jan 1 18:17:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13086419 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 7D9E6C4167B for ; Sun, 1 Jan 2023 18:20:39 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=J7E1z/3zma8prlUfwD8VvFRz9tl2Ednpfaamemb6s2A=; b=f3DvNr9PVkttlW 3up5q8r3oAZimvP92sYjY+RfAoS03Ox9kk8gC0/HhyrP7REGgjpx61Z7HJL1DyKVD4dwt8sGHygif xkXNffTqyNvNQQmgydFoODn+c6NTANoq4sGBNkKXiVEbzRcjAnmTAolT8Xq8LO4gMo1RxysvDsPZE iLbEx7yOyZFA2mG9U9ESBe3tCIOXoLHEWtwSNkR80+iwFQzdqNGtKEpSgcBDtcHPkj9jlblqM0E7B 5cgicgluWkW+7dxU0ZdgnfNxPtrE3DcwSOoBXmJ69yfKnV1sWP2Sd8rN5qS1nOvTPitGkGIxw3kjk 9QwxzNpQVhkk8CGy7jgw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pC2va-003d8P-9Q; Sun, 01 Jan 2023 18:19:22 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pC2tg-003cLS-Q8 for linux-arm-kernel@lists.infradead.org; Sun, 01 Jan 2023 18:17:28 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id D4DBF5C002F; Sun, 1 Jan 2023 13:17:19 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Sun, 01 Jan 2023 13:17:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= cc:cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1672597039; x=1672683439; bh=hv kPrr/ZBNzTZaPvAZqJb8WYe/S8XnUo9LM54WyjUhs=; b=faR80+YKxD7OBgqVfS GBWa1BvGuSV6B8ExirQNn27xe2gal16pNpGEgUjS22yAUQGhEBa3qQWVg4GYIJJU AiS9PKe4GrU++FSe1nSZWWqbMR6ZmdoIMGieoljSG4FjXOaWBuMk9FUaYl3Bhc2V PLscU0ydkDPmse2p6DX5ukW+i1QoKc2R+ZGlaZr+W/7cY6+uwVVs6NWR55GzSfWU Me459g7vOiaS+8bBk4yNqRju44/xhaGR9oTCP8mF47kIb7p3uBpKLgtUv3XhlpzK 6s9mlIxCvp5zarhvnTe2ebw/CoYO7ZmryRiWOrnNIVHRHYlIx5fX2bvFdgP7toPM 9OHQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1672597039; x=1672683439; bh=hvkPrr/ZBNzTZ aPvAZqJb8WYe/S8XnUo9LM54WyjUhs=; b=OfZwvdM/YIE2s+Lc5c3u3DmUlD8jI 5CbVZKrgVeynAkzMfxw2nRN3uKTpVs8FX8FJqDMhDcQgj1/BcZabK6+FlTRH13KQ 2aCXyuUtBbO9/4RF5RbOn5EXdC0TOTcQENCNmwGnEGL80D/EOIXkkGsPL/dolAP/ WtPzqUhEBwgbM+lAcd4NxTwzmGRVikN4gyhNZXFkMab/zUwNIQWA/dvhm9zi5BQl IUELh9ZIuBCDjTHPDzy/++W+JoqExea/8z4RbQ9hT17FOJYXs8jfUIDbBaz+9gVv H/APnztMrdWhGQYCbkeiDOuok8J3O8YM7j42p4iTX5HOxVXe8BxuiVa0g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrjedtgddutdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepufgrmhhu vghlucfjohhllhgrnhguuceoshgrmhhuvghlsehshhholhhlrghnugdrohhrgheqnecugg ftrfgrthhtvghrnhepudekteeuudehtdelteevgfduvddvjefhfedulefgudevgeeghefg udefiedtveetnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh homhepshgrmhhuvghlsehshhholhhlrghnugdrohhrgh X-ME-Proxy: Feedback-ID: i0ad843c9:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 1 Jan 2023 13:17:18 -0500 (EST) From: Samuel Holland To: Mark Rutland , Lorenzo Pieralisi , Sudeep Holla , Dmitry Osipenko , "Rafael J . Wysocki" Cc: Samuel Holland , John Ogness , Kai-Heng Feng , Luis Chamberlain , Petr Mladek , YueHaibing , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, tangmeng Subject: [PATCH v2 1/2] kernel/reboot: Use the static sys-off handler for any priority Date: Sun, 1 Jan 2023 12:17:14 -0600 Message-Id: <20230101181715.42199-2-samuel@sholland.org> X-Mailer: git-send-email 2.37.4 In-Reply-To: <20230101181715.42199-1-samuel@sholland.org> References: <20230101181715.42199-1-samuel@sholland.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230101_101725_057778_D79A51FF X-CRM114-Status: GOOD ( 15.38 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 and SBI on RISC-V, which should 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 drivers) do not need any per-instance data, so .cb_data could be NULL. Reviewed-by: Dmitry Osipenko Signed-off-by: Samuel Holland --- Changes in v2: - Update commit messages 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);