From nobody Fri Apr 3 04:33:07 2026 Received: from stravinsky.debian.org (stravinsky.debian.org [82.195.75.108]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1FFE392838 for ; Mon, 16 Mar 2026 11:56:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=82.195.75.108 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773662186; cv=none; b=LUKY2MdCrb+2N3QWgVddfcBYSxL41Ey3Vp92FU8Nd+spYykHUMTwuwy+eLiSaPzR2ddcoc09VtIOX5WiTdpk68jqgz2BT9m/l4CmvBSIDPWTbTooBJI+eDPuJHnr2+Ww5KxEI6t5PpzOO0UBHtJCCbQb3B99PHOyWXeFBZFLWY0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773662186; c=relaxed/simple; bh=051C+wlXXANkMIKsppb0xbp15xPloCr4ParEX+3dVfQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qcvDf/XqiP3riOlWfVpISjVB3d3p47OF0CSVlLCMSYD8r0jK9vXbwRdeeqc3tJUEHjoKkmxDEIMLIjQYOHn6Fn6Euxdv+sReiJbJHgVmpE7p36XnVk3NNUhmadpkIvfEfXs6FsPU8EffNgFR8o002MY/NzHVaqT3fr3bsR7JOOI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=none smtp.mailfrom=debian.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b=vVGp+VIt; arc=none smtp.client-ip=82.195.75.108 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=debian.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=debian.org header.i=@debian.org header.b="vVGp+VIt" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debian.org; s=smtpauto.stravinsky; h=X-Debian-User:Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description; bh=zlcVx0W0VtTFst28aefWpydWDS6cGWkZyYfBnt7a02Q=; b=vVGp+VItaaV2p2pJiYKm9hxnD8 LBsdzLfpw1Q+Rb2HUtT1dfD02BZgvsivANkiRByFgANPC5hIqrFTxpSUSPQyHFefXJk7fd6KJdN3M zNYCl+RZxxDkn9tMJEHFhJ9Ln4qKTXsVGMUMdLXYE1roDErharYaqo/ewk+FeWlMx/HDwxnqhFsdt 8yjg3ClOovkMacIJkRTAhrrukU9+o0nkMFkN+hBbi8qu6t+glTa1J74NINgkqlkS8k8AwML6h7utf kouLoohDDijyV5iuof9p3WomB0lW0yBuJwezY/4dKUrCgFMbB4uawJ84bAg50Axz/O2ljj6HWZFYT wraXQvFA==; Received: from authenticated user by stravinsky.debian.org with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94.2) (envelope-from ) id 1w26YV-0025zJ-RG; Mon, 16 Mar 2026 11:56:18 +0000 From: Breno Leitao Date: Mon, 16 Mar 2026 04:54:33 -0700 Subject: [PATCH v9 3/6] kho: persist blob size in KHO FDT Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260316-kho-v9-3-ed6dcd951988@debian.org> References: <20260316-kho-v9-0-ed6dcd951988@debian.org> In-Reply-To: <20260316-kho-v9-0-ed6dcd951988@debian.org> To: Alexander Graf , Mike Rapoport , Pasha Tatashin , Pratyush Yadav Cc: linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-mm@kvack.org, usama.arif@linux.dev, Breno Leitao , SeongJae Park , kernel-team@meta.com X-Mailer: b4 0.15-dev-363b9 X-Developer-Signature: v=1; a=openpgp-sha256; l=9060; i=leitao@debian.org; h=from:subject:message-id; bh=051C+wlXXANkMIKsppb0xbp15xPloCr4ParEX+3dVfQ=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBpt+/QAagOvEjH+4Kb2F7XeWd2dYke4ca0A+WRu CzHwqqx3/iJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCabfv0AAKCRA1o5Of/Hh3 bY1HD/9cURrNPM32kFPiGDQtiEdASq3a5nKciMcaXLOzru3nUFWMZZnNH7QhUq5Jn6WbCTAmAAl ajbvSmAtmF8NrE5+YLR7i+v3S0+BusZYY+oSpbZOufwpDS4cGWp3CUlxi6NdIbwEhQV6DQCeyjm oBZSmj4JChL0bDjbH4nfb2ekMQ3iI8PrKCNA87R1oztt/3pGqQ3c0ZLCKeeU60YTbmwj87yRw9J txXGBquXuW5HVbB+bxk3EOBygn8ZtUEId1x/ep9nSpwFDL02v7BBcFH5JvBnM5pgRJU3/2xrFgQ Ab3trrYYHQJrta3wDbxCCIKOs3U9NyFxtPIWVKzkOiA900xZdZrY4wc8jIGRkh9Qjw1FWneazwN ZGyjZwH/73MXUzZpiN1DTJIVkOSgKlUqTUytp5MGOqoI1na8I4ZlrFlg94GRNspRzghLz3gARm/ 2ss4+aWnDsPeHcURukMGGGfDmSS4BiMoEg/suPzJG1ZcfQtyuIM2lGb14OKRSk7aIYANZBOBX8J ja0cmHEJGf5kqwSD1EWhrljfIV2RyowPR9MPaxiw7CVdrS5bgrBQ3Py/lbRdra51cDM200pMYS9 N3BOgK9IybNBWtnxHQe7pFf76IqpTrkz08NiiDE7QTsKz/u4diwBKDIVZSP7tjwMCvL4ylFfFBq iqH42we+pFwcsaw== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao kho_add_subtree() accepts a size parameter but only forwards it to debugfs. The size is not persisted in the KHO FDT, so it is lost across kexec. This makes it impossible for the incoming kernel to determine the blob size without understanding the blob format. Store the blob size as a "blob-size" property in the KHO FDT alongside the "preserved-data" physical address. This allows the receiving kernel to recover the size for any blob regardless of format. Also extend kho_retrieve_subtree() with an optional size output parameter so callers can learn the blob size without needing to understand the blob format. Update all callers to pass NULL for the new parameter. Reviewed-by: Mike Rapoport (Microsoft) Signed-off-by: Breno Leitao --- include/linux/kexec_handover.h | 5 +++-- include/linux/kho/abi/kexec_handover.h | 20 ++++++++++++++++---- kernel/liveupdate/kexec_handover.c | 27 ++++++++++++++++++++++----- kernel/liveupdate/kexec_handover_debugfs.c | 3 ++- kernel/liveupdate/luo_core.c | 2 +- lib/test_kho.c | 2 +- mm/memblock.c | 2 +- 7 files changed, 46 insertions(+), 15 deletions(-) diff --git a/include/linux/kexec_handover.h b/include/linux/kexec_handover.h index 0666cf298c7f4..8968c56d2d73e 100644 --- a/include/linux/kexec_handover.h +++ b/include/linux/kexec_handover.h @@ -34,7 +34,7 @@ struct page *kho_restore_pages(phys_addr_t phys, unsigned= long nr_pages); void *kho_restore_vmalloc(const struct kho_vmalloc *preservation); int kho_add_subtree(const char *name, void *blob, size_t size); void kho_remove_subtree(void *blob); -int kho_retrieve_subtree(const char *name, phys_addr_t *phys); +int kho_retrieve_subtree(const char *name, phys_addr_t *phys, size_t *size= ); =20 void kho_memory_init(void); =20 @@ -104,7 +104,8 @@ static inline int kho_add_subtree(const char *name, voi= d *blob, size_t size) =20 static inline void kho_remove_subtree(void *blob) { } =20 -static inline int kho_retrieve_subtree(const char *name, phys_addr_t *phys) +static inline int kho_retrieve_subtree(const char *name, phys_addr_t *phys, + size_t *size) { return -EOPNOTSUPP; } diff --git a/include/linux/kho/abi/kexec_handover.h b/include/linux/kho/abi= /kexec_handover.h index 6b7d8ef550f98..7e847a2339b09 100644 --- a/include/linux/kho/abi/kexec_handover.h +++ b/include/linux/kho/abi/kexec_handover.h @@ -41,25 +41,28 @@ * restore the preserved data.:: * * / { - * compatible =3D "kho-v2"; + * compatible =3D "kho-v3"; * * preserved-memory-map =3D <0x...>; * * { * preserved-data =3D <0x...>; + * blob-size =3D <0x...>; * }; * * { * preserved-data =3D <0x...>; + * blob-size =3D <0x...>; * }; * ... ... * { * preserved-data =3D <0x...>; + * blob-size =3D <0x...>; * }; * }; * * Root KHO Node (/): - * - compatible: "kho-v2" + * - compatible: "kho-v3" * * Indentifies the overall KHO ABI version. * @@ -78,16 +81,25 @@ * * Physical address pointing to a subnode data blob that is also * being preserved. + * + * - blob-size: u64 + * + * Size in bytes of the preserved data blob. This is needed because + * blobs may use arbitrary formats (not just FDT), so the size + * cannot be determined from the blob content alone. */ =20 /* The compatible string for the KHO FDT root node. */ -#define KHO_FDT_COMPATIBLE "kho-v2" +#define KHO_FDT_COMPATIBLE "kho-v3" =20 /* The FDT property for the preserved memory map. */ #define KHO_FDT_MEMORY_MAP_PROP_NAME "preserved-memory-map" =20 /* The FDT property for preserved data blobs. */ -#define KHO_FDT_SUB_TREE_PROP_NAME "preserved-data" +#define KHO_SUB_TREE_PROP_NAME "preserved-data" + +/* The FDT property for the size of preserved data blobs. */ +#define KHO_SUB_TREE_SIZE_PROP_NAME "blob-size" =20 /** * DOC: Kexec Handover ABI for vmalloc Preservation diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_h= andover.c index 54fe59fe43acd..b768fb7b41280 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -768,6 +768,7 @@ int kho_add_subtree(const char *name, void *blob, size_= t size) { phys_addr_t phys =3D virt_to_phys(blob); void *root_fdt =3D kho_out.fdt; + u64 size_u64 =3D size; int err =3D -ENOMEM; int off, fdt_err; =20 @@ -784,11 +785,16 @@ int kho_add_subtree(const char *name, void *blob, siz= e_t size) goto out_pack; } =20 - err =3D fdt_setprop(root_fdt, off, KHO_FDT_SUB_TREE_PROP_NAME, + err =3D fdt_setprop(root_fdt, off, KHO_SUB_TREE_PROP_NAME, &phys, sizeof(phys)); if (err < 0) goto out_pack; =20 + err =3D fdt_setprop(root_fdt, off, KHO_SUB_TREE_SIZE_PROP_NAME, + &size_u64, sizeof(size_u64)); + if (err < 0) + goto out_pack; + WARN_ON_ONCE(kho_debugfs_blob_add(&kho_out.dbg, name, blob, size, false)); =20 @@ -817,7 +823,7 @@ void kho_remove_subtree(void *blob) const u64 *val; int len; =20 - val =3D fdt_getprop(root_fdt, off, KHO_FDT_SUB_TREE_PROP_NAME, &len); + val =3D fdt_getprop(root_fdt, off, KHO_SUB_TREE_PROP_NAME, &len); if (!val || len !=3D sizeof(phys_addr_t)) continue; =20 @@ -1314,13 +1320,14 @@ EXPORT_SYMBOL_GPL(is_kho_boot); * kho_retrieve_subtree - retrieve a preserved sub blob by its name. * @name: the name of the sub blob passed to kho_add_subtree(). * @phys: if found, the physical address of the sub blob is stored in @phy= s. + * @size: if not NULL and found, the size of the sub blob is stored in @si= ze. * * Retrieve a preserved sub blob named @name and store its physical - * address in @phys. + * address in @phys and optionally its size in @size. * * Return: 0 on success, error code on failure */ -int kho_retrieve_subtree(const char *name, phys_addr_t *phys) +int kho_retrieve_subtree(const char *name, phys_addr_t *phys, size_t *size) { const void *fdt =3D kho_get_fdt(); const u64 *val; @@ -1336,12 +1343,22 @@ int kho_retrieve_subtree(const char *name, phys_add= r_t *phys) if (offset < 0) return -ENOENT; =20 - val =3D fdt_getprop(fdt, offset, KHO_FDT_SUB_TREE_PROP_NAME, &len); + val =3D fdt_getprop(fdt, offset, KHO_SUB_TREE_PROP_NAME, &len); if (!val || len !=3D sizeof(*val)) return -EINVAL; =20 *phys =3D (phys_addr_t)*val; =20 + val =3D fdt_getprop(fdt, offset, KHO_SUB_TREE_SIZE_PROP_NAME, &len); + if (!val || len !=3D sizeof(*val)) { + pr_warn("broken KHO subnode '%s': missing or invalid blob-size property\= n", + name); + return -EINVAL; + } + + if (size) + *size =3D (size_t)*val; + return 0; } EXPORT_SYMBOL_GPL(kho_retrieve_subtree); diff --git a/kernel/liveupdate/kexec_handover_debugfs.c b/kernel/liveupdate= /kexec_handover_debugfs.c index cab923e4f5c8d..b416846810d78 100644 --- a/kernel/liveupdate/kexec_handover_debugfs.c +++ b/kernel/liveupdate/kexec_handover_debugfs.c @@ -125,7 +125,8 @@ __init void kho_in_debugfs_init(struct kho_debugfs *dbg= , const void *fdt) const u64 *fdt_phys; void *sub_fdt; =20 - fdt_phys =3D fdt_getprop(fdt, child, KHO_FDT_SUB_TREE_PROP_NAME, &len); + fdt_phys =3D fdt_getprop(fdt, child, + KHO_SUB_TREE_PROP_NAME, &len); if (!fdt_phys) continue; if (len !=3D sizeof(*fdt_phys)) { diff --git a/kernel/liveupdate/luo_core.c b/kernel/liveupdate/luo_core.c index 04d06a0906c0e..48b25c9abeda3 100644 --- a/kernel/liveupdate/luo_core.c +++ b/kernel/liveupdate/luo_core.c @@ -88,7 +88,7 @@ static int __init luo_early_startup(void) } =20 /* Retrieve LUO subtree, and verify its format. */ - err =3D kho_retrieve_subtree(LUO_FDT_KHO_ENTRY_NAME, &fdt_phys); + err =3D kho_retrieve_subtree(LUO_FDT_KHO_ENTRY_NAME, &fdt_phys, NULL); if (err) { if (err !=3D -ENOENT) { pr_err("failed to retrieve FDT '%s' from KHO: %pe\n", diff --git a/lib/test_kho.c b/lib/test_kho.c index 2631824373152..aa6a0956bb8b7 100644 --- a/lib/test_kho.c +++ b/lib/test_kho.c @@ -319,7 +319,7 @@ static int __init kho_test_init(void) if (!kho_is_enabled()) return 0; =20 - err =3D kho_retrieve_subtree(KHO_TEST_FDT, &fdt_phys); + err =3D kho_retrieve_subtree(KHO_TEST_FDT, &fdt_phys, NULL); if (!err) { err =3D kho_test_restore(fdt_phys); if (err) diff --git a/mm/memblock.c b/mm/memblock.c index 29e12ea2a854c..4f4bf1a9d7900 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -2533,7 +2533,7 @@ static void *__init reserve_mem_kho_retrieve_fdt(void) if (fdt) return fdt; =20 - err =3D kho_retrieve_subtree(MEMBLOCK_KHO_FDT, &fdt_phys); + err =3D kho_retrieve_subtree(MEMBLOCK_KHO_FDT, &fdt_phys, NULL); if (err) { if (err !=3D -ENOENT) pr_warn("failed to retrieve FDT '%s' from KHO: %d\n", --=20 2.52.0