Re: [PATCH v4 18/19] mm: memfd_luo: Add feature header to struct memfd_luo_folio_ser

From: tarunsahu

Date: Wed Dec 02 2026 - 05:01:12 EST


Pratyush Yadav <pratyush@xxxxxxxxxx> writes:

> On Tue, Nov 10 2026, Tarun Sahu wrote:
>
>> Precede each serialized folio entry in the preserved memfd folio array
>> with struct kho_ser_hdr via DECLARE_KHO_SER so future per-folio memfd
>> features can append fields to struct memfd_luo_folio_ser without breaking
>> compatibility between adjacent kernels.
>>
>> Allocate the preserved folio array using kho_ser_size(memfd_luo_folio_ser)
>> per entry and initialize each entry feature header in
>> memfd_luo_preserve_folios(). On the incoming path in
>> memfd_luo_discard_folios() and memfd_luo_retrieve_folios(), validate each
>> entry feature header with kho_ser_validate() and advance between entries
>> using fhdr->size so entries written with a different feature layout are
>> traversed accurately.
>
> No. The flags in each folio entry is a part of memfd's ABI. These flags
> don't have an ABI of their own. If the layout of memfd_luo_folio_ser
> changes, it goes in the memfd_luo_ser flags.
>
> Doubling the memory needed to preserve a memfd is not acceptable.

Based on recent discussion in hypervisor liveupdate meeting, we decided to omit
the kho_ser_hdr for collection entries and we will handle any changes to
their ABI by their parent structure. So for pci_dev_ser changes will be
handled by pci_ser feature header. and similarly memfd_luo_folio_ser
changes will be handled by memfd_luo_ser which is aligning with your
comment above.

I want to discuss on this approach, same I raised here [1]

collection entry that are allocated by kho_block can easily be
deserialized as kho block layer has entry_size that is also handed over
by previous kernel hence the current kernel can deserialize those
entries based on entry_size. There are no problem in this. (even
rollback is safe as well)

Collection entries that are allocated by kho_vmalloc, are part of an
array which resides inside a folio of order (= # of folios * sizeof(memfd_luo_folio_ser)).
During time of deserialization, kho_restore_vmalloc will just give the
array of pages (a folio) that should be deserialized in array of
collection entry which is memfd_luo_folio_ser, direct type cast with +1
in loop will not work as the size of memfd_luo_folio_ser might differ
across kernel. So, Like I suggested to have collection entry size in the
parent structure (folio_ser_entry_size) is acceptable design here?

struct memfd_luo_ser {

...
<kho_vmalloc ptr>
u64 folio_ser_entry_size;
}

~Tarun

[1]: https://lore.kernel.org/all/9huzmrrbpb7w.fsf@xxxxxxxxxxxxxxxxxxxxxx/

>
> [...]
>
> --
> Regards,
> Pratyush Yadav