From: Pratyush Yadav <pratyush@kernel.org>
To: Breno Leitao <leitao@debian.org>
Cc: Pratyush Yadav <pratyush@kernel.org>,
Pasha Tatashin <pasha.tatashin@soleen.com>,
akpm@linux-foundation.org, rppt@kernel.org, graf@amazon.com,
linux-kernel@vger.kernel.org, kexec@lists.infradead.org,
linux-mm@kvack.org, ricardo.neri-calderon@linux.intel.com,
kernel-team@meta.com
Subject: Re: [PATCH v4] kho: validate preserved memory map during population
Date: Tue, 20 Jan 2026 15:10:05 +0000 [thread overview]
Message-ID: <2vxzzf68e2wi.fsf@kernel.org> (raw)
In-Reply-To: <z2lraqiivexvfvokff4gmqyvbpswmfwhbkhv4u7lo3nnnyz346@mibnt7dkrvey> (Breno Leitao's message of "Mon, 19 Jan 2026 10:54:09 -0800")
On Mon, Jan 19 2026, Breno Leitao wrote:
> On Fri, Jan 16, 2026 at 04:21:28PM +0000, Pratyush Yadav wrote:
>> > On Tue, Dec 23, 2025 at 09:01:40AM -0500, Pasha Tatashin wrote:
>> >> If the previous kernel enabled KHO but did not call kho_finalize()
>> >> (e.g., CONFIG_LIVEUPDATE=n or userspace skipped the finalization step),
>> >> the 'preserved-memory-map' property in the FDT remains empty/zero.
>> >>
>> >> Previously, kho_populate() would succeed regardless of the memory map's
>> >> state, reserving the incoming scratch regions in memblock. However,
>> >> kho_memory_init() would later fail to deserialize the empty map. By that
>> >> time, the scratch regions were already registered, leading to partial
>> >> initialization and subsequent list corruption (freeing scratch area
>> >> twice) during kho_init().
>> >
>> > While trying my new patchset [0] on top of this patch, I got the
>> > following issue:
>> >
>> > [ 0.000000] KHO: disabling KHO revival: -2
>> >
>> > Trying to solve it, I come up with a change in kho_get_mem_map_phys() to
>> > distinguish no memory and error, see the patch attached later.
>> >
>> > This is what I used to test [0] on top of linux-next. Is this useful?
>> >
>> > Link: https://lore.kernel.org/all/20260108-kho-v3-1-b1d6b7a89342@debian.org/ [0]
>> >
>> > thanks
>> > --breno
>> >
>> > commit 5d7855fede8110d74942e1b67056ba589a1cb54a
>> > Author: Breno Leitao <leitao@debian.org>
>> > Date: Thu Jan 8 07:44:08 2026 -0800
>> >
>> > kho: allow KHO to work when no memory is preserved
>> >
>> > Fix KHO initialization failing when no memory pages were preserved by
>> > the previous kernel.
>> >
>> > Commit eda79a683a0a ("kho: validate preserved memory map during
>> > population") introduced kho_get_mem_map_phys() which returns the physical
>> > address of the preserved memory map directly as its return value. The
>> > caller then validates it with:
>> >
>> > mem_map_phys = kho_get_mem_map_phys(fdt);
>> > if (!mem_map_phys) {
>> > err = -ENOENT;
>> > goto out;
>> > }
>> >
>> > This creates an ambiguity: physical address 0 is used both as an error
>> > indicator (property missing/malformed) and as a valid value (property
>> > exists with value 0, meaning no memory was preserved).
>> >
>> > "No memory preserved" is a legitimate state. KHO provides features beyond
>> > memory page preservation, such as previous kernel version tracking and
>> > kexec count tracking. When the previous kernel enables KHO but doesn't
>> > preserve any memory pages, it sets 'preserved-memory-map' to 0. This is
>> > semantically different from "KHO not initialized" - it means "KHO is
>> > active, there's just nothing in the memory map."
>>
>> This isn't true. If you hand over _any_ state, you will at least need
>> the KHO FDT. And the KHO FDT is preserved memory (see the
>> kho_alloc_preserve() call in kho_init()). So I don't see how you can
>> ever have valid KHO with no memory.
>>
>> mem_map_phys _can_ be 0, but only when KHO was enabled but not used. And
>> that is of course also a valid use case.
>
> Oh, I was not finalizing KHO, and in commit e1c3bfd091f363c1
> ("kho: validate preserved memory map during population") started to fail this
> on purpose.
>
> So, I understand we want to fail if mem_map_phys = 0, but thn FDT was properly
> passed (how is it possible)? I know I can read
> KHO_PROP_PREVIOUS_RELEASE/KHO_PROP_PREVIOUS_RELEASE from the fdt, even when
> mem_map_phys is 0.
See commit d7255959b69a ("kho: allow kexec load before KHO
finalization") for more of an explanation of why this is done.
The FDT is always handed over because when the KHO image is set up, we
don't know if KHO will actually be used. On the next boot, it is
discarded if KHO was not finalized (that is, mem_map_phys == 0) since it
won't contain any memory to hand over.
Since you had the previous release in the FDT itself, you were able to
read it. If you move to subtrees as I suggested, then it would stop
working.
The KHO FDT is special in a way. We access it _before_ going into
scratch-only mode, and until then we just have to hope nobody
over-writes that (which is unlikely in early boot anyway). So it is safe
to use the contents of the FDT itself to signal if we have any useful
KHO state to hand over.
--
Regards,
Pratyush Yadav
next prev parent reply other threads:[~2026-01-20 15:10 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-23 14:01 Pasha Tatashin
2025-12-23 14:11 ` Pratyush Yadav
2026-01-08 18:03 ` Breno Leitao
2026-01-16 16:21 ` Pratyush Yadav
2026-01-18 6:11 ` Mike Rapoport
2026-01-20 15:11 ` Pratyush Yadav
2026-01-19 18:54 ` Breno Leitao
2026-01-20 15:10 ` Pratyush Yadav [this message]
2026-01-19 7:04 ` Zhu Yanjun
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=2vxzzf68e2wi.fsf@kernel.org \
--to=pratyush@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=graf@amazon.com \
--cc=kernel-team@meta.com \
--cc=kexec@lists.infradead.org \
--cc=leitao@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=pasha.tatashin@soleen.com \
--cc=ricardo.neri-calderon@linux.intel.com \
--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