[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251020100306.2709352-3-jasonmiu@google.com>
Date: Mon, 20 Oct 2025 03:03:05 -0700
From: Jason Miu <jasonmiu@...gle.com>
To: Alexander Graf <graf@...zon.com>, Andrew Morton <akpm@...ux-foundation.org>,
Baoquan He <bhe@...hat.com>, Changyuan Lyu <changyuanl@...gle.com>,
David Matlack <dmatlack@...gle.com>, David Rientjes <rientjes@...gle.com>,
Jason Gunthorpe <jgg@...dia.com>, Jason Miu <jasonmiu@...gle.com>, Mike Rapoport <rppt@...nel.org>,
Pasha Tatashin <pasha.tatashin@...een.com>, Pratyush Yadav <pratyush@...nel.org>,
kexec@...ts.infradead.org, linux-kernel@...r.kernel.org, linux-mm@...ck.org
Subject: [PATCH v2 2/3] memblock: kho: Remove KHO notifier usage
Remove the KHO notifier registration and callbacks from the memblock
subsystem. These notifiers were tied to the former KHO finalize and
abort events, which are no longer used.
Memblock now preserves its `reserve_mem` regions and registers its
metadata by calling kho_preserve_phys(), kho_preserve_folio(), and
kho_add_subtree() directly within its initialization function.
KHO selftest is also updated with this deprecation of notifier.
Signed-off-by: Jason Miu <jasonmiu@...gle.com>
---
include/linux/kexec_handover.h | 5 ++--
kernel/kexec_handover.c | 3 +-
lib/test_kho.c | 28 ++++---------------
mm/memblock.c | 45 +++++++-----------------------
tools/testing/selftests/kho/init.c | 19 -------------
5 files changed, 18 insertions(+), 82 deletions(-)
diff --git a/include/linux/kexec_handover.h b/include/linux/kexec_handover.h
index bc2f9e060a79..1f2ca09519a1 100644
--- a/include/linux/kexec_handover.h
+++ b/include/linux/kexec_handover.h
@@ -27,7 +27,7 @@ bool kho_is_enabled(void);
int kho_preserve_folio(struct folio *folio);
int kho_preserve_phys(phys_addr_t phys, size_t size);
struct folio *kho_restore_folio(phys_addr_t phys);
-int kho_add_subtree(struct kho_serialization *ser, const char *name, void *fdt);
+int kho_add_subtree(const char *name, void *fdt);
int kho_remove_subtree(const char *name);
int kho_retrieve_subtree(const char *name, phys_addr_t *phys);
@@ -59,8 +59,7 @@ static inline struct folio *kho_restore_folio(phys_addr_t phys)
return NULL;
}
-static inline int kho_add_subtree(struct kho_serialization *ser,
- const char *name, void *fdt)
+static inline int kho_add_subtree(const char *name, void *fdt)
{
return -EOPNOTSUPP;
}
diff --git a/kernel/kexec_handover.c b/kernel/kexec_handover.c
index 2fc5975690a7..1138b16fa546 100644
--- a/kernel/kexec_handover.c
+++ b/kernel/kexec_handover.c
@@ -688,7 +688,6 @@ static struct kho_out kho_out = {
/**
* kho_add_subtree - record the physical address of a sub FDT in KHO root tree.
- * @ser: serialization control object passed by KHO notifiers.
* @name: name of the sub tree.
* @fdt: the sub tree blob.
*
@@ -701,7 +700,7 @@ static struct kho_out kho_out = {
*
* Return: 0 on success, error code on failure
*/
-int kho_add_subtree(struct kho_serialization *ser, const char *name, void *fdt)
+int kho_add_subtree(const char *name, void *fdt)
{
void *root_fdt = page_to_virt(kho_out.ser.fdt);
u64 phys = (u64)virt_to_phys(fdt);
diff --git a/lib/test_kho.c b/lib/test_kho.c
index c2eb899c3b45..e4307587a713 100644
--- a/lib/test_kho.c
+++ b/lib/test_kho.c
@@ -38,33 +38,16 @@ struct kho_test_state {
static struct kho_test_state kho_test_state;
-static int kho_test_notifier(struct notifier_block *self, unsigned long cmd,
- void *v)
+static int kho_test_preserve(void)
{
- struct kho_test_state *state = &kho_test_state;
- struct kho_serialization *ser = v;
int err = 0;
- switch (cmd) {
- case KEXEC_KHO_ABORT:
- return NOTIFY_DONE;
- case KEXEC_KHO_FINALIZE:
- /* Handled below */
- break;
- default:
- return NOTIFY_BAD;
- }
-
- err |= kho_preserve_folio(state->fdt);
- err |= kho_add_subtree(ser, KHO_TEST_FDT, folio_address(state->fdt));
+ err |= kho_preserve_folio(kho_test_state.fdt);
+ err |= kho_add_subtree(KHO_TEST_FDT, folio_address(kho_test_state.fdt));
- return err ? NOTIFY_BAD : NOTIFY_DONE;
+ return err;
}
-static struct notifier_block kho_test_nb = {
- .notifier_call = kho_test_notifier,
-};
-
static int kho_test_save_data(struct kho_test_state *state, void *fdt)
{
phys_addr_t *folios_info __free(kvfree) = NULL;
@@ -191,7 +174,7 @@ static int kho_test_save(void)
if (err)
return err;
- return register_kho_notifier(&kho_test_nb);
+ return kho_test_preserve();
}
static int kho_test_restore_data(const void *fdt, int node)
@@ -295,7 +278,6 @@ static void kho_test_cleanup(void)
static void __exit kho_test_exit(void)
{
- unregister_kho_notifier(&kho_test_nb);
kho_test_cleanup();
}
module_exit(kho_test_exit);
diff --git a/mm/memblock.c b/mm/memblock.c
index 117d963e677c..602a16cb467a 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -2510,39 +2510,6 @@ int reserve_mem_release_by_name(const char *name)
#define RESERVE_MEM_KHO_NODE_COMPATIBLE "reserve-mem-v1"
static struct page *kho_fdt;
-static int reserve_mem_kho_finalize(struct kho_serialization *ser)
-{
- int err = 0, i;
-
- for (i = 0; i < reserved_mem_count; i++) {
- struct reserve_mem_table *map = &reserved_mem_table[i];
-
- err |= kho_preserve_phys(map->start, map->size);
- }
-
- err |= kho_preserve_folio(page_folio(kho_fdt));
- err |= kho_add_subtree(ser, MEMBLOCK_KHO_FDT, page_to_virt(kho_fdt));
-
- return notifier_from_errno(err);
-}
-
-static int reserve_mem_kho_notifier(struct notifier_block *self,
- unsigned long cmd, void *v)
-{
- switch (cmd) {
- case KEXEC_KHO_FINALIZE:
- return reserve_mem_kho_finalize((struct kho_serialization *)v);
- case KEXEC_KHO_ABORT:
- return NOTIFY_DONE;
- default:
- return NOTIFY_BAD;
- }
-}
-
-static struct notifier_block reserve_mem_kho_nb = {
- .notifier_call = reserve_mem_kho_notifier,
-};
-
static int __init prepare_kho_fdt(void)
{
int err = 0, i;
@@ -2583,7 +2550,7 @@ static int __init prepare_kho_fdt(void)
static int __init reserve_mem_init(void)
{
- int err;
+ int err, i;
if (!kho_is_enabled() || !reserved_mem_count)
return 0;
@@ -2592,7 +2559,15 @@ static int __init reserve_mem_init(void)
if (err)
return err;
- err = register_kho_notifier(&reserve_mem_kho_nb);
+ for (i = 0; i < reserved_mem_count; i++) {
+ struct reserve_mem_table *map = &reserved_mem_table[i];
+
+ err |= kho_preserve_phys(map->start, map->size);
+ }
+
+ err |= kho_preserve_folio(page_folio(kho_fdt));
+ err |= kho_add_subtree(MEMBLOCK_KHO_FDT, page_to_virt(kho_fdt));
+
if (err) {
put_page(kho_fdt);
kho_fdt = NULL;
diff --git a/tools/testing/selftests/kho/init.c b/tools/testing/selftests/kho/init.c
index 8034e24c6bf6..211d6bda8961 100644
--- a/tools/testing/selftests/kho/init.c
+++ b/tools/testing/selftests/kho/init.c
@@ -27,22 +27,6 @@ static int mount_filesystems(void)
return mount("proc", "/proc", "proc", 0, NULL);
}
-static int kho_enable(void)
-{
- const char enable[] = "1";
- int fd;
-
- fd = open(KHO_FINILIZE, O_RDWR);
- if (fd < 0)
- return -1;
-
- if (write(fd, enable, sizeof(enable)) != sizeof(enable))
- return 1;
-
- close(fd);
- return 0;
-}
-
static long kexec_file_load(int kernel_fd, int initrd_fd,
unsigned long cmdline_len, const char *cmdline,
unsigned long flags)
@@ -83,9 +67,6 @@ int main(int argc, char *argv[])
if (mount_filesystems())
goto err_reboot;
- if (kho_enable())
- goto err_reboot;
-
if (kexec_load())
goto err_reboot;
--
2.51.0.858.gf9c4a03a3a-goog
Powered by blists - more mailing lists