From patchwork Sat Nov 5 21:48:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13033257 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 4B056C4332F for ; Sat, 5 Nov 2022 21:50:20 +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=i4kscz0gdxZYGYK2Nn2In7ZenLuSud0eLAl6vstpgV8=; b=sHcuxwoUvyTFH3 Gyo9c9SjljK94YB4AcvN9f/pClDBHhEiroD0Yi/IZ3OougMnvUvp7oIWATz34izD6pCggNR+Cv6uc OAgIztkMXYueZWTDywhUBfARIJD0Vl0n4ahYdTG7yS1PzNNmxUGmtRiuamGVdpDhDGglbPDIREyo7 7PFSefXevfHaiEGDE9xEt6cguNy5tLgEHdEYRfIru9sBqK3wk3FvTcAdmd/kH7H+EqNAx/L4+frXv Me7jEzj5hUbPVNAPVEtyGmYvgANUIi2Xic8sfZy3Z/dm6itY7yGCKYFQoC463WVoWo9NOIlVMAbJR RQ5cmr12lmCrsLJ4kvHg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1orR2B-007I28-0Z; Sat, 05 Nov 2022 21:48:59 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1orR20-007I10-TP for linux-arm-kernel@lists.infradead.org; Sat, 05 Nov 2022 21:48:50 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 8D843320034E; Sat, 5 Nov 2022 17:48:46 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Sat, 05 Nov 2022 17:48:47 -0400 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=fm1; t=1667684926; x=1667771326; bh=Zc G1ArcUeKGaZd5PrcG3/1gsyCRPoz0HrnVVRDFda8o=; b=lt1OxjWmL1nd76byHp +iLUkjYf1FXz50/TIKpxCQ32IFhvnOi/5U6n/6LITuWcWty1X17uEPFrIkgP4J0X +zdzkEkXl3zqra9oQR3jcHgXUa5d/5xkHDhie31xFsRbN0Xduv2mRh4HHpULzyzN nvXloCvUet97MqU/X+toReAG5kVJe3vTpfGOmpe1VoRmKYGraaXOmKXwphZJ4sBj ZJKHdyJ7dTnJK30Hclt3Im9/ouLr5oiZl/kDS/ewBmzzDzmKTe1zCpoioG3tikBj X9UwDv6xQ/IpFOuiF3F5j2sAih1p0dZ4kmP3qOQkWBiXdBzsiqd5vijbajDVJBhI Mx0g== 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=fm3; t=1667684926; x=1667771326; bh=ZcG1ArcUeKGaZ d5PrcG3/1gsyCRPoz0HrnVVRDFda8o=; b=QxhX3TCnyL73D6/2ikOn311BWBU4F tyQcJAH7rIOr1ptw+OjFf5fdT8sZiNY42764LEbZIHxlLNfEr0fBw68M3a0k2y9P qlzX/A3NmkKqGnewHldOq0USkGFTCVwUbCrYEl6COC9/NKRnHDJ1wqNtzQIWKsrE tvhrjFfwb6cRRHyPlarOw2rL4TEdX7QfFW9MeM9I85BcXg3CLtt+IBY3YOIFap84 qhe+C2gY3aK+tOsIW11JwELtlk2fSnxe7Td25r1HS/Q/zI6HdZmqxNjYnHIXJNPK 8r4UwWO3ohG0tgHeYYY5KzzMynlsXo4x4a/TEEPEMYTQzJj2m2A3EzjSA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvgedrvdeggdefkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucggtf frrghtthgvrhhnpedukeetueduhedtleetvefguddvvdejhfefudelgfduveeggeehgfdu feeitdevteenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhg X-ME-Proxy: Feedback-ID: i0ad843c9:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 5 Nov 2022 17:48:45 -0400 (EDT) From: Samuel Holland To: Dmitry Osipenko , "Rafael J . Wysocki" , Mark Rutland , Lorenzo Pieralisi Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Samuel Holland Subject: [PATCH 1/2] kernel/reboot: Use the static sys-off handler for any priority Date: Sat, 5 Nov 2022 16:48:39 -0500 Message-Id: <20221105214841.7828-2-samuel@sholland.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221105214841.7828-1-samuel@sholland.org> References: <20221105214841.7828-1-samuel@sholland.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221105_144848_997055_3C449114 X-CRM114-Status: GOOD ( 13.27 ) 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, 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 Reviewed-by: Dmitry Osipenko --- 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);