From: "Jose A. Perez de Azpillaga" <azpijr@gmail.com>
To: Mike Rapoport <rppt@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Kees Cook <kees@kernel.org>, Alexander Graf <graf@amazon.com>,
Changyuan Lyu <changyuanl@google.com>
Cc: Tony Luck <tony.luck@intel.com>,
"Guilherme G. Piccoli" <gpiccoli@igalia.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Pratyush Yadav <pratyush@kernel.org>,
Pasha Tatashin <pasha.tatashin@soleen.com>,
kexec@lists.infradead.org,
"Jose A. Perez de Azpillaga" <azpijr@gmail.com>
Subject: [RFC PATCH 2/2] memblock: don't allocate reserve_mem regions from KHO bootmem
Date: Wed, 21 Oct 2026 23:10:46 +0200 [thread overview]
Message-ID: <20261021211058.83483-3-azpijr@gmail.com> (raw)
In-Reply-To: <20261021211058.83483-1-azpijr@gmail.com>
On a KHO boot, a reserve_mem region that can't be revived is allocated
from KHO_NOPRSRV memory, which includes the bootmem the next kernel
boots out of. With CONFIG_KEXEC_HANDOVER_DEBUG, preserving the region
then fails:
WARNING: kernel/liveupdate/kexec_handover.c:1245 at kho_preserve_pages+0x168/0x180
failed to prepare memblock FDT for KHO: -22
Without it, the next kernel puts its memmap on top of the region and
the ramoops records in it are lost.
Use the search that keeps HugeTLB pages out of bootmem, and keep the
mirrored memory fallback of memblock_phys_alloc().
Fixes: f99230780211 ("memblock: add KHO support for reserve_mem")
Signed-off-by: Jose A. Perez de Azpillaga <azpijr@gmail.com>
---
mm/memblock.c | 30 ++++++++++++++++++++++++++++--
1 file changed, 28 insertions(+), 2 deletions(-)
diff --git a/mm/memblock.c b/mm/memblock.c
index f43659688681..0fa9d6529285 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -2761,6 +2761,33 @@ static bool __init reserve_mem_kho_revive(const char *name, phys_addr_t size,
}
#endif /* CONFIG_KEXEC_HANDOVER */
+/*
+ * The region gets preserved with KHO, so it can't be in KHO bootmem. On a KHO
+ * boot only KHO_NOPRSRV memory is used at this point, and that is more than
+ * just bootmem.
+ */
+static phys_addr_t __init reserve_mem_alloc(phys_addr_t size, phys_addr_t align)
+{
+ enum memblock_flags flags = choose_memblock_flags();
+ phys_addr_t start;
+
+ start = memblock_find_outside_kho_bootmem(size, align, NUMA_NO_NODE,
+ flags);
+ if (!start && (flags & MEMBLOCK_MIRROR)) {
+ pr_warn("Could not allocate %pap bytes of mirrored memory\n",
+ &size);
+ start = memblock_find_outside_kho_bootmem(size, align,
+ NUMA_NO_NODE,
+ flags & ~MEMBLOCK_MIRROR);
+ }
+
+ if (!start || memblock_reserve_kern(start, size))
+ return 0;
+
+ memblock_prep_allocation(start, size, true);
+ return start;
+}
+
/*
* Parse reserve_mem=nn:align:name
*/
@@ -2829,8 +2856,7 @@ static int __init reserve_mem(char *p)
if (reserve_mem_kho_revive(name, size, align))
return 1;
- /* TODO: Allocation must be outside of KHO_NOPRSRV region */
- start = memblock_phys_alloc(size, align);
+ start = reserve_mem_alloc(size, align);
if (!start) {
pr_err("reserve_mem: memblock allocation failed\n");
return -ENOMEM;
--
2.55.0
prev parent reply other threads:[~2026-10-21 21:11 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-21 21:10 [RFC PATCH 0/2] memblock: keep reserve_mem regions out of " Jose A. Perez de Azpillaga
2026-10-21 21:10 ` [RFC PATCH 1/2] memblock: factor out the KHO bootmem check from memblock_alloc_hugetlb() Jose A. Perez de Azpillaga
2026-10-21 21:10 ` Jose A. Perez de Azpillaga [this message]
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=20261021211058.83483-3-azpijr@gmail.com \
--to=azpijr@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=changyuanl@google.com \
--cc=gpiccoli@igalia.com \
--cc=graf@amazon.com \
--cc=kees@kernel.org \
--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 \
--cc=tony.luck@intel.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
all inboxes | Powered by JetHome®