From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3972A606A32F for ; Mon, 26 Oct 2026 20:49:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=tHw0uJ5g; dkim=pass (2048-bit key, unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20251104 header.b=BZvBcIz3 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To: Content-Transfer-Encoding:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=PJBAWhG3vQY26e/Nvx85KnaVoYI7FZuNNNc/vdxGNMI=; b=tHw0uJ5gNXI8VUyiIZBb2tTxeI zPx0tA8zfDUoHM987ZVL/ykRT97UYG1T/g0t2iCwylNsnOXFXBFYMB8+uRJVQo7OazSRl6/GVMsWu 61ky+MvsW/g+qWwuvGHAyhDoumOQO5iZWTFAq/UgSV/EbsmWnR65TFeubs28RkWnwij4pQjwHk20l 2zzKDl2eiFs2MTw3uB3nFmbPosBe5Vjn3EGcQh2biu4uJIdWsPBp7MmNgkm6dEXhljPdDdyriGNeM GTKO0GiykCa3IvhBBwXVrMVGKjdKwBTivyYdnTTQMcbIFdom1XUwAy/6F+wKGj3fNd8jJWKKLiTG1 fWpDfO7A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xLRd2-00000003F9C-0Q5N; Mon, 26 Oct 2026 20:49:12 +0000 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xLRcz-00000003F7E-0iN7 for kexec@lists.infradead.org; Mon, 26 Oct 2026 20:49:10 +0000 Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-3ac6794fe45so2559935a91.0 for ; Mon, 26 Oct 2026 13:49:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1793047747; x=1793652547; darn=lists.infradead.org; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to:content-type; bh=PJBAWhG3vQY26e/Nvx85KnaVoYI7FZuNNNc/vdxGNMI=; b=BZvBcIz3xbVyVmpis6EsL+D5bk590Ts/aSf+BaskWEICUBeVTJr6xjGwoT2sbHFyyn lxNWpIdIqNPJ4lQZZyR8tgLDzJq8wLFreEUcZIqt4nlYUN9MIWdJDc3v0u4wscqEU5+S IfbFxg00F4t4Ly/m+c2i1p+C+e6PZn3cgLLoElzJXEcKek2ZLj+qM/MoQQBcBHlO5fMR jqyrdHa7f6IAG/1O/HHyt3CYd2Q4J4JG3hl/D+R5bdj8b3wQEhV30nMXe15q+PxemHbH oTWJzXceYlZfs7OctqtTYdPOSVpYFdepaWSpgW3OvjcKUsG/ySt1XDqQAYx1ebiQa9iX dGZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793047747; x=1793652547; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=PJB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SFJ+Ppa6G/Wfy5dDnnI9vXKVbw WFVUig0cTLUNB94LOjxRH1GOxg5Sc11OPEFmLLrlD+38mrBTUKeEcb4QtsjtU9RLwP9BKec8Feg pQJb3VnT7G+tkUAztl+gZl6fSY/nafrg8j4RYoFWWumheQscc79DqkdGMYBZIuPS+M2BLiqk0c9 cks33QXSm0bSO6bM X-Received: by 2002:a17:90b:5105:b0:3ac:9176:e81c with SMTP id 98e67ed59e1d1-3adeae76765mr6903041a91.46.1793047746368; Mon, 26 Oct 2026 13:49:06 -0700 (PDT) Received: from google.com (64.75.127.34.bc.googleusercontent.com. [34.127.75.64]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3ae4066aec8sm743744a91.15.2026.10.26.13.49.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2026 13:49:05 -0700 (PDT) Date: Mon, 26 Oct 2026 20:49:02 +0000 From: David Matlack To: Pasha Tatashin Cc: tarunsahu@google.com, Andrew Morton , joro@8bytes.org, Mike Rapoport , Pratyush Yadav , maz@kernel.org, arnd@arndb.de, jgg@nvidia.com, robin.murphy@arm.com, loganodell@google.com, oupton@kernel.org, kevin.tian@intel.com, alex@shazbot.org, dwmw2@infradead.org, pbonzini@redhat.com, seanjc@google.com, will@kernel.org, Alexander Graf , Bjorn Helgaas , baolu.lu@linux.intel.com, linux-arm-kernel@lists.infradead.org, linux-arch@vger.kernel.org, sagis@google.com, linux-mm@kvack.org, kvmarm@lists.linux.dev, iommu@lists.linux.dev, linux-pci@vger.kernel.org, kexec@lists.infradead.org, skhawaja@google.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH v2 3/4] liveupdate: Replace compatibility string with a 2-bit pair feature header Message-ID: References: X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261026_134909_219136_91948509 X-CRM114-Status: GOOD ( 41.08 ) X-Spam-Score: -17.6 (-----------------) X-BeenThere: kexec@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kexec" X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On 2026-10-25 04:38 PM, Pasha Tatashin wrote: > On Fri, Oct 23, 2026 at 9:50 AM David Matlack 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);