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 8008C606A31B for ; Mon, 26 Oct 2026 20:49:18 +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=BP7bkbcQ; 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=BP7bkbcQRS+xby7zYX2KFdAGTD m6LuT939ZzwDgwYRlaPZ1w++Gt701X+aZlc+UxAoCpNw68KaIbDDRdB1x61snqlvUonomYSEWnrxb nZqRr6o4vA+0EfBcWXV14xMTA5k76yu3Er/2qwSOevewVEdlGNPPssyrfg6SaMjHRs5VsAg+5Rdxp G+YJUMhmrgqEbGcTVts6pemJ48xky9FoXaR1b+XdvKyJc9cuPn0sNXNyft3fZI37jFdgAD/qnqwnK y1p3WlOHWMRPM3o7koURhEhzt7C0bR6qsRcaWJGriWtgoklXP2Exe53YD+rP4dSwasnf2JnGpDXbO 3/j+Sykw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xLRd0-00000003F8S-40vB; Mon, 26 Oct 2026 20:49:10 +0000 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xLRcz-00000003F7D-0PtK for linux-arm-kernel@lists.infradead.org; Mon, 26 Oct 2026 20:49:10 +0000 Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-3ab752f6244so3414272a91.2 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=PJBAWhG3vQ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IOZnQ3ngBJ+q5hVN9wrr Vwz7ot7aEqzuaLYmy7yWcE8cIsdzp6xlJY0REm6FQ0AadT4j7F2cYtrtcRegK5amNLTJnf3xysK fuaARGf51s29QEsyDW7r/JkNKgs9P6mzBkNa4oNSP9EgUhPBYs8KFnJ081nx//RTW0vyMOZgIGD q4oFsMvA4m1Mg2Vl 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_219561_0CBC55C5 X-CRM114-Status: GOOD ( 42.02 ) X-Spam-Score: -17.6 (-----------------) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" 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);