From: Samuel Holland <samuel@sholland.org>
To: Mark Rutland <mark.rutland@arm.com>,
Lorenzo Pieralisi <lpieralisi@kernel.org>,
Sudeep Holla <sudeep.holla@arm.com>,
Dmitry Osipenko <dmitry.osipenko@collabora.com>,
"Rafael J . Wysocki" <rafael.j.wysocki@intel.com>
Cc: Samuel Holland <samuel@sholland.org>,
John Ogness <john.ogness@linutronix.de>,
Kai-Heng Feng <kai.heng.feng@canonical.com>,
Luis Chamberlain <mcgrof@kernel.org>,
Petr Mladek <pmladek@suse.com>,
YueHaibing <yuehaibing@huawei.com>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, tangmeng <tangmeng@uniontech.com>
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 [thread overview]
Message-ID: <20230101181715.42199-2-samuel@sholland.org> (raw)
In-Reply-To: <20230101181715.42199-1-samuel@sholland.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 <dmitry.osipenko@collabora.com>
Signed-off-by: Samuel Holland <samuel@sholland.org>
---
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);
--
2.37.4
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2023-01-01 18:20 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-01 18:17 [PATCH v2 0/2] firmware/psci: Switch to the sys-off handler API Samuel Holland
2023-01-01 18:17 ` Samuel Holland [this message]
2023-01-01 18:17 ` [PATCH v2 2/2] " Samuel Holland
2023-01-25 16:50 ` Sudeep Holla
2023-01-25 12:53 ` [PATCH v2 0/2] " Dmitry Osipenko
2023-02-07 3:32 ` Samuel Holland
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230101181715.42199-2-samuel@sholland.org \
--to=samuel@sholland.org \
--cc=dmitry.osipenko@collabora.com \
--cc=john.ogness@linutronix.de \
--cc=kai.heng.feng@canonical.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=mark.rutland@arm.com \
--cc=mcgrof@kernel.org \
--cc=pmladek@suse.com \
--cc=rafael.j.wysocki@intel.com \
--cc=sudeep.holla@arm.com \
--cc=tangmeng@uniontech.com \
--cc=yuehaibing@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox