From: Pasha Tatashin <pasha.tatashin@soleen.com>
To: akpm@linux-foundation.org, brauner@kernel.org, corbet@lwn.net,
graf@amazon.com, jgg@ziepe.ca, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-mm@kvack.org,
masahiroy@kernel.org, ojeda@kernel.org,
pasha.tatashin@soleen.com, pratyush@kernel.org,
rdunlap@infradead.org, rppt@kernel.org, tj@kernel.org,
jasonmiu@google.com, dmatlack@google.com, skhawaja@google.com
Subject: [PATCH v6 01/10] kho: allow to drive kho from within kernel
Date: Sat, 18 Oct 2025 13:17:47 -0400 [thread overview]
Message-ID: <20251018171756.1724191-2-pasha.tatashin@soleen.com> (raw)
In-Reply-To: <20251018171756.1724191-1-pasha.tatashin@soleen.com>
Allow to do finalize and abort from kernel modules, so LUO could
drive the KHO sequence via its own state machine.
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Reviewed-by: Pratyush Yadav <pratyush@kernel.org>
---
include/linux/kexec_handover.h | 15 +++++++
kernel/kexec_handover.c | 74 ++++++++++++++++++++--------------
2 files changed, 59 insertions(+), 30 deletions(-)
diff --git a/include/linux/kexec_handover.h b/include/linux/kexec_handover.h
index 25042c1d8d54..04d0108db98e 100644
--- a/include/linux/kexec_handover.h
+++ b/include/linux/kexec_handover.h
@@ -67,6 +67,10 @@ void kho_memory_init(void);
void kho_populate(phys_addr_t fdt_phys, u64 fdt_len, phys_addr_t scratch_phys,
u64 scratch_len);
+
+int kho_finalize(void);
+int kho_abort(void);
+
#else
static inline bool kho_is_enabled(void)
{
@@ -139,6 +143,17 @@ static inline void kho_populate(phys_addr_t fdt_phys, u64 fdt_len,
phys_addr_t scratch_phys, u64 scratch_len)
{
}
+
+static inline int kho_finalize(void)
+{
+ return -EOPNOTSUPP;
+}
+
+static inline int kho_abort(void)
+{
+ return -EOPNOTSUPP;
+}
+
#endif /* CONFIG_KEXEC_HANDOVER */
#endif /* LINUX_KEXEC_HANDOVER_H */
diff --git a/kernel/kexec_handover.c b/kernel/kexec_handover.c
index 76f0940fb485..76c34ea923f0 100644
--- a/kernel/kexec_handover.c
+++ b/kernel/kexec_handover.c
@@ -1067,7 +1067,7 @@ static int kho_out_update_debugfs_fdt(void)
return err;
}
-static int kho_abort(void)
+static int __kho_abort(void)
{
int err;
unsigned long order;
@@ -1100,7 +1100,27 @@ static int kho_abort(void)
return err;
}
-static int kho_finalize(void)
+int kho_abort(void)
+{
+ int ret = 0;
+
+ if (!kho_enable)
+ return -EOPNOTSUPP;
+
+ guard(mutex)(&kho_out.lock);
+ if (!kho_out.finalized)
+ return -ENOENT;
+
+ ret = __kho_abort();
+ if (ret)
+ return ret;
+
+ kho_out.finalized = false;
+
+ return kho_out_update_debugfs_fdt();
+}
+
+static int __kho_finalize(void)
{
int err = 0;
u64 *preserved_mem_map;
@@ -1143,12 +1163,32 @@ static int kho_finalize(void)
abort:
if (err) {
pr_err("Failed to convert KHO state tree: %d\n", err);
- kho_abort();
+ __kho_abort();
}
return err;
}
+int kho_finalize(void)
+{
+ int ret;
+
+ if (!kho_enable)
+ return -EOPNOTSUPP;
+
+ guard(mutex)(&kho_out.lock);
+ if (kho_out.finalized)
+ return -EEXIST;
+
+ ret = __kho_finalize();
+ if (ret)
+ return ret;
+
+ kho_out.finalized = true;
+
+ return kho_out_update_debugfs_fdt();
+}
+
static int kho_out_finalize_get(void *data, u64 *val)
{
mutex_lock(&kho_out.lock);
@@ -1160,33 +1200,7 @@ static int kho_out_finalize_get(void *data, u64 *val)
static int kho_out_finalize_set(void *data, u64 _val)
{
- int ret = 0;
- bool val = !!_val;
-
- mutex_lock(&kho_out.lock);
-
- if (val == kho_out.finalized) {
- if (kho_out.finalized)
- ret = -EEXIST;
- else
- ret = -ENOENT;
- goto unlock;
- }
-
- if (val)
- ret = kho_finalize();
- else
- ret = kho_abort();
-
- if (ret)
- goto unlock;
-
- kho_out.finalized = val;
- ret = kho_out_update_debugfs_fdt();
-
-unlock:
- mutex_unlock(&kho_out.lock);
- return ret;
+ return (!!_val) ? kho_finalize() : kho_abort();
}
DEFINE_DEBUGFS_ATTRIBUTE(fops_kho_out_finalize, kho_out_finalize_get,
--
2.51.0.915.g61a8936c21-goog
next prev parent reply other threads:[~2025-10-18 17:18 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-18 17:17 [PATCH v6 00/10] liveupdate: Rework KHO for in-kernel users & Fix memory corruption Pasha Tatashin
2025-10-18 17:17 ` Pasha Tatashin [this message]
2025-10-20 7:43 ` [PATCH v6 01/10] kho: allow to drive kho from within kernel Mike Rapoport
2025-10-21 16:08 ` Pasha Tatashin
2025-10-18 17:17 ` [PATCH v6 02/10] kho: make debugfs interface optional Pasha Tatashin
2025-10-18 17:17 ` [PATCH v6 03/10] kho: drop notifiers Pasha Tatashin
2025-10-18 17:17 ` [PATCH v6 04/10] kho: add interfaces to unpreserve folios and page ranes Pasha Tatashin
2025-10-18 17:17 ` [PATCH v6 05/10] kho: don't unpreserve memory during abort Pasha Tatashin
2025-10-18 17:17 ` [PATCH v6 06/10] liveupdate: kho: move to kernel/liveupdate Pasha Tatashin
2025-10-18 17:17 ` [PATCH v6 07/10] kho: move kho debugfs directory to liveupdate Pasha Tatashin
2025-10-18 17:17 ` [PATCH v6 08/10] liveupdate: kho: warn and fail on metadata or preserved memory in scratch area Pasha Tatashin
2025-10-20 7:56 ` Mike Rapoport
2025-10-20 21:56 ` Pasha Tatashin
2025-10-18 17:17 ` [PATCH v6 09/10] liveupdate: kho: Increase metadata bitmap size to PAGE_SIZE Pasha Tatashin
2025-10-20 8:03 ` Mike Rapoport
2025-10-20 22:09 ` Pasha Tatashin
2025-10-18 17:17 ` [PATCH v6 10/10] liveupdate: kho: allocate metadata directly from the buddy allocator Pasha Tatashin
2025-10-20 8:05 ` Mike Rapoport
2025-10-20 22:17 ` Pasha Tatashin
2025-10-20 8:34 ` [PATCH v6 00/10] liveupdate: Rework KHO for in-kernel users & Fix memory corruption Mike Rapoport
2025-10-20 13:46 ` Pasha Tatashin
2025-10-20 13:47 ` Pasha Tatashin
2025-10-20 18:12 ` Mike Rapoport
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=20251018171756.1724191-2-pasha.tatashin@soleen.com \
--to=pasha.tatashin@soleen.com \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=corbet@lwn.net \
--cc=dmatlack@google.com \
--cc=graf@amazon.com \
--cc=jasonmiu@google.com \
--cc=jgg@ziepe.ca \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=masahiroy@kernel.org \
--cc=ojeda@kernel.org \
--cc=pratyush@kernel.org \
--cc=rdunlap@infradead.org \
--cc=rppt@kernel.org \
--cc=skhawaja@google.com \
--cc=tj@kernel.org \
/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