Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

liveupdate: luo_core: integrate with KHO

Integrate the LUO with the KHO framework to enable passing LUO state
across a kexec reboot.

This patch implements the lifecycle integration with KHO:

1. Incoming State: During early boot (`early_initcall`), LUO checks if
KHO is active. If so, it retrieves the "LUO" subtree, verifies the
"luo-v1" compatibility string, and reads the `liveupdate-number` to
track the update count.

2. Outgoing State: During late initialization (`late_initcall`), LUO
allocates a new FDT for the next kernel, populates it with the basic
header (compatible string and incremented update number), and
registers it with KHO (`kho_add_subtree`).

3. Finalization: The `liveupdate_reboot()` notifier is updated to invoke
`kho_finalize()`. This ensures that all memory segments marked for
preservation are properly serialized before the kexec jump.

Link: https://lkml.kernel.org/r/20251125165850.3389713-3-pasha.tatashin@soleen.com
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Reviewed-by: Pratyush Yadav <pratyush@kernel.org>
Tested-by: David Matlack <dmatlack@google.com>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Cc: Aleksander Lobakin <aleksander.lobakin@intel.com>
Cc: Alexander Graf <graf@amazon.com>
Cc: Alice Ryhl <aliceryhl@google.com>
Cc: Andriy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: anish kumar <yesanishhere@gmail.com>
Cc: Anna Schumaker <anna.schumaker@oracle.com>
Cc: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Borislav Betkov <bp@alien8.de>
Cc: Chanwoo Choi <cw00.choi@samsung.com>
Cc: Chen Ridong <chenridong@huawei.com>
Cc: Chris Li <chrisl@kernel.org>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Daniel Wagner <wagi@kernel.org>
Cc: Danilo Krummrich <dakr@kernel.org>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: David Jeffery <djeffery@redhat.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Guixin Liu <kanie@linux.alibaba.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Ira Weiny <ira.weiny@intel.com>
Cc: Jann Horn <jannh@google.com>
Cc: Jason Gunthorpe <jgg@nvidia.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Joanthan Cameron <Jonathan.Cameron@huawei.com>
Cc: Joel Granados <joel.granados@kernel.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Lennart Poettering <lennart@poettering.net>
Cc: Leon Romanovsky <leon@kernel.org>
Cc: Leon Romanovsky <leonro@nvidia.com>
Cc: Lukas Wunner <lukas@wunner.de>
Cc: Marc Rutland <mark.rutland@arm.com>
Cc: Masahiro Yamada <masahiroy@kernel.org>
Cc: Matthew Maurer <mmaurer@google.com>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Myugnjoo Ham <myungjoo.ham@samsung.com>
Cc: Parav Pandit <parav@nvidia.com>
Cc: Pratyush Yadav <ptyadav@amazon.de>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Saeed Mahameed <saeedm@nvidia.com>
Cc: Samiullah Khawaja <skhawaja@google.com>
Cc: Song Liu <song@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Stuart Hayes <stuart.w.hayes@gmail.com>
Cc: Tejun Heo <tj@kernel.org>
Cc: Thomas Gleinxer <tglx@linutronix.de>
Cc: Thomas Weißschuh <linux@weissschuh.net>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Cc: William Tu <witu@nvidia.com>
Cc: Yoann Congal <yoann.congal@smile.fr>
Cc: Zhu Yanjun <yanjun.zhu@linux.dev>
Cc: Zijun Hu <quic_zijuhu@quicinc.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Pasha Tatashin and committed by
Andrew Morton
1aece821 9e2fd062

