Re: [PATCH v4 02/19] kho: block: Record the entry size in the block header

From: Pratyush Yadav

Date: Fri Nov 20 2026 - 11:11:17 EST


On Tue, Nov 10 2026, Tarun Sahu wrote:

> Subsystems using the KHO Serialization Blocks framework currently do
> not record the serialized entry size in the block header. The entry size
> is only known to individual callers, which must track and store it in an
> owning serialized data structure. If a newer source kernel adds fields
> to an entry, the changed entry size breaks the stride when an older
> target kernel iterates over blocks.
>
> Add an entry_size field to struct kho_block_header_ser. On the outgoing
> side, record bs->entry_size into every block header during allocation.
> During restoration, derive the entry stride directly from the block
> header instead of relying on caller-supplied dimensions. The
> kho_block_set_init() interface remains unchanged. A zero entry size,
> or one that differs between blocks of a set, is rejected during
> restoration.

Yeah, I agree with David here. It makes little sense to have callers
pass in the entry size only to have it ignored (or, only used for
rejection). It would be much better to use the recorded entry size and
hand it over to callers.

>
> This change modifies the serialized layout of struct kho_block_header_ser
> and shifts the offset of serialized entries within preserved blocks.
> Bump KHO_FDT_COMPATIBLE from kho-v4 to kho-v5 so that pre-v5 and post-v5
> kernels cleanly reject mismatched handover state during boot. Also
> update the stale compatible string example in the documentation.
>
> Suggested-by: Pratyush Yadav <pratyush@xxxxxxxxxx>
> Signed-off-by: Tarun Sahu <tarunsahu@xxxxxxxxxx>
> ---
> include/linux/kho/abi/block.h | 10 ++++----
> include/linux/kho/abi/kexec_handover.h | 6 ++---
> kernel/liveupdate/kho_block.c | 32 +++++++++++++++++++++++---
> 3 files changed, 38 insertions(+), 10 deletions(-)
>
> diff --git a/include/linux/kho/abi/block.h b/include/linux/kho/abi/block.h
> index 36bdbaf9b3b8..a40b0906c821 100644
> --- a/include/linux/kho/abi/block.h
> +++ b/include/linux/kho/abi/block.h
> @@ -40,9 +40,10 @@
>
> /**
> * struct kho_block_header_ser - Header for the serialized data block.
> - * @next: Physical address of the next struct kho_block_header_ser.
> - * @count: The number of entries that immediately follow this header in the
> - * memory block.
> + * @next: Physical address of the next struct kho_block_header_ser.
> + * @count: The number of entries that immediately follow this header in the
> + * memory block.
> + * @entry_size: The size in bytes of each serialized entry in the block.
> *
> * This structure is located at the beginning of a block of physical memory
> * preserved across a kexec. It provides the necessary metadata to interpret
> @@ -51,9 +52,10 @@
> struct kho_block_header_ser {
> u64 next;
> u64 count;
> + u64 entry_size;

I think this is the wrong place to put this. This header goes before
each block, so it should only hold metadata _for this block_, not for
the whole data structure. Because if you do that, you end up having the
field present in each block, but only the first block is special and the
value is only valid there. The feature header coming later makes this
problem worse.

I think we should follow down the lines of kho_vmalloc and have a
out-of-band structure that describes the whole block set, and then each
block only holds metadata relevant to it.

So this would look like:

struct kho_block_ser {
DECLARE_KHOSER_PTR(first, struct kho_block_header_ser *);
u64 entry_size;
/* Other things like flags, size, etc... */
};

[...]

--
Regards,
Pratyush Yadav