Re: [PATCH v4 07/19] kho: vmalloc: Add the feature header
From: Pratyush Yadav
Date: Thu Nov 26 2026 - 13:03:54 EST
On Tue, Nov 10 2026, Tarun Sahu wrote:
> Register struct kho_vmalloc with the KHO serialization feature header
> mechanism to allow future additive fields or feature extensions without
> breaking live update ABI compatibility.
>
> Add DECLARE_KHO_SER(kho_vmalloc, 16, 0, 0) to register the 16-byte
> structure with 0 required and 0 optional features. Update function
> prototypes in include/linux/kexec_handover.h to take
> DECLARE_KHO_SER_HDR(kho_vmalloc, *fhdr) parameters, documenting which
> registered structure the feature header belongs to while enforcing
> compile-time type verification.
>
> In kho_preserve_vmalloc(), initialize the feature header with
> kho_ser_init() and access the payload fields via kho_ser_payload().
> In kho_restore_vmalloc(), validate incoming required features with
> kho_ser_validate() and access payload fields via kho_ser_payload().
> In kho_unpreserve_vmalloc(), access payload fields via kho_ser_payload().
> The chunk page format and traversal remain unchanged.
>
> Update memfd_luo and test_kho to pass typed feature header pointers
> and use kho_ser_size() for allocation sizing.
>
> Signed-off-by: Tarun Sahu <tarunsahu@xxxxxxxxxx>
[...]
> diff --git a/include/linux/kho/abi/memfd.h b/include/linux/kho/abi/memfd.h
> index 7b49dd6d7e2a..b0597c438973 100644
> --- a/include/linux/kho/abi/memfd.h
> +++ b/include/linux/kho/abi/memfd.h
> @@ -80,9 +80,9 @@ static_assert(!IS_ENABLED(CONFIG_64BIT) ||
> * @seals: The seals present on the memfd. The seals are uABI so it is safe
> * to directly use them in the ABI.
> * @flags: Flags for the file. Unused flag bits must be set to 0.
> - * @nr_folios: Number of folios in the folios array.
> - * @folios: Pointer to KHO vmalloc descriptor for the array of
> - * struct memfd_luo_folio_ser.
> + * @nr_folios: Number of folios in the folios array.
> + * @folios_fhdr: Pointer to KHO vmalloc descriptor for the array of
> + * struct memfd_luo_folio_ser.
> */
> struct memfd_luo_ser {
> u64 pos;
> @@ -90,7 +90,7 @@ struct memfd_luo_ser {
> u32 seals;
> u32 flags;
> u64 nr_folios;
> - DECLARE_KHOSER_PTR(folios, struct kho_vmalloc *);
> + DECLARE_KHOSER_PTR(folios_fhdr, DECLARE_KHO_SER_HDR(kho_vmalloc, *));
This doesn't _only_ point to the feature header. It points to the
vmalloc buffer of of folios, conceptually. So it should be called
"folios". Reading folios_fhdr everywhere is super confusing and hard to
read. Users of KHO vmalloc should be pointing to the KHO malloc
serialization structure, not to its headers or so on.
The feature header is an implementation detail of kho_vmalloc (same for
others). It should not be visible to its callers.
> };
>
> static_assert(sizeof(struct memfd_luo_ser) == 40);
> diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_handover.c
> index 641a3b4c88fb..6e428df717cc 100644
> --- a/kernel/liveupdate/kexec_handover.c
> +++ b/kernel/liveupdate/kexec_handover.c
> @@ -1378,20 +1378,20 @@ static void kho_vmalloc_unpreserve_chunk(struct kho_vmalloc_chunk *chunk,
> /**
> * kho_preserve_vmalloc - preserve memory allocated with vmalloc() across kexec
> * @ptr: pointer to the area in vmalloc address space
> - * @preservation: placeholder for preservation metadata
> + * @fhdr: placeholder for preservation metadata
> *
> * Instructs KHO to preserve the area in vmalloc address space at @ptr. The
> * physical pages mapped at @ptr will be preserved and on successful return
> - * @preservation will hold the physical address of a structure that describes
> - * the preservation.
> + * @fhdr will hold the preservation metadata.
> *
> * NOTE: The memory allocated with vmalloc_node() variants cannot be reliably
> * restored on the same node
> *
> * Return: 0 on success, error code on failure
> */
> -int kho_preserve_vmalloc(void *ptr, struct kho_vmalloc *preservation)
> +int kho_preserve_vmalloc(void *ptr, DECLARE_KHO_SER_HDR(kho_vmalloc, *fhdr))
> {
> + struct kho_vmalloc *vmalloc_ser;
> struct kho_vmalloc_chunk *chunk;
> struct vm_struct *vm = find_vm_area(ptr);
> unsigned int order, flags, nr_contig_pages;
> @@ -1404,13 +1404,18 @@ int kho_preserve_vmalloc(void *ptr, struct kho_vmalloc *preservation)
> if (vm->flags & ~KHO_VMALLOC_SUPPORTED_FLAGS)
> return -EOPNOTSUPP;
>
> + kho_ser_init(fhdr, kho_vmalloc);
> +
> + vmalloc_ser = kho_ser_payload(fhdr, kho_vmalloc);
> +
> flags = vmalloc_flags_to_kho(vm->flags);
> order = get_vm_area_page_order(vm);
> + vmalloc_ser->order = order;
Nit: Why is this moving around? Seems like a stray change.
Also, renaming preservation to vmalloc_ser adds a lot of noise to your
diff. Perhaps keep it as-is for now?
>
> chunk = new_vmalloc_chunk(NULL);
> if (!chunk)
> return -ENOMEM;
> - KHOSER_STORE_PTR(preservation->first, chunk);
> + KHOSER_STORE_PTR(vmalloc_ser->first, chunk);
>
> nr_contig_pages = (1 << order);
> for (int i = 0; i < vm->nr_pages; i += nr_contig_pages) {
[...]
--
Regards,
Pratyush Yadav