From: Andrey Ryabinin <arbn@yandex-team.com>
To: linux-kernel@vger.kernel.org
Cc: Alexander Graf <graf@amazon.com>, Mike Rapoport <rppt@kernel.org>,
James Gowans <jgowans@amazon.com>,
Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Baoquan He <bhe@redhat.com>,
kexec@lists.infradead.org, Pratyush Yadav <ptyadav@amazon.de>,
Jason Gunthorpe <jgg@nvidia.com>,
Pasha Tatashin <pasha.tatashin@soleen.com>,
David Rientjes <rientjes@google.com>,
Pratyush Yadav <pratyush@kernel.org>,
Changyuan Lyu <changyuanl@google.com>,
Jonathan Corbet <corbet@lwn.net>,
linux-doc@vger.kernel.org,
Andrey Ryabinin <ryabinin.a.a@gmail.com>,
Chris Li <chrisl@kernel.org>,
Ashish.Kalra@amd.com, William Tu <witu@nvidia.com>,
David Matlack <dmatlack@google.com>,
Andrey Ryabinin <arbn@yandex-team.com>,
Rob Herring <robh@kernel.org>,
Saravana Kannan <saravanak@google.com>,
devicetree@vger.kernel.org
Subject: [PATCH v3 4/7] kho: replace KHO FDT with kstate metadata
Date: Tue, 9 Sep 2025 22:14:39 +0200 [thread overview]
Message-ID: <20250909201446.13138-5-arbn@yandex-team.com> (raw)
In-Reply-To: <20250909201446.13138-1-arbn@yandex-team.com>
Store KSTATE physical address & size instead of FDT in kho_data.
and initialize KSTATE from kho_populate().
To be able to use FDT in parallel with KSTATE place FDT
address&size into 'struct kho_fdt' and save/restore it using KSTATE.
This finishes wiring KSTATE with KHO, making it fully functional.
Signed-off-by: Andrey Ryabinin <arbn@yandex-team.com>
---
arch/x86/include/uapi/asm/setup_data.h | 4 +-
arch/x86/kernel/kexec-bzimage64.c | 6 +--
arch/x86/kernel/setup.c | 3 +-
drivers/of/fdt.c | 6 +--
include/linux/kexec.h | 2 +-
include/linux/kstate.h | 1 +
kernel/liveupdate/kexec_handover.c | 60 +++++++++++++++++++++-----
7 files changed, 61 insertions(+), 21 deletions(-)
diff --git a/arch/x86/include/uapi/asm/setup_data.h b/arch/x86/include/uapi/asm/setup_data.h
index 2671c4e1b3a0..844f5b93473f 100644
--- a/arch/x86/include/uapi/asm/setup_data.h
+++ b/arch/x86/include/uapi/asm/setup_data.h
@@ -83,8 +83,8 @@ struct ima_setup_data {
* Locations of kexec handover metadata
*/
struct kho_data {
- __u64 fdt_addr;
- __u64 fdt_size;
+ __u64 kstate_addr;
+ __u64 kstate_size;
__u64 scratch_addr;
__u64 scratch_size;
} __attribute__((packed));
diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c
index 24a41f0e0cf1..1bf9474d4286 100644
--- a/arch/x86/kernel/kexec-bzimage64.c
+++ b/arch/x86/kernel/kexec-bzimage64.c
@@ -253,12 +253,12 @@ static void setup_kho(const struct kimage *image, struct boot_params *params,
sd->len = sizeof(struct kho_data);
/* Only add if we have all KHO images in place */
- if (!image->kho.fdt || !image->kho.scratch)
+ if (!image->kho.kstate || !image->kho.scratch)
return;
/* Add setup data */
- kho->fdt_addr = image->kho.fdt;
- kho->fdt_size = PAGE_SIZE;
+ kho->kstate_addr = image->kho.kstate;
+ kho->kstate_size = PAGE_SIZE;
kho->scratch_addr = image->kho.scratch->mem;
kho->scratch_size = image->kho.scratch->bufsz;
sd->next = params->hdr.setup_data;
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 1b2edd07a3e1..eedcf4be8985 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -467,7 +467,8 @@ static void __init add_kho(u64 phys_addr, u32 data_len)
return;
}
- kho_populate(kho->fdt_addr, kho->fdt_size, kho->scratch_addr, kho->scratch_size);
+ kho_populate(kho->kstate_addr, kho->kstate_size, kho->scratch_addr,
+ kho->scratch_size);
early_memunmap(kho, size);
}
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 0edd639898a6..f682ef6a1187 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -893,8 +893,8 @@ static void __init early_init_dt_check_kho(void)
if (l != (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32))
return;
- fdt_start = dt_mem_next_cell(dt_root_addr_cells, &p);
- fdt_size = dt_mem_next_cell(dt_root_addr_cells, &p);
+ kstate_start = dt_mem_next_cell(dt_root_addr_cells, &p);
+ kstate_size = dt_mem_next_cell(dt_root_addr_cells, &p);
p = of_get_flat_dt_prop(node, "linux,kho-scratch", &l);
if (l != (dt_root_addr_cells + dt_root_size_cells) * sizeof(__be32))
@@ -903,7 +903,7 @@ static void __init early_init_dt_check_kho(void)
scratch_start = dt_mem_next_cell(dt_root_addr_cells, &p);
scratch_size = dt_mem_next_cell(dt_root_addr_cells, &p);
- kho_populate(fdt_start, fdt_size, scratch_start, scratch_size);
+ kho_populate(kstate_addr, kstate_size, scratch_start, scratch_size);
}
#ifdef CONFIG_SERIAL_EARLYCON
diff --git a/include/linux/kexec.h b/include/linux/kexec.h
index 39fe3e6cd282..ebf70361269f 100644
--- a/include/linux/kexec.h
+++ b/include/linux/kexec.h
@@ -416,7 +416,7 @@ struct kimage {
struct {
struct kexec_segment *scratch;
- phys_addr_t fdt;
+ phys_addr_t kstate;
} kho;
/* Core ELF header buffer */
diff --git a/include/linux/kstate.h b/include/linux/kstate.h
index 53992593cb19..5a95960e5b03 100644
--- a/include/linux/kstate.h
+++ b/include/linux/kstate.h
@@ -94,6 +94,7 @@ struct kstate_field {
enum kstate_ids {
KSTATE_FOLIO_ID = 1,
+ KSTATE_KHO_FDT_ID,
KSTATE_LAST_ID = -1,
};
diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c
index f1c6378b2657..216cb58553d6 100644
--- a/kernel/liveupdate/kexec_handover.c
+++ b/kernel/liveupdate/kexec_handover.c
@@ -806,6 +806,10 @@ int kho_abort(void)
goto unlock;
}
+ ret = kstate_abort();
+ if (ret)
+ goto unlock;
+
ret = __kho_abort();
if (ret)
goto unlock;
@@ -984,6 +988,25 @@ int kho_retrieve_subtree(const char *name, phys_addr_t *phys)
}
EXPORT_SYMBOL_GPL(kho_retrieve_subtree);
+
+#define KHO_FDT_INSTANCE_ID 1
+
+static struct kho_fdt {
+ phys_addr_t fdt_phys;
+ u64 fdt_len;
+} kho_fdt;
+
+struct kstate_description kho_fdt_state = {
+ .name = "kho_fdt",
+ .version_id = 1,
+ .id = KSTATE_KHO_FDT_ID,
+ .fields = (const struct kstate_field[]) {
+ KSTATE_BASE_TYPE(fdt_phys, struct kho_fdt, phys_addr_t),
+ KSTATE_BASE_TYPE(fdt_len, struct kho_fdt, u64),
+ KSTATE_END_OF_LIST()
+ },
+};
+
static __init int kho_init(void)
{
int err = 0;
@@ -1000,13 +1023,20 @@ static __init int kho_init(void)
}
kho_out.fdt = page_to_virt(fdt_page);
- err = kho_debugfs_init();
+ err = kstate_register(&kho_fdt_state, &kho_fdt, KHO_FDT_INSTANCE_ID);
if (err)
goto err_free_fdt;
+ kho_fdt.fdt_phys = page_to_phys(fdt_page);
+ kho_fdt.fdt_len = PAGE_SIZE;
+
+ err = kho_debugfs_init();
+ if (err)
+ goto err_free_kstate;
+
err = kho_out_debugfs_init(&kho_out.dbg);
if (err)
- goto err_free_fdt;
+ goto err_free_kstate;
if (fdt) {
kho_in_debugfs_init(&kho_in.dbg, fdt);
@@ -1025,6 +1055,8 @@ static __init int kho_init(void)
return 0;
+err_free_kstate:
+ kstate_unregister(&kho_fdt_state, &kho_fdt, KHO_FDT_INSTANCE_ID);
err_free_fdt:
put_page(fdt_page);
kho_out.fdt = NULL;
@@ -1165,24 +1197,30 @@ static int __init kho_scratch_init(phys_addr_t scratch_phys, u64 scratch_len)
return err;
}
-void __init kho_populate(phys_addr_t fdt_phys, u64 fdt_len,
- phys_addr_t scratch_phys, u64 scratch_len)
+void __init kho_populate(phys_addr_t kstate_phys, u64 kstate_len,
+ phys_addr_t scratch_phys, u64 scratch_len)
{
-
int err = 0;
- unsigned int scratch_cnt = scratch_len / sizeof(*kho_scratch);
- err = kho_fdt_init(fdt_phys, fdt_len);
+ err = kho_scratch_init(scratch_phys, scratch_len);
if (err)
goto out;
- err = kho_scratch_init(scratch_phys, scratch_len);
+ err = kstate_early_init(kstate_phys, kstate_len);
+ if (err)
+ goto out;
+
+ err = kstate_restore(&kho_fdt_state, &kho_fdt, KHO_FDT_INSTANCE_ID);
+ if (err)
+ goto out;
+
+ err = kho_fdt_init(kho_fdt.fdt_phys, kho_fdt.fdt_len);
if (err)
goto out;
- kho_in.fdt_phys = fdt_phys;
+ kho_in.fdt_phys = kho_fdt.fdt_phys;
kho_in.scratch_phys = scratch_phys;
- kho_scratch_cnt = scratch_cnt;
+ kho_scratch_cnt = scratch_len / sizeof(*kho_scratch);
pr_info("found kexec handover data. Will skip init for some devices\n");
out:
@@ -1201,7 +1239,7 @@ int kho_fill_kimage(struct kimage *image)
if (!kho_enable)
return 0;
- image->kho.fdt = virt_to_phys(kho_out.fdt);
+ image->kho.kstate = kstate_out_paddr;
scratch_size = sizeof(*kho_scratch) * kho_scratch_cnt;
scratch = (struct kexec_buf){
--
2.49.1
next prev parent reply other threads:[~2025-09-09 20:15 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-09 20:14 [PATCH v3 0/7] KSTATE: [de]serialization framework for KHO Andrey Ryabinin
2025-09-09 20:14 ` [PATCH v3 1/7] kho: move fdt setup in separate helper Andrey Ryabinin
2025-09-09 20:14 ` [PATCH v3 2/7] kho: move scratch memory " Andrey Ryabinin
2025-09-09 20:14 ` [PATCH v3 3/7] kstate: Add KSTATE - [de]serialization framework for KHO Andrey Ryabinin
2025-09-09 20:14 ` Andrey Ryabinin [this message]
2025-09-10 16:50 ` [PATCH v3 4/7] kho: replace KHO FDT with kstate metadata Rob Herring
2025-09-11 16:54 ` Andrey Ryabinin
2025-09-09 20:14 ` [PATCH v3 5/7] kstate, test: add test module for testing kstate subsystem Andrey Ryabinin
2025-09-10 0:33 ` Randy Dunlap
2025-09-11 17:00 ` Andrey Ryabinin
2025-09-09 20:14 ` [PATCH v3 6/7] mm/memblock: Use KSTATE instead of kho to preserve preserved_mem_table Andrey Ryabinin
2025-09-15 11:47 ` Jason Gunthorpe
2025-09-18 19:00 ` Andrey Ryabinin
2025-09-18 23:14 ` Jason Gunthorpe
2025-09-09 20:14 ` [PATCH v3 7/7] Documentation, kstate: Add KSTATE documentation Andrey Ryabinin
2025-09-10 0:53 ` Bagas Sanjaya
2025-09-11 17:07 ` Andrey Ryabinin
2025-09-10 1:00 ` Randy Dunlap
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=20250909201446.13138-5-arbn@yandex-team.com \
--to=arbn@yandex-team.com \
--cc=Ashish.Kalra@amd.com \
--cc=akpm@linux-foundation.org \
--cc=bhe@redhat.com \
--cc=bp@alien8.de \
--cc=changyuanl@google.com \
--cc=chrisl@kernel.org \
--cc=corbet@lwn.net \
--cc=dave.hansen@linux.intel.com \
--cc=devicetree@vger.kernel.org \
--cc=dmatlack@google.com \
--cc=graf@amazon.com \
--cc=hpa@zytor.com \
--cc=jgg@nvidia.com \
--cc=jgowans@amazon.com \
--cc=kexec@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mingo@redhat.com \
--cc=pasha.tatashin@soleen.com \
--cc=pratyush@kernel.org \
--cc=ptyadav@amazon.de \
--cc=rientjes@google.com \
--cc=robh@kernel.org \
--cc=rppt@kernel.org \
--cc=ryabinin.a.a@gmail.com \
--cc=saravanak@google.com \
--cc=tglx@linutronix.de \
--cc=witu@nvidia.com \
--cc=x86@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