From nobody Thu Apr 9 12:00:54 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 092DD3A7F6C for ; Mon, 9 Mar 2026 13:42:22 +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=1773063744; cv=none; b=NKlfJ3+pYoiNCvVm6f27x6XRhO8mZpOPq21Ekz3sV/DYmcTXaCxOhs85fd+OvEAyt0pva3K25muA/H35AtNkTcHxW2MjEOYc8I69Ufjbw4c4PtJNiLGLPpSkHI+l0/mtibV12DgFDYXGAAUOSEDESG+2RMxnKkTZmG7d5ZZW3Cw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773063744; c=relaxed/simple; bh=aU0aIKTD5Anicm9v3gMTJTcMaA4+bBorKPfkcBjPpeQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lNbtnPhrvOl4sw5eVzxyqzxgRtmoJYy6Uq+DccbBz1qDLo1o/matA+ZeA4Bwkk56trpugVJsARVXV44N9YB1Quu6ZUodqaZT6eAdZmmqcj9BhWj8buJUxUQvteI+RoUOMzqWTQw0lnFGAU5f9KbFCtNTTXtM5u7tNuRdf85UArU= 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=Ubhtqgy4; 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="Ubhtqgy4" 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=/9ZZhOrRGryuFNle00hDqS1xUJYiiR7dmjtWIiWkagc=; b=Ubhtqgy4HMwanqCg2PYREW8y45 C7UCIT1SQKJXy9BmmpvP/cBYRX9MA4G/OF3A3T5Maak+/vnK+mMpR/VhZW4o71GoratWh6eIztgDP QSq2MSWMrhZA/eYyq7badpL2BM4Ops2gdIUfhKYs3krh0I8UsVbSOc8RXxkjxqb8AYO/pMTbWLvxt BgE+PxqqHDGp+soUuW+AwfEqcLa2AWjUycizw7Yc09L/5PjkQOzhkEI0ZScPKxQfrlceE/gCUYplw 9b/mNMsQgvKllBOrc/auV7DRv4mPtAeNTVm5Hki5JrrQ4drb0eAcUDKLaTE6aGzYllNlBpfTYI+rj 9zgDh7Jw==; 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 1vzasG-002G3H-5V; Mon, 09 Mar 2026 13:42:20 +0000 From: Breno Leitao Date: Mon, 09 Mar 2026 06:41:44 -0700 Subject: [PATCH v8 1/6] kho: add size parameter to kho_add_subtree() 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: <20260309-kho-v8-1-c3abcf4ac750@debian.org> References: <20260309-kho-v8-0-c3abcf4ac750@debian.org> In-Reply-To: <20260309-kho-v8-0-c3abcf4ac750@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, usamaarif642@gmail.com, Breno Leitao , SeongJae Park , kernel-team@meta.com X-Mailer: b4 0.15-dev-363b9 X-Developer-Signature: v=1; a=openpgp-sha256; l=9284; i=leitao@debian.org; h=from:subject:message-id; bh=aU0aIKTD5Anicm9v3gMTJTcMaA4+bBorKPfkcBjPpeQ=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBprs4ydBOVZ3Yk/BUJ+QELIZEuEZLFQIhio9Yca 2h0XKXcDiqJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaa7OMgAKCRA1o5Of/Hh3 bQ9kEACUcvuCGCaVsyjc7znsMxQtUt+CeEDKYnkHGl9+c72+2NVpRZM22wMADYwSpYyd7h4rhW8 lDrZ4Bk4CAY2rha7FCH43wLRRvuEuAitusS0x+U8p6UDpBqZyZTWbJ2Ov443LvyA9Ifu7oa7MG8 fjKrYWQGtJ0EAxOdfuoZCGaP6/R/Lt4M9GGW5Tz2ayh1vxjfdjQvp99J/BWH+8k1HonZVb5if/h an9Zte9i686AXecTnFdGMOCgZV+egnivY7X9aHJtrC+BsEpYLOCJAFKi5AkkwrD8J4Y8Xsvfj8q 2zryyhx2UBPhCB7w/wv9741Sjce/dRs5HcSWNWKboqmkK8vvXO+0P0RqERHIrtzOlAnlBzOjgOC 5XkNrR+8myuX7WsFaY3LjZrh4ld04QSgJkFwMWmirMAzS7nepf01f1LB7A6goGRRriJ2ZkhYzAx wHAs3ObVG8Pd6eym5X6pngGW9PZ+MWAR+7RbDVs5prll29q41y929rdCeL+Si41Olu34iCoHWGk jQZkDEliMJlII0k57J2uA2h9WXOdFXQsiMWKw+Mk6NXSbcU705nIYEnuD9W6ffriSZeH4EYy4ln sdwxXqP09ZJ3sO6I5YOPWYJ2ZZOPp0BFCbyjGPBFRWQ3udhT038Bg9mTJxdMG5N3SnkCU/+RUJE ZohD9f2CIAd9xCA== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao kho_add_subtree() assumes the fdt argument is always an FDT and calls fdt_totalsize() on it in the debugfs code path. This assumption will break if a caller passes arbitrary data instead of an FDT. When CONFIG_KEXEC_HANDOVER_DEBUGFS is enabled, kho_debugfs_fdt_add() calls __kho_debugfs_fdt_add(), which executes: f->wrapper.size =3D fdt_totalsize(fdt); Fix this by adding an explicit size parameter to kho_add_subtree() so callers specify the blob size. This allows subtrees to contain arbitrary data formats, not just FDTs. Update all callers: - memblock.c: use fdt_totalsize(fdt) - luo_core.c: use fdt_totalsize(fdt_out) - test_kho.c: use fdt_totalsize() - kexec_handover.c (root fdt): use fdt_totalsize(kho_out.fdt) Also update __kho_debugfs_fdt_add() to receive the size explicitly instead of computing it internally via fdt_totalsize(). In kho_in_debugfs_init(), pass fdt_totalsize() for the root FDT and sub-blobs since all current users are FDTs. A subsequent patch will persist the size in the KHO FDT so the incoming side can handle non-FDT blobs correctly. Suggested-by: Pratyush Yadav Reviewed-by: Mike Rapoport (Microsoft) Signed-off-by: Breno Leitao Reviewed-by: Pratyush Yadav --- include/linux/kexec_handover.h | 4 ++-- kernel/liveupdate/kexec_handover.c | 8 +++++--- kernel/liveupdate/kexec_handover_debugfs.c | 15 +++++++++------ kernel/liveupdate/kexec_handover_internal.h | 5 +++-- kernel/liveupdate/luo_core.c | 3 ++- lib/test_kho.c | 3 ++- mm/memblock.c | 2 +- 7 files changed, 24 insertions(+), 16 deletions(-) diff --git a/include/linux/kexec_handover.h b/include/linux/kexec_handover.h index ac4129d1d7416..abb1d324f42d0 100644 --- a/include/linux/kexec_handover.h +++ b/include/linux/kexec_handover.h @@ -32,7 +32,7 @@ void kho_restore_free(void *mem); struct folio *kho_restore_folio(phys_addr_t phys); 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 *fdt); +int kho_add_subtree(const char *name, void *fdt, size_t size); void kho_remove_subtree(void *fdt); int kho_retrieve_subtree(const char *name, phys_addr_t *phys); =20 @@ -97,7 +97,7 @@ static inline void *kho_restore_vmalloc(const struct kho_= vmalloc *preservation) return NULL; } =20 -static inline int kho_add_subtree(const char *name, void *fdt) +static inline int kho_add_subtree(const char *name, void *fdt, size_t size) { return -EOPNOTSUPP; } diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_h= andover.c index b64f36a452965..55bdc5d2d1929 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -752,6 +752,7 @@ static void __init kho_reserve_scratch(void) * kho_add_subtree - record the physical address of a sub FDT in KHO root = tree. * @name: name of the sub tree. * @fdt: the sub tree blob. + * @size: size of the blob in bytes. * * Creates a new child node named @name in KHO root FDT and records * the physical address of @fdt. The pages of @fdt must also be preserved @@ -763,7 +764,7 @@ static void __init kho_reserve_scratch(void) * * Return: 0 on success, error code on failure */ -int kho_add_subtree(const char *name, void *fdt) +int kho_add_subtree(const char *name, void *fdt, size_t size) { phys_addr_t phys =3D virt_to_phys(fdt); void *root_fdt =3D kho_out.fdt; @@ -788,7 +789,7 @@ int kho_add_subtree(const char *name, void *fdt) if (err < 0) goto out_pack; =20 - WARN_ON_ONCE(kho_debugfs_fdt_add(&kho_out.dbg, name, fdt, false)); + WARN_ON_ONCE(kho_debugfs_fdt_add(&kho_out.dbg, name, fdt, size, false)); =20 out_pack: fdt_pack(root_fdt); @@ -1452,7 +1453,8 @@ static __init int kho_init(void) } =20 WARN_ON_ONCE(kho_debugfs_fdt_add(&kho_out.dbg, "fdt", - kho_out.fdt, true)); + kho_out.fdt, + fdt_totalsize(kho_out.fdt), true)); =20 return 0; =20 diff --git a/kernel/liveupdate/kexec_handover_debugfs.c b/kernel/liveupdate= /kexec_handover_debugfs.c index 3f395fbd978f4..b5a1e09ca8f14 100644 --- a/kernel/liveupdate/kexec_handover_debugfs.c +++ b/kernel/liveupdate/kexec_handover_debugfs.c @@ -24,7 +24,7 @@ struct fdt_debugfs { }; =20 static int __kho_debugfs_fdt_add(struct list_head *list, struct dentry *di= r, - const char *name, const void *fdt) + const char *name, const void *fdt, size_t size) { struct fdt_debugfs *f; struct dentry *file; @@ -34,7 +34,7 @@ static int __kho_debugfs_fdt_add(struct list_head *list, = struct dentry *dir, return -ENOMEM; =20 f->wrapper.data =3D (void *)fdt; - f->wrapper.size =3D fdt_totalsize(fdt); + f->wrapper.size =3D size; =20 file =3D debugfs_create_blob(name, 0400, dir, &f->wrapper); if (IS_ERR(file)) { @@ -49,7 +49,7 @@ static int __kho_debugfs_fdt_add(struct list_head *list, = struct dentry *dir, } =20 int kho_debugfs_fdt_add(struct kho_debugfs *dbg, const char *name, - const void *fdt, bool root) + const void *fdt, size_t size, bool root) { struct dentry *dir; =20 @@ -58,7 +58,7 @@ int kho_debugfs_fdt_add(struct kho_debugfs *dbg, const ch= ar *name, else dir =3D dbg->sub_fdt_dir; =20 - return __kho_debugfs_fdt_add(&dbg->fdt_list, dir, name, fdt); + return __kho_debugfs_fdt_add(&dbg->fdt_list, dir, name, fdt, size); } =20 void kho_debugfs_fdt_remove(struct kho_debugfs *dbg, void *fdt) @@ -112,7 +112,8 @@ __init void kho_in_debugfs_init(struct kho_debugfs *dbg= , const void *fdt) goto err_rmdir; } =20 - err =3D __kho_debugfs_fdt_add(&dbg->fdt_list, dir, "fdt", fdt); + err =3D __kho_debugfs_fdt_add(&dbg->fdt_list, dir, "fdt", fdt, + fdt_totalsize(fdt)); if (err) goto err_rmdir; =20 @@ -120,6 +121,7 @@ __init void kho_in_debugfs_init(struct kho_debugfs *dbg= , const void *fdt) int len =3D 0; const char *name =3D fdt_get_name(fdt, child, NULL); const u64 *fdt_phys; + void *sub_fdt; =20 fdt_phys =3D fdt_getprop(fdt, child, "fdt", &len); if (!fdt_phys) @@ -129,8 +131,9 @@ __init void kho_in_debugfs_init(struct kho_debugfs *dbg= , const void *fdt) name, len); continue; } + sub_fdt =3D phys_to_virt(*fdt_phys); err =3D __kho_debugfs_fdt_add(&dbg->fdt_list, sub_fdt_dir, name, - phys_to_virt(*fdt_phys)); + sub_fdt, fdt_totalsize(sub_fdt)); if (err) { pr_warn("failed to add fdt %s to debugfs: %pe\n", name, ERR_PTR(err)); diff --git a/kernel/liveupdate/kexec_handover_internal.h b/kernel/liveupdat= e/kexec_handover_internal.h index 9a832a35254cf..2a28cb8db9b0a 100644 --- a/kernel/liveupdate/kexec_handover_internal.h +++ b/kernel/liveupdate/kexec_handover_internal.h @@ -27,7 +27,7 @@ int kho_debugfs_init(void); void kho_in_debugfs_init(struct kho_debugfs *dbg, const void *fdt); int kho_out_debugfs_init(struct kho_debugfs *dbg); int kho_debugfs_fdt_add(struct kho_debugfs *dbg, const char *name, - const void *fdt, bool root); + const void *fdt, size_t size, bool root); void kho_debugfs_fdt_remove(struct kho_debugfs *dbg, void *fdt); #else static inline int kho_debugfs_init(void) { return 0; } @@ -35,7 +35,8 @@ static inline void kho_in_debugfs_init(struct kho_debugfs= *dbg, const void *fdt) { } static inline int kho_out_debugfs_init(struct kho_debugfs *dbg) { return 0= ; } static inline int kho_debugfs_fdt_add(struct kho_debugfs *dbg, const char = *name, - const void *fdt, bool root) { return 0; } + const void *fdt, size_t size, + bool root) { return 0; } static inline void kho_debugfs_fdt_remove(struct kho_debugfs *dbg, void *fdt) { } #endif /* CONFIG_KEXEC_HANDOVER_DEBUGFS */ diff --git a/kernel/liveupdate/luo_core.c b/kernel/liveupdate/luo_core.c index 84ac728d63baa..04d06a0906c0e 100644 --- a/kernel/liveupdate/luo_core.c +++ b/kernel/liveupdate/luo_core.c @@ -172,7 +172,8 @@ static int __init luo_fdt_setup(void) if (err) goto exit_free; =20 - err =3D kho_add_subtree(LUO_FDT_KHO_ENTRY_NAME, fdt_out); + err =3D kho_add_subtree(LUO_FDT_KHO_ENTRY_NAME, fdt_out, + fdt_totalsize(fdt_out)); if (err) goto exit_free; luo_global.fdt_out =3D fdt_out; diff --git a/lib/test_kho.c b/lib/test_kho.c index 7ef9e40618696..2631824373152 100644 --- a/lib/test_kho.c +++ b/lib/test_kho.c @@ -143,7 +143,8 @@ static int kho_test_preserve(struct kho_test_state *sta= te) if (err) goto err_unpreserve_data; =20 - err =3D kho_add_subtree(KHO_TEST_FDT, folio_address(state->fdt)); + err =3D kho_add_subtree(KHO_TEST_FDT, folio_address(state->fdt), + fdt_totalsize(folio_address(state->fdt))); if (err) goto err_unpreserve_data; =20 diff --git a/mm/memblock.c b/mm/memblock.c index ae6a5af46bd78..29e12ea2a854c 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -2488,7 +2488,7 @@ static int __init prepare_kho_fdt(void) if (err) goto err_unpreserve_fdt; =20 - err =3D kho_add_subtree(MEMBLOCK_KHO_FDT, fdt); + err =3D kho_add_subtree(MEMBLOCK_KHO_FDT, fdt, fdt_totalsize(fdt)); if (err) goto err_unpreserve_fdt; =20 --=20 2.47.3