From nobody Thu Apr 9 10:31:49 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 Acked-by: SeongJae Park 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 From nobody Thu Apr 9 10:31:49 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 5B9B03AA1AE for ; Mon, 9 Mar 2026 13:42:27 +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=1773063749; cv=none; b=gJsQAkKNFuUEpC3py2l/QXeREeng+rJ+kt9jOJzIP2G42thppOGDB6Zef/us7//PnPCcM4FtI1bpTliwDJQ6jxMzO2LHMXccgdB/L7ZI0zVL/0aBug9cSdeoRdfMi1lVYI1P7YXVVIicTavvpHreell9GtYx79JC1U11wYnelg0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773063749; c=relaxed/simple; bh=YDthdgiQbZvgrpt+Me0u+UlmR+Dfg+aF1caFkoII/jo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FMpKatgyoaHn880ae7kfXrPSkflvvNbW5IW1gq4Om/P9bMlLMYD8JtEwJMLm030UrTJ0nLXMVTmnWdIOnCO/kBrzT/21qMk1RmJYOT0znPnMbFfsz8NE2K/Urj7oTzlY9UdW3mcZnTagk/BE5IA8JFN0sx+/9AXa2c5MI2y0IzQ= 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=ispJttgT; 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="ispJttgT" 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=9d/snK4xVbWikBAE/m/zmi9nqno2C5hPckyJRYlDt8s=; b=ispJttgTKZuUuNl9uz2O19j/TS XTDKJszUFwGRh0B1vgPte46/UyHled4rILSSd/STz5zcA0WBBFHGZL9kp3OHfmAtTAz7DqQaIxYFE Bs75b6PDZtfQUZYo9/OyeCI3z7MXff718ybN+jlU7LLL7m1omfhGMYYifOetji2dsKSpRXGNynUsA OwkDErIFg2f9IZoEoSJehfO8quZ3NMLP8mD/ZZ9X69XrNch9GP9GUk+pTitWNQP+Sp4nTarCM/Ej2 V0au41yJ6dLn0kpdt/Soc0DRDqRJG261yaly5Uror+hj3JAY/U8BooxLq4vHLAOLMLsDuJ9nEI7M4 kI9FezuA==; 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 1vzasK-002G3Q-9T; Mon, 09 Mar 2026 13:42:24 +0000 From: Breno Leitao Date: Mon, 09 Mar 2026 06:41:45 -0700 Subject: [PATCH v8 2/6] kho: rename fdt parameter to blob in kho_add/remove_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-2-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=10553; i=leitao@debian.org; h=from:subject:message-id; bh=YDthdgiQbZvgrpt+Me0u+UlmR+Dfg+aF1caFkoII/jo=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBprs4yIwriGYppcItJb79pnuFcumHUllGkpjheZ 4ZCM2nxaTGJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaa7OMgAKCRA1o5Of/Hh3 bf9iD/48CLBfW2ZKolE5ndIKiButWnvgudDa1uIOBW2MDCb2rmPNP6u0Jbo0F1rBoQAVMFcN8fE bxAtp9xo9qham8OqEDDVKJCd9trNznYhMDYZiaDooMBMlNw1o7BBTCMfmTweLJyaYTNCH0i9j65 ivQRWZA3oh+uwBcoVv8syD+vILmZbpNCEBXcftwwmQwKdTpdb1wN2hAqepbGYpkQIZL1UPHUsVr KXENuncC2DJ7Xk7aFPtOZb1tw2Tw+nUJn9fKuT+l4afWBlu+8E6O7jxgdFmeXCrkkRkHNFipFeu ZQ0IzoJS9sHDpxQLk46wFwFatFCmUONn2nFNUqmjVExW5BzUJgZY+Z+WBN22dT13BVd4E+LiP84 S+VBCnspJneZuts5sbnkWHLW9g+XSfhk0FSOLjxhN3B9+MLVraWLnzjjlIBpoEU5Dt0hmkpMvTF xmIsvVwMoue0J7qMkUHV+Zj2+Teq+ovRu612Kx2t1O0/9/Yu2wyIpzWK1pO3pXJYHPfvaBqZogZ 7YmtL3VrFP/AclZio/11pYSqpW/ziJEaRlYBuJXm0evj68cEN2mnT66m1EBLSlVpbc6X1lQMvSZ 8cb70FMSvdmbHaz7RFau2OJdf/wCMb+YfIyHdSKo6D2kEUzWAfelAw4X+55LwVe+jPQGmaE/4Ef 5zPtZP+celYcjaw== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao Since kho_add_subtree() now accepts arbitrary data blobs (not just FDTs), rename the parameter from 'fdt' to 'blob' to better reflect its purpose. Apply the same rename to kho_remove_subtree() for consistency. Also rename kho_debugfs_fdt_add() and kho_debugfs_fdt_remove() to kho_debugfs_blob_add() and kho_debugfs_blob_remove() respectively, with the same parameter rename from 'fdt' to 'blob'. Signed-off-by: Breno Leitao Reviewed-by: Mike Rapoport (Microsoft) Acked-by: SeongJae Park Reviewed-by: Pratyush Yadav --- Documentation/admin-guide/mm/kho.rst | 2 +- include/linux/kexec_handover.h | 8 +++---- kernel/liveupdate/kexec_handover.c | 33 +++++++++++++++----------= ---- kernel/liveupdate/kexec_handover_debugfs.c | 25 +++++++++++----------- kernel/liveupdate/kexec_handover_internal.h | 16 +++++++------- 5 files changed, 43 insertions(+), 41 deletions(-) diff --git a/Documentation/admin-guide/mm/kho.rst b/Documentation/admin-gui= de/mm/kho.rst index cb9a20f649206..6a4ddf3440465 100644 --- a/Documentation/admin-guide/mm/kho.rst +++ b/Documentation/admin-guide/mm/kho.rst @@ -80,5 +80,5 @@ stabilized. it finished to interpret their metadata. =20 ``/sys/kernel/debug/kho/in/sub_fdts/`` - Similar to ``kho/out/sub_fdts/``, but contains sub FDT blobs + Similar to ``kho/out/sub_fdts/``, but contains sub blobs of KHO producers passed from the old kernel. diff --git a/include/linux/kexec_handover.h b/include/linux/kexec_handover.h index abb1d324f42d0..0666cf298c7f4 100644 --- a/include/linux/kexec_handover.h +++ b/include/linux/kexec_handover.h @@ -32,8 +32,8 @@ 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, size_t size); -void kho_remove_subtree(void *fdt); +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); =20 void kho_memory_init(void); @@ -97,12 +97,12 @@ static inline void *kho_restore_vmalloc(const struct kh= o_vmalloc *preservation) return NULL; } =20 -static inline int kho_add_subtree(const char *name, void *fdt, size_t size) +static inline int kho_add_subtree(const char *name, void *blob, size_t siz= e) { return -EOPNOTSUPP; } =20 -static inline void kho_remove_subtree(void *fdt) { } +static inline void kho_remove_subtree(void *blob) { } =20 static inline int kho_retrieve_subtree(const char *name, phys_addr_t *phys) { diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_h= andover.c index 55bdc5d2d1929..54fe59fe43acd 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -749,13 +749,13 @@ static void __init kho_reserve_scratch(void) } =20 /** - * kho_add_subtree - record the physical address of a sub FDT in KHO root = tree. + * kho_add_subtree - record the physical address of a sub blob in KHO root= tree. * @name: name of the sub tree. - * @fdt: the sub tree blob. + * @blob: 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 + * the physical address of @blob. The pages of @blob must also be preserved * by KHO for the new kernel to retrieve it after kexec. * * A debugfs blob entry is also created at @@ -764,9 +764,9 @@ static void __init kho_reserve_scratch(void) * * Return: 0 on success, error code on failure */ -int kho_add_subtree(const char *name, void *fdt, size_t size) +int kho_add_subtree(const char *name, void *blob, size_t size) { - phys_addr_t phys =3D virt_to_phys(fdt); + phys_addr_t phys =3D virt_to_phys(blob); void *root_fdt =3D kho_out.fdt; int err =3D -ENOMEM; int off, fdt_err; @@ -789,7 +789,8 @@ int kho_add_subtree(const char *name, void *fdt, size_t= size) if (err < 0) goto out_pack; =20 - WARN_ON_ONCE(kho_debugfs_fdt_add(&kho_out.dbg, name, fdt, size, false)); + WARN_ON_ONCE(kho_debugfs_blob_add(&kho_out.dbg, name, blob, + size, false)); =20 out_pack: fdt_pack(root_fdt); @@ -798,9 +799,9 @@ int kho_add_subtree(const char *name, void *fdt, size_t= size) } EXPORT_SYMBOL_GPL(kho_add_subtree); =20 -void kho_remove_subtree(void *fdt) +void kho_remove_subtree(void *blob) { - phys_addr_t target_phys =3D virt_to_phys(fdt); + phys_addr_t target_phys =3D virt_to_phys(blob); void *root_fdt =3D kho_out.fdt; int off; int err; @@ -822,7 +823,7 @@ void kho_remove_subtree(void *fdt) =20 if ((phys_addr_t)*val =3D=3D target_phys) { fdt_del_node(root_fdt, off); - kho_debugfs_fdt_remove(&kho_out.dbg, fdt); + kho_debugfs_blob_remove(&kho_out.dbg, blob); break; } } @@ -1310,11 +1311,11 @@ bool is_kho_boot(void) EXPORT_SYMBOL_GPL(is_kho_boot); =20 /** - * kho_retrieve_subtree - retrieve a preserved sub FDT by its name. - * @name: the name of the sub FDT passed to kho_add_subtree(). - * @phys: if found, the physical address of the sub FDT is stored in @phys. + * 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. * - * Retrieve a preserved sub FDT named @name and store its physical + * Retrieve a preserved sub blob named @name and store its physical * address in @phys. * * Return: 0 on success, error code on failure @@ -1452,9 +1453,9 @@ static __init int kho_init(void) return 0; } =20 - WARN_ON_ONCE(kho_debugfs_fdt_add(&kho_out.dbg, "fdt", - kho_out.fdt, - fdt_totalsize(kho_out.fdt), true)); + WARN_ON_ONCE(kho_debugfs_blob_add(&kho_out.dbg, "fdt", + 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 b5a1e09ca8f14..7a100f2bf3947 100644 --- a/kernel/liveupdate/kexec_handover_debugfs.c +++ b/kernel/liveupdate/kexec_handover_debugfs.c @@ -23,8 +23,9 @@ struct fdt_debugfs { struct dentry *file; }; =20 -static int __kho_debugfs_fdt_add(struct list_head *list, struct dentry *di= r, - const char *name, const void *fdt, size_t size) +static int __kho_debugfs_blob_add(struct list_head *list, struct dentry *d= ir, + const char *name, const void *blob, + size_t size) { struct fdt_debugfs *f; struct dentry *file; @@ -33,7 +34,7 @@ static int __kho_debugfs_fdt_add(struct list_head *list, = struct dentry *dir, if (!f) return -ENOMEM; =20 - f->wrapper.data =3D (void *)fdt; + f->wrapper.data =3D (void *)blob; f->wrapper.size =3D size; =20 file =3D debugfs_create_blob(name, 0400, dir, &f->wrapper); @@ -48,8 +49,8 @@ static int __kho_debugfs_fdt_add(struct list_head *list, = struct dentry *dir, return 0; } =20 -int kho_debugfs_fdt_add(struct kho_debugfs *dbg, const char *name, - const void *fdt, size_t size, bool root) +int kho_debugfs_blob_add(struct kho_debugfs *dbg, const char *name, + const void *blob, size_t size, bool root) { struct dentry *dir; =20 @@ -58,15 +59,15 @@ int kho_debugfs_fdt_add(struct kho_debugfs *dbg, const = char *name, else dir =3D dbg->sub_fdt_dir; =20 - return __kho_debugfs_fdt_add(&dbg->fdt_list, dir, name, fdt, size); + return __kho_debugfs_blob_add(&dbg->fdt_list, dir, name, blob, size); } =20 -void kho_debugfs_fdt_remove(struct kho_debugfs *dbg, void *fdt) +void kho_debugfs_blob_remove(struct kho_debugfs *dbg, void *blob) { struct fdt_debugfs *ff; =20 list_for_each_entry(ff, &dbg->fdt_list, list) { - if (ff->wrapper.data =3D=3D fdt) { + if (ff->wrapper.data =3D=3D blob) { debugfs_remove(ff->file); list_del(&ff->list); kfree(ff); @@ -112,8 +113,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, - fdt_totalsize(fdt)); + err =3D __kho_debugfs_blob_add(&dbg->fdt_list, dir, "fdt", fdt, + fdt_totalsize(fdt)); if (err) goto err_rmdir; =20 @@ -132,8 +133,8 @@ __init void kho_in_debugfs_init(struct kho_debugfs *dbg= , const void *fdt) continue; } sub_fdt =3D phys_to_virt(*fdt_phys); - err =3D __kho_debugfs_fdt_add(&dbg->fdt_list, sub_fdt_dir, name, - sub_fdt, fdt_totalsize(sub_fdt)); + err =3D __kho_debugfs_blob_add(&dbg->fdt_list, sub_fdt_dir, name, + 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 2a28cb8db9b0a..0399ff1077750 100644 --- a/kernel/liveupdate/kexec_handover_internal.h +++ b/kernel/liveupdate/kexec_handover_internal.h @@ -26,19 +26,19 @@ extern unsigned int kho_scratch_cnt; 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, size_t size, bool root); -void kho_debugfs_fdt_remove(struct kho_debugfs *dbg, void *fdt); +int kho_debugfs_blob_add(struct kho_debugfs *dbg, const char *name, + const void *blob, size_t size, bool root); +void kho_debugfs_blob_remove(struct kho_debugfs *dbg, void *blob); #else static inline int kho_debugfs_init(void) { return 0; } 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, size_t size, - bool root) { return 0; } -static inline void kho_debugfs_fdt_remove(struct kho_debugfs *dbg, - void *fdt) { } +static inline int kho_debugfs_blob_add(struct kho_debugfs *dbg, + const char *name, const void *blob, + size_t size, bool root) { return 0; } +static inline void kho_debugfs_blob_remove(struct kho_debugfs *dbg, + void *blob) { } #endif /* CONFIG_KEXEC_HANDOVER_DEBUGFS */ =20 #ifdef CONFIG_KEXEC_HANDOVER_DEBUG --=20 2.47.3 From nobody Thu Apr 9 10:31:49 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 E0A173A7F6C for ; Mon, 9 Mar 2026 13:42:30 +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=1773063752; cv=none; b=pTooOIJGmTceMjndex64PMnl6kwaEeI3OXAN8RzEeUIqF3oxAwkGC7Bc1/Ub2AucVvLc40+h4YikAEh5anRzNTfp52QjmJ/qncvXc0MRoN2M8BvPDCD8uCp9EyWUDYTrZYvH5AtGigVAv9niSj5NAj2OD4DkHx4uXLTU2d/XRt4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773063752; c=relaxed/simple; bh=u26q8+424ryPZEmQMXhYg2CGtc4uVC9Yg6zN9YqpvT4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UXVE51gof4lLCwXkJztJA93wmkUf1mxfHb29DgR9Jb/m43nxsEIbC/5slOwFJ4ED8DZE/QbbRBnBBUd9Mh0PSZDD4ZzL3rP/e+6LM84vgADIebhFJUImNDBkqqwseITYgeRYVKS5PkuOT8dhwpbW1asERfANXG4a0srwgQbPrp0= 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=Ce0ODBoe; 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="Ce0ODBoe" 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=EKYiyJc2pJTId+ldlpo0ZDLrgplXezO3UOz8MUOHHDk=; b=Ce0ODBoeTLUkw2GDjIX+TE/apq hs9NMI8U3pQ/r9k91L9p4putmJhOMMfUP1HBCk5r1y0RQx8LBLuDhSdYUb61jxDDJTfzj4AOynmOh 3CiepRCrLuw3koKtlqaH9vGpWrtANO8oUhwb1OVTM8Tyy3KmDwCalGTC2j2pbdAJc3djfE3tRMfv/ 1NwJI3ULOWhACH6H452hBTsXh/6vh5bozKxRkWMsTe72HiLv+eE8MTCJOc+Qf2fk4waV4l93evGVS 2nTBMISlCbv+IrpLxENh0o97GMbC+gOW68aa/OJonjF0nUk8+pm1OiB/uejXh0moteYPaOeHBhrCi CN76lGdw==; 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 1vzasO-002G3d-CS; Mon, 09 Mar 2026 13:42:28 +0000 From: Breno Leitao Date: Mon, 09 Mar 2026 06:41:46 -0700 Subject: [PATCH v8 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: <20260309-kho-v8-3-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=8235; i=leitao@debian.org; h=from:subject:message-id; bh=u26q8+424ryPZEmQMXhYg2CGtc4uVC9Yg6zN9YqpvT4=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBprs4yZ+R2PEvk3C6myQX9u+605PCBk1NmnfWrT 1G6bFo2c++JAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaa7OMgAKCRA1o5Of/Hh3 bfSWEACl5uvGO0nE7tsUZ2bnuyNeoKjAT2ZPG9CarGKMFgDS4OnBKRyrlvqrFS6ZDYajMmI3gNO i5rOD3G/nuNifuByKm9SDuyhElTgIYjKOBg/CrwhWBdLdcTu9IsNvrlvE3aNUKQhAivEWEuPqMb wzPFhvTAfwg7wZ+/E8QhvJbZEyleiy7yW/7XMNyXZI34hkCm1Fg1QvYfGSmERMXaig+NSxWgPTl W+aJqQlQT8usiwCHNLA2QarHv3W7c5NJBf/8mJzIIZMUILv3mzi2vm8fFk8M0xbhDlMR/x+zr0M fwmMEwEs8+2cnZ+YpXgh6Dl6yyKpy8elEctki7rrVm9/KyLAofm+wty5LsBGiWSQzAfyHh9pLoe jh/+l96OsmXF3hIRJt1oAWshd3gyQBbksI9bC5eethWgb+dgzaYwYbOsnXbS2Zlm4dOXmyJT9DR xdlYexLV9zQCKkt2nEpp2+kE23pdP2kbCXO+sFwpebSDOdcSYlBBiklk8YJHGKnSCdz5QTrtDyB nZqcTGE2ajVvYRG2y0Dd77JPXseCSbG70m0FULyLXOUPaUoXNjcjjbP5HQ2l/K850F6Ae69A0kS mbcoBKVyE+6H9rugxWZBp2EQB27wL5E7FZMdv2ZmjO2ZjlU8RmjPIqhEW88sc7SSxWgAr02N40y VZRtuqutpp5721g== 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. Signed-off-by: Breno Leitao Acked-by: SeongJae Park Reviewed-by: Mike Rapoport (Microsoft) --- include/linux/kexec_handover.h | 5 +++-- include/linux/kho/abi/kexec_handover.h | 20 ++++++++++++++++---- kernel/liveupdate/kexec_handover.c | 26 +++++++++++++++++++++----- kernel/liveupdate/luo_core.c | 2 +- lib/test_kho.c | 2 +- mm/memblock.c | 2 +- 6 files changed, 43 insertions(+), 14 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..1f22705d5d246 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,21 @@ 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 + if (size) { + val =3D fdt_getprop(fdt, offset, KHO_SUB_TREE_SIZE_PROP_NAME, + &len); + if (val && len =3D=3D sizeof(*val)) + *size =3D (size_t)*val; + else + *size =3D 0; + } + return 0; } EXPORT_SYMBOL_GPL(kho_retrieve_subtree); 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.47.3 From nobody Thu Apr 9 10:31:49 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 0B6173AE6EB for ; Mon, 9 Mar 2026 13:42:34 +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=1773063756; cv=none; b=l7ZNJhemPobFFdjgMEnwXw0iUtv0h8RIQZ2zJ3DuS5cUGijix0MPXlxDYt+/7D89Vm07BgjcnpCYPlO9UVcL3KbReTrsr9xGIeKNjl6RNeEqUS8G5DEjgtCVwiZ8jo1F3OJd+oOXUARvGW8dk6EqZBPFRaktpFnlTHepkNXujV8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773063756; c=relaxed/simple; bh=pgo9Bbif/Iq2LY22Zf8vKl/gIhQNmdeP3CUxMaHZ9Dw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kuORffVGoUGJ5p2y66lgQbAmzqlSpPYfdRQQ9dCRXwvNcULm4XePWX84dhUAcG+xIFdt4ZkgbYUY7/F2yKGvHIJwFj1MObhRYpb8g7w/XKABJ3UgMbdDfQV6TgqVTmqsq65tsvRSXZHL8wl6gtUTW5Oybijbr/UuGZdISfmgkpo= 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=dDG+1siO; 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="dDG+1siO" 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=Ki42cLPnp8Qeyh0kILceJ+Cv5Lvk3JbK3h54C1+Mwj8=; b=dDG+1siO5bIqzBPb12wlG3NvS5 EN79ITNUuMRYWb1u/3APu6BeWNKyTmA6hToFHqiHqlkdiRKIA9vIrtstl2+uBPp6ulVEXPpHIY8S+ /qPvP4qh9R+kZxaNl4rFrhkU83Nxe5JPXoNHmSYP96GQfkng196aUNuNdDxm1mK8+5+Y15RgAjmud tmX9OHDK9qsmmC/NOlJliGldXPzZ5sFU2q578//Lo06FbVEOh2aJ9xaWuGi4pzMMviTq09uIs7/mN oj2A4LlDnp2AqxBzyRMT+39n4fJOunQF+VSc8FjsK8f/S0NZeXOxCePsuZ5IsPMoJgEhsFOa0Ao48 Bg65Ng3w==; 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 1vzasS-002G3r-Hy; Mon, 09 Mar 2026 13:42:32 +0000 From: Breno Leitao Date: Mon, 09 Mar 2026 06:41:47 -0700 Subject: [PATCH v8 4/6] kho: fix kho_in_debugfs_init() to handle non-FDT blobs 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-4-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=2751; i=leitao@debian.org; h=from:subject:message-id; bh=pgo9Bbif/Iq2LY22Zf8vKl/gIhQNmdeP3CUxMaHZ9Dw=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBprs4yoKfrHmBJbEuCrYV9rdiomUpCNqeGUD49s JR++cG0exWJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaa7OMgAKCRA1o5Of/Hh3 bQWLD/98p0l+FcT2BDdyTKmRTYD8ikYqEE7RChHTT4zoIMfKc1BwA+xtvZUUAVJXhXqdxUS4s79 0uGsW8iYers5S5MQIn79gWL44duPHmAIANIZlzBe7WE1lV7JYculVbw67zBpCKv8MZcRrDmJoHx GXw4uVdTrXe/EXgvJlAmNEfmamGKe0nLq93P9LRUcKsgVgTKW71hQBlvxv5XP8MZfaoU9swIWc3 2PpJHC+cXA3+rEbXG1KVzM+eVyT7MPLMhuTKKdfbFyyAT9tPZ9UkiMpJKtVbgueuLN7KpWHhohR wd7sj7uHsMfWsL2bQtpf888+xZYLqRGvqn8ioA3lb/KGw4l8DVoXzqazDibQ0w1X/3+aiop5AY1 KWBQ+FZnaQEFlmCT5lfX4fdDOyCFB4AI1OSlCS6hEiOUvRtV5RZ3s10bhyBx9CnPAoH2f06ci/G g0Z3LvvdcOCNz1lcOodOu0cQkFRmUL8LmD4wEmRybFtMps5ZPVVax00gYgv+kjZEMUvWBpht5jG kVMFwn0VVfXGiSgMrTOIO/BVvgu0CHkibLtrXdCMSru24HseBgV62fjTDdmyFEPfQ0W1L6oUFV9 rI+y+a4L7i2QX/SaGirRr5UdNjaw2HaQeX60PK6zOS/K9JBcmIV5R9PfadMTGQXO4KJuIEoU0D9 Nc+zunbNNdsk26Q== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao kho_in_debugfs_init() has two problems when displaying incoming sub-blobs in debugfs: 1. It uses the hardcoded property name "fdt" instead of KHO_SUB_TREE_PROP_NAME ("preserved-data"), so it never finds subtrees stored by the current kho_add_subtree(). 2. It calls fdt_totalsize() to determine blob sizes, which assumes all blobs are FDTs. This breaks for non-FDT blobs like struct kho_kexec_metadata. Fix both issues by using KHO_SUB_TREE_PROP_NAME to find subtrees and reading the "blob-size" property from the FDT (persisted by kho_add_subtree()) instead of calling fdt_totalsize(). Signed-off-by: Breno Leitao Acked-by: SeongJae Park Reviewed-by: Mike Rapoport (Microsoft) Reviewed-by: Pratyush Yadav --- kernel/liveupdate/kexec_handover_debugfs.c | 34 ++++++++++++++++++++------= ---- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/kernel/liveupdate/kexec_handover_debugfs.c b/kernel/liveupdate= /kexec_handover_debugfs.c index 7a100f2bf3947..257ee8a52be66 100644 --- a/kernel/liveupdate/kexec_handover_debugfs.c +++ b/kernel/liveupdate/kexec_handover_debugfs.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "kexec_handover_internal.h" =20 static struct dentry *debugfs_root; @@ -121,23 +122,34 @@ __init void kho_in_debugfs_init(struct kho_debugfs *d= bg, const void *fdt) fdt_for_each_subnode(child, fdt, 0) { int len =3D 0; const char *name =3D fdt_get_name(fdt, child, NULL); - const u64 *fdt_phys; - void *sub_fdt; + const u64 *blob_phys; + const u64 *blob_size; + void *blob; =20 - fdt_phys =3D fdt_getprop(fdt, child, "fdt", &len); - if (!fdt_phys) + blob_phys =3D fdt_getprop(fdt, child, + KHO_SUB_TREE_PROP_NAME, &len); + if (!blob_phys) continue; - if (len !=3D sizeof(*fdt_phys)) { - pr_warn("node %s prop fdt has invalid length: %d\n", - name, len); + if (len !=3D sizeof(*blob_phys)) { + pr_warn("node %s prop %s has invalid length: %d\n", + name, KHO_SUB_TREE_PROP_NAME, len); continue; } - sub_fdt =3D phys_to_virt(*fdt_phys); + + blob_size =3D fdt_getprop(fdt, child, + KHO_SUB_TREE_SIZE_PROP_NAME, &len); + if (!blob_size || len !=3D sizeof(*blob_size)) { + pr_warn("node %s missing or invalid %s property\n", + name, KHO_SUB_TREE_SIZE_PROP_NAME); + continue; + } + + blob =3D phys_to_virt(*blob_phys); err =3D __kho_debugfs_blob_add(&dbg->fdt_list, sub_fdt_dir, name, - sub_fdt, fdt_totalsize(sub_fdt)); + blob, *blob_size); if (err) { - pr_warn("failed to add fdt %s to debugfs: %pe\n", name, - ERR_PTR(err)); + pr_warn("failed to add blob %s to debugfs: %pe\n", + name, ERR_PTR(err)); continue; } } --=20 2.47.3 From nobody Thu Apr 9 10:31:49 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 2EFD13C6A5C for ; Mon, 9 Mar 2026 13:42:39 +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=1773063762; cv=none; b=QCYDSfTVkjKTOongAKXqtHDxktxbUZ3kf63k/7YgD0yCoTHLZIxgOclspVBIScHSpuP22N1TDr1VGPy5KKFI9Cdmc69N42wHvYBzwrk523sZguPEvC78+AgyxXj/UwroYAhJAUC2IqUr+VWmZFr3n8dz/eCPMjvIxhjotWiUs5g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773063762; c=relaxed/simple; bh=wFUQv960bxV6n7TCJD4FMZFCiB/JTLz1Skv4YLrEGDo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZFF2wNuVVUy2Gl9ijAXM1VE9DPwQKIrklkHQSKORDbDiFl4mOsYox2vhnaaUl0Dz4iQ9Krt0zqwyKLJEMfZT3c+1cK+ifd/0cCQtn2j06q+VBCf7ltqs8qn+DHMDAZcOWHZy2qyt7AEcHhrCCxQzmVwJYW7Ta8YnAEEbe0KPekQ= 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=FHCl0iht; 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="FHCl0iht" 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=blrIoTJexK9V0SlE9m9/WXlOitlTxjozBKun7UC+eh8=; b=FHCl0ihtv2OIcDfxgAcjQsZ13S bVrK4lbShDHCpY4HOHDe31fGqD+MOaqYf3HJ7OmAqhsUpH4+BAQMhGTBQu4+eI6rhKzskHaaVVdPS x9mV9YDX+NbL4UuTcA51fXuaTqIPHTospvcWEvNxzNRNBM1eWSGg21jrA0TWAvKdz4dy+fczghxT0 Z/rC61fvjGn8FclbAMdRIqihWnChq3jI+6NerOwUI6G6D/dOtSEaZ9jDkO/iQNt54EJ/Cu3/+UeRA 1VK++OJP8t60D5Lj4+uQYvhrrwjH5kuersshZWVI5wEib2AtpWJUL97dHbu+Xh6iqp9Q62PR9bAWz Mi3YgEBA==; 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 1vzasW-002G47-HZ; Mon, 09 Mar 2026 13:42:36 +0000 From: Breno Leitao Date: Mon, 09 Mar 2026 06:41:48 -0700 Subject: [PATCH v8 5/6] kho: kexec-metadata: track previous kernel chain 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-5-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=6984; i=leitao@debian.org; h=from:subject:message-id; bh=wFUQv960bxV6n7TCJD4FMZFCiB/JTLz1Skv4YLrEGDo=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBprs4zTCZed02jaYw/bWAOKaoOVGmOZXpy/X8YT cQPE+vNHfOJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaa7OMwAKCRA1o5Of/Hh3 bQbPD/9aJTG4urF72fJIr1nRxjL5YeMpUnN/2wI3qvPGXyebkyYTLLxD4GTqj7rLxkiqYrTtDRl t276tDdGD2Vl0S9X62sPgZagsEa2nMAyTmq03uZE/TXjM5dyVvKGIyZW1Y5GFgmLskD+t+uzrqE nuZYh78BaRoT2Ni0pnyUyL3vx0mSGW9wC2pdF3rFf7HrTM9AuVXFgHs0toqaQaPvZlda2YLLnfp j1ZcC9pBMeQhAl8vZUghV9QdRgfmEjsMJx/ybghubXZOS+I4nB5pqAo22+vu/3YhF1vK8M0d43e g1Spk+6JWdxlsPG3fu37hWB6U20KtmJPGikbDDjv5pgxs6kgg2JI6zFGp+QXBVXT6FNSc4YCn1T SuCXUhcRCAVXVmWM9tl4gC2JAa1dqe9V/SOK8dvu7gGVlsBd0ltaB7poT3PFPp/NrqFSMCdDG7j AXSKMy98e7jxuyi2bkfN/oCMGeN65GP2hYQT3Efa305saMqySSvVHbt6m8bSSIiIYAICaUk8O3H 7tVoxzfWlaxbQNmfJsoU1GPWNonwpZBWWE7jkWpalUOiccl+Esti2716A5CbTxxwI1zO+GzUYDf gtiwrWEm23A8t1rLFapudKYYH/8qnAgCEtzfI5RBC5wd4pvIlte29UdlqY0RYjvVrxCPdY5DFwX W5/izPj42rd01kA== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao Use Kexec Handover (KHO) to pass the previous kernel's version string and the number of kexec reboots since the last cold boot to the next kernel, and print it at boot time. Example output: [ 0.000000] KHO: exec from: 6.19.0-rc4-next-20260107 (count 1) Motivation =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Bugs that only reproduce when kexecing from specific kernel versions are difficult to diagnose. These issues occur when a buggy kernel kexecs into a new kernel, with the bug manifesting only in the second kernel. Recent examples include the following commits: * eb2266312507 ("x86/boot: Fix page table access in 5-level to 4-level pag= ing transition") * 77d48d39e991 ("efistub/tpm: Use ACPI reclaim memory for event log to avo= id corruption") * 64b45dd46e15 ("x86/efi: skip memattr table on kexec boot") As kexec-based reboots become more common, these version-dependent bugs are appearing more frequently. At scale, correlating crashes to the previous kernel version is challenging, especially when issues only occur in specific transition scenarios. Implementation =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D The kexec metadata is stored as a plain C struct (struct kho_kexec_metadata) rather than FDT format, for simplicity and direct field access. It is registered via kho_add_subtree() as a separate subtree, keeping it independent from the core KHO ABI. This design choice: - Keeps the core KHO ABI minimal and stable - Allows the metadata format to evolve independently - Avoids requiring version bumps for all KHO consumers (LUO, etc.) when the metadata format changes The struct kho_kexec_metadata contains two fields: - previous_release: The kernel version that initiated the kexec - kexec_count: Number of kexec boots since last cold boot On cold boot, kexec_count starts at 0 and increments with each kexec. The count helps identify issues that only manifest after multiple consecutive kexec reboots. Acked-by: SeongJae Park Reviewed-by: Mike Rapoport (Microsoft) Signed-off-by: Breno Leitao --- include/linux/kho/abi/kexec_handover.h | 31 ++++++++++++++ kernel/liveupdate/kexec_handover.c | 75 ++++++++++++++++++++++++++++++= ++++ 2 files changed, 106 insertions(+) diff --git a/include/linux/kho/abi/kexec_handover.h b/include/linux/kho/abi= /kexec_handover.h index 7e847a2339b09..832390f96f49c 100644 --- a/include/linux/kho/abi/kexec_handover.h +++ b/include/linux/kho/abi/kexec_handover.h @@ -14,6 +14,7 @@ #include #include #include +#include =20 #include =20 @@ -101,6 +102,36 @@ /* The FDT property for the size of preserved data blobs. */ #define KHO_SUB_TREE_SIZE_PROP_NAME "blob-size" =20 +/** + * DOC: Kexec Metadata ABI + * + * The "kexec-metadata" subtree stores optional metadata about the kexec c= hain. + * It is registered via kho_add_subtree(), keeping it independent from the= core + * KHO ABI. This allows the metadata format to evolve without affecting ot= her + * KHO consumers. + * + * The metadata is stored as a plain C struct rather than FDT format for + * simplicity and direct field access. + */ + +/** + * struct kho_kexec_metadata - Kexec metadata passed between kernels + * @previous_release: Kernel version string that initiated the kexec + * @kexec_count: Number of kexec boots since last cold boot + * + * This structure is preserved across kexec and allows the new kernel to + * identify which kernel it was booted from and how many kexec reboots + * have occurred. + * + * __NEW_UTS_LEN is part of uABI, so it safe to use it in here. + */ +struct kho_kexec_metadata { + char previous_release[__NEW_UTS_LEN + 1]; + u32 kexec_count; +} __packed; + +#define KHO_METADATA_NODE_NAME "kexec-metadata" + /** * DOC: Kexec Handover ABI for vmalloc Preservation * diff --git a/kernel/liveupdate/kexec_handover.c b/kernel/liveupdate/kexec_h= andover.c index 1f22705d5d246..7bac80e9a29a4 100644 --- a/kernel/liveupdate/kexec_handover.c +++ b/kernel/liveupdate/kexec_handover.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -1285,6 +1286,8 @@ EXPORT_SYMBOL_GPL(kho_restore_free); struct kho_in { phys_addr_t fdt_phys; phys_addr_t scratch_phys; + char previous_release[__NEW_UTS_LEN + 1]; + u32 kexec_count; struct kho_debugfs dbg; }; =20 @@ -1408,6 +1411,74 @@ static __init int kho_out_fdt_setup(void) return err; } =20 +static void __init kho_in_kexec_metadata(void) +{ + struct kho_kexec_metadata *metadata; + phys_addr_t metadata_phys; + int err; + + err =3D kho_retrieve_subtree(KHO_METADATA_NODE_NAME, &metadata_phys, + NULL); + if (err) + /* This is fine, previous kernel didn't export metadata */ + return; + metadata =3D phys_to_virt(metadata_phys); + + /* + * Copy data to the kernel structure that will persist during + * kernel lifetime. + */ + kho_in.kexec_count =3D metadata->kexec_count; + strscpy(kho_in.previous_release, metadata->previous_release, + sizeof(kho_in.previous_release)); + + pr_info("exec from: %s (count %u)\n", kho_in.previous_release, + kho_in.kexec_count); +} + +/* + * Create kexec metadata to pass kernel version and boot count to the + * next kernel. This keeps the core KHO ABI minimal and allows the + * metadata format to evolve independently. + */ +static __init int kho_out_kexec_metadata(void) +{ + struct kho_kexec_metadata *metadata; + int err; + + metadata =3D kho_alloc_preserve(sizeof(*metadata)); + if (IS_ERR(metadata)) + return PTR_ERR(metadata); + + strscpy(metadata->previous_release, init_uts_ns.name.release, + sizeof(metadata->previous_release)); + /* kho_in.kexec_count is set to 0 on cold boot */ + metadata->kexec_count =3D kho_in.kexec_count + 1; + + err =3D kho_add_subtree(KHO_METADATA_NODE_NAME, metadata, + sizeof(*metadata)); + if (err) + kho_unpreserve_free(metadata); + + return err; +} + +static int __init kho_kexec_metadata_init(const void *fdt) +{ + int err; + + if (fdt) + kho_in_kexec_metadata(); + + /* Populate kexec metadata for the possible next kexec */ + err =3D kho_out_kexec_metadata(); + if (err) + pr_warn("failed to initialize kexec-metadata subtree: %d\n", + err); + + return err; +} + static __init int kho_init(void) { struct kho_radix_tree *tree =3D &kho_out.radix_tree; @@ -1441,6 +1512,10 @@ static __init int kho_init(void) if (err) goto err_free_fdt; =20 + err =3D kho_kexec_metadata_init(fdt); + if (err) + goto err_free_fdt; + for (int i =3D 0; i < kho_scratch_cnt; i++) { unsigned long base_pfn =3D PHYS_PFN(kho_scratch[i].addr); unsigned long count =3D kho_scratch[i].size >> PAGE_SHIFT; --=20 2.47.3 From nobody Thu Apr 9 10:31:49 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 EC9213C6A21 for ; Mon, 9 Mar 2026 13:42:42 +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=1773063764; cv=none; b=VNxwmiW1CHooEYnbZ3yY9SjaTcGkZxKpIaOLS3XGg47UAx8U295lKTO1fFeo/bnW0zufQU5kLVJ78JCyGEcJYFqvB3Wrar6v7o116q2Xh+lWx5yp6S546SvYEZhQZ7uDjl420C0g7xR3h3BZRdjq1WZ3kurhabzcO0x3JeUnD6Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773063764; c=relaxed/simple; bh=GuS2S3Wn71jXKGx9RIpG1q7JVYnitQ1EXkky0LyglZk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WWuSmjuTBvQY9+k6f6WQI+3oiMoFy0cVXypW20AcvDdvB0ttW49UjcaWPl30RgQROm0Fvh+VHi8x4FE1mew2IXDA2Ou5oJHvvJ50BYOTAciKW8Z3pc/qO/wFoyQT6AEW+XxNBToBqlZCma/9yr8bE9eTdE97X6siFAocRF4qkBI= 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=QnXvFd2E; 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="QnXvFd2E" 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=O7Ml/vJyi0FRJgghGtQCc2586RzghnjwSv1hQiNW19c=; b=QnXvFd2Et5S90TK4Ts/A++2Ztl Cn/VR9gXgY/yUvfvqBzs6m7idnfnCuJpz9xk1huJY677VCStJcKu3lGhGjGPYntaChOsBlxa0KkK3 lq4feo/BjeHAMPAzBVwhmn6M4jCiBDGDZagI83LFOx90LaVIemMdN4DdP8zB+H0RDceNcJPzpjNcI Tebz/53FVEPqzrgkcNKeiKGnwt4krm7LfX5+X5WciPzDX0JEr+gwI8N3lad5FNMCTAdqboaikDpWn qKkK1CYSwBT5bOPFTETm8PmaVYQRcDqoVVKGd6flSNNmaa56En8XONgahWyMIJodab1IiJQ0+/Fp7 IGgthkzA==; 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 1vzasa-002G4H-Nw; Mon, 09 Mar 2026 13:42:41 +0000 From: Breno Leitao Date: Mon, 09 Mar 2026 06:41:49 -0700 Subject: [PATCH v8 6/6] kho: document kexec-metadata tracking feature 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-6-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=2486; i=leitao@debian.org; h=from:subject:message-id; bh=GuS2S3Wn71jXKGx9RIpG1q7JVYnitQ1EXkky0LyglZk=; b=owEBbQKS/ZANAwAIATWjk5/8eHdtAcsmYgBprs4ze/rUp861RrV5t62pTbJLJtbdntrR9AyI8 qkmZylG1YeJAjMEAAEIAB0WIQSshTmm6PRnAspKQ5s1o5Of/Hh3bQUCaa7OMwAKCRA1o5Of/Hh3 bZgPD/4v3Yod2PPxx34KIn9K3RWl7jTuWUrsFK1hW5GuknLIksUYSy1hNqVshjLJL0tJFoK3wbK Vtx8cP6mtyX6+bJqGT38vExtFo2tWIe/55xDb6xyYSFvL4b+tj3K3+A6nHr4S+5Pq94JzrFg99V NXoqxOcxj46lsy5L5BHNIABY5rDqSuHF84zlo/2CJ+7pMUrS25J5mMwyPpbbWBQuRZLk7JS190/ k6Uqk0QxlwagjSHgnnjKNxib/DwMW76TD67dadJv4hzW4JKA+zZvfKYG+wvfPs9dDdDb8ydbMHy sPol8dSYkjkF8rrvyXAFuzX3FMjQ8tmxTZInP/oXcwhfYGKDaUgYKb20OKL1CwkEUHZfOxlqIUx tlEPhKfp3oCZuYTt+HIQqeXLLNbIxRUdcAAag4DjWGdHgYnwbvrF35b1NZyDN7s0bCMAEb3mHQ/ OH8tyo88JiSVeNtJcd7fHF6i6L9B3jxJY953cHHLrHlYOpFJKe5QEO4kZ82UEiP7F5vjAOC82w3 Ce7XCPByc1m/rvbfXZnpIalWvsCeDzgO/XgUO/mNL7PVsHabR18OWb8DkeaBqsOg5xZ4Bz4v1dT /j6A+KxuQ8FbDrNLwb3mInMqwr2JH+L2rHio50MXWAPzeFhnPGkMnSSGknAarZQp+tpypF8BbJi 1Z9KvPbhp3tRUEw== X-Developer-Key: i=leitao@debian.org; a=openpgp; fpr=AC8539A6E8F46702CA4A439B35A3939FFC78776D X-Debian-User: leitao Add documentation for the kexec-metadata feature that tracks the previous kernel version and kexec boot count across kexec reboots. This helps diagnose bugs that only reproduce when kexecing from specific kernel versions. Suggested-by: Mike Rapoport Reviewed-by: Mike Rapoport (Microsoft) Signed-off-by: Breno Leitao Acked-by: SeongJae Park Reviewed-by: Pratyush Yadav --- Documentation/admin-guide/mm/kho.rst | 39 ++++++++++++++++++++++++++++++++= ++++ 1 file changed, 39 insertions(+) diff --git a/Documentation/admin-guide/mm/kho.rst b/Documentation/admin-gui= de/mm/kho.rst index 6a4ddf3440465..2c26e560bd78a 100644 --- a/Documentation/admin-guide/mm/kho.rst +++ b/Documentation/admin-guide/mm/kho.rst @@ -42,6 +42,45 @@ For example, if you used ``reserve_mem`` command line pa= rameter to create an early memory reservation, the new kernel will have that memory at the same physical address as the old kernel. =20 +Kexec Metadata +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +KHO automatically tracks metadata about the kexec chain, passing informati= on +about the previous kernel to the next kernel. This feature helps diagnose +bugs that only reproduce when kexecing from specific kernel versions. + +On each KHO kexec, the kernel logs the previous kernel's version and the +number of kexec reboots since the last cold boot:: + + [ 0.000000] KHO: exec from: 6.19.0-rc4-next-20260107 (count 1) + +The metadata includes: + +``previous_release`` + The kernel version string (from ``uname -r``) of the kernel that + initiated the kexec. + +``kexec_count`` + The number of kexec boots since the last cold boot. On cold boot, + this counter starts at 0 and increments with each kexec. This helps + identify issues that only manifest after multiple consecutive kexec + reboots. + +Use Cases +--------- + +This metadata is particularly useful for debugging kexec transition bugs, +where a buggy kernel kexecs into a new kernel and the bug manifests only +in the second kernel. Examples of such bugs include: + +- Memory corruption from the previous kernel affecting the new kernel +- Incorrect hardware state left by the previous kernel +- Firmware/ACPI state issues that only appear in kexec scenarios + +At scale, correlating crashes to the previous kernel version enables +faster root cause analysis when issues only occur in specific kernel +transition scenarios. + debugfs Interfaces =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 --=20 2.47.3