mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chris Down <chris@chrisdown.name>
To: rppt@kernel.org, pasha.tatashin@soleen.com, pratyush@kernel.org
Cc: graf@amazon.com, kexec@lists.infradead.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, kernel-team@meta.com
Subject: [PATCH v2 1/2] kho: skip bootmem setup in kho_init() if bootmem was inherited
Date: Tue, 01 Dec 2026 22:32:09 -0800	[thread overview]
Message-ID: <ac61194cf889a29d390438b68ee9fd30e28d468b.1796126791.git.chris@chrisdown.name> (raw)
In-Reply-To: <cover.1796126791.git.chris@chrisdown.name>

On a cold boot, kho_reserve_bootmem() reserves the bootmem areas in
memblock, and kho_init() later releases them to the page allocator as
CMA. A kernel that was handed its bootmem areas by the previous kernel
boots out of them instead. kho_init() must leave them alone.

kho_init() tells the two cases apart by whether there is a handover
FDT. That doesn't work if kho_mem_retrieve() fails. It clears
kho_in.fdt_phys so that KHO users don't treat the boot as a KHO boot,
but the bootmem areas are still the inherited ones. kho_init() would
then run init_cma_reserved_pageblock() over memory that is in use.

Nothing makes kho_mem_retrieve() fail at the moment, but the next
patch does. Test kho_in.bootmem_phys instead, which is what
kho_memory_init() uses to choose between retrieving the handover and
reserving new bootmem areas.

Signed-off-by: Chris Down <chris@chrisdown.name>
---
 kernel/liveupdate/kho_core.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/kernel/liveupdate/kho_core.c b/kernel/liveupdate/kho_core.c
index 15fb892a4412..43ecef317cfd 100644
--- a/kernel/liveupdate/kho_core.c
+++ b/kernel/liveupdate/kho_core.c
@@ -1928,10 +1928,16 @@ static __init int kho_init(void)
 	if (err)
 		goto err_free_fdt;
 
-	if (fdt) {
+	if (fdt)
 		kho_in_debugfs_init(&kho_in.dbg, fdt);
+
+	/*
+	 * We've booted from the inherited bootmem. That means this kernel is
+	 * already using it. As such, leave it alone even if the handover is
+	 * dropped later.
+	 */
+	if (kho_in.bootmem_phys)
 		return 0;
-	}
 
 	for (int i = 0; i < kho_bootmem_cnt; i++) {
 		unsigned long base_pfn = PHYS_PFN(kho_bootmem[i].addr);
-- 
2.56.1


  reply	other threads:[~2026-12-02  6:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  6:32 [PATCH v2 0/2] kho: handle failures to reserve preserved memory Chris Down
2026-12-02  6:32 ` Chris Down [this message]
2026-12-02  6:32 ` [PATCH v2 2/2] kho: drop the handover if preserved memory can't be reserved Chris Down

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=ac61194cf889a29d390438b68ee9fd30e28d468b.1796126791.git.chris@chrisdown.name \
    --to=chris@chrisdown.name \
    --cc=graf@amazon.com \
    --cc=kernel-team@meta.com \
    --cc=kexec@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=pasha.tatashin@soleen.com \
    --cc=pratyush@kernel.org \
    --cc=rppt@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

all inboxes | Powered by JetHome®