[RFC PATCH v2 3/4] liveupdate: Replace compatibility string with a 2-bit pair feature header
David Matlack
dmatlack at google.com
Mon Oct 26 13:49:02 PDT 2026
On 2026-10-25 04:38 PM, Pasha Tatashin wrote:
> On Fri, Oct 23, 2026 at 9:50 AM David Matlack <dmatlack at google.com> wrote:
> > Sure but why deal with all the complexity just to save 8 bytes? All of
> > these structs are allocated on folios and there are kilobytes of unused
> > space to fit this header. And even if we optimize that we are talking
> > about 8 bytes per FH/FLB... or 16 bytes for structs with arch-specific
> > sub-structs like the KVM ones.
>
> The reason I care about keeping the header compact is that we are
> defining a foundational kernel ABI and want to use this header across
> almost every serialized data structure so we can evolve them later
> without breaking compatibility. While some top-level structs are on
> sparse folios today, other serialized structs are tightly packed, and
> we are looking to add KHO slab support in the future where tightly
> packed allocations will be common.
My intuition is we will have a small number of headers per preserved
file and per preserved FLB. One for the top-level struct and then
optionally a few more for sub-structs like arch-specific data. That is
why I am less worried 8 bytes per header, even if we fix the folio
problem.
Maybe where our visions differ is when there are collections of
serialized structs, like KHO blocks. For collections I don't think the
elements will each have their own headers. Otherwise the elements could
be different sizes.
Instead I think the struct that owns the collection will have a header
that includes features for fields in the elements. The header defines
which fields in all elements are valid. The field contents then convey
the per-element information (which might include 0 or -1 values to
convey this specific element doesn't have this data).
> That said, in your proposal, as long as nr_flags == 0 is allowed when
> a struct has no feature flags yet, luo_ser_hdr_size(hdr) is already 8
> bytes and only grows to 16 bytes on the first feature flag. I am OK
> with that.
Yeah the header will be 8 bytes until the first flag is defined, at
which point it will grow to 16 bytes.
Great, sounds like we are aligned on the header. s/luo/kho also sounds
good to me.
> > > This is not an issue on the incoming path, we never cast incoming data
> > > to struct name##_hdr or access ->payload directly. Instead, we parse
> > > the incoming buffer, dynamically compute the header size from the
> > > continuation bits, and cast the payload offset to "struct name *"
> > > based on the negotiated feature flags.
> >
> > How?
> >
> > This is the only data structure that describes the header. Are you
> > saying the incoming path will parse the header purely with a void *? Or
> > use this header but just be careful not to access payload?
> >
> > We should have one header structure that can be used on the incoming and
> > outgoing path. We should not have one header data structure that can be
> > used on the outgoing path and one that can be used on the incoming
> > path.
> >
> > Also we need a standard header that can be shared across all structs,
> > not a per struct header. Otherwise you will need to do weird casting and
> > overlays to implement the shared helper routines that parse it.
>
> Having DECLARE_KHO_SER_WRAP() in include/linux/kho/abi/ makes it
> immediately clear just by looking at kho/abi/ which serialized structs
> have the versioned header and which do not, while also enforcing the
> header when preserving and static-asserting the combined struct size a
> compile time.
>
> So with your header (and let's use KHO as we want to version KHO
> structs as well):
>
> struct kho_ser_hdr {
> __u32 size; /* Size of header + payload in bytes */
> __u32 nr_flags; /* Number of features encoded in flags[] */
> __u64 flags[];
> };
>
> The wrapped struct will look like:
>
> #define DECLARE_KHO_SER_WRAP(name, expected_size, nr_feats) \
> struct name##_wrap { \
> __u32 size; \
> __u32 nr_flags; \
> __u64 flags[DIV_ROUND_UP(nr_feats, 32)]; \
> struct name payload; \
> }; \
> static_assert(sizeof(struct name##_wrap) == (expected_size), \
> "struct " #name " size mismatch!")
>
> On the incoming kernel we don't use struct name##_wrap, but we use
> struct kho_ser_hdr for the wrapped data, validate the flags, and
> unwrap it via kho_ser_payload(hdr) to get back the struct name *
> payload type.
I still think it's not advisable to define name##_wrap since anyone
could accidentally start using it on the incoming path and we wouldn't
notice at first (especially since same kernel Live Update tests would
keep working totally fine). I also don't think asserting the combined
size buys us anything. The header size is just a function of the
number of features, and what we are trying to protect against is
structs embedded in the payload changing size.
So I would just do:
/* Marks struct name as a KHO serialized payload with a kho_ser_hdr. */
#define DECLARE_KHO_SER(name, payload_size) \
static_assert(sizeof(struct name) == (payload_size))
DECLARE_KHO_SER(luo_memfd_ser, 16);
Plus helpers that allocate and initialize the header and return the
payload as a typed pointer. Both the outgoing and incoming paths find
the payload the same way, by computing its offset from the header,
rather than through a struct with a fixed payload offset:
/* outgoing */
hdr = kho_ser_alloc(luo_memfd_ser, LUO_MEMFD_NR_FEATS);
ser = kho_ser_payload(hdr, luo_memfd_ser);
/* incoming */
hdr = phys_to_virt(args->serialized_data);
ser = kho_ser_payload(hdr, luo_memfd_ser);
More information about the kexec
mailing list