+233 -1
+58
include/linux/kho/abi/luo.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + /* 4 + * Copyright (c) 2025, Google LLC. 5 + * Pasha Tatashin <pasha.tatashin@soleen.com> 6 + */ 7 + 8 + /** 9 + * DOC: Live Update Orchestrator ABI 10 + * 11 + * This header defines the stable Application Binary Interface used by the 12 + * Live Update Orchestrator to pass state from a pre-update kernel to a 13 + * post-update kernel. The ABI is built upon the Kexec HandOver framework 14 + * and uses a Flattened Device Tree to describe the preserved data. 15 + * 16 + * This interface is a contract. Any modification to the FDT structure, node 17 + * properties, compatible strings, or the layout of the `__packed` serialization 18 + * structures defined here constitutes a breaking change. Such changes require 19 + * incrementing the version number in the relevant `_COMPATIBLE` string to 20 + * prevent a new kernel from misinterpreting data from an old kernel. 21 + * 22 + * Changes are allowed provided the compatibility version is incremented; 23 + * however, backward/forward compatibility is only guaranteed for kernels 24 + * supporting the same ABI version. 25 + * 26 + * FDT Structure Overview: 27 + * The entire LUO state is encapsulated within a single KHO entry named "LUO". 28 + * This entry contains an FDT with the following layout: 29 + * 30 + * .. code-block:: none 31 + * 32 + * / { 33 + * compatible = "luo-v1"; 34 + * liveupdate-number = <...>; 35 + * }; 36 + * 37 + * Main LUO Node (/): 38 + * 39 + * - compatible: "luo-v1" 40 + * Identifies the overall LUO ABI version. 41 + * - liveupdate-number: u64 42 + * A counter tracking the number of successful live updates performed. 43 + */ 44 + 45 + #ifndef _LINUX_KHO_ABI_LUO_H 46 + #define _LINUX_KHO_ABI_LUO_H 47 + 48 + /* 49 + * The LUO FDT hooks all LUO state for sessions, fds, etc. 50 + * In the root it also carries "liveupdate-number" 64-bit property that 51 + * corresponds to the number of live-updates performed on this machine. 52 + */ 53 + #define LUO_FDT_SIZE PAGE_SIZE 54 + #define LUO_FDT_KHO_ENTRY_NAME "LUO" 55 + #define LUO_FDT_COMPATIBLE "luo-v1" 56 + #define LUO_FDT_LIVEUPDATE_NUM "liveupdate-number" 57 + 58 + #endif /* _LINUX_KHO_ABI_LUO_H */
+153 -1
kernel/liveupdate/luo_core.c
··· 41 41 42 42 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 43 43 44 + #include <linux/io.h> 45 + #include <linux/kexec_handover.h> 46 + #include <linux/kho/abi/luo.h> 44 47 #include <linux/kobject.h> 48 + #include <linux/libfdt.h> 45 49 #include <linux/liveupdate.h> 46 50 #include <linux/miscdevice.h> 51 + #include <linux/mm.h> 52 + #include <linux/sizes.h> 53 + #include <linux/string.h> 54 + #include <linux/unaligned.h> 55 + 56 + #include "kexec_handover_internal.h" 57 + #include "luo_internal.h" 47 58 48 59 static struct { 49 60 bool enabled; 61 + void *fdt_out; 62 + void *fdt_in; 63 + u64 liveupdate_num; 50 64 } luo_global; 51 65 52 66 static int __init early_liveupdate_param(char *buf) ··· 68 54 return kstrtobool(buf, &luo_global.enabled); 69 55 } 70 56 early_param("liveupdate", early_liveupdate_param); 57 + 58 + static int __init luo_early_startup(void) 59 + { 60 + phys_addr_t fdt_phys; 61 + int err, ln_size; 62 + const void *ptr; 63 + 64 + if (!kho_is_enabled()) { 65 + if (liveupdate_enabled()) 66 + pr_warn("Disabling liveupdate because KHO is disabled\n"); 67 + luo_global.enabled = false; 68 + return 0; 69 + } 70 + 71 + /* Retrieve LUO subtree, and verify its format. */ 72 + err = kho_retrieve_subtree(LUO_FDT_KHO_ENTRY_NAME, &fdt_phys); 73 + if (err) { 74 + if (err != -ENOENT) { 75 + pr_err("failed to retrieve FDT '%s' from KHO: %pe\n", 76 + LUO_FDT_KHO_ENTRY_NAME, ERR_PTR(err)); 77 + return err; 78 + } 79 + 80 + return 0; 81 + } 82 + 83 + luo_global.fdt_in = phys_to_virt(fdt_phys); 84 + err = fdt_node_check_compatible(luo_global.fdt_in, 0, 85 + LUO_FDT_COMPATIBLE); 86 + if (err) { 87 + pr_err("FDT '%s' is incompatible with '%s' [%d]\n", 88 + LUO_FDT_KHO_ENTRY_NAME, LUO_FDT_COMPATIBLE, err); 89 + 90 + return -EINVAL; 91 + } 92 + 93 + ln_size = 0; 94 + ptr = fdt_getprop(luo_global.fdt_in, 0, LUO_FDT_LIVEUPDATE_NUM, 95 + &ln_size); 96 + if (!ptr || ln_size != sizeof(luo_global.liveupdate_num)) { 97 + pr_err("Unable to get live update number '%s' [%d]\n", 98 + LUO_FDT_LIVEUPDATE_NUM, ln_size); 99 + 100 + return -EINVAL; 101 + } 102 + 103 + luo_global.liveupdate_num = get_unaligned((u64 *)ptr); 104 + pr_info("Retrieved live update data, liveupdate number: %lld\n", 105 + luo_global.liveupdate_num); 106 + 107 + return 0; 108 + } 109 + 110 + static int __init liveupdate_early_init(void) 111 + { 112 + int err; 113 + 114 + err = luo_early_startup(); 115 + if (err) { 116 + luo_global.enabled = false; 117 + luo_restore_fail("The incoming tree failed to initialize properly [%pe], disabling live update\n", 118 + ERR_PTR(err)); 119 + } 120 + 121 + return err; 122 + } 123 + early_initcall(liveupdate_early_init); 124 + 125 + /* Called during boot to create outgoing LUO fdt tree */ 126 + static int __init luo_fdt_setup(void) 127 + { 128 + const u64 ln = luo_global.liveupdate_num + 1; 129 + void *fdt_out; 130 + int err; 131 + 132 + fdt_out = kho_alloc_preserve(LUO_FDT_SIZE); 133 + if (IS_ERR(fdt_out)) { 134 + pr_err("failed to allocate/preserve FDT memory\n"); 135 + return PTR_ERR(fdt_out); 136 + } 137 + 138 + err = fdt_create(fdt_out, LUO_FDT_SIZE); 139 + err |= fdt_finish_reservemap(fdt_out); 140 + err |= fdt_begin_node(fdt_out, ""); 141 + err |= fdt_property_string(fdt_out, "compatible", LUO_FDT_COMPATIBLE); 142 + err |= fdt_property(fdt_out, LUO_FDT_LIVEUPDATE_NUM, &ln, sizeof(ln)); 143 + err |= fdt_end_node(fdt_out); 144 + err |= fdt_finish(fdt_out); 145 + if (err) 146 + goto exit_free; 147 + 148 + err = kho_add_subtree(LUO_FDT_KHO_ENTRY_NAME, fdt_out); 149 + if (err) 150 + goto exit_free; 151 + luo_global.fdt_out = fdt_out; 152 + 153 + return 0; 154 + 155 + exit_free: 156 + kho_unpreserve_free(fdt_out); 157 + pr_err("failed to prepare LUO FDT: %d\n", err); 158 + 159 + return err; 160 + } 161 + 162 + /* 163 + * late initcall because it initializes the outgoing tree that is needed only 164 + * once userspace starts using /dev/liveupdate. 165 + */ 166 + static int __init luo_late_startup(void) 167 + { 168 + int err; 169 + 170 + if (!liveupdate_enabled()) 171 + return 0; 172 + 173 + err = luo_fdt_setup(); 174 + if (err) 175 + luo_global.enabled = false; 176 + 177 + return err; 178 + } 179 + late_initcall(luo_late_startup); 71 180 72 181 /* Public Functions */ 73 182 ··· 206 69 */ 207 70 int liveupdate_reboot(void) 208 71 { 209 - return 0; 72 + int err; 73 + 74 + if (!liveupdate_enabled()) 75 + return 0; 76 + 77 + err = kho_finalize(); 78 + if (err) { 79 + pr_err("kho_finalize failed %d\n", err); 80 + /* 81 + * kho_finalize() may return libfdt errors, to aboid passing to 82 + * userspace unknown errors, change this to EAGAIN. 83 + */ 84 + err = -EAGAIN; 85 + } 86 + 87 + return err; 210 88 } 211 89 212 90 /**
+22
kernel/liveupdate/luo_internal.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + 3 + /* 4 + * Copyright (c) 2025, Google LLC. 5 + * Pasha Tatashin <pasha.tatashin@soleen.com> 6 + */ 7 + 8 + #ifndef _LINUX_LUO_INTERNAL_H 9 + #define _LINUX_LUO_INTERNAL_H 10 + 11 + #include <linux/liveupdate.h> 12 + 13 + /* 14 + * Handles a deserialization failure: devices and memory is in unpredictable 15 + * state. 16 + * 17 + * Continuing the boot process after a failure is dangerous because it could 18 + * lead to leaks of private data. 19 + */ 20 + #define luo_restore_fail(__fmt, ...) panic(__fmt, ##__VA_ARGS__) 21 + 22 + #endif /* _LINUX_LUO_INTERNAL_H */