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: 37978 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3864186wrt; Sun, 1 Jan 2023 10:18:25 -0800 (PST) X-Google-Smtp-Source: AMrXdXtzP49vJlBt3YPuROqUsmhOv15faeoOg2tNyz5SxtBQ8eNCO5uj8yL1i8IRKFcTmsRm6uqw X-Received: by 2002:a62:6442:0:b0:581:eca5:12a3 with SMTP id y63-20020a626442000000b00581eca512a3mr10783626pfb.10.1672597104969; Sun, 01 Jan 2023 10:18:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672597104; cv=none; d=google.com; s=arc-20160816; b=BbJckgV50mVWYDtgctd38DjNGe8BmhfhGOA4Qe0W3HOKe6lusa40gVA20TXNQ42dU4 F/9D+ThwqQU0VggL6OFDkp7GdGDBWSogvtRzMP5IY2YwqMnOV6X1ZAXcQS5GAC0ViXwN 3b8DrbBSnPe7rl3QVWngLNjlqJz8QGp2wg+hQUk4r5TbrOxikGVlZ4LFZtsz4PmTeGHZ RPVtxv4TbSWuQ48t55S+oszwTXqEcrV9w9S/3EXkC0SRRdKcz7RlNeyAs7yIaoRSwFZM 5bD1fUwUGtPNAeBqVXJEDv4Jwj+8NmiDPIOsnYkfc8V64x9ojKtL4LgxqpzLs7LQTSUD e+WQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=hvkPrr/ZBNzTZaPvAZqJb8WYe/S8XnUo9LM54WyjUhs=; b=P9YUc9ZfBG1CkbQ5gVHFRd9g11CCLtnMzR3ij3wscQPlutE/I6Xc85s5C9IU8u3SEd wJcLkztEDaO82Jovq1FdJ9ebEzVkJZdNBepAKeXr/bVNmzsn8qKPeq4+TrCSOO5HgOwS 4yhRa975lJDMFV6TNOXcLpjvDOg+ED3RD95GfELCP1gdqX+8cBAInln+5/syHHYx9Ub5 rI3iw5cYL+OArmgjCtE0xO9iusPDrWNsYiP0Wx6HIInPzyrEuNuQH2tNbPlI2+MoVdJ6 YfjGGyPDNrtBnBW+hQ4HSXm5BJbH27VPCAckneVIW/G+i3KD5gIEoMmjxNJXCKMmQHoJ AF8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sholland.org header.s=fm3 header.b=faR80+YK; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b="OfZwvdM/"; 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=sholland.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z8-20020aa78888000000b0056ea2b1b0fesi29216446pfe.119.2023.01.01.10.18.12; Sun, 01 Jan 2023 10:18:24 -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=@sholland.org header.s=fm3 header.b=faR80+YK; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b="OfZwvdM/"; 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=sholland.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230301AbjAASR2 (ORCPT + 99 others); Sun, 1 Jan 2023 13:17:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229447AbjAASRY (ORCPT ); Sun, 1 Jan 2023 13:17:24 -0500 Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 358D92AFD for ; Sun, 1 Jan 2023 10:17:22 -0800 (PST) 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-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753845181944824566?= X-GMAIL-MSGID: =?utf-8?q?1753845181944824566?= 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);